-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pages Editor: implement basic "Add Tasks" functionality (#6888)
* TasksPage: add helper functions for creating new Steps & Tasks. Also style buttons. * TasksPage: implement createTask and createStep functions * TasksPage: prepare update payload. Add safety check in case tasks/steps not generated. * TasksPage: implement functional 'Add Tasks' button * TasksPage: add temporary reset button * TasksPage: cleanup. Move functions to own helpers dir * createStep: add missing stepKey Co-authored-by: Jim O'Donnell <[email protected]> * createTask: use default tasks from PFE code * Cleanup: remove minor console log * convertKeyToIndex: simplify --------- Co-authored-by: Jim O'Donnell <[email protected]>
- Loading branch information
1 parent
2206ef8
commit 4a08cf1
Showing
8 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const TASK_KEY_PREFIX = 'T'; | ||
export const STEP_KEY_PREFIX = 'P'; // Steps are known as Pages to users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Transforms "T1234" (string) to 1234 (number). | ||
Returns 0 by default. | ||
*/ | ||
/* eslint-disable radix */ | ||
|
||
export default function convertKeyToIndex(taskKeyOrStepKey = '') { | ||
const indexStr = taskKeyOrStepKey?.replace(/^(\D)+/g, ''); | ||
return parseInt(indexStr) || 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
Creates a Step, with tasks, that's ready to be inserted into a Workflow. | ||
*/ | ||
|
||
export default function createStep(stepKey, taskKeys = []) { | ||
return [stepKey, { stepKey, taskKeys }]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Creates an empty/placeholder Task that's ready to be inserted into a Workflow. | ||
NOTE: the Task Key isn't handled by this function. Whatever's calling this | ||
function needs to assign the appropriate Task Key to this Task, and then add it | ||
to the Workflow. | ||
*/ | ||
|
||
import tasks from '../../../classifier/tasks'; | ||
|
||
export default function createTask(taskType) { | ||
return tasks[taskType]?.getDefaultTask(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Searches the Workflow's existing Steps and finds the next available Step Key. | ||
- Goes through workflow.steps and finds steps in the format of P0, P1, P2, etc | ||
- Finds the LARGEST/HIGHEST key and returns one higher. | ||
- e.g. if given [P0, P1, P5], this will return P6. | ||
- Return P0 by default. | ||
*/ | ||
|
||
import { STEP_KEY_PREFIX } from './constants.js'; | ||
import convertKeyToIndex from './convertKeyToIndex.js'; | ||
|
||
export default function getNewStepKey(steps = []) { | ||
let newIndex = 0; | ||
const stepKeys = steps.map((step) => (step[0] || '')).filter((step) => (step.length > 0)); | ||
stepKeys.forEach((stepKey) => { | ||
const index = convertKeyToIndex(stepKey); | ||
newIndex = (newIndex <= index) ? index + 1 : newIndex; | ||
}); | ||
return `${STEP_KEY_PREFIX}${newIndex}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Searches the Workflow's existing Tasks and finds the next available Task Key. | ||
- Goes through workflow.tasks and finds keys in the format of T0, T1, T2, etc | ||
- Finds the LARGEST/HIGHEST key and returns one higher. | ||
- e.g. if given [T0, T1, T5], this will return T6. | ||
- Return T0 by default. | ||
*/ | ||
|
||
import { TASK_KEY_PREFIX } from './constants.js'; | ||
import convertKeyToIndex from './convertKeyToIndex.js'; | ||
|
||
export default function getNewTaskKey(tasks = {}) { | ||
let newIndex = 0; | ||
const taskKeys = Object.keys(tasks); | ||
taskKeys.forEach((taskKey) => { | ||
const index = convertKeyToIndex(taskKey); | ||
newIndex = (newIndex <= index) ? index + 1 : newIndex; | ||
}); | ||
return `${TASK_KEY_PREFIX}${newIndex}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ $fontWeightBoldPlus = 700 | |
|
||
button | ||
color: $black | ||
cursor: pointer | ||
font-family: $fontFamilies | ||
|
||
&.big | ||
|