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

Commit

Permalink
fix: OPTIC-109: Blank draft should not be created when an annotation …
Browse files Browse the repository at this point in the history
…is submitted (#1562)

* fix: OPTIC-109: Blank draft should not be created when an annotation is submitted

* dont save a draft after the submission has started

* ensure we arent double submitting drafts

* dont need statusCallback

* update cypress
  • Loading branch information
bmartel authored and Wesley Lima committed Sep 25, 2023
1 parent 410981b commit 1c4bab3
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 37 deletions.
35 changes: 34 additions & 1 deletion src/components/BottomBar/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ export const Controls = controlsInjector(observer(({ store, history, annotation

if (isInProgress) return;
setIsInProgress(true);

const selected = store.annotationStore?.selected;

if(addedCommentThisSession){
selected?.submissionInProgress();
callback();
} else if((currentComment ?? '').trim()) {
e.preventDefault();
selected?.submissionInProgress();
await commentFormSubmit();
callback();
} else {
Expand All @@ -74,7 +79,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
if(store.hasInterface('comments:reject') ?? true) {
buttonHandler(e, () => store.rejectAnnotation({}), 'Please enter a comment before rejecting');
} else {
console.log('rejecting');
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.rejectAnnotation({});
}
Expand All @@ -91,6 +98,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
buttons.push(
<ButtonTooltip key="accept" title="Accept annotation: [ Ctrl+Enter ]">
<Button aria-label="accept-annotation" disabled={disabled} look="primary" onClick={async () => {
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.acceptAnnotation();
}}>
Expand All @@ -106,6 +116,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
buttons.push(
<ButtonTooltip key="cancel-skip" title="Cancel skip: []">
<Button aria-label="cancel-skip" disabled={disabled} look="primary" onClick={async () => {
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.unskipTask();
}}>
Expand All @@ -121,6 +134,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
if(store.hasInterface('comments:skip') ?? true) {
buttonHandler(e, () => store.skipTask({}), 'Please enter a comment before skipping');
} else {
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.skipTask({});
}
Expand All @@ -146,6 +162,10 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
onClick={async (event) => {
event.preventDefault();

const selected = store.annotationStore?.selected;

selected?.submissionInProgress();

if ('URLSearchParams' in window) {
const searchParams = new URLSearchParams(window.location.search);

Expand All @@ -154,6 +174,7 @@ export const Controls = controlsInjector(observer(({ store, history, annotation

window.history.pushState(null, '', newRelativePathQuery);
}

await store.commentStore.commentFormSubmit();
onClickMethod();
}}
Expand All @@ -179,6 +200,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
mod={{ has_icon: useExitOption, disabled: isDisabled }}
onClick={async (event) => {
if (event.target.classList.contains('lsf-dropdown__trigger')) return;
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.submitAnnotation();
}}
Expand Down Expand Up @@ -211,6 +235,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
mod={{ has_icon: useExitOption, disabled: isDisabled }}
onClick={async (event) => {
if (event.target.classList.contains('lsf-dropdown__trigger')) return;
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.updateAnnotation();
}}
Expand Down Expand Up @@ -241,6 +268,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
<ButtonTooltip key="submit" title={title}>
<Elem name="tooltip-wrapper">
<Button aria-label="submit" disabled={disabled || submitDisabled} look={look} onClick={async () => {
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.submitAnnotation();
}}>
Expand All @@ -256,6 +286,9 @@ export const Controls = controlsInjector(observer(({ store, history, annotation
const button = (
<ButtonTooltip key="update" title="Update this task: [ Alt+Enter ]">
<Button aria-label="submit" disabled={disabled || submitDisabled} look={look} onClick={async () => {
const selected = store.annotationStore?.selected;

selected?.submissionInProgress();
await store.commentStore.commentFormSubmit();
store.updateAnnotation();
}}>
Expand Down
11 changes: 11 additions & 0 deletions src/stores/Annotation/Annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export const Annotation = types
draftSelected: false,
autosaveDelay: 5000,
isDraftSaving: false,
submissionStarted: 0,
versions: {},
resultSnapshot: '',
}))
Expand Down Expand Up @@ -666,6 +667,8 @@ export const Annotation = types
}),

async saveDraft(params) {
// There is no draft to save as it was already saved as an annotation
if (self.submissionStarted) return;
// if this is now a history item or prediction don't save it
if (!self.editable) return;

Expand All @@ -679,15 +682,23 @@ export const Annotation = types
self.setDraftSaving(true);
return self.store.submitDraft(self, params).then((res) => {
self.onDraftSaved(res);

return res;
});
},

submissionInProgress() {
self.submissionStarted = Date.now();
},

saveDraftImmediately() {
if (self.autosave) self.autosave.flush();
},

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

const res = await self.saveDraft(null);

return res;
Expand Down
4 changes: 2 additions & 2 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,12 @@ export default types
}
/* eslint-enable no-unused-vars */

function submitDraft(c, params = {}, statusCallback) {
function submitDraft(c, params = {}) {
return new Promise(resolve => {
const events = getEnv(self).events;

if (!events.hasEvent('submitDraft')) return resolve();
const res = events.invokeFirst('submitDraft', self, c, params, statusCallback);
const res = events.invokeFirst('submitDraft', self, c, params);

if (res && res.then) res.then(resolve);
else resolve(res);
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"cvg:summary": "nyc report --temp-dir=.nyc_output --reporter=text-summary --cwd=. --exclude-after-remap false"
},
"dependencies": {
"@heartexlabs/ls-test": "git+ssh://[email protected]/heartexlabs/ls-frontend-test#522adf318dce98b535fc8f9646791b3a1a2aeebb"
"@heartexlabs/ls-test": "git+ssh://[email protected]/heartexlabs/ls-frontend-test#4c67cf3278d16b39715e55e330d86a5065aca7ba"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand Down
Loading

0 comments on commit 1c4bab3

Please sign in to comment.