Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lab): clear references to a task key after deleting a task #7099

Open
wants to merge 3 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
4 changes: 3 additions & 1 deletion app/pages/lab-fem/workflow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import TaskOptions from '../lab/workflow-components/task-options.jsx';
import TaskEditor from '../lab/workflow-components/task-editor.jsx';
import TaskPicker from '../lab/workflow-components/task-picker.jsx';
import { isThisProjectUsingFEMLab, isWorkflowUsingJSONSubjects, FEM_LAB_PREVIEW_HOST } from './fem-lab-utilities.js';
import removeTaskKeyFromWorkflow from '../lab/helpers/removeTaskKeyFromWorkflow.js';

const DEMO_SUBJECT_SET_ID = process.env.NODE_ENV === 'production'
? '6' // Cats
Expand Down Expand Up @@ -848,8 +849,9 @@ class EditWorkflowPage extends Component {
changes[`tasks.${taskKey}`] = undefined;
this.props.workflow.update(changes);
}
removeTaskKeyFromWorkflow(this.props.workflow, taskKey);

return this.updateFirstTask();
return this.updateFirstTask().save();
}
}
};
Expand Down
14 changes: 14 additions & 0 deletions app/pages/lab/helpers/removeTaskKeyFromWorkflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function removeTaskKeyFromWorkflow(workflow, taskKey) {
const changes = {};
Object.entries(workflow.tasks).forEach(([key, task]) => {
if (task.next === taskKey) {
changes[`tasks.${key}.next`] = '';
}
task.answers?.forEach((answer, index) => {
if (answer.next === taskKey) {
changes[`tasks.${key}.answers.${index}.next`] = '';
}
});
});
return workflow.update(changes);
}
43 changes: 43 additions & 0 deletions app/pages/lab/helpers/removeTaskKeyFromWorkflow.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect } from 'chai';
import sinon from 'sinon';
import removeTaskKeyFromWorkflow from './removeTaskKeyFromWorkflow.js';

describe('removeTaskKeyFromWorkflow', function () {
let workflow;

beforeEach(function () {
workflow = {
tasks: {
'T1': {
type: 'single',
answers: [
{ label: 'Yes', next: 'T3' },
{ label: 'No', next: 'T2' }
]
},
'T2': {
type: 'multiple',
next: 'T3',
answers: [
{ label: 'Blue' },
{ label: 'Green' }
]
},
'T3': {
type: 'text',
next: ''
}
},
update: sinon.stub(),
save: sinon.stub()
};
});

it('should delete the selected key from each task', function () {
removeTaskKeyFromWorkflow(workflow, 'T3');
expect(workflow.update).to.have.been.calledWith({
'tasks.T1.answers.0.next': '',
'tasks.T2.next': ''
});
});
});
7 changes: 3 additions & 4 deletions app/pages/lab/workflow.jsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request: changes to app/pages/lab/workflow.jsx should also be replicated, if possible, on app/pages/lab-fem/workflow.jsx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and rebased to the latest changes on the main branch.

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { Component, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import handleInputChange from '../../lib/handle-input-change.js';
import TriggeredModalForm from 'modal-form/triggered';
import ModalFormDialog from 'modal-form/dialog';
import apiClient from 'panoptes-client/lib/api-client';
import ChangeListener from '../../components/change-listener.cjsx';
import RetirementRulesEditor from '../../components/retirement-rules-editor.cjsx';
import {Link} from 'react-router';
import MultiImageSubjectOptionsEditor from '../../components/multi-image-subject-options-editor.jsx';
import taskComponents from '../../classifier/tasks/index.js';
import AutoSave from '../../components/auto-save.coffee';
import FileButton from '../../components/file-button.cjsx';
import WorkflowCreateForm from './workflow-create-form.cjsx';
import workflowActions from './actions/workflow.js';
import classnames from 'classnames';
Expand All @@ -21,6 +18,7 @@ import Tutorials from './workflow-components/tutorials.jsx';
import TaskOptions from './workflow-components/task-options.jsx';
import TaskPicker from './workflow-components/task-picker.jsx';
import TaskEditor from './workflow-components/task-editor.jsx';
import removeTaskKeyFromWorkflow from './helpers/removeTaskKeyFromWorkflow.js';

const DEMO_SUBJECT_SET_ID = process.env.NODE_ENV === 'production'
? '6' // Cats
Expand Down Expand Up @@ -807,8 +805,9 @@ class EditWorkflowPage extends Component {
changes[`tasks.${taskKey}`] = undefined;
this.props.workflow.update(changes);
}
removeTaskKeyFromWorkflow(this.props.workflow, taskKey);

return this.updateFirstTask();
return this.updateFirstTask().save();
}
}
}
Expand Down
Loading
Loading