Enhance section movement functionality in TrainingUnitSectionsEditor
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 38s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m8s
Test Suite / pytest-backend (pull_request) Successful in 34s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 12s
Test Suite / k6 /health Baseline (pull_request) Successful in 33s
Test Suite / playwright-tests (pull_request) Successful in 1m8s

- Updated the onMoveSectionsAcrossSlots function to support additional parameters for improved section movement across slots, including handling for parallel phase indices and insertion points.
- Refined logic for moving sections between slots, ensuring proper handling of parallel streams and enhancing the overall section management experience.
This commit is contained in:
Lars committed 2026-05-16 08:34:30 +02:00
1 parent 7d2661a8e8
commit 8c07cf36ee
2 files changed
+156 -16

No files matched your search

@@ -15,6 +15,9 @@ import {
buildPlanPayloadForSave,
hydrateExercisePlanningRow,
reorderBlockIntoParallelStreamEnd,
indicesOfParallelPhase,
reorderSectionBeforeParallelRunAsWholeGroup,
reorderSectionAsFirstInParallelStream,
} from '../utils/trainingUnitSectionsForm'
const DND_FW_SLOT = 'application/x-shinkan-framework-slot'
@@ -561,7 +564,17 @@ export default function TrainingFrameworkProgramEditPage() {
}
const moveSectionsAcrossFrameworkSlots = useCallback(
({ fromSlot, fromSectionIdx, toSlot, toSectionIdx, toParallelStream }) => {
(payload) => {
const {
fromSlot,
fromSectionIdx,
toSlot,
toSectionIdx,
toParallelStream,
parallelPhaseRunOrderIndex,
insertBeforeParallelInTarget,
firstInParallelStreamInTarget,
} = payload
setForm((prev) => {
const slots = prev.slots.map((sl) => ({
...sl,
@@ -579,15 +592,7 @@ export default function TrainingFrameworkProgramEditPage() {
}
const fromSecs = slots[fromSlot].sections
if (
typeof fromSectionIdx !== 'number' ||
fromSectionIdx < 0 ||
fromSectionIdx >= fromSecs.length
) {
return prev
}
const [block] = fromSecs.splice(fromSectionIdx, 1)
const toSecs = slots[toSlot].sections
const applyParallelStreamEnd =
toParallelStream != null && toParallelStream.po != null && toParallelStream.so != null
@@ -598,6 +603,43 @@ export default function TrainingFrameworkProgramEditPage() {
}
: null
/** Gesamten Parallel-Lauf aus fromSlot an toSectionIdx in toSlot legen */
if (parallelPhaseRunOrderIndex != null && parallelPhaseRunOrderIndex !== '') {
const po = Number(parallelPhaseRunOrderIndex) || 0
const idxs = indicesOfParallelPhase(fromSecs, po)
if (!idxs.length) {
return prev
}
const blocks = idxs.map((i) => fromSecs[i])
for (const i of [...idxs].sort((a, b) => b - a)) {
fromSecs.splice(i, 1)
}
if (fromSlot === toSlot) {
let insertAt = Number(toSectionIdx) || 0
for (const i of idxs) {
if (i < insertAt) insertAt -= 1
}
insertAt = Math.max(0, Math.min(insertAt, fromSecs.length))
fromSecs.splice(insertAt, 0, ...blocks)
slots[fromSlot].sections = fromSecs
return { ...prev, slots }
}
const insertAt = Math.max(0, Math.min(Number(toSectionIdx) || 0, toSecs.length))
toSecs.splice(insertAt, 0, ...blocks)
slots[toSlot].sections = toSecs
return { ...prev, slots }
}
if (
typeof fromSectionIdx !== 'number' ||
fromSectionIdx < 0 ||
fromSectionIdx >= fromSecs.length
) {
return prev
}
const [block] = fromSecs.splice(fromSectionIdx, 1)
if (fromSlot === toSlot) {
let insertAt = toSectionIdx
if (fromSectionIdx < toSectionIdx) insertAt = toSectionIdx - 1
@@ -605,15 +647,45 @@ export default function TrainingFrameworkProgramEditPage() {
fromSecs.splice(insertAt, 0, block)
if (applyParallelStreamEnd) {
slots[fromSlot].sections = applyParallelStreamEnd(fromSecs, insertAt)
} else {
slots[fromSlot].sections = fromSecs
}
return { ...prev, slots }
}
const toSecs = slots[toSlot].sections
if (insertBeforeParallelInTarget != null && insertBeforeParallelInTarget !== '') {
const tpo = Number(insertBeforeParallelInTarget) || 0
const pIdxs = indicesOfParallelPhase(toSecs, tpo)
const ins = pIdxs.length ? pIdxs[0] : toSecs.length
toSecs.splice(ins, 0, block)
slots[toSlot].sections = reorderSectionBeforeParallelRunAsWholeGroup(toSecs, ins, tpo)
return { ...prev, slots }
}
if (
firstInParallelStreamInTarget != null &&
firstInParallelStreamInTarget.po != null &&
firstInParallelStreamInTarget.so != null
) {
const fpo = Number(firstInParallelStreamInTarget.po) || 0
const fso = Number(firstInParallelStreamInTarget.so) || 0
const nextSecs = [...toSecs, block]
const movedFromI = nextSecs.length - 1
slots[toSlot].sections = reorderSectionAsFirstInParallelStream(
nextSecs,
movedFromI,
fpo,
fso
)
return { ...prev, slots }
}
const ia = Math.max(0, Math.min(toSectionIdx, toSecs.length))
toSecs.splice(ia, 0, block)
if (applyParallelStreamEnd) {
slots[toSlot].sections = applyParallelStreamEnd(toSecs, ia)
} else {
slots[toSlot].sections = toSecs
}
return { ...prev, slots }
})