Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

fix: LSDV-5177: Fix draft loss on switching tasks in quick view mode #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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");

Expand Down
5 changes: 5 additions & 0 deletions src/utils/feature-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
27 changes: 27 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,30 @@ export const absoluteURL = (path = "") => {
export const isDefined = <T>(value?: T): value is NonNullable<T> => {
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);
});
};