Skip to content

Commit

Permalink
TasksPage: adding/moving/deleting pages triggers linear workflow rules
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunanoordin committed May 17, 2024
1 parent 1aa4a41 commit be8cae0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/pages/lab-pages-editor/components/TasksPage/TasksPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import createStep from '../../helpers/createStep.js';
import createTask from '../../helpers/createTask.js';
import getNewStepKey from '../../helpers/getNewStepKey.js';
import getNewTaskKey from '../../helpers/getNewTaskKey.js';
import linkStepsInWorkflow from '../../helpers/linkStepsInWorkflow.js';
import moveItemInArray from '../../helpers/moveItemInArray.js';
import cleanupTasksAndSteps from '../../helpers/cleanupTasksAndSteps.js';
// import strings from '../../strings.json'; // TODO: move all text into strings
Expand Down Expand Up @@ -40,7 +41,7 @@ export default function TasksPage() {
if (!workflow) return;
const newTaskKey = getNewTaskKey(workflow.tasks);
const newTask = createTask(taskType);
const steps = workflow.steps?.slice() || [];
let steps = workflow.steps?.slice() || [];

let step
if (stepIndex < 0) {
Expand Down Expand Up @@ -70,6 +71,10 @@ export default function TasksPage() {
[newTaskKey]: newTask
};

if (linkStepsInWorkflow) {
steps = linkStepsInWorkflow(steps, tasks);
}

await update({ tasks, steps });
return (stepIndex < 0) ? steps.length - 1 : stepIndex;
}
Expand Down Expand Up @@ -125,7 +130,10 @@ export default function TasksPage() {
const oldSteps = workflow.steps || [];
if (from < 0 || to < 0 || from >= oldSteps.length || to >= oldSteps.length) return;

const steps = moveItemInArray(oldSteps, from, to);
let steps = moveItemInArray(oldSteps, from, to);
if (linkStepsInWorkflow) {
steps = linkStepsInWorkflow(steps, workflow.tasks);
}
update({ steps });
}

Expand All @@ -142,6 +150,9 @@ export default function TasksPage() {

// cleanedupTasksAndSteps() will also remove tasks not associated with any step.
const cleanedTasksAndSteps = cleanupTasksAndSteps(newTasks, newSteps);
if (linkStepsInWorkflow) {
cleanedTasksAndSteps.steps = linkStepsInWorkflow(cleanedTasksAndSteps.steps, cleanedTasksAndSteps.tasks);
}
update(cleanedTasksAndSteps);
}

Expand Down

0 comments on commit be8cae0

Please sign in to comment.