feat(training-units): enhance section editing with insert functionality
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Successful in 56s
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Successful in 56s
- Added new CSS styles for insert slots and buttons to improve UI for adding items between sections. - Implemented functionality in the TrainingUnitSectionsEditor to allow users to insert notes and exercises at specified positions within sections. - Updated the TrainingFrameworkProgramEditPage to support the new insert functionality, ensuring seamless integration with existing features. - Enhanced state management to handle insert positions effectively, improving user experience during section editing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
e41908af73
commit
bfaf532ab2
4 files changed
+338
-66
No files matched your search
@@ -609,6 +609,7 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
<TrainingUnitSectionsEditor
|
||||
heading={`Ablauf · Session ${si + 1}`}
|
||||
sections={slot.sections}
|
||||
betweenInsertMenus={false}
|
||||
showExecutionExtras={false}
|
||||
wideExerciseGrid
|
||||
slotIndex={si}
|
||||
@@ -628,11 +629,15 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
),
|
||||
}))
|
||||
}}
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex }) =>
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex, insertBeforeIndex }) =>
|
||||
setSectionPickerCtx({
|
||||
slotIdx: si,
|
||||
sectionIndex,
|
||||
itemIndex: typeof itemIndex === 'number' ? itemIndex : undefined,
|
||||
insertBeforeIndex:
|
||||
typeof insertBeforeIndex === 'number' && Number.isFinite(insertBeforeIndex)
|
||||
? insertBeforeIndex
|
||||
: undefined,
|
||||
})
|
||||
}
|
||||
onPeekExercise={(id, variantId) =>
|
||||
@@ -1096,7 +1101,7 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
if (row) rows.push(row)
|
||||
}
|
||||
if (!rows.length) return
|
||||
const { slotIdx, sectionIndex: sIdx, itemIndex: iIdx } = sectionPickerCtx
|
||||
const { slotIdx, sectionIndex: sIdx, itemIndex: iIdx, insertBeforeIndex } = sectionPickerCtx
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((sl, ii) => {
|
||||
@@ -1121,7 +1126,13 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
if (tail.length) items.splice(iIdx + 1, 0, ...tail)
|
||||
return { ...sec, items }
|
||||
}
|
||||
return { ...sec, items: [...items, ...rows] }
|
||||
const rawAt =
|
||||
typeof insertBeforeIndex === 'number' && Number.isFinite(insertBeforeIndex)
|
||||
? insertBeforeIndex
|
||||
: items.length
|
||||
const at = Math.max(0, Math.min(rawAt, items.length))
|
||||
items.splice(at, 0, ...rows)
|
||||
return { ...sec, items }
|
||||
}),
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -150,7 +150,7 @@ function TrainingPlanningPage() {
|
||||
const [moduleApplyList, setModuleApplyList] = useState([])
|
||||
const [moduleApplyModuleId, setModuleApplyModuleId] = useState('')
|
||||
const [moduleApplySectionIx, setModuleApplySectionIx] = useState(0)
|
||||
const [moduleApplyInsertSlot, setModuleApplyInsertSlot] = useState('__end__')
|
||||
const [moduleApplyInsertSlot, setModuleApplyInsertSlot] = useState('before:0')
|
||||
const [moduleApplyErr, setModuleApplyErr] = useState('')
|
||||
|
||||
const [startDate, setStartDate] = useState(today)
|
||||
@@ -684,10 +684,27 @@ function TrainingPlanningPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const openModuleApplyModal = useCallback(async () => {
|
||||
const openModuleApplyModal = useCallback(async (placement) => {
|
||||
setModuleApplyErr('')
|
||||
setModuleApplySectionIx(0)
|
||||
setModuleApplyInsertSlot('__end__')
|
||||
const secs = planningFormRef.current?.sections ?? []
|
||||
let secIx = 0
|
||||
let before = 0
|
||||
if (secs.length) {
|
||||
if (placement && typeof placement.sectionIndex === 'number') {
|
||||
secIx = Math.min(Math.max(0, placement.sectionIndex), secs.length - 1)
|
||||
const items = Array.isArray(secs[secIx]?.items) ? secs[secIx].items : []
|
||||
const cap = items.length
|
||||
if (typeof placement.insertBeforeIndex === 'number' && Number.isFinite(placement.insertBeforeIndex)) {
|
||||
before = Math.min(Math.max(0, placement.insertBeforeIndex), cap)
|
||||
} else before = cap
|
||||
} else {
|
||||
const items = Array.isArray(secs[0]?.items) ? secs[0].items : []
|
||||
before = items.length
|
||||
secIx = 0
|
||||
}
|
||||
}
|
||||
setModuleApplySectionIx(secIx)
|
||||
setModuleApplyInsertSlot(`before:${before}`)
|
||||
setModuleApplyOpen(true)
|
||||
try {
|
||||
const list = await api.listTrainingModules()
|
||||
@@ -716,13 +733,13 @@ function TrainingPlanningPage() {
|
||||
}
|
||||
if (secIx < 0 || secIx >= baseSections.length) secIx = 0
|
||||
|
||||
let insertBefore = null
|
||||
if (moduleApplyInsertSlot === '__end__') insertBefore = 'end'
|
||||
else if (moduleApplyInsertSlot === '__start__') insertBefore = 'start'
|
||||
else if (typeof moduleApplyInsertSlot === 'string' && moduleApplyInsertSlot.startsWith('before:')) {
|
||||
const secItems = Array.isArray(baseSections[secIx]?.items) ? baseSections[secIx].items : []
|
||||
const itemCap = secItems.length
|
||||
let insertBefore = itemCap
|
||||
if (typeof moduleApplyInsertSlot === 'string' && moduleApplyInsertSlot.startsWith('before:')) {
|
||||
const zi = parseInt(moduleApplyInsertSlot.slice('before:'.length), 10)
|
||||
insertBefore = Number.isFinite(zi) ? zi : 'end'
|
||||
} else insertBefore = 'end'
|
||||
if (Number.isFinite(zi)) insertBefore = Math.min(Math.max(0, zi), itemCap)
|
||||
}
|
||||
|
||||
setModuleApplyBusy(true)
|
||||
setModuleApplyErr('')
|
||||
@@ -742,7 +759,7 @@ function TrainingPlanningPage() {
|
||||
} finally {
|
||||
setModuleApplyBusy(false)
|
||||
}
|
||||
}, [moduleApplyModuleId, moduleApplySectionIx, moduleApplyInsertSlot, formData.sections])
|
||||
}, [moduleApplyModuleId, moduleApplySectionIx, moduleApplyInsertSlot])
|
||||
|
||||
const handleTakeLead = async (unit) => {
|
||||
if (!user?.id) return
|
||||
@@ -1955,8 +1972,11 @@ function TrainingPlanningPage() {
|
||||
className="form-input"
|
||||
value={String(moduleApplySectionIx)}
|
||||
onChange={(e) => {
|
||||
setModuleApplySectionIx(parseInt(e.target.value, 10))
|
||||
setModuleApplyInsertSlot('__end__')
|
||||
const newIx = parseInt(e.target.value, 10)
|
||||
setModuleApplySectionIx(newIx)
|
||||
const secsNow = planningFormRef.current?.sections ?? []
|
||||
const len = Array.isArray(secsNow[newIx]?.items) ? secsNow[newIx].items.length : 0
|
||||
setModuleApplyInsertSlot(`before:${len}`)
|
||||
}}
|
||||
disabled={moduleApplyBusy || !formData.sections?.length}
|
||||
>
|
||||
@@ -1976,8 +1996,10 @@ function TrainingPlanningPage() {
|
||||
onChange={(e) => setModuleApplyInsertSlot(e.target.value)}
|
||||
disabled={moduleApplyBusy || !(formData.sections?.length > 0)}
|
||||
>
|
||||
<option value="__end__">Ans Ende einfügen (nach allen Einträgen)</option>
|
||||
<option value="__start__">An den Anfang (vor dem ersten Eintrag)</option>
|
||||
<option value={`before:${moduleApplyTargetItems.length}`}>
|
||||
Ans Ende einfügen (nach allen Einträgen)
|
||||
</option>
|
||||
<option value="before:0">An den Anfang (vor dem ersten Eintrag)</option>
|
||||
{moduleApplyTargetItems.map((row, xi) => {
|
||||
const labelPart =
|
||||
row.item_type === 'note'
|
||||
@@ -2526,14 +2548,6 @@ function TrainingPlanningPage() {
|
||||
<button type="button" className="btn btn-secondary" onClick={handleSaveAsTemplate}>
|
||||
Vorlage aus Aufbau speichern
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
onClick={openModuleApplyModal}
|
||||
title="Modulpositionen hier einfügen (Kopie, auch ohne zwischengespeicherte Einheit)"
|
||||
>
|
||||
Modul einfügen…
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
sections={formData.sections}
|
||||
@@ -2544,10 +2558,17 @@ function TrainingPlanningPage() {
|
||||
sections: updater(prev.sections),
|
||||
}))
|
||||
}
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex }) => {
|
||||
onRequestTrainingModulePick={(ctx) => {
|
||||
void openModuleApplyModal(ctx)
|
||||
}}
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex, insertBeforeIndex }) => {
|
||||
setExercisePickerTarget({
|
||||
sIdx: sectionIndex,
|
||||
iIdx: typeof itemIndex === 'number' ? itemIndex : undefined,
|
||||
insertBeforeIndex:
|
||||
typeof insertBeforeIndex === 'number' && Number.isFinite(insertBeforeIndex)
|
||||
? insertBeforeIndex
|
||||
: undefined,
|
||||
})
|
||||
setExercisePickerOpen(true)
|
||||
}}
|
||||
@@ -2700,7 +2721,7 @@ function TrainingPlanningPage() {
|
||||
if (row) rows.push(row)
|
||||
}
|
||||
if (!rows.length) return
|
||||
const { sIdx, iIdx } = exercisePickerTarget
|
||||
const { sIdx, iIdx, insertBeforeIndex } = exercisePickerTarget
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
sections: prev.sections.map((s, si) => {
|
||||
@@ -2720,7 +2741,13 @@ function TrainingPlanningPage() {
|
||||
if (tail.length) items.splice(iIdx + 1, 0, ...tail)
|
||||
return { ...s, items }
|
||||
}
|
||||
return { ...s, items: [...items, ...rows] }
|
||||
const rawAt =
|
||||
typeof insertBeforeIndex === 'number' && Number.isFinite(insertBeforeIndex)
|
||||
? insertBeforeIndex
|
||||
: items.length
|
||||
const at = Math.max(0, Math.min(rawAt, items.length))
|
||||
items.splice(at, 0, ...rows)
|
||||
return { ...s, items }
|
||||
}),
|
||||
}))
|
||||
setExercisePickerOpen(false)
|
||||
|
||||
Reference in new issue
Block a user