Refactor training phase handling in backend and enhance TrainingUnitSectionsEditor
All checks were successful
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m7s
All checks were successful
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m7s
- Updated the backend logic to ensure strict ordering of phase indices, preventing UNIQUE constraint violations when phases are duplicated. - Enhanced the TrainingUnitSectionsEditor component with new state management for editing phase titles and stream names, improving user interaction. - Implemented conditional rendering for input fields to facilitate inline editing of phase titles and stream names, streamlining the editing process.
This commit is contained in:
parent
2e761161ef
commit
613fedfaff
|
|
@ -1261,9 +1261,9 @@ def _replace_unit_phases(
|
||||||
status_code=400,
|
status_code=400,
|
||||||
detail="phase_kind muss whole_group oder parallel sein",
|
detail="phase_kind muss whole_group oder parallel sein",
|
||||||
)
|
)
|
||||||
p_oix = ph.get("order_index")
|
# Reihenfolge strikt aus der Liste (pi): vermeidet UNIQUE(tu, order_index)-Kollisionen,
|
||||||
if p_oix is None:
|
# wenn der Client dieselbe phase_order_index mehrfach trägt (z. B. nach Zuordnungswechseln).
|
||||||
p_oix = pi
|
p_oix = int(pi)
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO training_unit_phases (training_unit_id, order_index, phase_kind, title, guidance_notes)
|
INSERT INTO training_unit_phases (training_unit_id, order_index, phase_kind, title, guidance_notes)
|
||||||
|
|
@ -1272,7 +1272,7 @@ def _replace_unit_phases(
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
unit_id,
|
unit_id,
|
||||||
int(p_oix),
|
p_oix,
|
||||||
kind,
|
kind,
|
||||||
ph.get("title"),
|
ph.get("title"),
|
||||||
ph.get("guidance_notes"),
|
ph.get("guidance_notes"),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react'
|
import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { GripVertical, Pencil, X } from 'lucide-react'
|
import { GripVertical, Pencil, X } from 'lucide-react'
|
||||||
import CombinationMethodProfileEditor from './CombinationMethodProfileEditor'
|
import CombinationMethodProfileEditor from './CombinationMethodProfileEditor'
|
||||||
import CombinationPlanBracket from './CombinationPlanBracket'
|
import CombinationPlanBracket from './CombinationPlanBracket'
|
||||||
|
|
@ -532,6 +532,13 @@ export default function TrainingUnitSectionsEditor({
|
||||||
const [dropSectionBand, setDropSectionBand] = useState(null)
|
const [dropSectionBand, setDropSectionBand] = useState(null)
|
||||||
/** Aktiver Reiter pro paralleler Phase (phaseOrder → streamOrder). */
|
/** Aktiver Reiter pro paralleler Phase (phaseOrder → streamOrder). */
|
||||||
const [parallelStreamTabByPhase, setParallelStreamTabByPhase] = useState({})
|
const [parallelStreamTabByPhase, setParallelStreamTabByPhase] = useState({})
|
||||||
|
/** `${phaseOrder}:${streamOrder}` während Stream-Name bearbeitet wird */
|
||||||
|
const [streamNameEditKey, setStreamNameEditKey] = useState(null)
|
||||||
|
const [streamNameDraft, setStreamNameDraft] = useState('')
|
||||||
|
const [phaseTitleEditPo, setPhaseTitleEditPo] = useState(null)
|
||||||
|
const [phaseTitleDraft, setPhaseTitleDraft] = useState('')
|
||||||
|
const skipStreamNameBlurSave = useRef(false)
|
||||||
|
const skipPhaseTitleBlurSave = useRef(false)
|
||||||
/** { slot: number, beforeIdx: number } */
|
/** { slot: number, beforeIdx: number } */
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -1054,19 +1061,69 @@ export default function TrainingUnitSectionsEditor({
|
||||||
>
|
>
|
||||||
Phase
|
Phase
|
||||||
</label>
|
</label>
|
||||||
<input
|
{(() => {
|
||||||
className="form-input"
|
const hi = firstSectionIndexByParallelPhase.get(parallelPhaseOrder)
|
||||||
style={{ flex: '2 1 160px', maxWidth: '280px', marginBottom: 0 }}
|
const phaseTitleStr =
|
||||||
value={
|
hi != null && list[hi]?.planLoc?.phaseTitle != null
|
||||||
(() => {
|
? String(list[hi].planLoc.phaseTitle)
|
||||||
const hi = firstSectionIndexByParallelPhase.get(parallelPhaseOrder)
|
: ''
|
||||||
const t = hi != null ? list[hi]?.planLoc?.phaseTitle : null
|
const editingPhase = phaseTitleEditPo === parallelPhaseOrder
|
||||||
return t != null ? String(t) : ''
|
return editingPhase ? (
|
||||||
})()
|
<input
|
||||||
}
|
className="form-input"
|
||||||
onChange={(e) => updateParallelPhaseTitleAll(parallelPhaseOrder, e.target.value)}
|
style={{ flex: '2 1 200px', maxWidth: '320px', marginBottom: 0 }}
|
||||||
placeholder={`Bezeichnung (z. B. Drill runden · Phase ${parallelPhaseOrder})`}
|
autoFocus
|
||||||
/>
|
value={phaseTitleDraft}
|
||||||
|
onChange={(e) => setPhaseTitleDraft(e.target.value)}
|
||||||
|
onBlur={() => {
|
||||||
|
if (!skipPhaseTitleBlurSave.current) {
|
||||||
|
updateParallelPhaseTitleAll(parallelPhaseOrder, phaseTitleDraft)
|
||||||
|
}
|
||||||
|
skipPhaseTitleBlurSave.current = false
|
||||||
|
setPhaseTitleEditPo(null)
|
||||||
|
}}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') e.currentTarget.blur()
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
skipPhaseTitleBlurSave.current = true
|
||||||
|
setPhaseTitleEditPo(null)
|
||||||
|
e.currentTarget.blur()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder="Bezeichnung der Phase (z. B. Drill-Runde)"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
flex: '2 1 200px',
|
||||||
|
maxWidth: '320px',
|
||||||
|
fontSize: '0.86rem',
|
||||||
|
fontWeight: 600,
|
||||||
|
color: 'var(--text1)',
|
||||||
|
lineHeight: 1.35,
|
||||||
|
padding: '6px 4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(phaseTitleStr || '').trim() ||
|
||||||
|
`Phase ${parallelPhaseOrder} · Namen per Stift bearbeiten`}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="tu-icon-btn"
|
||||||
|
style={{ padding: '6px', color: 'var(--text2)' }}
|
||||||
|
aria-label="Phasen-Bezeichnung bearbeiten"
|
||||||
|
title="Namen bearbeiten"
|
||||||
|
onClick={() => {
|
||||||
|
setPhaseTitleEditPo(parallelPhaseOrder)
|
||||||
|
setPhaseTitleDraft(phaseTitleStr)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pencil size={16} strokeWidth={2} aria-hidden />
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
})()}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
|
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
|
||||||
|
|
@ -1105,46 +1162,104 @@ export default function TrainingUnitSectionsEditor({
|
||||||
const si = sectionIndicesForParallelStream(list, parallelPhaseOrder, so)
|
const si = sectionIndicesForParallelStream(list, parallelPhaseOrder, so)
|
||||||
const titleSource = si.length ? list[si[0]]?.planLoc?.streamTitle : null
|
const titleSource = si.length ? list[si[0]]?.planLoc?.streamTitle : null
|
||||||
const streamName = titleSource != null ? String(titleSource) : ''
|
const streamName = titleSource != null ? String(titleSource) : ''
|
||||||
|
const editKey = `${parallelPhaseOrder}:${so}`
|
||||||
|
const editingStream = streamNameEditKey === editKey
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`p${parallelPhaseOrder}-chip-s${so}`}
|
key={`p${parallelPhaseOrder}-chip-s${so}`}
|
||||||
role="tab"
|
|
||||||
aria-selected={sel}
|
|
||||||
className={sel ? 'tu-stream-chip tu-stream-chip--active' : 'tu-stream-chip'}
|
|
||||||
style={{
|
style={{
|
||||||
display: 'inline-flex',
|
display: 'inline-flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
gap: '6px',
|
gap: '4px',
|
||||||
padding: '4px 6px 4px 8px',
|
padding: '4px 6px 4px 8px',
|
||||||
borderRadius: '999px',
|
borderRadius: '999px',
|
||||||
cursor: 'pointer',
|
|
||||||
border: sel ? `2px solid ${pv.border}` : `1px solid ${pv.border}`,
|
border: sel ? `2px solid ${pv.border}` : `1px solid ${pv.border}`,
|
||||||
background: sel ? pv.tabBgActive : pv.tabBg,
|
background: sel ? pv.tabBgActive : pv.tabBg,
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
}}
|
}}
|
||||||
onClick={() =>
|
|
||||||
setParallelStreamTabByPhase((prev) => ({ ...prev, [parallelPhaseOrder]: so }))
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<input
|
{editingStream ? (
|
||||||
className="form-input"
|
<input
|
||||||
|
className="form-input"
|
||||||
|
autoFocus
|
||||||
|
style={{
|
||||||
|
minWidth: '7rem',
|
||||||
|
maxWidth: '12rem',
|
||||||
|
margin: 0,
|
||||||
|
padding: '4px 8px',
|
||||||
|
fontSize: '0.8rem',
|
||||||
|
borderRadius: '8px',
|
||||||
|
}}
|
||||||
|
value={streamNameDraft}
|
||||||
|
onChange={(e) => setStreamNameDraft(e.target.value)}
|
||||||
|
onBlur={() => {
|
||||||
|
if (!skipStreamNameBlurSave.current) {
|
||||||
|
updateParallelStreamTitleAll(parallelPhaseOrder, so, streamNameDraft)
|
||||||
|
}
|
||||||
|
skipStreamNameBlurSave.current = false
|
||||||
|
setStreamNameEditKey(null)
|
||||||
|
}}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') e.currentTarget.blur()
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
skipStreamNameBlurSave.current = true
|
||||||
|
setStreamNameEditKey(null)
|
||||||
|
e.currentTarget.blur()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
placeholder={`Gruppe ${so + 1}`}
|
||||||
|
aria-label={`Name Gruppe ${so + 1}`}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="tab"
|
||||||
|
aria-selected={sel}
|
||||||
|
style={{
|
||||||
|
flex: '1 1 auto',
|
||||||
|
minWidth: '5.5rem',
|
||||||
|
maxWidth: '12rem',
|
||||||
|
margin: 0,
|
||||||
|
padding: '6px 10px',
|
||||||
|
fontSize: '0.85rem',
|
||||||
|
fontWeight: sel ? 600 : 500,
|
||||||
|
border: 'none',
|
||||||
|
background: 'transparent',
|
||||||
|
color: 'var(--text1)',
|
||||||
|
textAlign: 'left',
|
||||||
|
cursor: 'pointer',
|
||||||
|
borderRadius: '8px',
|
||||||
|
}}
|
||||||
|
onClick={() =>
|
||||||
|
setParallelStreamTabByPhase((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[parallelPhaseOrder]: so,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{(streamName || '').trim() || `Gruppe ${so + 1}`}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="tu-icon-btn"
|
||||||
style={{
|
style={{
|
||||||
minWidth: '5.5rem',
|
flex: '0 0 auto',
|
||||||
maxWidth: '11rem',
|
padding: '4px',
|
||||||
margin: 0,
|
color: 'var(--text2)',
|
||||||
padding: '4px 8px',
|
|
||||||
fontSize: '0.8rem',
|
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
flex: '1 1 auto',
|
|
||||||
}}
|
}}
|
||||||
value={streamName}
|
title="Gruppennamen bearbeiten"
|
||||||
onChange={(e) =>
|
aria-label="Gruppennamen bearbeiten"
|
||||||
updateParallelStreamTitleAll(parallelPhaseOrder, so, e.target.value)
|
onClick={(e) => {
|
||||||
}
|
e.stopPropagation()
|
||||||
onClick={(e) => e.stopPropagation()}
|
setStreamNameEditKey(editKey)
|
||||||
placeholder={`Gruppe ${so + 1}`}
|
setStreamNameDraft(streamName)
|
||||||
aria-label={`Name Stream ${so + 1}`}
|
}}
|
||||||
/>
|
>
|
||||||
|
<Pencil size={15} strokeWidth={2} aria-hidden />
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="tu-icon-btn"
|
className="tu-icon-btn"
|
||||||
|
|
@ -1871,8 +1986,17 @@ export default function TrainingUnitSectionsEditor({
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
|
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
|
||||||
onClick={addParallelPhaseTwoStreams}
|
onClick={addParallelPhaseTwoStreams}
|
||||||
|
disabled={
|
||||||
|
list.length > 0 &&
|
||||||
|
list[list.length - 1]?.planLoc?.phaseKind === 'parallel'
|
||||||
|
}
|
||||||
|
title={
|
||||||
|
list.length > 0 && list[list.length - 1]?.planLoc?.phaseKind === 'parallel'
|
||||||
|
? 'Splitten direkt nach einem parallelen Block ist un\u00fcblich. Zuerst eine Ganzgruppen-Phase oder einen Ganzgruppen-Abschnitt anf\u00fcgen, dann erneut splitten.'
|
||||||
|
: 'Zwei parallele Gruppen mit je einem Abschnitt anlegen'
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Zwei Gruppen parallel
|
Gruppen splitten
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user