import {Box, Stack} from '@sanity/ui' import {useContext} from 'react' import {TreeContext} from '../context' import {rootOrphans} from '../core/tree/rootOrphans' import type {DocumentConcepts, TopConceptTerm, ChildConceptTerm} from '../types' import {ConceptRow} from './ConceptRow' import {NoConcepts} from './guides' /** * #### Tree View * Fetches the complete tree of concepts in a concept scheme, stemming * from Top Concepts or Orphans. Displays the tree in a nested list. */ export const TreeStructure = ({ concepts, inputComponent, selectConcept, }: { concepts: DocumentConcepts | null inputComponent: boolean selectConcept: (conceptId: {_ref: string; _type: 'reference'; _originalId?: string}) => void }) => { // Rows read their own visibility from context; only the id is needed here, // to remount every root row — and so the whole tree — on expand or collapse. const {globalVisibility: {treeId} = {treeId: 'default'}} = useContext(TreeContext) || {} if (!concepts?.topConcepts?.length && !concepts?.concepts?.length) { return } return ( {concepts?.topConcepts?.map((concept: TopConceptTerm) => ( ))} {rootOrphans(concepts).map((concept: ChildConceptTerm) => ( ))} ) }