Implement Framework Import Modal with Enhanced Filtering and Styling
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 36s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m27s
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 36s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m27s
- Introduced a new modal for importing training framework sessions, featuring a backdrop and panel for improved user experience. - Added comprehensive filtering options for focus areas, training types, and target groups, utilizing a structured filter state. - Enhanced session duration handling with distinct duration collection and display, improving clarity in program selection. - Updated utility functions to support new filtering capabilities and session duration management, ensuring a cohesive user interface.
This commit is contained in:
1 parent
9353909fda
commit
9c3494a7ea
4 files changed
+806
-212
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { formatSessionDurationRange } from './trainingDurationUtils'
|
||||
import { formatDurationDisplay, formatSessionDurationRange } from './trainingDurationUtils'
|
||||
|
||||
export function frameworkSessionDurationLabel(row) {
|
||||
return formatSessionDurationRange(row?.session_duration_min, row?.session_duration_max, {
|
||||
@@ -21,28 +21,129 @@ function parseIdList(raw) {
|
||||
return []
|
||||
}
|
||||
|
||||
function rowMatchesDuration(row, targetMin, toleranceMin = 10) {
|
||||
if (targetMin == null || targetMin === '' || Number.isNaN(Number(targetMin))) return true
|
||||
const t = Number(targetMin)
|
||||
/** Eindeutige Session-Dauern (Minuten) aus allen Rahmen in der Liste. */
|
||||
export function collectDistinctSessionDurationsMinutes(rows) {
|
||||
const set = new Set()
|
||||
for (const r of rows || []) {
|
||||
const lo = r.session_duration_min
|
||||
const hi = r.session_duration_max
|
||||
if (lo != null && lo !== '' && Number.isFinite(Number(lo))) set.add(Number(lo))
|
||||
if (hi != null && hi !== '' && Number.isFinite(Number(hi))) set.add(Number(hi))
|
||||
}
|
||||
return [...set].sort((a, b) => a - b)
|
||||
}
|
||||
|
||||
function programDurationBounds(row) {
|
||||
const lo = row.session_duration_min != null ? Number(row.session_duration_min) : null
|
||||
const hi = row.session_duration_max != null ? Number(row.session_duration_max) : null
|
||||
if (lo == null && hi == null) return true
|
||||
if (lo != null && hi != null) {
|
||||
return t >= lo - toleranceMin && t <= hi + toleranceMin
|
||||
if (lo != null && Number.isFinite(lo) && lo > 0) {
|
||||
const hiEff = hi != null && Number.isFinite(hi) && hi > 0 ? hi : lo
|
||||
return { lo, hi: hiEff }
|
||||
}
|
||||
const single = lo ?? hi
|
||||
return single != null && Math.abs(single - t) <= toleranceMin
|
||||
if (hi != null && Number.isFinite(hi) && hi > 0) {
|
||||
return { lo: hi, hi }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Überlappung Programm-Session-Spanne mit Filter-Spanne (Minuten). */
|
||||
function rowMatchesDurationRange(row, fromMin, toMin) {
|
||||
const hasFrom = fromMin != null && fromMin !== '' && !Number.isNaN(Number(fromMin))
|
||||
const hasTo = toMin != null && toMin !== '' && !Number.isNaN(Number(toMin))
|
||||
if (!hasFrom && !hasTo) return true
|
||||
|
||||
const bounds = programDurationBounds(row)
|
||||
if (!bounds) return false
|
||||
|
||||
const fLo = hasFrom ? Number(fromMin) : bounds.lo
|
||||
const fHi = hasTo ? Number(toMin) : hasFrom ? Number(fromMin) : bounds.hi
|
||||
const filterLo = Math.min(fLo, fHi)
|
||||
const filterHi = Math.max(fLo, fHi)
|
||||
|
||||
return bounds.lo <= filterHi && bounds.hi >= filterLo
|
||||
}
|
||||
|
||||
function rowMatchesDurationPreset(row, presetMin, toleranceMin = 10) {
|
||||
if (presetMin == null || presetMin === '' || Number.isNaN(Number(presetMin))) return true
|
||||
const t = Number(presetMin)
|
||||
const bounds = programDurationBounds(row)
|
||||
if (!bounds) return false
|
||||
return t >= bounds.lo - toleranceMin && t <= bounds.hi + toleranceMin
|
||||
}
|
||||
|
||||
export const EMPTY_FRAMEWORK_IMPORT_FILTERS = {
|
||||
query: '',
|
||||
focusAreaIds: [],
|
||||
trainingTypeIds: [],
|
||||
targetGroupIds: [],
|
||||
durationMode: 'any',
|
||||
durationRangeFrom: '',
|
||||
durationRangeTo: '',
|
||||
durationPresetMin: null,
|
||||
}
|
||||
|
||||
export function hasActiveFrameworkImportFilters(filters = {}) {
|
||||
const f = { ...EMPTY_FRAMEWORK_IMPORT_FILTERS, ...filters }
|
||||
if ((f.query || '').trim()) return true
|
||||
if ((f.focusAreaIds || []).length) return true
|
||||
if ((f.trainingTypeIds || []).length) return true
|
||||
if ((f.targetGroupIds || []).length) return true
|
||||
if (f.durationMode === 'range') {
|
||||
if (String(f.durationRangeFrom || '').trim() !== '') return true
|
||||
if (String(f.durationRangeTo || '').trim() !== '') return true
|
||||
}
|
||||
if (f.durationMode === 'preset' && f.durationPresetMin != null) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Kurzbeschreibung aktiver Filter (für Zusammenfassung außerhalb des Panels).
|
||||
*/
|
||||
export function summarizeFrameworkImportFilters(filters = {}, catalogs = {}) {
|
||||
const f = { ...EMPTY_FRAMEWORK_IMPORT_FILTERS, ...filters }
|
||||
const parts = []
|
||||
const q = (f.query || '').trim()
|
||||
if (q) parts.push(`Suche: „${q}"`)
|
||||
|
||||
const nameById = (list, id) => list?.find((x) => String(x.id) === String(id))?.name || id
|
||||
|
||||
if ((f.focusAreaIds || []).length) {
|
||||
const names = f.focusAreaIds.map((id) => nameById(catalogs.focusAreas, id))
|
||||
parts.push(`Fokus: ${names.join(', ')}`)
|
||||
}
|
||||
if ((f.trainingTypeIds || []).length) {
|
||||
const names = f.trainingTypeIds.map((id) => nameById(catalogs.trainingTypes, id))
|
||||
parts.push(`Trainingsart: ${names.join(', ')}`)
|
||||
}
|
||||
if ((f.targetGroupIds || []).length) {
|
||||
const names = f.targetGroupIds.map((id) => nameById(catalogs.targetGroups, id))
|
||||
parts.push(`Zielgruppe: ${names.join(', ')}`)
|
||||
}
|
||||
|
||||
if (f.durationMode === 'range') {
|
||||
const a = String(f.durationRangeFrom || '').trim()
|
||||
const b = String(f.durationRangeTo || '').trim()
|
||||
if (a || b) {
|
||||
const fromLbl = a ? formatDurationDisplay(Number(a), { empty: a }) : '—'
|
||||
const toLbl = b ? formatDurationDisplay(Number(b), { empty: b }) : '—'
|
||||
parts.push(`Dauer: ${fromLbl} – ${toLbl}`)
|
||||
}
|
||||
} else if (f.durationMode === 'preset' && f.durationPresetMin != null) {
|
||||
parts.push(`Dauer: ${formatDurationDisplay(f.durationPresetMin)}`)
|
||||
}
|
||||
|
||||
return parts
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-Filter für Rahmenprogramm-Auswahl (Liste / Import-Dialog).
|
||||
*/
|
||||
export function filterFrameworkPrograms(rows, filters = {}) {
|
||||
const q = (filters.query || '').trim().toLowerCase()
|
||||
const focusIds = new Set((filters.focusAreaIds || []).map(String))
|
||||
const typeIds = new Set((filters.trainingTypeIds || []).map(String))
|
||||
const tgIds = new Set((filters.targetGroupIds || []).map(String))
|
||||
const durationTarget = filters.durationTargetMin
|
||||
const f = { ...EMPTY_FRAMEWORK_IMPORT_FILTERS, ...filters }
|
||||
const q = (f.query || '').trim().toLowerCase()
|
||||
const focusIds = new Set((f.focusAreaIds || []).map(String))
|
||||
const typeIds = new Set((f.trainingTypeIds || []).map(String))
|
||||
const tgIds = new Set((f.targetGroupIds || []).map(String))
|
||||
|
||||
return (rows || []).filter((r) => {
|
||||
if (q) {
|
||||
@@ -74,7 +175,12 @@ export function filterFrameworkPrograms(rows, filters = {}) {
|
||||
if (!tg.some((id) => tgIds.has(id))) return false
|
||||
}
|
||||
|
||||
if (!rowMatchesDuration(r, durationTarget)) return false
|
||||
if (f.durationMode === 'range') {
|
||||
if (!rowMatchesDurationRange(r, f.durationRangeFrom, f.durationRangeTo)) return false
|
||||
} else if (f.durationMode === 'preset') {
|
||||
if (!rowMatchesDurationPreset(r, f.durationPresetMin)) return false
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
collectDistinctSessionDurationsMinutes,
|
||||
filterFrameworkPrograms,
|
||||
hasActiveFrameworkImportFilters,
|
||||
} from './frameworkProgramListHelpers.js'
|
||||
|
||||
describe('frameworkProgramListHelpers', () => {
|
||||
const rows = [
|
||||
{ id: 1, title: 'A', session_duration_min: 60, session_duration_max: 60, focus_area_ids: [1] },
|
||||
{ id: 2, title: 'B', session_duration_min: 90, session_duration_max: 120, focus_area_ids: [2] },
|
||||
{ id: 3, title: 'C', session_duration_min: null, session_duration_max: null },
|
||||
]
|
||||
|
||||
it('collectDistinctSessionDurationsMinutes', () => {
|
||||
expect(collectDistinctSessionDurationsMinutes(rows)).toEqual([60, 90, 120])
|
||||
})
|
||||
|
||||
it('filterFrameworkPrograms duration preset', () => {
|
||||
const out = filterFrameworkPrograms(rows, { durationMode: 'preset', durationPresetMin: 90 })
|
||||
expect(out.map((r) => r.id)).toEqual([2])
|
||||
})
|
||||
|
||||
it('filterFrameworkPrograms duration range overlap', () => {
|
||||
const out = filterFrameworkPrograms(rows, {
|
||||
durationMode: 'range',
|
||||
durationRangeFrom: '75',
|
||||
durationRangeTo: '100',
|
||||
})
|
||||
expect(out.map((r) => r.id)).toEqual([2])
|
||||
})
|
||||
|
||||
it('hasActiveFrameworkImportFilters', () => {
|
||||
expect(hasActiveFrameworkImportFilters({})).toBe(false)
|
||||
expect(hasActiveFrameworkImportFilters({ query: 'x' })).toBe(true)
|
||||
expect(hasActiveFrameworkImportFilters({ durationMode: 'preset', durationPresetMin: 60 })).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user