Skip to content

Commit 4544620

Browse files
committed
the first (add) or last (remove) annotation
1 parent cf6281c commit 4544620

File tree

1 file changed

+19
-2
lines changed
  • services/static-webserver/client/source/class/osparc/data/model

1 file changed

+19
-2
lines changed

services/static-webserver/client/source/class/osparc/data/model/StudyUI.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
349349
const op = patch.op;
350350
const path = patch.path;
351351
const value = patch.value;
352-
const annotationId = path.split("/")[3];
352+
let annotationId = path.split("/")[3];
353353
switch (op) {
354354
case "add": {
355355
const annotation = this.addAnnotation(value, annotationId);
@@ -361,7 +361,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
361361
this.fireDataEvent("annotationRemoved", annotationId);
362362
break;
363363
case "replace":
364-
if (annotationId in this.getAnnotations()) {
364+
if (annotationId && annotationId in this.getAnnotations()) {
365365
const annotation = this.getAnnotations()[annotationId];
366366
if (annotation) {
367367
if (path.includes("/color")) {
@@ -370,6 +370,23 @@ qx.Class.define("osparc.data.model.StudyUI", {
370370
this.__updateAnnotationAttributesFromPatch(annotation, path, value);
371371
}
372372
}
373+
} else {
374+
// the first (add) or last (remove) annotation will fall here
375+
if (value && Object.keys(value).length) {
376+
// first added
377+
annotationId = Object.keys(value)[0];
378+
const annotationData = Object.values(value)[0];
379+
const annotation = this.addAnnotation(annotationData, annotationId);
380+
this.fireDataEvent("annotationAdded", annotation);
381+
} else {
382+
// last removed
383+
const currentIds = Object.keys(this.getAnnotations());
384+
if (currentIds.length === 1) {
385+
annotationId = currentIds[0];
386+
this.removeAnnotation(annotationId);
387+
this.fireDataEvent("annotationRemoved", annotationId);
388+
}
389+
}
373390
}
374391
break;
375392
}

0 commit comments

Comments
 (0)