1- import merge from 'lodash/merge' ;
21import * as React from 'react' ;
32import PopupReply from '../components/Popups/PopupReply' ;
43import RegionCreator from './RegionCreator' ;
54import RegionList from './RegionList' ;
65import RegionRect , { RegionRectRef } from './RegionRect' ;
76import { AnnotationRegion , Rect } from '../@types' ;
7+ import { CreateArg } from './actions' ;
88import { CreatorItem , CreatorStatus } from '../store/creator' ;
99import { scaleShape } from './regionUtil' ;
1010import './RegionAnnotations.scss' ;
1111
1212type Props = {
1313 activeAnnotationId : string | null ;
1414 annotations : AnnotationRegion [ ] ;
15- createRegion : ( arg : { location : number ; message : string ; shape : Rect } ) => void ;
15+ createRegion : ( arg : CreateArg ) => void ;
1616 isCreating : boolean ;
17+ message : string ;
1718 page : number ;
1819 scale : number ;
1920 setActiveAnnotationId : ( annotationId : string | null ) => void ;
21+ setMessage : ( message : string ) => void ;
2022 setStaged : ( staged : CreatorItem | null ) => void ;
2123 setStatus : ( status : CreatorStatus ) => void ;
2224 staged ?: CreatorItem | null ;
@@ -36,11 +38,6 @@ export default class RegionAnnotations extends React.PureComponent<Props, State>
3638
3739 state : State = { } ;
3840
39- setStaged ( data : Partial < CreatorItem > | null ) : void {
40- const { page, setStaged, staged } = this . props ;
41- setStaged ( data ? merge ( { location : page , message : '' } , staged , data ) : data ) ;
42- }
43-
4441 setStatus ( status : CreatorStatus ) : void {
4542 const { setStatus } = this . props ;
4643 setStatus ( status ) ;
@@ -53,44 +50,46 @@ export default class RegionAnnotations extends React.PureComponent<Props, State>
5350 } ;
5451
5552 handleCancel = ( ) : void => {
56- this . setStaged ( null ) ;
53+ const { setMessage, setStaged } = this . props ;
54+ setMessage ( '' ) ;
55+ setStaged ( null ) ;
5756 this . setStatus ( CreatorStatus . init ) ;
5857 } ;
5958
6059 handleChange = ( text ?: string ) : void => {
61- this . setStaged ( { message : text } ) ;
60+ const { setMessage } = this . props ;
61+ setMessage ( text || '' ) ;
6262 } ;
6363
6464 handleStart = ( ) : void => {
65- this . setStaged ( null ) ;
65+ const { setStaged } = this . props ;
66+ setStaged ( null ) ;
6667 this . setStatus ( CreatorStatus . init ) ;
6768 } ;
6869
6970 handleStop = ( shape : Rect ) : void => {
70- const { scale } = this . props ;
71-
72- this . setStaged ( { shape : scaleShape ( shape , scale , true ) } ) ;
71+ const { page, scale, setStaged } = this . props ;
72+ setStaged ( { location : page , shape : scaleShape ( shape , scale , true ) } ) ;
7373 this . setStatus ( CreatorStatus . staged ) ;
7474 } ;
7575
7676 handleSubmit = ( ) : void => {
77- const { createRegion, staged } = this . props ;
77+ const { createRegion, message , staged } = this . props ;
7878
7979 if ( ! staged ) {
8080 return ;
8181 }
8282
83- createRegion ( staged ) ;
83+ createRegion ( { ... staged , message } ) ;
8484 } ;
8585
8686 setRectRef = ( rectRef : RegionRectRef ) : void => {
8787 this . setState ( { rectRef } ) ;
8888 } ;
8989
9090 render ( ) : JSX . Element {
91- const { activeAnnotationId, annotations, isCreating, scale, staged, status } = this . props ;
91+ const { activeAnnotationId, annotations, isCreating, message , scale, staged, status } = this . props ;
9292 const { rectRef } = this . state ;
93- const canDraw = ! staged || ! staged . message ;
9493 const canReply = status !== CreatorStatus . init ;
9594 const isPending = status === CreatorStatus . pending ;
9695
@@ -108,7 +107,6 @@ export default class RegionAnnotations extends React.PureComponent<Props, State>
108107 { /* Layer 2: Drawn (unsaved) incomplete annotation target, if any */ }
109108 { isCreating && (
110109 < RegionCreator
111- canDraw = { canDraw }
112110 className = "ba-RegionAnnotations-creator"
113111 onStart = { this . handleStart }
114112 onStop = { this . handleStop }
@@ -131,7 +129,7 @@ export default class RegionAnnotations extends React.PureComponent<Props, State>
131129 onChange = { this . handleChange }
132130 onSubmit = { this . handleSubmit }
133131 reference = { rectRef }
134- value = { staged . message }
132+ value = { message }
135133 />
136134 </ div >
137135 ) }
0 commit comments