Enhance TrainingUnitSectionsEditor with advanced phase management features
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m13s
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m13s
- Introduced new utility functions for managing phase runs, including the ability to swap adjacent phase runs and move phase runs up or down by their order. - Updated the TrainingUnitSectionsEditor to incorporate these new functions, allowing for improved reordering of sections within parallel phases. - Enhanced the moveSection logic to support movement across different phase types, ensuring better user experience when managing sections. - Refactored the reorderBlocksImmutable function to accommodate plan location adjustments during section reordering, improving overall functionality.
This commit is contained in:
1 parent
613fedfaff
commit
a0a0be8bef
2 files changed
+186
-34
No files matched your search
@@ -721,7 +721,7 @@ function stripPlanLoc(sec) {
|
||||
return rest
|
||||
}
|
||||
|
||||
function inheritPlanLocForPhasedSave(sections) {
|
||||
export function inheritPlanLocForPhasedSave(sections) {
|
||||
let prev = {
|
||||
phaseKind: 'whole_group',
|
||||
phaseOrderIndex: 0,
|
||||
@@ -732,7 +732,7 @@ function inheritPlanLocForPhasedSave(sections) {
|
||||
streamNotes: null,
|
||||
streamAssignedTrainerProfileIds: null,
|
||||
}
|
||||
return sections.map((s) => {
|
||||
return (sections || []).map((s) => {
|
||||
if (s?.planLoc && s.planLoc.phaseKind) {
|
||||
prev = { ...s.planLoc }
|
||||
return { ...s, planLoc: prev }
|
||||
@@ -741,6 +741,87 @@ function inheritPlanLocForPhasedSave(sections) {
|
||||
})
|
||||
}
|
||||
|
||||
/** Phasen-„Runs“ in der flachen Abschnittsliste (Reihenfolge wie beim Speichern). */
|
||||
export function phaseRunsFromSections(sections) {
|
||||
const norm = inheritPlanLocForPhasedSave(sections)
|
||||
const runs = []
|
||||
let i = 0
|
||||
while (i < norm.length) {
|
||||
const loc0 = norm[i]?.planLoc
|
||||
if (!loc0?.phaseKind) {
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
const pOi = loc0.phaseOrderIndex ?? 0
|
||||
const pk = loc0.phaseKind === 'parallel' ? 'parallel' : 'whole_group'
|
||||
const start = i
|
||||
while (i < norm.length) {
|
||||
const L = norm[i]?.planLoc
|
||||
if (!L?.phaseKind) break
|
||||
const pk2 = L.phaseKind === 'parallel' ? 'parallel' : 'whole_group'
|
||||
if ((L.phaseOrderIndex ?? 0) !== pOi || pk2 !== pk) break
|
||||
i += 1
|
||||
}
|
||||
runs.push({ phaseKind: pk, phaseOrderIndex: pOi, start, end: i })
|
||||
}
|
||||
return runs
|
||||
}
|
||||
|
||||
/** Vertauscht zwei unmittelbar benachbarte Runs (upperRunIndex = erste der beiden). */
|
||||
export function swapAdjacentPhaseRuns(prev, upperRunIndex) {
|
||||
const runs = phaseRunsFromSections(prev)
|
||||
const a = upperRunIndex
|
||||
const b = upperRunIndex + 1
|
||||
if (a < 0 || b >= runs.length) return prev
|
||||
const rgA = runs[a]
|
||||
const rgB = runs[b]
|
||||
const head = prev.slice(0, rgA.start)
|
||||
const blA = prev.slice(rgA.start, rgA.end)
|
||||
const blB = prev.slice(rgB.start, rgB.end)
|
||||
const tail = prev.slice(rgB.end)
|
||||
return [...head, ...blB, ...blA, ...tail]
|
||||
}
|
||||
|
||||
export function movePhaseRunUpByPhaseOrder(prev, phaseOrderIndex) {
|
||||
const po = Number(phaseOrderIndex) || 0
|
||||
const runs = phaseRunsFromSections(prev)
|
||||
const rIdx = runs.findIndex((r) => r.phaseKind === 'parallel' && r.phaseOrderIndex === po)
|
||||
if (rIdx <= 0) return prev
|
||||
return swapAdjacentPhaseRuns(prev, rIdx - 1)
|
||||
}
|
||||
|
||||
export function movePhaseRunDownByPhaseOrder(prev, phaseOrderIndex) {
|
||||
const po = Number(phaseOrderIndex) || 0
|
||||
const runs = phaseRunsFromSections(prev)
|
||||
const rIdx = runs.findIndex((r) => r.phaseKind === 'parallel' && r.phaseOrderIndex === po)
|
||||
if (rIdx < 0 || rIdx >= runs.length - 1) return prev
|
||||
return swapAdjacentPhaseRuns(prev, rIdx)
|
||||
}
|
||||
|
||||
/**
|
||||
* Abschnitt verschieben und planLoc an der Einfügestelle an Nachbarn anpassen
|
||||
* (z. B. Ganzgruppe in parallelen Stream).
|
||||
*/
|
||||
export function reorderBlocksImmutableWithPlanLoc(prev, fromI, toBeforeIdx) {
|
||||
const arr = [...prev]
|
||||
if (fromI < 0 || fromI >= arr.length) return prev
|
||||
const [moved] = arr.splice(fromI, 1)
|
||||
let insertAt = toBeforeIdx
|
||||
if (fromI < toBeforeIdx) insertAt = toBeforeIdx - 1
|
||||
insertAt = Math.max(0, Math.min(insertAt, arr.length))
|
||||
const below = arr[insertAt]
|
||||
const above = arr[insertAt - 1]
|
||||
const ref = below ?? above
|
||||
let nextMoved = { ...moved }
|
||||
if (ref?.planLoc?.phaseKind) {
|
||||
nextMoved = { ...moved, planLoc: { ...ref.planLoc } }
|
||||
} else {
|
||||
nextMoved = stripPlanLoc(moved)
|
||||
}
|
||||
arr.splice(insertAt, 0, nextMoved)
|
||||
return arr
|
||||
}
|
||||
|
||||
function buildPhasesPayloadFromFlat(sections) {
|
||||
const norm = inheritPlanLocForPhasedSave(sections)
|
||||
const phases = []
|
||||
|
||||
Reference in new issue
Block a user