From 4dec5ebb356fbba8b622f8b40225f8350ba3497d Mon Sep 17 00:00:00 2001 From: "Shaun A. Noordin" Date: Fri, 26 Apr 2024 17:05:05 +0100 Subject: [PATCH] TasksPage: setting Starting Page will now just rearrange Steps --- .../components/TasksPage/ExperimentalPanel.jsx | 2 +- .../components/TasksPage/TasksPage.jsx | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/pages/lab-pages-editor/components/TasksPage/ExperimentalPanel.jsx b/app/pages/lab-pages-editor/components/TasksPage/ExperimentalPanel.jsx index c5377ad67d..6d18b28da5 100644 --- a/app/pages/lab-pages-editor/components/TasksPage/ExperimentalPanel.jsx +++ b/app/pages/lab-pages-editor/components/TasksPage/ExperimentalPanel.jsx @@ -13,7 +13,7 @@ export default function ExperimentalPanel({ function experimentalQuickSetup() { update({ - first_task: 'P0', + first_task: '', tasks: { 'T0': { answers: [ diff --git a/app/pages/lab-pages-editor/components/TasksPage/TasksPage.jsx b/app/pages/lab-pages-editor/components/TasksPage/TasksPage.jsx index f42fca4ab0..e8a55f77d9 100644 --- a/app/pages/lab-pages-editor/components/TasksPage/TasksPage.jsx +++ b/app/pages/lab-pages-editor/components/TasksPage/TasksPage.jsx @@ -20,6 +20,7 @@ export default function TasksPage() { const newTaskDialog = useRef(null); const [ activeStepIndex, setActiveStepIndex ] = useState(-1); // Tracks which Step is being edited. const [ activeDragItem, setActiveDragItem ] = useState(-1); // Keeps track of active item being dragged (StepItem). This is because "dragOver" CAN'T read the data from dragEnter.dataTransfer.getData(). + const firstStepKey = workflow?.steps?.[0]?.[0] || ''; const isActive = true; // TODO /* @@ -155,8 +156,10 @@ export default function TasksPage() { } function handleChangeStartingPage(e) { - const first_task = e?.target?.value || ''; - update({ first_task }); + const targetStepKey = e?.target?.value || ''; + const targetStepIndex = workflow?.steps?.findIndex(([stepKey]) => stepKey === targetStepKey) || -1; + if (targetStepIndex < 0) return; + moveStep(targetStepIndex, 0); } // Changes the optional "next page" of a step/page @@ -228,7 +231,7 @@ export default function TasksPage() { aria-label="Choose starting Page" className="flex-item" onChange={handleChangeStartingPage} - defaultValue={workflow?.first_task || ''} + value={firstStepKey} > {workflow.steps?.map(([stepKey, stepBody]) => ( @@ -236,7 +239,7 @@ export default function TasksPage() { key={`choose-starting-page-${stepKey}`} value={stepKey} > - {workflow.first_task === stepKey && 'Starting page: '} + {firstStepKey === stepKey && 'Starting page: '} {stepBody?.taskKeys?.join(', ') || `(${stepKey})` /* Note: if you see the stepKey instead of the taskKeys, something's wrong. */} ))}