import {Button, Text, Box, Badge} from '@sanity/ui' import {Tooltip} from '@sanity/ui/tooltip' import {useCallback} from 'react' import type {ChildConceptTerm} from '../../types' import {SLOT_PADDING_X} from '../../hooks' /** * #### Concept Select Link * Writes a concept _ref from the hierarchy tree to the current document */ export function ConceptSelectLink({ concept, topConcept = false, orphan = false, selectConcept, }: { concept: ChildConceptTerm topConcept?: boolean orphan?: boolean selectConcept?: (conceptRef: { _ref: string _type: 'reference' _originalId: string | undefined }) => void }) { const {prefLabel, id, _originalId, recommended} = concept ?? {} const displayLabel = prefLabel || '[new concept]' const handleClick = useCallback(() => { if (!selectConcept) return const conceptRef = { _ref: id, _type: 'reference' as const, _originalId, } selectConcept(conceptRef) }, [id, _originalId, selectConcept]) return ( <> {selectConcept && ( {`Select "${prefLabel}"`} {recommended && ` (recommended)`} } fallbackPlacements={['right', 'left', 'bottom']} placement="top" portal > )} ) }