From 0f79079c034dec0e96a74377347d6f7118d21604 Mon Sep 17 00:00:00 2001 From: Travis1282 Date: Tue, 5 Dec 2023 00:27:05 -0600 Subject: [PATCH 1/6] track time traveller update times to compare with draft update times, save notify about changes --- src/sdk/lsf-sdk.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index 1151652b..f8e9a486 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -677,24 +677,24 @@ export class LSFWrapper { }; draftToast = (status) => { - if (status === 200 || status === 201) this.datamanager.invoke("toast", { message: "Draft saved successfully", type: "info" }); else if (status !== undefined) this.datamanager.invoke("toast", { message: "There was an error saving your draft", type: "error" }); } + needsDraftSave = (annotation) => annotation?.history?.hasChanges && new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved); + saveDraft = async (target = null) => { - const selected = target || this.lsf?.annotationStore?.selected; - const hasChanges = selected.history.hasChanges; - const submissionInProgress = selected?.submissionStarted; - const draftIsFresh = new Date(selected.draftSaved) > new Date() - selected.autosaveDelay; + const annotation = target || this.lsf?.annotationStore?.selected; + const hasChanges = this.needsDraftSave(annotation); + const submissionInProgress = annotation?.submissionStarted; - if (selected?.isDraftSaving || draftIsFresh) { - await when(() => !selected.isDraftSaving); + if (annotation?.isDraftSaving) { + await when(() => !annotation.isDraftSaving); this.draftToast(200); } - else if (hasChanges && selected && !submissionInProgress) { - const res = await selected?.saveDraftImmediatelyWithResults(); + else if (hasChanges && annotation && !submissionInProgress) { + const res = await annotation?.saveDraftImmediatelyWithResults(); const status = res?.$meta?.status; this.draftToast(status); @@ -704,6 +704,8 @@ export class LSFWrapper { onSubmitDraft = async (studio, annotation, params = {}) => { const annotationDoesntExist = !annotation.pk; const data = { body: this.prepareData(annotation, { draft: true }) }; // serializedAnnotation + const hasChanges = this.needsDraftSave(annotation); + const showToast = params?.useToast && hasChanges; Object.assign(data.body, params); @@ -712,7 +714,8 @@ export class LSFWrapper { if (annotation.draftId > 0) { // draft has been already created const res = await this.datamanager.apiCall("updateDraft", { draftID: annotation.draftId }, data); - + + showToast && this.draftToast(res?.$meta?.status); return res; } else { @@ -728,6 +731,8 @@ export class LSFWrapper { ); } response?.id && annotation.setDraftId(response?.id); + showToast && this.draftToast(response?.$meta?.status); + return response; } }; From e6e26d899ffed021c73badbc9a22e4b3aa488bdc Mon Sep 17 00:00:00 2001 From: Travis Clark Date: Fri, 8 Dec 2023 14:50:37 -0600 Subject: [PATCH 2/6] delete draft toast, control for no draft time --- src/sdk/lsf-sdk.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index f8e9a486..1d974921 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -682,7 +682,7 @@ export class LSFWrapper { } - needsDraftSave = (annotation) => annotation?.history?.hasChanges && new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved); + needsDraftSave = (annotation) => annotation?.history?.hasChanges && (annotation.draftSaved ? new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved) : true); saveDraft = async (target = null) => { const annotation = target || this.lsf?.annotationStore?.selected; @@ -707,6 +707,8 @@ export class LSFWrapper { const hasChanges = this.needsDraftSave(annotation); const showToast = params?.useToast && hasChanges; + if (params?.useToast) delete params.useToast; + Object.assign(data.body, params); await this.saveUserLabels(); From 4c458a2ce8c8e6a48a221a7723acbe91c4ce9dbf Mon Sep 17 00:00:00 2001 From: Travis Clark Date: Fri, 8 Dec 2023 15:45:31 -0600 Subject: [PATCH 3/6] formatting update --- src/sdk/lsf-sdk.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index 1d974921..299385c6 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -679,10 +679,11 @@ export class LSFWrapper { draftToast = (status) => { if (status === 200 || status === 201) this.datamanager.invoke("toast", { message: "Draft saved successfully", type: "info" }); else if (status !== undefined) this.datamanager.invoke("toast", { message: "There was an error saving your draft", type: "error" }); - } - needsDraftSave = (annotation) => annotation?.history?.hasChanges && (annotation.draftSaved ? new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved) : true); + needsDraftSave = (annotation) => + annotation?.history?.hasChanges && + (annotation.draftSaved ? new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved) : true); saveDraft = async (target = null) => { const annotation = target || this.lsf?.annotationStore?.selected; From 2e35577da00104647c3673cbbaad1568cf41b451 Mon Sep 17 00:00:00 2001 From: Travis Clark Date: Fri, 8 Dec 2023 16:44:49 -0600 Subject: [PATCH 4/6] revert needs draft logic for save draft --- src/sdk/lsf-sdk.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index 299385c6..9a95ff76 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -686,21 +686,22 @@ export class LSFWrapper { (annotation.draftSaved ? new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved) : true); saveDraft = async (target = null) => { - const annotation = target || this.lsf?.annotationStore?.selected; - const hasChanges = this.needsDraftSave(annotation); - const submissionInProgress = annotation?.submissionStarted; + const selected = target || this.lsf?.annotationStore?.selected; + const hasChanges = selected.history.hasChanges; + const submissionInProgress = selected?.submissionStarted; + const draftIsFresh = new Date(selected.draftSaved) > new Date() - selected.autosaveDelay; - if (annotation?.isDraftSaving) { - await when(() => !annotation.isDraftSaving); + if (selected?.isDraftSaving || draftIsFresh) { + await when(() => !selected.isDraftSaving); this.draftToast(200); } - else if (hasChanges && annotation && !submissionInProgress) { - const res = await annotation?.saveDraftImmediatelyWithResults(); + else if (hasChanges && selected && !submissionInProgress) { + const res = await selected?.saveDraftImmediatelyWithResults(); const status = res?.$meta?.status; this.draftToast(status); } - }; + }; onSubmitDraft = async (studio, annotation, params = {}) => { const annotationDoesntExist = !annotation.pk; From 7b0790dec12a585482ce2a453eb2c80b45e9c2c9 Mon Sep 17 00:00:00 2001 From: Travis Date: Wed, 27 Dec 2023 21:03:48 -0600 Subject: [PATCH 5/6] improve draft needs save logic --- src/sdk/lsf-sdk.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/sdk/lsf-sdk.js b/src/sdk/lsf-sdk.js index 9a95ff76..d7b65c2c 100644 --- a/src/sdk/lsf-sdk.js +++ b/src/sdk/lsf-sdk.js @@ -681,21 +681,21 @@ export class LSFWrapper { else if (status !== undefined) this.datamanager.invoke("toast", { message: "There was an error saving your draft", type: "error" }); } - needsDraftSave = (annotation) => - annotation?.history?.hasChanges && - (annotation.draftSaved ? new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved) : true); + needsDraftSave = (annotation) => { + if (annotation.history?.hasChanges && !annotation.draftSaved) return true; + if (annotation.history?.hasChanges && new Date(annotation.history.lastAdditionTime) > new Date(annotation.draftSaved)) return true; + return false; + } saveDraft = async (target = null) => { const selected = target || this.lsf?.annotationStore?.selected; - const hasChanges = selected.history.hasChanges; - const submissionInProgress = selected?.submissionStarted; - const draftIsFresh = new Date(selected.draftSaved) > new Date() - selected.autosaveDelay; + const hasChanges = this.needsDraftSave(selected); - if (selected?.isDraftSaving || draftIsFresh) { + if (selected?.isDraftSaving) { await when(() => !selected.isDraftSaving); this.draftToast(200); } - else if (hasChanges && selected && !submissionInProgress) { + else if (hasChanges && selected) { const res = await selected?.saveDraftImmediatelyWithResults(); const status = res?.$meta?.status; @@ -708,9 +708,10 @@ export class LSFWrapper { const data = { body: this.prepareData(annotation, { draft: true }) }; // serializedAnnotation const hasChanges = this.needsDraftSave(annotation); const showToast = params?.useToast && hasChanges; + // console.log('onSubmitDraft', params?.useToast, hasChanges); if (params?.useToast) delete params.useToast; - + Object.assign(data.body, params); await this.saveUserLabels(); From 9d6770904f393efa34e5ad8d7218c1496a20b568 Mon Sep 17 00:00:00 2001 From: Travis Date: Wed, 3 Jan 2024 17:12:10 -0600 Subject: [PATCH 6/6] remove await from row click --- src/components/MainView/DataViewOld/Table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MainView/DataViewOld/Table.js b/src/components/MainView/DataViewOld/Table.js index 4a423509..04924098 100644 --- a/src/components/MainView/DataViewOld/Table.js +++ b/src/components/MainView/DataViewOld/Table.js @@ -125,7 +125,7 @@ export const DataView = injector( } else if (e.metaKey || e.ctrlKey) { window.open(`./?task=${itemID}`, "_blank"); } else { - if (isFF(FF_OPTIC_2)) await store._sdk.lsf?.saveDraft(); + if (isFF(FF_OPTIC_2)) store._sdk.lsf?.saveDraft(); getRoot(view).startLabeling(item); } },