sanity-io / sanity-plugin-internationalized-array

A plugin to register array fields with a custom input component to store field values in multiple languages, queryable by using the language ID as an array `_key`.
MIT License
42 stars 10 forks source link

feat: adding some suspense and GROQ goodness 💖 #5

Closed stipsan closed 1 year ago

stipsan commented 1 year ago

Big fan of you and your work @SimeonGriggs, after using this plugin in a new starter I found an opportunity to share back a smol PR 😌

SimeonGriggs commented 1 year ago

Absolutely amazing work 🤩

One small thing before we make it official, I'm wondering if we could/should pass more props to the languages function.

For example, I might want to load specific languages based on a value in the document, or the role of the current user. Is there a larger context object we could pass in that also includes the client?

stipsan commented 1 year ago

One small thing before we make it official, I'm wondering if we could/should pass more props to the languages function.

For example, I might want to load specific languages based on a value in the document, or the role of the current user. Is there a larger context object we could pass in that also includes the client?

We could follow the precedent of productionUrl (its context argument, not the prev bit and not the reducer flow): https://github.com/sanity-io/sanity/blob/c1676f69750c804694265c168204b99065eb4032/packages/sanity/src/core/config/configPropertyReducers.ts#L39-L49

The context here does indeed contain the current document and the current user, it also uses the getClient pattern seen elsewhere in the Studio, instead of providing the client instance eagerly:

/** @public */
export interface ConfigContext {
  projectId: string
  dataset: string
  schema: Schema
  currentUser: CurrentUser | null
  getClient: (options: SourceClientOptions) => SanityClient
}

export interface ResolveProductionUrlContext extends ConfigContext {
  document: SanityDocumentLike
}

I think the reason why it uses getClient is because of the apiVersion requirenment 🤔

SimeonGriggs commented 1 year ago

I like that. I'm very keen to have access to the same contextual options wherever possible.

SimeonGriggs commented 1 year ago

Going to merge as-is, there's probably other ways around what I'm describing.

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.5.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: