Force-closing all editors during ID override, cf. issue #4

This commit is contained in:
Rainer Simon 2020-05-01 11:08:00 +02:00
parent 41bd28185e
commit 5554a54df8
1 changed files with 22 additions and 6 deletions

View File

@ -75,6 +75,27 @@ export default class TextAnnotator extends Component {
} }
} }
/**
* A convenience method that allows the external application to
* override the autogenerated Id.
*
* Usually, the override will happen almost immediately after
* the annotation is created. But we need to be defensive and assume
* that the override might come in with considerable delay, thus
* the user might have made further edits already.
*/
overrideId = originalId => forcedId => {
// Force the editors to close, otherwise their annotations will be orphaned
if (this.state.selectedAnnotation || this.state.selectedRelation) {
this.setState({
selectedAnnotation: null,
selectedRelation: null
}, () => this.highlighter.overrideId(originalId, forcedId));
} else {
this.highlighter.overrideId(originalId, forcedId);
}
}
/** Common handler for annotation CREATE or UPDATE **/ /** Common handler for annotation CREATE or UPDATE **/
onCreateOrUpdateAnnotation = method => (annotation, previous) => { onCreateOrUpdateAnnotation = method => (annotation, previous) => {
this.clearState(); this.clearState();
@ -82,16 +103,11 @@ export default class TextAnnotator extends Component {
this.selectionHandler.clearSelection(); this.selectionHandler.clearSelection();
this.highlighter.addOrUpdateAnnotation(annotation, previous); this.highlighter.addOrUpdateAnnotation(annotation, previous);
// A convenience method that allows the external application to
// override the autogenerated Id
const overrideId = originalId => forcedId =>
this.highlighter.overrideId(originalId, forcedId);
// Call CREATE or UPDATE handler // Call CREATE or UPDATE handler
if (previous) if (previous)
this.props[method](annotation.clone(), previous.clone()); this.props[method](annotation.clone(), previous.clone());
else else
this.props[method](annotation.clone(), overrideId(annotation.id)); this.props[method](annotation.clone(), this.overrideId(annotation.id));
} }
onDeleteAnnotation = annotation => { onDeleteAnnotation = annotation => {