From 9e25fcc2e652d9b150635091dac62750c84b89ba Mon Sep 17 00:00:00 2001 From: Travis1282 Date: Tue, 17 Oct 2023 12:55:24 -0500 Subject: [PATCH 1/3] fix: optic-124: save and update have success/fail toast messages --- src/sdk/lsf-sdk.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index 5adf08ba..1f44236e 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -563,7 +563,12 @@ export class LSFWrapper { { body }, // don't react on duplicated annotations error { errorHandler: result => result.status === 409 }, - ); + ).then(result => { + const status = result.$meta?.status; + + if (status === 200 || status === 201) return this.datamanager.invoke("toast", { message: "Annotation saved successfully", type: "info" }); + else if (status !== undefined) return this.datamanager.invoke("toast", { message: "There was an error saving your Annotation", type: "error" }); + }); }, false, loadNext, exitStream); }; @@ -587,7 +592,12 @@ export class LSFWrapper { { body: serializedAnnotation, }, - ); + ).then(result => { + const status = result?.$meta?.status; + + if (status === 200 || status === 201) return this.datamanager.invoke("toast", { message: "Annotation updated successfully", type: "info" }); + else if (status !== undefined) return this.datamanager.invoke("toast", { message: "There was an error updating your Annotation", type: "error" }); + }); }); this.datamanager.invoke("updateAnnotation", ls, annotation, result); @@ -649,7 +659,7 @@ export class LSFWrapper { saveDraft = async (target = null) => { const selected = target || this.lsf?.annotationStore?.selected; const hasChanges = !!selected?.history.undoIdx && !selected?.submissionStarted; - + if (!hasChanges || !selected) return; const res = await selected?.saveDraftImmediatelyWithResults(); const status = res?.$meta?.status; From a73b540fbcd612d15c3975c09376618799938fb0 Mon Sep 17 00:00:00 2001 From: Travis1282 Date: Thu, 19 Oct 2023 15:46:34 -0500 Subject: [PATCH 2/3] async over promises --- src/sdk/lsf-sdk.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index 1f44236e..66e3d71d 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -556,20 +556,19 @@ export class LSFWrapper { const exitStream = this.shouldExitStream(); const loadNext = exitStream ? false : this.shouldLoadNext(); - await this.submitCurrentAnnotation("submitAnnotation", async (taskID, body) => { + const result = await this.submitCurrentAnnotation("submitAnnotation", async (taskID, body) => { return await this.datamanager.apiCall( "submitAnnotation", { taskID }, { body }, // don't react on duplicated annotations error { errorHandler: result => result.status === 409 }, - ).then(result => { - const status = result.$meta?.status; - - if (status === 200 || status === 201) return this.datamanager.invoke("toast", { message: "Annotation saved successfully", type: "info" }); - else if (status !== undefined) return this.datamanager.invoke("toast", { message: "There was an error saving your Annotation", type: "error" }); - }); + ); }, false, loadNext, exitStream); + const status = result.$meta?.status; + + if (status === 200 || status === 201) this.datamanager.invoke("toast", { message: "Annotation saved successfully", type: "info" }); + else if (status !== undefined) this.datamanager.invoke("toast", { message: "There was an error saving your Annotation", type: "error" }); }; /** @private */ @@ -592,13 +591,12 @@ export class LSFWrapper { { body: serializedAnnotation, }, - ).then(result => { - const status = result?.$meta?.status; - - if (status === 200 || status === 201) return this.datamanager.invoke("toast", { message: "Annotation updated successfully", type: "info" }); - else if (status !== undefined) return this.datamanager.invoke("toast", { message: "There was an error updating your Annotation", type: "error" }); - }); + ); }); + const status = result?.$meta?.status; + + if (status === 200 || status === 201) this.datamanager.invoke("toast", { message: "Annotation updated successfully", type: "info" }); + else if (status !== undefined) this.datamanager.invoke("toast", { message: "There was an error updating your Annotation", type: "error" }); this.datamanager.invoke("updateAnnotation", ls, annotation, result); @@ -853,6 +851,7 @@ export class LSFWrapper { } else { await this.loadTask(); } + return result; } /** @private */ From 2b141cacebb38ce657db45ea3bc54d988056e720 Mon Sep 17 00:00:00 2001 From: bmartel Date: Thu, 19 Oct 2023 16:07:25 -0500 Subject: [PATCH 3/3] Update src/sdk/lsf-sdk.js --- src/sdk/lsf-sdk.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index 66e3d71d..39f38658 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -657,7 +657,6 @@ export class LSFWrapper { saveDraft = async (target = null) => { const selected = target || this.lsf?.annotationStore?.selected; const hasChanges = !!selected?.history.undoIdx && !selected?.submissionStarted; - if (!hasChanges || !selected) return; const res = await selected?.saveDraftImmediatelyWithResults(); const status = res?.$meta?.status;