LiamMartens / sanity-plugin-intl-input

Intl input for Sanity with a cleaner UI than a default solution
MIT License
111 stars 22 forks source link

Version 5.3 breaks singleton functionality #83

Closed heggemsnes closed 3 years ago

heggemsnes commented 3 years ago

Hi

With 5.3 the new UI doesn't redirect correctly to edit page for singletons. I noticed there was an existing issue for this #6 but I didn't really have any problems as the translations redirected to i.e: http://localhost:3333/studio/desk/__edit__i18n.siteConfig.en_US%2Ctype%3DsiteConfig

With 5.3 it just tries to redirect to http://localhost:3333/studio/desk/i18n.siteConfig.en_US showing nothing open for a singleton.

To reproduce Setup Sanity with singleton document as bellow with 5.3. Will not work. Install sanity-plugin-intl-input@5.2.1 and it works pretty good.

Desk structure:

import * as Structure from "sanity-plugin-intl-input/lib/structure"

import { MdSettings } from "react-icons/md"

// Hide document types that we already have a structure definition for
const hiddenDocTypes = (listItem) => !["siteConfig"].includes(listItem.getId())

// or manual implementation to use with your own custom desk structure
export const getDefaultDocumentNode = (props) => {
  if (props.schemaType === "page" || props.schemaType == "siteConfig") {
    return S.document().views(
      Structure.getDocumentNodeViewsForSchemaType(props.schemaType)
    )
  }
  return S.document()
}

// eslint-disable-next-line import/no-anonymous-default-export
export default () =>
  S.list()
    .title("i18n test site")
    .items([
      S.listItem()
        .title("Innstillinger")
        .icon(MdSettings)
        .child(
          S.document()
            .views(Structure.getDocumentNodeViewsForSchemaType("siteConfig"))
            .title("Innstillinger")
            .schemaType("siteConfig")
            .documentId("siteConfig")
        ),
      ...S.documentTypeListItems().filter(hiddenDocTypes),
    ])

Language object:

export default {
  base: "nb_NO",
  languages: ["nb_NO", "en_US", "nl_NL", "VIKING_NO"],
  messages: {
    loading: "Loading languages...",
    missing: "Missing",
    draft: "Draft",
    publishing: "Publishing...",
    publish: "Publish",
    deleteAll: {
      buttonTitle: "Delete (incl. translations)",
      deleting: "Deleting...",
    },
    duplicateAll: {
      buttonTitle: "Duplicate (incl. translations)",
      duplicating: "Duplicating...",
    },
    translationsMaintenance: {
      title: "Translation Maintenance",
      selectSchemaPlaceholder: "Select schema type",
      idStructureMismatch: "document(s) with mismatched ID structures",
      missingLanguageField: "document(s) are missing the language field",
      missingDocumentRefs: "document(s) have missing translation references",
      orphanDocuments: "orphaned translation document(s)",
      referenceBehaviorMismatch:
        "document(s) with mismatched reference behaviors",
      fix: "Fix",
    },
  },
  fieldNames: {
    lang: "__i18n_lang",
    references: "__i18n_refs",
  },
}