diff --git a/package-lock.json b/package-lock.json index 2273c87..29f7413 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@sanity/ui": "^1.2.2", "@sanity/uuid": "^3.0.1", "sanity-plugin-internationalized-array": "^1.6.0", - "sanity-plugin-utils": "^1.6.1" + "sanity-plugin-utils": "^1.6.2" }, "devDependencies": { "@commitlint/cli": "^17.4.4", @@ -15884,9 +15884,9 @@ } }, "node_modules/sanity-plugin-utils": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/sanity-plugin-utils/-/sanity-plugin-utils-1.6.1.tgz", - "integrity": "sha512-iuslQj2eA7sHLhYXryoR+mvU3kVmws7dvAxsA0Wa+Pt5oXBhSEGB4vkp3VtdXMh94hHUDulvm2+r9rNrJ2LyUA==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/sanity-plugin-utils/-/sanity-plugin-utils-1.6.2.tgz", + "integrity": "sha512-zn4sKLaLG5ZcibPNB8RfTjU32sear2XIHPxIoIWJCHXO3yD+JEq+/MvkwW7CnfdEcZeXPfb5DEx1CGjIQwO3Iw==", "dependencies": { "@sanity/icons": "^2.2.2", "@sanity/incompatible-plugin": "^1.0.4", @@ -30657,9 +30657,9 @@ } }, "sanity-plugin-utils": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/sanity-plugin-utils/-/sanity-plugin-utils-1.6.1.tgz", - "integrity": "sha512-iuslQj2eA7sHLhYXryoR+mvU3kVmws7dvAxsA0Wa+Pt5oXBhSEGB4vkp3VtdXMh94hHUDulvm2+r9rNrJ2LyUA==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/sanity-plugin-utils/-/sanity-plugin-utils-1.6.2.tgz", + "integrity": "sha512-zn4sKLaLG5ZcibPNB8RfTjU32sear2XIHPxIoIWJCHXO3yD+JEq+/MvkwW7CnfdEcZeXPfb5DEx1CGjIQwO3Iw==", "requires": { "@sanity/icons": "^2.2.2", "@sanity/incompatible-plugin": "^1.0.4", diff --git a/package.json b/package.json index 8e99b8f..525a34e 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@sanity/ui": "^1.2.2", "@sanity/uuid": "^3.0.1", "sanity-plugin-internationalized-array": "^1.6.0", - "sanity-plugin-utils": "^1.6.1" + "sanity-plugin-utils": "^1.6.2" }, "devDependencies": { "@commitlint/cli": "^17.4.4", diff --git a/src/components/DocumentInternationalizationMenu.tsx b/src/components/DocumentInternationalizationMenu.tsx index c09a278..3973df7 100644 --- a/src/components/DocumentInternationalizationMenu.tsx +++ b/src/components/DocumentInternationalizationMenu.tsx @@ -10,7 +10,7 @@ import { useClickOutside, } from '@sanity/ui' import {uuid} from '@sanity/uuid' -import {FormEvent, useCallback, useMemo, useState} from 'react' +import {FormEvent, useCallback, useEffect, useMemo, useState} from 'react' import {useEditState} from 'sanity' import {useTranslationMetadata} from '../hooks/useLanguageMetadata' @@ -24,7 +24,8 @@ import Warning from './Warning' export function DocumentInternationalizationMenu( props: DocumentInternationalizationMenuProps ) { - const {schemaType, documentId} = props + const {documentId} = props + const schemaType = props.schemaType.name const {languageField, supportedLanguages} = useDocumentInternationalizationContext() diff --git a/src/plugin.tsx b/src/plugin.tsx index 30d5c7e..624bdff 100644 --- a/src/plugin.tsx +++ b/src/plugin.tsx @@ -25,16 +25,7 @@ export const documentInternationalization = definePlugin( if (schemaTypes.length === 0) { throw new Error( - 'You must specify at least one schema type on which to enable document internationalization. Update the `schemaTypes` option in te documentInternationalization() configuration.' - ) - } - - const renderLanguageFilter = (schemaType: string, documentId: string) => { - return ( - + 'You must specify at least one schema type on which to enable document internationalization. Update the `schemaTypes` option in the documentInternationalization() configuration.' ) } @@ -96,7 +87,11 @@ export const documentInternationalization = definePlugin( const {schemaType, documentId} = ctx return schemaTypes.includes(schemaType) && documentId - ? [...prev, () => renderLanguageFilter(schemaType, documentId)] + ? [ + ...prev, + (props) => + DocumentInternationalizationMenu({...props, documentId}), + ] : prev }, badges: (prev, {schemaType}) => { diff --git a/src/types.ts b/src/types.ts index b92b876..b0a04a5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ import type { FieldDefinition, KeyedObject, + ObjectSchemaType, Reference, SanityClient, } from 'sanity' @@ -43,6 +44,6 @@ export type Metadata = { } export type DocumentInternationalizationMenuProps = { - schemaType: string + schemaType: ObjectSchemaType documentId: string }