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

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

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading