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 (#1637)
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

* change where lastUpdate is set

* serialize before draft save, pass params

* fix time traveller time save

---------

Co-authored-by: Travis Clark <[email protected]>
  • Loading branch information
Travis1282 and Travis Clark authored Jan 8, 2024
1 parent 2a748d6 commit 08aa5b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/TopBar/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const Actions = ({ store }) => {
const isViewAll = annotationStore.viewingAll;

const onToggleVisibility = useCallback(() => {
!isViewAll && entity.saveDraftImmediatelyWithResults({ useToast: true });
annotationStore.toggleViewingAllAnnotations();
}, [annotationStore]);

Expand Down
7 changes: 6 additions & 1 deletion src/components/TopBar/TopBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const TopBar = observer(({ store }) => {

const isViewAll = annotationStore?.viewingAll === true;

const toggleViewAll = () => {
!isViewAll && entity.saveDraftImmediatelyWithResults({ useToast: true });
annotationStore.toggleViewingAllAnnotations();
};

return store ? (
<Block name="topbar" mod={{ newLabelingUI: isFF(FF_DEV_3873) }}>
{isFF(FF_DEV_3873) ? (
Expand All @@ -31,7 +36,7 @@ export const TopBar = observer(({ store }) => {
icon={<IconViewAll />}
type="text"
aria-label="View All"
onClick={() => annotationStore.toggleViewingAllAnnotations()}
onClick={toggleViewAll}
primary={ isViewAll }
style={{
height: 36,
Expand Down
3 changes: 2 additions & 1 deletion src/core/TimeTraveller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const TimeTraveller = types
undoIdx: 0,
targetPath: '',
skipNextUndoState: types.optional(types.boolean, false),

lastAdditionTime: types.optional(types.Date, new Date()),
createdIdx: 0,
})
.volatile(() => ({
Expand Down Expand Up @@ -102,6 +102,7 @@ const TimeTraveller = types
self.undoIdx = self.history.length - 1;
replaceNextUndoState = false;
changesDuringFreeze = false;
self.lastAdditionTime = new Date();
},

reinit(force = true) {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/Annotation/Annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,11 @@ export const Annotation = types
if (self.autosave) self.autosave.flush();
},

async saveDraftImmediatelyWithResults() {
async saveDraftImmediatelyWithResults(params) {
// There is no draft to save as it was already saved as an annotation
if (self.submissionStarted || self.isDraftSaving) return {};
self.setDraftSaving(true);
const res = await self.saveDraft(null);
const res = await self.saveDraft(params);

return res;
},
Expand Down

0 comments on commit 08aa5b5

Please sign in to comment.