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

- 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:
LarsandClaude Sonnet 4.6 committed 2026-05-12 22:05:22 +02:00
1 parent e41908af73
commit bfaf532ab2
4 files changed
+338 -66

No files matched your search

@@ -10,6 +10,9 @@ import {
const DND_TU_ITEM = 'application/x-shinkan-training-unit-item'
const DND_TU_SECTION = 'application/x-shinkan-training-section-v1'
/** Optische Trennlinie: wird als normale Zwischen-Anmerkung gespeichert (Inhalt nur dieser Marker). */
const SECTION_INSERT_SEPARATOR_BODY = '---'
function normalizedPlanningModuleChainId(raw) {
if (raw == null || raw === '') return null
const n = typeof raw === 'number' ? raw : Number(raw)
@@ -48,6 +51,7 @@ export default function TrainingUnitSectionsEditor({
sections,
onSectionsChange,
onRequestExercisePick,
onRequestTrainingModulePick,
onPeekExercise,
showExecutionExtras = false,
heading = 'Abschnitte & Übungen',
@@ -58,6 +62,8 @@ export default function TrainingUnitSectionsEditor({
enableSectionDragReorder = true,
slotIndex = null,
onMoveSectionsAcrossSlots = null,
/** Dünnes „+“ zwischen Einträge: Popup für Typ (Übung, Modul, …) */
betweenInsertMenus = true,
}) {
const ensure = (prev) =>
prev && prev.length ? prev : [defaultSection()]
@@ -99,16 +105,32 @@ export default function TrainingUnitSectionsEditor({
})
}
const insertItemAt = useCallback(
(sIdx, beforeIx, row) => {
patch((prev) =>
prev.map((s, i) => {
if (i !== sIdx) return s
const items = [...(s.items || [])]
const ix = Math.max(
0,
Math.min(Number(beforeIx) || 0, items.length)
)
items.splice(ix, 0, row)
return { ...s, items }
})
)
},
[patch]
)
const addItem = (sIdx, kind) => {
patch((prev) =>
prev.map((s, i) =>
i !== sIdx
? s
: {
...s,
items: [...(s.items || []), kind === 'note' ? noteRow() : exerciseRow()],
}
)
prev.map((s, i) => {
if (i !== sIdx) return s
const items = [...(s.items || [])]
items.push(kind === 'note' ? noteRow() : exerciseRow())
return { ...s, items }
})
)
}
@@ -149,6 +171,8 @@ export default function TrainingUnitSectionsEditor({
}
const [textEdit, setTextEdit] = useState(null)
/** { sIdx: number, beforeIx: number } – Einfüge-Popup („+“ zwischen Zeilen) */
const [insertChooser, setInsertChooser] = useState(null)
const [draggingPos, setDraggingPos] = useState(null)
const [dropTargetPos, setDropTargetPos] = useState(null)
@@ -164,6 +188,20 @@ export default function TrainingUnitSectionsEditor({
return () => window.removeEventListener('keydown', onKey)
}, [textEdit])
useEffect(() => {
if (!insertChooser) return
const onKey = (e) => {
if (e.key === 'Escape') setInsertChooser(null)
}
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [insertChooser])
const closeInsertChooser = useCallback(() => setInsertChooser(null), [])
const insertSlotKeyPrefix =
slotIndex !== null && slotIndex !== undefined ? `sl${slotIndex}-` : ''
const clearSectionDnD = () => setDropSectionBand(null)
const onSectionDragStart = (e, sIdx) => {
@@ -351,6 +389,29 @@ export default function TrainingUnitSectionsEditor({
setTextEdit(null)
}
const renderBetweenInsertBand = (sIdx, beforeIx, itemCount) => {
const posLabel =
beforeIx === 0
? 'vor dem ersten Eintrag'
: beforeIx >= itemCount
? 'am Ende des Abschnitts'
: `vor Eintrag ${beforeIx + 1}`
return (
<div className="tu-insert-slot">
<button
type="button"
className="tu-insert-slot__btn"
aria-haspopup="dialog"
aria-label={`Inhalt einfügen (${posLabel})`}
title={`Hier einfügen (${posLabel})`}
onClick={() => setInsertChooser({ sIdx, beforeIx })}
>
+
</button>
</div>
)
}
const list = ensure(sections)
return (
@@ -506,6 +567,8 @@ export default function TrainingUnitSectionsEditor({
</p>
)}
{betweenInsertMenus ? renderBetweenInsertBand(sIdx, 0, itemCount) : null}
{(sec.items || []).map((it, iIdx) => {
const dropHere =
enableItemDragReorder &&
@@ -536,10 +599,11 @@ export default function TrainingUnitSectionsEditor({
(curMn != null ? `Modul #${curMn}` : '')
if (it.item_type === 'note') {
const isSepLine = (it.note_body || '').trim() === SECTION_INSERT_SEPARATOR_BODY
const notePv = truncatePreview(it.note_body || '', 260)
const noteHasText = Boolean((it.note_body || '').trim())
const noteHasText = Boolean((it.note_body || '').trim()) && !isSepLine
return (
<Fragment key={`it-${sIdx}-${iIdx}`}>
<Fragment key={`${insertSlotKeyPrefix}sec-${sIdx}-blk-${iIdx}`}>
{showModuleBand ? (
<div
className="tu-planning-module-band"
@@ -549,7 +613,13 @@ export default function TrainingUnitSectionsEditor({
Baustein: {modBandTitle}
</div>
) : null}
<div className={`${rowCommon} tu-item-row--note`} {...dndRowProps}>
<div
className={
`${rowCommon} tu-item-row--note` +
(isSepLine ? ' tu-item-row--separator-note' : '')
}
{...dndRowProps}
>
{enableItemDragReorder ? (
<span
className="tu-row-grip"
@@ -582,19 +652,29 @@ export default function TrainingUnitSectionsEditor({
</button>
</div>
<div className="tu-item-row__body tu-item-row__body--note">
<span className="tu-item-row__meta-label">Zwischen-Anmerkung</span>
<p
className={`tu-item-row__preview tu-item-row__preview--clamp${noteHasText ? '' : ' tu-item-row__preview--empty'}`}
title={noteHasText ? (it.note_body || '').trim() : undefined}
>
{noteHasText ? notePv : '—'}
</p>
<span className="tu-item-row__meta-label">
{isSepLine ? 'Trennung' : 'Zwischen-Anmerkung'}
</span>
{isSepLine ? (
<div
className="tu-item-row__separator-line"
role="separator"
aria-label="Trennlinie im Ablauf"
/>
) : (
<p
className={`tu-item-row__preview tu-item-row__preview--clamp${noteHasText ? '' : ' tu-item-row__preview--empty'}`}
title={noteHasText ? (it.note_body || '').trim() : undefined}
>
{noteHasText ? notePv : '—'}
</p>
)}
</div>
<button
type="button"
className="tu-icon-btn"
title="Zwischen-Anmerkung bearbeiten"
aria-label="Zwischen-Anmerkung bearbeiten"
title={isSepLine ? 'Trennung bearbeiten' : 'Zwischen-Anmerkung bearbeiten'}
aria-label={isSepLine ? 'Trennung bearbeiten' : 'Zwischen-Anmerkung bearbeiten'}
onClick={() =>
setTextEdit({
kind: 'zwischen-note',
@@ -610,12 +690,13 @@ export default function TrainingUnitSectionsEditor({
type="button"
className="tu-item-row__remove"
title="Entfernen"
aria-label="Zwischen-Anmerkung entfernen"
aria-label={isSepLine ? 'Trennung entfernen' : 'Zwischen-Anmerkung entfernen'}
onClick={() => removeItem(sIdx, iIdx)}
>
✗
</button>
</div>
{betweenInsertMenus ? renderBetweenInsertBand(sIdx, iIdx + 1, itemCount) : null}
</Fragment>
)
}
@@ -632,7 +713,7 @@ export default function TrainingUnitSectionsEditor({
: Number(it.exercise_variant_id)
return (
<Fragment key={`it-${sIdx}-${iIdx}`}>
<Fragment key={`${insertSlotKeyPrefix}sec-${sIdx}-blk-${iIdx}`}>
{showModuleBand ? (
<div
className="tu-planning-module-band"
@@ -820,6 +901,7 @@ export default function TrainingUnitSectionsEditor({
</div>
) : null}
</div>
{betweenInsertMenus ? renderBetweenInsertBand(sIdx, iIdx + 1, itemCount) : null}
</Fragment>
)
})}
@@ -837,21 +919,30 @@ export default function TrainingUnitSectionsEditor({
/>
) : null}
<div style={{ marginTop: '0.65rem', display: 'flex', flexWrap: 'wrap', gap: '6px' }}>
<button
type="button"
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
onClick={() => onRequestExercisePick?.({ sectionIndex: sIdx })}
>
+ Übung
</button>
<button
type="button"
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
onClick={() => addItem(sIdx, 'note')}
>
+ Anmerkung
</button>
<div style={{ marginTop: '0.65rem' }}>
{betweenInsertMenus ? (
<p style={{ margin: 0, fontSize: '0.8rem', color: 'var(--text3)', lineHeight: 1.45, maxWidth: '42rem' }}>
Über die +-Zeilen zwischen den Einträgen fügst du an der gewünschten Stelle Inhalte ein. Reihenfolge
weiter per Ziehen oder den Pfeiltasten ändern.
</p>
) : (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '6px' }}>
<button
type="button"
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
onClick={() => onRequestExercisePick?.({ sectionIndex: sIdx })}
>
+ Übung
</button>
<button
type="button"
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
onClick={() => addItem(sIdx, 'note')}
>
+ Anmerkung
</button>
</div>
)}
</div>
</div>
</Fragment>
@@ -889,6 +980,91 @@ export default function TrainingUnitSectionsEditor({
+ Abschnitt hinzufügen
</button>
{insertChooser ? (
<div
className="tu-textedit-backdrop"
role="presentation"
onMouseDown={(e) => {
if (e.target === e.currentTarget) closeInsertChooser()
}}
>
<div
className="tu-textedit-panel"
role="dialog"
aria-modal="true"
aria-labelledby="tu-insert-chooser-title"
onMouseDown={(e) => e.stopPropagation()}
>
<h4 id="tu-insert-chooser-title" className="tu-textedit-title">
An dieser Stelle einfügen
</h4>
<p style={{ margin: '0 0 0.75rem', fontSize: '0.86rem', color: 'var(--text2)', lineHeight: 1.45 }}>
Die neue Zeile erscheint genau hier; Reihenfolge kannst du wie gewohnt per Ziehen oder Pfeilen
ändern.
</p>
<div className="tu-insert-chooser-actions">
<button
type="button"
className="btn btn-primary tu-insert-chooser-actions__full"
onClick={() => {
const { sIdx, beforeIx } = insertChooser
closeInsertChooser()
onRequestExercisePick?.({
sectionIndex: sIdx,
insertBeforeIndex: beforeIx,
})
}}
>
Übung auswählen …
</button>
{onRequestTrainingModulePick ? (
<button
type="button"
className="btn btn-secondary tu-insert-chooser-actions__full"
onClick={() => {
const ctx = { ...insertChooser }
closeInsertChooser()
onRequestTrainingModulePick({
sectionIndex: ctx.sIdx,
insertBeforeIndex: ctx.beforeIx,
})
}}
>
Trainingsmodul …
</button>
) : null}
<button
type="button"
className="btn btn-secondary tu-insert-chooser-actions__full"
onClick={() => {
const { sIdx, beforeIx } = insertChooser
insertItemAt(sIdx, beforeIx, noteRow())
closeInsertChooser()
}}
>
Zwischen-Anmerkung
</button>
<button
type="button"
className="btn btn-secondary tu-insert-chooser-actions__full"
onClick={() => {
const { sIdx, beforeIx } = insertChooser
const r = noteRow()
r.note_body = SECTION_INSERT_SEPARATOR_BODY
insertItemAt(sIdx, beforeIx, r)
closeInsertChooser()
}}
>
Trennlinie
</button>
<button type="button" className="btn btn-secondary tu-insert-chooser-actions__full" onClick={closeInsertChooser}>
Abbrechen
</button>
</div>
</div>
</div>
) : null}
{textEdit ? (
<div
className="tu-textedit-backdrop"