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

Commit

Permalink
fix: OPTIC-113: Draft save on switch history and exit (#1598)
Browse files Browse the repository at this point in the history
* fix: optic-113: draft save on switch history

* set draft saving flag sooner

* fix draft getting stuck

* Update src/components/CurrentEntity/AnnotationHistory.tsx

Co-authored-by: bmartel <[email protected]>

---------

Co-authored-by: bmartel <[email protected]>
  • Loading branch information
Travis1282 and bmartel authored Nov 2, 2023
1 parent a134880 commit 6f46b95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/components/CurrentEntity/AnnotationHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ const AnnotationHistoryComponent: FC<any> = ({
const annotation = annotationStore.selected;
const lastItem = history?.length ? history[0] : null;
const hasChanges = annotation.history.hasChanges;

// if user makes changes at the first time there are no draft yet
const isDraftSelected = !annotationStore.selectedHistory && (annotation.draftSelected || (!annotation.versions.draft && hasChanges));

return (
<Block name="annotation-history" mod={{ inline }}>
{showDraft && (
Expand All @@ -121,6 +122,7 @@ const AnnotationHistoryComponent: FC<any> = ({
const isSelected = isLastItem && !selectedHistory && showDraft
? !isDraftSelected
: selectedHistory?.id === item.id;


return (
<HistoryItem
Expand All @@ -137,14 +139,11 @@ const AnnotationHistoryComponent: FC<any> = ({
annotationStore.selectHistory(isSelected ? null : item);
return;
}


if (hasChanges) {
annotation.saveDraftImmediately();
// wait for draft to be saved before switching to history
await when(() => !annotation.isDraftSaving);
}

if (isLastItem || isSelected) {
// last history state and draft are actual annotation, not from history
// and if user clicks on already selected item we should switch to last state
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,8 +696,8 @@ export const Annotation = types

async saveDraftImmediatelyWithResults() {
// There is no draft to save as it was already saved as an annotation
if (self.submissionStarted) return {};

if (self.submissionStarted || self.isDraftSaving) return {};
self.setDraftSaving(true);
const res = await self.saveDraft(null);

return res;
Expand Down

0 comments on commit 6f46b95

Please sign in to comment.