Skip to content

Commit

Permalink
Add input to remove the deprecated concept management controls Boolean
Browse files Browse the repository at this point in the history
Custom input component used to prevent users from
seeing a "scheme error" message.
  • Loading branch information
andybywire committed Sep 18, 2024
1 parent ddb0104 commit fc508ca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/components/inputs/ManagementControls.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Stack space={2}>
<Inline space={[3, 3, 4]}>
{props.renderDefault(props)}
<Button tone="primary" fontSize={2} onClick={handleChange} text="Remove Value" />
</Inline>
</Stack>
)
}
1 change: 1 addition & 0 deletions src/components/inputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './RdfUri'
export * from './Identifier'
export * from './InputHierarchy'
export * from './HierarchyInput'
export * from './ManagementControls'
12 changes: 10 additions & 2 deletions src/skosConceptScheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {randomKey} from '@sanity/util/content'
import baseIriField from './modules/baseIriField'
import {Identifier} from './components/inputs'
import NodeTree from './components/NodeTree'
import {ManagementControls} from './components/inputs'

/**
* Sanity document scheme for SKOS Concept Schemes
Expand Down Expand Up @@ -46,9 +47,16 @@ export default function skosConceptScheme(
defineField({
name: 'controls',
title: 'Concept Management Controls',
description: 'Show concept management controls in hierarchy view',
deprecated: {
reason:
'This field was used for a previous version of the plugin and is no longer needed. Remove the value to hide this field.',
},
type: 'boolean',
initialValue: true,
readOnly: true,
hidden: ({document}) => document?.controls === undefined,
components: {
input: ManagementControls,
},
}),
...baseIriField,
defineField({
Expand Down

0 comments on commit fc508ca

Please sign in to comment.