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

feat: OPTIC-107: Draft saving on view all #280

Merged
merged 7 commits into from
Jan 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/components/MainView/DataViewOld/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand Down
26 changes: 18 additions & 8 deletions src/sdk/lsf-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,42 +677,50 @@ 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) => {
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;

this.draftToast(status);
}
};
};

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;
// console.log('onSubmitDraft', params?.useToast, hasChanges);

if (params?.useToast) delete params.useToast;

Object.assign(data.body, params);

await this.saveUserLabels();

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 {
Expand All @@ -728,6 +736,8 @@ export class LSFWrapper {
);
}
response?.id && annotation.setDraftId(response?.id);
showToast && this.draftToast(response?.$meta?.status);

return response;
}
};
Expand Down