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

Commit

Permalink
feat: OPTIC-3: Enable users to submit and pause their lead time by re…
Browse files Browse the repository at this point in the history
…turning to the dm list (#225)

* feat: optic-3: enable users to submit and pause their lead time by returning to the dm list

* navagate to projects using the LSH window reference

* navagate to projects using the LSH window reference

* use await over then

* invoke react router in lsp to navagate before new task is loaded
  • Loading branch information
Travis1282 authored Sep 11, 2023
1 parent 4c702ac commit da095bf
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/sdk/lsf-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ export class LSFWrapper {
await nextAction();
}

exitStream() {
this.datamanager.invoke("navigate", 'projects');
}

selectTask(task, annotationID, fromHistory = false) {
const needsAnnotationsMerge = task && this.task?.id === task.id;
const annotations = needsAnnotationsMerge ? [...this.annotations] : [];
Expand Down Expand Up @@ -541,6 +545,9 @@ export class LSFWrapper {

/** @private */
onSubmitAnnotation = async () => {
const exitStream = this.shouldExitStream();
const loadNext = exitStream ? false : this.shouldLoadNext();

await this.submitCurrentAnnotation("submitAnnotation", async (taskID, body) => {
return await this.datamanager.apiCall(
"submitAnnotation",
Expand All @@ -549,13 +556,14 @@ export class LSFWrapper {
// don't react on duplicated annotations error
{ errorHandler: result => result.status === 409 },
);
}, false, this.shouldLoadNext());
}, false, loadNext, exitStream);
};

/** @private */
onUpdateAnnotation = async (ls, annotation, extraData) => {
const { task } = this;
const serializedAnnotation = this.prepareData(annotation);
const exitStream = this.shouldExitStream();

Object.assign(serializedAnnotation, extraData);

Expand All @@ -576,6 +584,8 @@ export class LSFWrapper {

this.datamanager.invoke("updateAnnotation", ls, annotation, result);

if (exitStream) return this.exitStream();

const isRejectedQueue = isDefined(task.default_selected_annotation);

if (isRejectedQueue) {
Expand Down Expand Up @@ -732,6 +742,20 @@ export class LSFWrapper {
return urlParam !== 'notifications';
}

shouldExitStream = () => {
const paramName = "exitStream";
const urlParam = new URLSearchParams(location.search).get(paramName);
const searchParams = new URLSearchParams(window.location.search);

searchParams.delete(paramName);
let newRelativePathQuery = window.location.pathname;

if (searchParams.toString()) newRelativePathQuery += '?' + searchParams.toString();
window.history.pushState(null, '', newRelativePathQuery);
return !!urlParam;
}


// Proxy events that are unused by DM integration
onEntityCreate = (...args) => this.datamanager.invoke("onEntityCreate", ...args);
onEntityDelete = (...args) => this.datamanager.invoke("onEntityDelete", ...args);
Expand All @@ -749,7 +773,7 @@ export class LSFWrapper {

this.loadTask(prevTaskId, prevAnnotationId, true);
}
async submitCurrentAnnotation(eventName, submit, includeId = false, loadNext = true) {
async submitCurrentAnnotation(eventName, submit, includeId = false, loadNext = true, exitStream) {
const { taskID, currentAnnotation } = this;
const unique_id = this.task.unique_lock_id;
const serializedAnnotation = this.prepareData(currentAnnotation, { includeId });
Expand Down Expand Up @@ -781,11 +805,10 @@ export class LSFWrapper {
if (isFF(FF_DEV_2887) && ['submitAnnotation', 'skipTask'].includes(eventName) && this.lsf?.commentStore?.persistQueuedComments) {
await this.lsf.commentStore.persistQueuedComments();
}

// this.history?.add(taskID, currentAnnotation.pk);
}

this.setLoading(false);
if (exitStream) return this.exitStream();

if (!loadNext || this.datamanager.isExplorer) {
await this.loadTask(taskID, currentAnnotation.pk, true);
Expand Down

0 comments on commit da095bf

Please sign in to comment.