From 1c04d0f022ee3a348e672f3a5896cfb782ed869c Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 25 May 2023 23:10:47 +0100 Subject: [PATCH 1/2] fix: LSDV-5177:Fix draft loss on switching tasks in quick view mode --- src/stores/AppStore.js | 6 +++++- src/utils/feature-flags.js | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 2fabef39..05c3187d 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -1,6 +1,6 @@ import { destroy, flow, types } from "mobx-state-tree"; import { Modal } from "../components/Common/Modal/Modal"; -import { FF_DEV_2887, isFF } from "../utils/feature-flags"; +import { FF_DEV_2887, FF_LSDV_5177, isFF } from "../utils/feature-flags"; import { History } from "../utils/history"; import { isDefined } from "../utils/utils"; import { Action } from "./Action"; @@ -323,6 +323,10 @@ export const AppStore = types } }; + if (isFF(FF_LSDV_5177)) { + self.LSF?.lsf?.annotationStore?.selected?.saveDraftImmediately?.(); + } + if (isFF(FF_DEV_2887) && self.LSF?.lsf?.annotationStore?.selected?.commentStore?.hasUnsaved) { Modal.confirm({ title: "You have unsaved changes", diff --git a/src/utils/feature-flags.js b/src/utils/feature-flags.js index 7a503d6e..649ada86 100644 --- a/src/utils/feature-flags.js +++ b/src/utils/feature-flags.js @@ -59,6 +59,11 @@ export const FF_LOPS_E_3 = "fflag_feat_all_lops_e_3_datasets_short"; */ export const FF_LSDV_4711 = 'fflag_fix_all_lsdv_4711_cors_errors_accessing_task_data_short'; +/** + * Add forced draft saving on switching between different tasks in Quick View. + */ +export const FF_LSDV_5177 = 'fflag_fix_front_lsdv_5177_save_draft_on_task_switch_250523_short'; + // Customize flags const flags = {}; From 1dda282a4402e9039da18e4348d28d43dcaeb2cf Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 26 May 2023 01:49:27 +0100 Subject: [PATCH 2/2] Add waiting before task switching --- src/stores/AppStore.js | 14 +++++++++----- src/utils/helpers.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 05c3187d..7a9eca38 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -1,6 +1,7 @@ import { destroy, flow, types } from "mobx-state-tree"; import { Modal } from "../components/Common/Modal/Modal"; import { FF_DEV_2887, FF_LSDV_5177, isFF } from "../utils/feature-flags"; +import { waitFor } from "../utils/helpers"; import { History } from "../utils/history"; import { isDefined } from "../utils/utils"; import { Action } from "./Action"; @@ -297,7 +298,14 @@ export const AppStore = types if (self.dataStore.loadingItem) return; - const nextAction = () => { + const nextAction = async () => { + + if (isFF(FF_LSDV_5177)) { + self.LSF?.lsf?.annotationStore?.selected?.saveDraftImmediately?.(); + await waitFor(()=>{ + return !self.LSF?.lsf?.annotationStore?.selected?.isDraftSaving; + }); + } self.SDK.setMode("labeling"); @@ -323,10 +331,6 @@ export const AppStore = types } }; - if (isFF(FF_LSDV_5177)) { - self.LSF?.lsf?.annotationStore?.selected?.saveDraftImmediately?.(); - } - if (isFF(FF_DEV_2887) && self.LSF?.lsf?.annotationStore?.selected?.commentStore?.hasUnsaved) { Modal.confirm({ title: "You have unsaved changes", diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 4bb76e91..94882ecd 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -114,3 +114,30 @@ export const absoluteURL = (path = "") => { export const isDefined = (value?: T): value is NonNullable => { return value !== null && value !== undefined; }; + +export const delay = (timeout: number) => + new Promise((resolve) => setTimeout(resolve, timeout)); + +type WaitForOptions = { + delay: number, + tries: number +} +const defaultWaitForOptions = { + delay: 16, + tries: 15, +}; + +export const waitFor = (predicate:()=>boolean, options:WaitForOptions) => { + const opt = Object.assign({}, defaultWaitForOptions, options); + + return new Promise(async (resolve) => { + for (let i = opt.tries;i--;){ + if (await predicate()) { + return resolve(true); + } + await delay(opt.delay); + } + resolve(false); + }); +}; +