@@ -29,20 +29,27 @@ const LabelSelectorContainer = styled("div")({ display: "flex" })
29
29
export default function RelationshipAnnotator (
30
30
props : RelationshipAnnotatorProps
31
31
) {
32
- console . log ( { props } )
33
32
const [ highlightedItems , changeHighlightedItems ] = useState ( [ ] )
34
- const [ relationships , setRelationships ] = useState ( props . relationships || [ ] )
33
+ const [ relationships , setRelationships ] = useState (
34
+ props . initialRelationships || [ ]
35
+ )
35
36
const [ activePair , setActivePair ] = useState ( null )
36
37
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
39
43
? props . initialSequence . flatMap ( entity =>
40
- entity . label
44
+ entity . label ||
45
+ ( entity . textId && textIdsInRelationship . has ( entity . textId ) )
41
46
? [ withId ( entity ) ]
42
47
: stringToSequence ( entity . text , props . separatorRegex ) . map ( withId )
43
48
)
44
49
: stringToSequence ( props . document ) . map ( withId )
45
- )
50
+ } )
51
+
52
+ console . log ( sequence , relationships )
46
53
47
54
const labels = creatingRelationships
48
55
? props . relationshipLabels
0 commit comments