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

fix: LSDV-4864: LEAP-148: Magic Wand doesn't work with MIG #175

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/sdk/dm-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export class DataManager {
const annotationID = annotation?.id ?? task.lastAnnotation?.id;

// this.lsf.loadTask(task.id, annotationID);
this.lsf.selectTask(task, annotationID);
await this.lsf.selectTask(task, annotationID);
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/sdk/lsf-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class LSFWrapper {
// for preload it's good to always load the first one
const annotation = task.annotations[0];

this.selectTask(task, annotation?.id, true);
await this.selectTask(task, annotation?.id, true);
}

return false;
Expand Down Expand Up @@ -294,7 +294,7 @@ export class LSFWrapper {
});

// Add new data from received task
if (newTask) this.selectTask(newTask, annotationID, fromHistory);
if (newTask) await this.selectTask(newTask, annotationID, fromHistory);
};

if (isFF(FF_DEV_2887) && this.lsf?.commentStore?.hasUnsaved) {
Expand All @@ -316,14 +316,14 @@ export class LSFWrapper {
this.datamanager.invoke("navigate", 'projects');
}

selectTask(task, annotationID, fromHistory = false) {
async selectTask(task, annotationID, fromHistory = false) {
const needsAnnotationsMerge = task && this.task?.id === task.id;
const annotations = needsAnnotationsMerge ? [...this.annotations] : [];

this.task = task;

if (needsAnnotationsMerge) {
this.task.mergeAnnotations(annotations);
await this.task.mergeAnnotations(annotations);
}

this.loadUserLabels();
Expand Down Expand Up @@ -596,7 +596,7 @@ export class LSFWrapper {
/** @private */
onUpdateAnnotation = async (ls, annotation, extraData) => {
const { task } = this;
const serializedAnnotation = this.prepareData(annotation);
const serializedAnnotation = await this.prepareData(annotation);
const exitStream = this.shouldExitStream();

Object.assign(serializedAnnotation, extraData);
Expand Down Expand Up @@ -705,7 +705,9 @@ export class LSFWrapper {

onSubmitDraft = async (studio, annotation, params = {}) => {
const annotationDoesntExist = !annotation.pk;
const data = { body: this.prepareData(annotation, { draft: true }) }; // serializedAnnotation
const data = {
body: await this.prepareData(annotation, { draft: true }),
}; // serializedAnnotation
const hasChanges = this.needsDraftSave(annotation);
const showToast = params?.useToast && hasChanges;
// console.log('onSubmitDraft', params?.useToast, hasChanges);
Expand Down Expand Up @@ -788,7 +790,9 @@ export class LSFWrapper {
body: { annotation: null },
});
} else {
const annotationData = { body: this.prepareData(currentAnnotation) };
const annotationData = {
body: await this.prepareData(currentAnnotation),
};

await this.datamanager.apiCall("createDraftForTask", {
taskID: this.task.id,
Expand Down Expand Up @@ -857,7 +861,7 @@ export class LSFWrapper {
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 });
const serializedAnnotation = await this.prepareData(currentAnnotation, { includeId });

if (unique_id) {
serializedAnnotation.unique_id = unique_id;
Expand Down Expand Up @@ -900,7 +904,7 @@ export class LSFWrapper {
}

/** @private */
prepareData(annotation, { includeId, draft } = {}) {
async prepareData(annotation, { includeId, draft } = {}) {
const userGenerate =
!annotation.userGenerate || annotation.sentUserGenerate;

Expand All @@ -911,7 +915,7 @@ export class LSFWrapper {

const result = {
lead_time,
result: (draft ? annotation.versions.draft : annotation.serializeAnnotation()) ?? [],
result: (draft ? annotation.versions.draft : await annotation.serializeAnnotation()) ?? [],
draft_id: annotation.draftId,
parent_prediction: annotation.parent_prediction,
parent_annotation: annotation.parent_annotation,
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/lsf-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export const annotationToServer = (
};
};

export const getAnnotationSnapshot = (c: LSFAnnotation) => ({
export const getAnnotationSnapshot = async (c: LSFAnnotation) => ({
id: c.id,
pk: c.pk,
result: c.serializeAnnotation(),
result: await c.serializeAnnotation(),
leadTime: c.leadTime,
userGenerate: !!c.userGenerate,
sentUserGenerate: !!c.sentUserGenerate,
Expand Down
22 changes: 13 additions & 9 deletions src/stores/DataStores/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ export const create = (columns) => {
},
}))
.actions((self) => ({
mergeAnnotations(annotations) {
// skip drafts, they'll be added later
self.annotations = annotations.filter(a => a.pk).map((c) => {
mergeAnnotations: flow(function *(annotations) {
const merged = annotations.filter(a => a.pk).map(async (c) => {
const existingAnnotation = self.annotations.find(
(ec) => ec.id === Number(c.pk),
);
Expand All @@ -62,26 +61,31 @@ export const create = (columns) => {
id: c.id,
pk: c.pk,
draftId: c.draftId,
result: c.serializeAnnotation(),
result: await c.serializeAnnotation(),
bmartel marked this conversation as resolved.
Show resolved Hide resolved
leadTime: c.leadTime,
userGenerate: !!c.userGenerate,
sentUserGenerate: !!c.sentUserGenerate,
};
}
});
},

updateAnnotation(annotation) {
// skip drafts, they'll be added later
self.annotations = yield Promise.all(merged);
}),

updateAnnotation: flow(function *(annotation) {
const existingAnnotation = self.annotations.find((c) => {
return c.id === Number(annotation.pk) || c.pk === annotation.pk;
});

const snapshot = yield getAnnotationSnapshot(annotation);

if (existingAnnotation) {
Object.assign(existingAnnotation, getAnnotationSnapshot(annotation));
Object.assign(existingAnnotation, snapshot);
} else {
self.annotations.push(getAnnotationSnapshot(annotation));
self.annotations.push(snapshot);
}
},
}),

deleteAnnotation(annotation) {
const index = self.annotations.findIndex((c) => {
Expand Down
2 changes: 1 addition & 1 deletion src/types/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ export interface LSFAnnotation extends LSFAnnotationData {

// editable: boolean;

serializeAnnotation(): APIResult[];
serializeAnnotation(): Promise<APIResult[]>;
}