Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Autocomplete when tags field is not on root document #12

Open
Tracked by #28
aaadotpm opened this issue Jan 27, 2021 · 4 comments
Open
Tracked by #28

[FEATURE] Autocomplete when tags field is not on root document #12

aaadotpm opened this issue Jan 27, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@aaadotpm
Copy link

aaadotpm commented Jan 27, 2021

Great work on this plugin, thank you!

Is your feature request related to a problem? Please describe.
I'm trying to use the tags field inside an object (which will be included in several documents).
Unfortunately, the plugin does not register the tags made inside for instance metadata.tags for reuse.

Describe the solution you'd like
I would like to be able to define an option of where the plugin looks for the tags field so that I can get autocomplete inside objects.

This would also allow (although I don't have an example use case) for different sets of tags based on their document path/or field name.

For instance:
options: { tagsPath: 'metadata.tags' }
or options: { tagsPath: 'metadata.keywords' }

Describe alternatives you've considered
Having only the tags field on the root document (this works, but is not particularly elegant)

Happy to discuss, and or contribute to this (with guidance)!

@aaadotpm aaadotpm added the enhancement New feature or request label Jan 27, 2021
@wildseansy
Copy link
Contributor

wildseansy commented Feb 1, 2021

@S-G-K - does #13 solve your need?

@igorovic
Copy link

I have the same issue as @S-G-K . I may be wrong but #13 doesn't seem to resolve our issue.

In my case I have project object with a nested mainImage object. And the tags are on the mainImage.
sanity-plugin-autocomplete-tags is not able to find the tags on mainImage since it looks only on project documents.

Snippets of my shemas

documents/project.js

export default {
  name: 'project',
  type: 'document',
  title: 'Project',
  fields: [
    {
      name: 'title',
      type: 'string',
      title: 'Title'
    },
    {
      name: 'mainImage',
      type: 'mainImage',
      title: 'Main image'
    }
}

objects/mainImage.js

export default {
  name: 'mainImage',
  type: 'image',
  title: 'Image',
  options: {
    hotspot: true,
    accept: 'image/*'
  },
  validation: Rule => Rule.required().error('A main image is required!'),
  fields: [
    {
      name: 'description',
      type: 'string',
      title: 'Descritpion',
      description: 'La description aide à optimiser le SEO',
      options: {
        isHighlighted: true
      },
      validation: Rule => Rule.error('You have to fill out the description text.').required()
    },
    {
      name: 'tags',
      title: 'Tags',
      type: 'tags',
      options: {
        isHighlighted: true 
      }
    }
  ],
  preview: {
    select: {
      imageUrl: 'asset.url',
      title: 'caption'
    }
  }
}

Suggestion

I think the plugin should recognize the type of document on which it is set so it will query sanity api on the right document and not on the parent document.
In my case, the parent document is project and mainImage is an object nested inside the project document.

@rosnovsky
Copy link
Owner

Thank you for this. I'll take a look over the weekend. I think I made it work with nested objects initially, but there were some quirks to work out

@rosnovsky
Copy link
Owner

So sorry that this "over the weekend" turned into "by the end of this year", but I finally got some time to work on this, and hopefully will have this working, well, by the end of this year :)

@rosnovsky rosnovsky added this to the v1.1 milestone Dec 20, 2021
@rosnovsky rosnovsky mentioned this issue Dec 20, 2021
8 tasks
@rosnovsky rosnovsky modified the milestones: v1.1, v2 Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

No branches or pull requests

4 participants