@@ -13,6 +13,7 @@ type Props = {
1313 annotations : AnnotationRegion [ ] ;
1414 createRegion : ( arg : CreateArg ) => void ;
1515 isCreating : boolean ;
16+ isDiscoverabilityEnabled : boolean ;
1617 isRotated : boolean ;
1718 location : number ;
1819 message : string ;
@@ -33,6 +34,7 @@ export default class RegionAnnotations extends React.PureComponent<Props, State>
3334 static defaultProps = {
3435 annotations : [ ] ,
3536 isCreating : false ,
37+ isDiscoverabilityEnabled : false ,
3638 isRotated : false ,
3739 } ;
3840
@@ -76,34 +78,60 @@ export default class RegionAnnotations extends React.PureComponent<Props, State>
7678 createRegion ( { ...staged , message } ) ;
7779 } ;
7880
81+ renderCreator = ( ) : JSX . Element => {
82+ const { isCreating, isRotated } = this . props ;
83+ const canCreate = isCreating && ! isRotated ;
84+
85+ return (
86+ < >
87+ { canCreate && (
88+ < RegionCreator
89+ className = "ba-RegionAnnotations-creator"
90+ onStart = { this . handleStart }
91+ onStop = { this . handleStop }
92+ />
93+ ) }
94+ </ >
95+ ) ;
96+ } ;
97+
98+ renderList = ( ) : JSX . Element => {
99+ const { activeAnnotationId, annotations } = this . props ;
100+
101+ return (
102+ < RegionList
103+ activeId = { activeAnnotationId }
104+ annotations = { annotations }
105+ className = "ba-RegionAnnotations-list"
106+ onSelect = { this . handleAnnotationActive }
107+ />
108+ ) ;
109+ } ;
110+
79111 setRectRef = ( rectRef : RegionRectRef ) : void => {
80112 this . setState ( { rectRef } ) ;
81113 } ;
82114
83115 render ( ) : JSX . Element {
84- const { activeAnnotationId , annotations , isCreating , isRotated, message, staged, status } = this . props ;
116+ const { isCreating , isDiscoverabilityEnabled , isRotated, message, staged, status } = this . props ;
85117 const { rectRef } = this . state ;
86118 const canCreate = isCreating && ! isRotated ;
87119 const canReply = status !== CreatorStatus . started && status !== CreatorStatus . init ;
88120 const isPending = status === CreatorStatus . pending ;
89121
90122 return (
91123 < >
92- { /* Layer 1: Saved annotations */ }
93- < RegionList
94- activeId = { activeAnnotationId }
95- annotations = { annotations }
96- className = "ba-RegionAnnotations-list"
97- onSelect = { this . handleAnnotationActive }
98- />
99-
100- { /* Layer 2: Drawn (unsaved) incomplete annotation target, if any */ }
101- { canCreate && (
102- < RegionCreator
103- className = "ba-RegionAnnotations-creator"
104- onStart = { this . handleStart }
105- onStop = { this . handleStop }
106- />
124+ { isDiscoverabilityEnabled ? (
125+ < >
126+ { /* With discoverability, put the RegionCreator below the RegionList so that existing regions can be clicked */ }
127+ { this . renderCreator ( ) }
128+ { this . renderList ( ) }
129+ </ >
130+ ) : (
131+ < >
132+ { this . renderList ( ) }
133+ { this . renderCreator ( ) }
134+ </ >
107135 ) }
108136
109137 { /* Layer 3a: Staged (unsaved) annotation target, if any */ }
0 commit comments