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

Commit

Permalink
feat: OPTIC-107: Draft saving on view all (#280)
Browse files Browse the repository at this point in the history
* track time traveller update times to compare with draft update times, save notify about changes

* delete draft toast, control for no draft time

* formatting update

* revert needs draft logic for save draft

* improve draft needs save logic

* remove await from row click

---------

Co-authored-by: Travis Clark <[email protected]>
  • Loading branch information
Travis1282 and Travis Clark authored Jan 4, 2024
1 parent a8e6e5e commit b200608
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
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

0 comments on commit b200608

Please sign in to comment.