From 6bcde77df8f396b9d6c1ef22ebb9d5ee31fbd41e Mon Sep 17 00:00:00 2001 From: hlomzik Date: Wed, 23 Mar 2022 18:01:15 +0300 Subject: [PATCH 1/4] feat: DEV-2005: Prefetch tasks in quick view --- src/stores/AppStore.js | 18 +++++++++++++++--- src/stores/DataStores/tasks.js | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index bc70d72a..de35098e 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -190,9 +190,13 @@ export const AppStore = types select: !!taskID && !!annotationID, }); } else { - yield self.taskStore.loadTask(taskID, { - select: !!taskID && !!annotationID, - }); + const task = self.taskStore.list.find(({ id }) => id === taskID); + + if (!task?.full_data_loaded_at) { + yield self.taskStore.loadTask(taskID, { + select: !!taskID && !!annotationID, + }); + } } if (annotationID !== undefined) { @@ -202,6 +206,12 @@ export const AppStore = types } }), + prefetchTasks() { + const ids = self.taskStore.list.filter(t => !t.full_data_loaded_at).map(t => t.id); + + ids.forEach(id => self.taskStore.loadTask(id, { select: false })); + }, + unsetTask(options) { try { self.annotationStore.unset(); @@ -272,6 +282,8 @@ export const AppStore = types } self.setTask(labelingParams); + + self.prefetchTasks(); } else { self.closeLabeling(); } diff --git a/src/stores/DataStores/tasks.js b/src/stores/DataStores/tasks.js index edb64a9f..638f0cc1 100644 --- a/src/stores/DataStores/tasks.js +++ b/src/stores/DataStores/tasks.js @@ -60,6 +60,7 @@ export const create = (columns) => { assigned_task: false, queue: types.optional(types.maybeNull(types.string), null), updated_by: types.optional(types.array(Assignee), []), + full_data_loaded_at: types.maybeNull(types.string), }) .views((self) => ({ get lastAnnotation() { @@ -192,6 +193,7 @@ export const create = (columns) => { task = self.updateItem(taskID ?? taskData.id, { ...snapshot, source: JSON.stringify(taskData), + full_data_loaded_at: (new Date()).toISOString(), }); } From d9f79cdf8801deb86511bfc9fcadbcb65932aa4b Mon Sep 17 00:00:00 2001 From: hlomzik Date: Wed, 23 Mar 2022 18:03:22 +0300 Subject: [PATCH 2/4] reuse isLabelStream in DM SDK --- src/sdk/dm-sdk.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sdk/dm-sdk.js b/src/sdk/dm-sdk.js index 26c9d071..23f7d562 100644 --- a/src/sdk/dm-sdk.js +++ b/src/sdk/dm-sdk.js @@ -378,7 +378,7 @@ export class DataManager { ...this.labelStudioOptions, task: this.store.taskStore.selected, // annotation: this.store.annotationStore.selected, - isLabelStream: this.mode === 'labelstream', + isLabelStream: this.isLabelStream, }); } @@ -396,7 +396,6 @@ export class DataManager { this.store.annotationStore.selected, ]; - const isLabelStream = this.mode === 'labelstream'; const taskExists = isDefined(this.lsf.task) && isDefined(task); const taskSelected = this.lsf.task?.id === task?.id; @@ -405,7 +404,7 @@ export class DataManager { return; } - if (!isLabelStream && (!taskSelected || isDefined(annotation))) { + if (!this.isLabelStream && (!taskSelected || isDefined(annotation))) { const annotationID = annotation?.id ?? task.lastAnnotation?.id; // this.lsf.loadTask(task.id, annotationID); From 3fb60c15029015a40ac5e532c2abccfdfd7a78b4 Mon Sep 17 00:00:00 2001 From: hlomzik Date: Wed, 23 Mar 2022 18:05:05 +0300 Subject: [PATCH 3/4] fix react keys error In tasks with multiple annotations from the same user --- src/components/Table/CellViews/Annotators/Annotators.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Table/CellViews/Annotators/Annotators.js b/src/components/Table/CellViews/Annotators/Annotators.js index c6e487f8..4052a50a 100644 --- a/src/components/Table/CellViews/Annotators/Annotators.js +++ b/src/components/Table/CellViews/Annotators/Annotators.js @@ -19,7 +19,7 @@ export const Annotators = (cell) => { return ( - {renderable.map((item) => { + {renderable.map((item, i) => { const user = item.user ?? item; const { annotated, reviewed, review } = item; @@ -27,7 +27,7 @@ export const Annotators = (cell) => { return ( { e.preventDefault(); From f28a9e286c1f3da5af624f71afe09961b50c6c43 Mon Sep 17 00:00:00 2001 From: hlomzik Date: Tue, 5 Apr 2022 03:40:16 +0400 Subject: [PATCH 4/4] Don't lock tasks during prefetch --- src/stores/AppStore.js | 2 +- src/stores/DataStores/tasks.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index de35098e..e34680de 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -209,7 +209,7 @@ export const AppStore = types prefetchTasks() { const ids = self.taskStore.list.filter(t => !t.full_data_loaded_at).map(t => t.id); - ids.forEach(id => self.taskStore.loadTask(id, { select: false })); + ids.forEach(id => self.taskStore.loadTask(id, { select: false, lock: false })); }, unsetTask(options) { diff --git a/src/stores/DataStores/tasks.js b/src/stores/DataStores/tasks.js index 638f0cc1..c27b59a5 100644 --- a/src/stores/DataStores/tasks.js +++ b/src/stores/DataStores/tasks.js @@ -138,13 +138,13 @@ export const create = (columns) => { }, }) .actions((self) => ({ - loadTask: flow(function* (taskID, { select = true } = {}) { + loadTask: flow(function* (taskID, { select = true, lock = true } = {}) { if (!isDefined(taskID)) { console.warn("Task ID must be provided"); return; } - self.setLoading(taskID); + if (lock) self.setLoading(taskID); const taskData = yield self.root.apiCall("task", { taskID }); @@ -152,7 +152,7 @@ export const create = (columns) => { if (select !== false) self.setSelected(task); - self.finishLoading(taskID); + if (lock) self.finishLoading(taskID); return task; }),