From fc508ca9dafb3fbfcb99235c543a37ee1f666a21 Mon Sep 17 00:00:00 2001 From: Andy Fitzgerald Date: Wed, 18 Sep 2024 16:30:01 -0700 Subject: [PATCH] Add input to remove the deprecated concept management controls Boolean Custom input component used to prevent users from seeing a "scheme error" message. --- src/components/inputs/ManagementControls.tsx | 37 ++++++++++++++++++++ src/components/inputs/index.ts | 1 + src/skosConceptScheme.tsx | 12 +++++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/components/inputs/ManagementControls.tsx diff --git a/src/components/inputs/ManagementControls.tsx b/src/components/inputs/ManagementControls.tsx new file mode 100644 index 0000000..4e16d9b --- /dev/null +++ b/src/components/inputs/ManagementControls.tsx @@ -0,0 +1,37 @@ +import {useCallback} from 'react' +import {unset} from 'sanity' +import {Button, Inline, Stack, useToast} from '@sanity/ui' + +/** + * #### Input Component for Deprecated Management Controls Field + * The Management Controls field was used for a previous version + * of the plugin and was set by default when creating a new scheme. + * It has been set to "Deprecated." This control will allow users + * to delete the value from the input to hide the field, without + * otherwise seeing an error int their schema. + * - Input is only visible if no identifier has been assigned + * - Input disappears once an ID is generated + */ +export const ManagementControls = (props: any) => { + const {onChange} = props + const toast = useToast() + + const handleChange = useCallback(() => { + onChange(unset()) + toast.push({ + status: 'success', + title: 'Value removed.', + duration: 2500, + closable: true, + }) + }, [onChange, toast]) + + return ( + + + {props.renderDefault(props)} +