-
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 Branching Controls (#6991)
* pages-editor-pt13 - prepare branching controls * Move canStepBranch into its own function * WIP. Add BranchingControls. Refactor how StepItem gets steps * BranchingControls: list 'next' options for each answer * BranchingControls: style up * BranchingControls: style next arrows * BracnhingControls: Implement branching choices * TasksPage: add (hardcoded) Preview Workflow button * StepItem: style update. Add outline when dragging * TasksPage: fix missing rel=noopener noreferrer * PagesEditor: replace anonymous functions with DEFAULT_HANDLER const * SingleQuestionTask: fix accessibility. Fix Form Submit (Enter key) bug * TextTask: fix accessibility
- Loading branch information
1 parent
0e611cf
commit 38d95c3
Showing
12 changed files
with
259 additions
and
66 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
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
79 changes: 79 additions & 0 deletions
79
app/pages/lab-pages-editor/components/TasksPage/components/StepItem/BranchingControls.jsx
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,79 @@ | ||
const DEFAULT_HANDLER = () => {}; | ||
|
||
export default function BranchingControls({ | ||
allSteps = [], | ||
task, | ||
taskKey, | ||
updateAnswerNext = DEFAULT_HANDLER | ||
}) { | ||
if (!task || !taskKey) return null; | ||
|
||
const answers = task.answers || [] | ||
|
||
function onChange(e) { | ||
const next = e.target?.value; | ||
const index = e?.target?.dataset.index; | ||
updateAnswerNext(taskKey, index, next); | ||
} | ||
|
||
return ( | ||
<ul className="branching-controls"> | ||
{answers.map((answer, index) => ( | ||
<li key={`branching-controls-answer-${index}`}> | ||
<div className="fake-button">{answer.label}</div> | ||
<NextStepArrow className="next-arrow" /> | ||
<select | ||
className={(!answer?.next) ? 'next-is-submit' : ''} | ||
data-index={index} | ||
onChange={onChange} | ||
value={answer?.next || ''} | ||
> | ||
<option | ||
value={''} | ||
> | ||
Submit | ||
</option> | ||
{allSteps.map(([stepKey, stepBody]) => { | ||
const taskKeys = stepBody?.taskKeys?.toString() || '(none)'; | ||
return ( | ||
<option | ||
key={`branching-controls-answer-${index}-option-${stepKey}`} | ||
value={stepKey} | ||
> | ||
{taskKeys} | ||
</option> | ||
); | ||
})} | ||
</select> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} | ||
|
||
function NextStepArrow({ | ||
alt, | ||
className = 'icon', | ||
color = 'currentColor', | ||
height = 48, | ||
pad = 4, | ||
strokeWidth = 2, | ||
width = 16 | ||
}) { | ||
const xA = 0 + pad; | ||
const xB = width * 0.5; | ||
const xC = width - pad; | ||
const yA = 0 + pad; | ||
const yB = height - (width / 2); | ||
const yC = height - pad; | ||
|
||
return ( | ||
<svg aria-label={alt} width={width} height={height} className={className}> | ||
<g stroke={color} strokeWidth={strokeWidth}> | ||
<line x1={xB} y1={yA} x2={xB} y2={yC} /> | ||
<line x1={xA} y1={yB} x2={xB} y2={yC} /> | ||
<line x1={xC} y1={yB} x2={xB} y2={yC} /> | ||
</g> | ||
</svg> | ||
); | ||
} |
6 changes: 4 additions & 2 deletions
6
app/pages/lab-pages-editor/components/TasksPage/components/StepItem/DropTarget.jsx
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
Oops, something went wrong.