sanity-plugin-autocomplete-tags icon indicating copy to clipboard operation
sanity-plugin-autocomplete-tags copied to clipboard

Dynamic data in Preset of tags

Open MartCube opened this issue 3 years ago • 2 comments

Hello there :wave: great work for creating this plugin :+1: This is more of a question then a feature. Instead of writing manually the Preset of tags , I want to add array of document reference ( exp: array of document slug ) I'm new in Sanity so I'm not sure is this possible to write it. If you can provide any demo code that would be great

MartCube avatar Jan 05 '22 10:01 MartCube

I think if preload could also be an async function that returns array, that would be flexible enough to cover a bunch of use cases. For example to solve the original question of getting document titles and slugs as tags with this change it would be:

import sanityClient from "part:@sanity/base/client"

// ...

{
  name: 'tags',
  type: 'tags',
  options: {
    preload() {
        return sanityClient.fetch('*[_type == "document"] { "label": title, "value": slug.current }')
    }
  }
}

It would also work for what I need which is let me load the tag list out of a global settings document.

gpoole avatar Mar 23 '22 05:03 gpoole

I know you asked this a while ago @MartCube and you've probably already figured it out, but just re-reading your question it sounds like maybe you wanted an array of references instead?

gpoole avatar Mar 23 '22 05:03 gpoole