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

Commit 63f7e01

Browse files
juliosgarbibmartel
andauthored
feat: LSDV-3936: Task history is stored on the backend (#1181)
* feat: lsdv-3936: Task history is stored on the backend * Update src/stores/AppStore.js Co-authored-by: bmartel <[email protected]> --------- Co-authored-by: bmartel <[email protected]>
1 parent 18fc2e5 commit 63f7e01

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/components/App/App.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ class App extends Component {
7878
>
7979
<Result status="success" title={getEnv(this.props.store).messages.NO_NEXT_TASK} />
8080
<Block name="sub__result">You have completed all tasks in the queue!</Block>
81-
{store.canGoPrevTask && (
82-
<Button onClick={() => store.prevTask()} look="outlined" style={{ margin: '16px 0' }}>
83-
Go to Previous Task
84-
</Button>
85-
)}
81+
<Button onClick={e => store.prevTask(e, true)} look="outlined" style={{ margin: '16px 0' }}>
82+
Go to Previous Task
83+
</Button>
8684
</Block>
8785
);
8886
}

src/stores/AppStore.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,22 +435,25 @@ export default types
435435
});
436436
}
437437

438+
function setTaskHistory(taskHistory) {
439+
self.taskHistory = taskHistory;
440+
}
441+
438442
/**
439443
*
440444
* @param {*} taskObject
441445
* @param {*[]} taskHistory
442446
*/
443-
function assignTask(taskObject, taskHistory) {
447+
function assignTask(taskObject) {
444448
if (taskObject && !Utils.Checkers.isString(taskObject.data)) {
445449
taskObject = {
446450
...taskObject,
447451
data: JSON.stringify(taskObject.data),
448452
};
449453
}
450454
self.task = Task.create(taskObject);
451-
if (taskHistory) {
452-
self.taskHistory = taskHistory;
453-
} else if (!self.taskHistory.some((x) => x.taskId === self.task.id)) {
455+
456+
if (!self.taskHistory.some((x) => x.taskId === self.task.id)) {
454457
self.taskHistory.push({
455458
taskId: self.task.id,
456459
annotationId: null,
@@ -734,9 +737,11 @@ export default types
734737
}
735738
}
736739

737-
function prevTask() {
738-
if (self.canGoPrevTask) {
739-
const { taskId, annotationId } = self.taskHistory[self.taskHistory.findIndex((x) => x.taskId === self.task.id) - 1];
740+
function prevTask(e, shouldGoBack = false) {
741+
const length = shouldGoBack ? self.taskHistory.length - 1 : self.taskHistory.findIndex((x) => x.taskId === self.task.id) - 1;
742+
743+
if (self.canGoPrevTask || shouldGoBack) {
744+
const { taskId, annotationId } = self.taskHistory[length];
740745

741746
getEnv(self).events.invoke('prevTask', taskId, annotationId);
742747
}
@@ -772,6 +777,7 @@ export default types
772777

773778
skipTask,
774779
unskipTask,
780+
setTaskHistory,
775781
submitDraft,
776782
submitAnnotation,
777783
updateAnnotation,

0 commit comments

Comments
 (0)