Skip to content
This repository was 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 2 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 @@ -441,7 +441,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 @@ -238,7 +238,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 @@ -274,7 +274,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 @@ -292,14 +292,14 @@ export class LSFWrapper {
await nextAction();
}

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 @@ -546,7 +546,7 @@ export class LSFWrapper {
/** @private */
onUpdateAnnotation = async (ls, annotation, extraData) => {
const { task } = this;
const serializedAnnotation = this.prepareData(annotation);
const serializedAnnotation = await this.prepareData(annotation);

Object.assign(serializedAnnotation, extraData);

Expand Down Expand Up @@ -621,7 +621,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

Object.assign(data.body, params);

Expand Down Expand Up @@ -692,7 +694,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 @@ -743,7 +747,7 @@ export class LSFWrapper {
async submitCurrentAnnotation(eventName, submit, includeId = false, loadNext = true) {
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 @@ -786,15 +790,15 @@ export class LSFWrapper {
}

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

const result = {
// task execution time, always summed up with previous values
lead_time: (new Date() - annotation.loadedDate) / 1000 + Number(annotation.leadTime ?? 0),
// don't serialize annotations twice for drafts
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 @@ -63,10 +63,10 @@ export const annotationToServer = (annotation: LSFAnnotation): APIAnnotation =>
};
};

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 @@ -41,9 +41,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 @@ -55,26 +54,31 @@ export const create = (columns) => {
id: c.id,
pk: c.pk,
draftId: c.draftId,
result: c.serializeAnnotation(),
result: await c.serializeAnnotation(),
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 @@ -97,5 +97,5 @@ export interface LSFAnnotation extends LSFAnnotationData {

// editable: boolean;

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