@@ -29,20 +29,27 @@ const LabelSelectorContainer = styled("div")({ display: "flex" })
2929export default function RelationshipAnnotator (
3030 props : RelationshipAnnotatorProps
3131) {
32- console . log ( { props } )
3332 const [ highlightedItems , changeHighlightedItems ] = useState ( [ ] )
34- const [ relationships , setRelationships ] = useState ( props . relationships || [ ] )
33+ const [ relationships , setRelationships ] = useState (
34+ props . initialRelationships || [ ]
35+ )
3536 const [ activePair , setActivePair ] = useState ( null )
3637 const [ creatingRelationships , setCreatingRelationships ] = useState ( true )
37- const [ sequence , changeSequence ] = useState ( ( ) =>
38- props . initialSequence
38+ const [ sequence , changeSequence ] = useState ( ( ) => {
39+ const textIdsInRelationship = new Set (
40+ relationships . flatMap ( ( { to, from } ) => [ to , from ] )
41+ )
42+ return props . initialSequence
3943 ? props . initialSequence . flatMap ( entity =>
40- entity . label
44+ entity . label ||
45+ ( entity . textId && textIdsInRelationship . has ( entity . textId ) )
4146 ? [ withId ( entity ) ]
4247 : stringToSequence ( entity . text , props . separatorRegex ) . map ( withId )
4348 )
4449 : stringToSequence ( props . document ) . map ( withId )
45- )
50+ } )
51+
52+ console . log ( sequence , relationships )
4653
4754 const labels = creatingRelationships
4855 ? props . relationshipLabels
0 commit comments