diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 2fabef39..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, isFF } from "../utils/feature-flags"; +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"); 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 = {}; 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); + }); +}; +