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

feat: DEV-2005: Prefetch tasks in Quick View #39

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/components/Table/CellViews/Annotators/Annotators.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export const Annotators = (cell) => {

return (
<Block name="annotators">
{renderable.map((item) => {
{renderable.map((item, i) => {
const user = item.user ?? item;
const { annotated, reviewed, review } = item;

const userpicIsFaded = (isDefined(annotated) && annotated === false) || (isDefined(reviewed) && reviewed === false);

return (
<Elem
key={`user-${user.id}`}
key={`user-${user.id}-${i}`}
name="item"
onClick={(e) => {
e.preventDefault();
Expand Down
5 changes: 2 additions & 3 deletions src/sdk/dm-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand All @@ -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;

Expand All @@ -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);
Expand Down
18 changes: 15 additions & 3 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, lock: false }));
},

unsetTask(options) {
try {
self.annotationStore.unset();
Expand Down Expand Up @@ -272,6 +282,8 @@ export const AppStore = types
}

self.setTask(labelingParams);

self.prefetchTasks();
} else {
self.closeLabeling();
}
Expand Down
8 changes: 5 additions & 3 deletions src/stores/DataStores/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -137,21 +138,21 @@ 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 });

const task = self.applyTaskSnapshot(taskData, taskID);

if (select !== false) self.setSelected(task);

self.finishLoading(taskID);
if (lock) self.finishLoading(taskID);

return task;
}),
Expand Down Expand Up @@ -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(),
});
}

Expand Down