From 49027717724a49f77ec4e24148f772637345f4dc Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 15 May 2026 10:14:17 +0200 Subject: [PATCH] Enhance TrainingUnitSectionsEditor with improved section visibility logic - Added logic to determine visibility of drop bands for sections in parallel phases, enhancing user experience during reordering. - Updated the reorderBlocksImmutableWithPlanLoc function to better handle plan location adjustments based on section types and their positions. - Improved handling of section indices for parallel streams, ensuring accurate representation of active streams and their corresponding sections. --- .../components/TrainingUnitSectionsEditor.jsx | 22 ++++++++++++++++++- .../src/utils/trainingUnitSectionsForm.js | 15 +++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/TrainingUnitSectionsEditor.jsx b/frontend/src/components/TrainingUnitSectionsEditor.jsx index 6337b52..a6d9e93 100644 --- a/frontend/src/components/TrainingUnitSectionsEditor.jsx +++ b/frontend/src/components/TrainingUnitSectionsEditor.jsx @@ -1173,8 +1173,28 @@ export default function TrainingUnitSectionsEditor({ enableParallelPhaseControls && pl?.phaseKind === 'parallel' && (pl.parallelStreamOrderIndex ?? 0) !== activeParallelStream + const firstGlobalIdxThisPhase = + parallelPhaseOrder != null + ? firstSectionIndexByParallelPhase.get(parallelPhaseOrder) + : null + const firstVisibleIdxActiveStream = + parallelPhaseOrder != null && streamOrdersForParallelPhase.length + ? sectionIndicesForParallelStream( + list, + parallelPhaseOrder, + activeParallelStream + )[0] + : null + const hideDropBandBeforeOrphanFirstVisible = + parallelPhaseOrder != null && + firstVisibleIdxActiveStream != null && + sIdx === firstVisibleIdxActiveStream && + firstGlobalIdxThisPhase != null && + sIdx !== firstGlobalIdxThisPhase + const showSectionDropBandBefore = - pl?.phaseKind !== 'parallel' || !hideParallelSection + (pl?.phaseKind !== 'parallel' || !hideParallelSection) && + !hideDropBandBeforeOrphanFirstVisible const bandActiveBefore = (bx) => enableSectionDragReorder && diff --git a/frontend/src/utils/trainingUnitSectionsForm.js b/frontend/src/utils/trainingUnitSectionsForm.js index e79c131..4a8ed02 100644 --- a/frontend/src/utils/trainingUnitSectionsForm.js +++ b/frontend/src/utils/trainingUnitSectionsForm.js @@ -814,7 +814,19 @@ export function reorderBlocksImmutableWithPlanLoc(prev, fromI, toBeforeIdx) { const above = insertAt > 0 ? arr[insertAt - 1] : undefined let planLocNext = null - if (below?.planLoc?.phaseKind) { + const belowKind = below?.planLoc?.phaseKind + const aboveKind = above?.planLoc?.phaseKind + + if ( + belowKind === 'parallel' && + (!above || aboveKind === 'whole_group') + ) { + if (aboveKind === 'whole_group') { + planLocNext = { ...above.planLoc } + } else { + planLocNext = defaultPlanLocWholeGroup(0) + } + } else if (belowKind) { planLocNext = { ...below.planLoc } } else if (insertAt === arr.length) { if (!above) { @@ -875,7 +887,6 @@ export function reorderBlockIntoParallelStreamEnd(prev, fromI, phaseOrderIndex, insertAt = phaseIdx[phaseIdx.length - 1] + 1 } - if (fromI < insertAt) insertAt -= 1 insertAt = Math.max(0, Math.min(insertAt, arr.length)) arr.splice(insertAt, 0, { ...moved, planLoc: { ...planLocTemplate } }) return arr