sanity icon indicating copy to clipboard operation
sanity copied to clipboard

initialValue and initialValue template functions should allow setting dynamic _id

Open fabien opened this issue 3 years ago • 5 comments
trafficstars

Is your feature request related to a problem? Please describe.

For some document types, I would like to prefix the _id for an item when it's created. These documents should be kept private, even within their public dataset (90% is public, 10% is private, interconnected/referenced documents). This functionality makes use of the behavior outlined in the last 'Gotcha' here: https://www.sanity.io/docs/ids

Describe the solution you'd like

Quite simply, creating a document with either document-level initialValue or initialValueTemplates functions should be able to supply the _id to be used initially.

While this already appears to work at first glance, the document's _id will actually be taken from the one supplied by Studio's url to that document. In other words, it will always be overwritten by the one set when clicking the 'create' button (and passed on through the url parameters).

Describe alternatives you've considered

This workaround used to fix this: https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1636981159134900?thread_ts=1634810149.029000&cid=C9Z7RC3V1

However, it only worked for that particular node of the Structure Builder, which means it was a rather fragile solution. For example, the newly introduced 'create reference in-place' functionality would forego this altogether.

Unfortunately, the workaround above stopped working recently: https://github.com/sanity-io/sanity/issues/2977#issuecomment-991587599

fabien avatar Dec 11 '21 12:12 fabien

This is related to https://github.com/sanity-io/sanity/issues/2646

fabien avatar Dec 11 '21 16:12 fabien

Hi @fabien,

We've been thinking about this internally as well and we'd like to address it with some bigger affordance that fixes this issue and #2646

I'll follow up here when we figure out more of what that will look like.

ricokahler avatar Dec 13 '21 16:12 ricokahler

Thanks @ricokahler!

fabien avatar Dec 13 '21 16:12 fabien

@ricokahler Any updates on how you think that would work? We're also keen to use our own ID formats, as we will use IDs from some Sanity objects directly in our backend database and would like to match our internal ID format

billinghamj avatar Feb 03 '22 12:02 billinghamj

@ricokahler any update? It's been over 6 months and with the advent of v3 I feel this is long overdue. It's a serious blocker in my case, because I'd like to be able to keep certain documents hidden within a public dataset.

fabien avatar Jul 12 '22 10:07 fabien

Hi!

We are currently working on improving our workflows and follow-up on our open GitHub repository. In that work, we have decided to close most issues older than the release of Sanity Studio v3.

We value your feedback, so if this issue is still important to you and relevant for Sanity Studio v3, please search for relevant open issues. If you can’t find any, open a new one and link to relevant comments in this thread. For questions about how to do something, please post them in the slack community.

kmelve avatar Jan 11 '23 20:01 kmelve

@kmelve Unless this is something v3 can do today, this remains high on my wishlist.

fabien avatar Jan 12 '23 14:01 fabien