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

Merged
merged 11 commits into from
Jan 8, 2024
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});
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -696,11 +696,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
Loading