More relationship CRUD behavior cleanup

This commit is contained in:
Rainer Simon 2020-04-28 12:10:25 +02:00
parent b162443053
commit b5517e54d1
3 changed files with 9 additions and 4 deletions

View File

@ -130,10 +130,15 @@ export default class TextAnnotator extends Component {
this.relationsLayer.addOrUpdateRelation(relation, previous); this.relationsLayer.addOrUpdateRelation(relation, previous);
this.closeRelationsEditor(); this.closeRelationsEditor();
if (previous) // This method will always receive a 'previous' connection -
this.props.onAnnotationUpdated(relation.annotation, previous.annotation); // if the previous is just an empty connection, fire 'create',
else // otherwise, fire 'update'
const isNew = previous.annotation.bodies.length === 0;
if (isNew)
this.props.onAnnotationCreated(relation.annotation); this.props.onAnnotationCreated(relation.annotation);
else
this.props.onAnnotationUpdated(relation.annotation, previous.annotation);
} }
/** 'Delete' on the relation editor popup **/ /** 'Delete' on the relation editor popup **/

View File

@ -51,7 +51,6 @@ export default class Connection extends EventEmitter {
/** Initializes a fixed connection from an annotation **/ /** Initializes a fixed connection from an annotation **/
initFromAnnotation = function(contentEl, svgEl, annotation) { initFromAnnotation = function(contentEl, svgEl, annotation) {
console.log('init', annotation);
const [ fromId, toId ] = annotation.target.map(t => t.id); const [ fromId, toId ] = annotation.target.map(t => t.id);
const relation = annotation.bodies[0].value; const relation = annotation.bodies[0].value;

View File

@ -72,6 +72,7 @@ export default class RelationEditor extends Component {
onSubmit = () => { onSubmit = () => {
const updatedAnnotation = this.props.relation.annotation.clone({ const updatedAnnotation = this.props.relation.annotation.clone({
motivation: 'linking',
body: [{ body: [{
type: 'TextualBody', type: 'TextualBody',
value: this.state.content, value: this.state.content,