feat: enhance exercise filtering capabilities with new catalog rules
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 7s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 28s
Test Suite / pytest-backend (pull_request) Successful in 5s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 7s
Test Suite / playwright-tests (pull_request) Failing after 28s
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 7s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 28s
Test Suite / pytest-backend (pull_request) Successful in 5s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 7s
Test Suite / playwright-tests (pull_request) Failing after 28s
- Introduced new filtering options for style directions, training types, and target groups in the exercise list. - Implemented catalog rule picker components to manage inclusion and exclusion of exercise attributes. - Updated utility functions to handle new catalog rules for improved filtering logic. - Enhanced the ExercisesListPage and ExercisePickerModal to support the new filtering features, improving user experience.
This commit is contained in:
1 parent
518918a6e5
commit
b9d27b59b0
7 files changed
+637
-382
No files matched your search
@@ -17,12 +17,15 @@ import { useAuth } from '../context/AuthContext'
|
||||
import { SKILL_LEVEL_OPTIONS } from '../constants/skillLevels'
|
||||
import MultiSelectCombo from '../components/MultiSelectCombo'
|
||||
import ExerciseFocusRulePicker from '../components/ExerciseFocusRulePicker'
|
||||
import CatalogRulePicker from '../components/CatalogRulePicker'
|
||||
import ExerciseProgressionGraphPanel from '../components/ExerciseProgressionGraphPanel'
|
||||
import PageSectionNav from '../components/PageSectionNav'
|
||||
import {
|
||||
INITIAL_EXERCISE_LIST_FILTERS,
|
||||
mergeExerciseListPrefsFromApi,
|
||||
compactExerciseListPrefsPayload,
|
||||
splitMnCatalogRules,
|
||||
splitScalarCatalogRules,
|
||||
} from '../constants/exerciseListFilters'
|
||||
import { sanitizeExerciseRichText, coerceApiNameList } from '../utils/sanitizeHtml'
|
||||
import { canUserRequestExerciseDelete } from '../utils/exercisePermissions'
|
||||
@@ -51,6 +54,22 @@ function statusLabel(s) {
|
||||
return STATUS_LABELS[s] || s || '—'
|
||||
}
|
||||
|
||||
function pushCatalogRuleFilterChips(chips, field, rules, options, topicLabel, setFilters) {
|
||||
;(rules || []).forEach((r) => {
|
||||
const rid = String(r.id ?? r.focus_area_id ?? '')
|
||||
const opt = options.find((o) => String(o.id) === rid)
|
||||
chips.push({
|
||||
key: `${field}-${r.key}`,
|
||||
label: `${topicLabel}: ${r.mode === 'forbid' ? '−' : '+'} ${opt?.label ?? rid}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
[field]: (prev[field] || []).filter((x) => x.key !== r.key),
|
||||
})),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function exerciseFocusNames(ex) {
|
||||
const fromApi = coerceApiNameList(ex.focus_area_names)
|
||||
if (fromApi.length) return fromApi
|
||||
@@ -222,19 +241,7 @@ function ExercisesListPage() {
|
||||
const filterChips = useMemo(() => {
|
||||
const chips = []
|
||||
|
||||
;(filters.focus_rules || []).forEach((r) => {
|
||||
const opt = focusOptions.find((o) => String(o.id) === String(r.focus_area_id))
|
||||
const verb = r.mode === 'forbid' ? 'Fokus ohne' : 'Fokus mit'
|
||||
chips.push({
|
||||
key: `fr-${r.key}`,
|
||||
label: `${verb}: ${opt?.label ?? r.focus_area_id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
focus_rules: prev.focus_rules.filter((x) => x.key !== r.key),
|
||||
})),
|
||||
})
|
||||
})
|
||||
pushCatalogRuleFilterChips(chips, 'focus_rules', filters.focus_rules, focusOptions, 'Fokus', setFilters)
|
||||
|
||||
if (filters.focus_only_without) {
|
||||
chips.push({
|
||||
@@ -256,11 +263,37 @@ function ExercisesListPage() {
|
||||
})),
|
||||
})
|
||||
})
|
||||
|
||||
pushCatalogRuleFilterChips(
|
||||
chips,
|
||||
'style_direction_rules',
|
||||
filters.style_direction_rules,
|
||||
styleOptions,
|
||||
'Stil',
|
||||
setFilters
|
||||
)
|
||||
pushCatalogRuleFilterChips(
|
||||
chips,
|
||||
'training_type_rules',
|
||||
filters.training_type_rules,
|
||||
trainingTypeOptions,
|
||||
'Trainingsstil',
|
||||
setFilters
|
||||
)
|
||||
pushCatalogRuleFilterChips(
|
||||
chips,
|
||||
'target_group_rules',
|
||||
filters.target_group_rules,
|
||||
targetGroupOptions,
|
||||
'Zielgruppe',
|
||||
setFilters
|
||||
)
|
||||
|
||||
;(filters.style_direction_ids || []).forEach((id) => {
|
||||
const opt = styleOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
key: `sd-${id}`,
|
||||
label: `Stil: ${opt?.label ?? id}`,
|
||||
label: `Stil (ODER, älter): ${opt?.label ?? id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
@@ -272,7 +305,7 @@ function ExercisesListPage() {
|
||||
const opt = trainingTypeOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
key: `tt-${id}`,
|
||||
label: `Trainingsstil: ${opt?.label ?? id}`,
|
||||
label: `Trainingsstil (ODER, älter): ${opt?.label ?? id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
@@ -284,7 +317,7 @@ function ExercisesListPage() {
|
||||
const opt = targetGroupOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
key: `tg-${id}`,
|
||||
label: `Zielgruppe: ${opt?.label ?? id}`,
|
||||
label: `Zielgruppe (ODER, älter): ${opt?.label ?? id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
@@ -292,6 +325,7 @@ function ExercisesListPage() {
|
||||
})),
|
||||
})
|
||||
})
|
||||
|
||||
;(filters.skill_ids || []).forEach((id) => {
|
||||
const opt = skillOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
@@ -320,55 +354,15 @@ function ExercisesListPage() {
|
||||
})
|
||||
}
|
||||
|
||||
;(filters.visibility_any || []).forEach((id) => {
|
||||
const opt = visibilityOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
key: `vis-${id}`,
|
||||
label: `Sichtbarkeit: ${opt?.label ?? id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
visibility_any: prev.visibility_any.filter((x) => String(x) !== String(id)),
|
||||
})),
|
||||
})
|
||||
})
|
||||
;(filters.status_any || []).forEach((id) => {
|
||||
const opt = statusOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
key: `st-${id}`,
|
||||
label: `Status: ${opt?.label ?? id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
status_any: prev.status_any.filter((x) => String(x) !== String(id)),
|
||||
})),
|
||||
})
|
||||
})
|
||||
|
||||
;(filters.visibility_exclude_any || []).forEach((id) => {
|
||||
const opt = visibilityOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
key: `vex-${id}`,
|
||||
label: `Sichtbarkeit ausblenden: ${opt?.label ?? id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
visibility_exclude_any: prev.visibility_exclude_any.filter((x) => String(x) !== String(id)),
|
||||
})),
|
||||
})
|
||||
})
|
||||
;(filters.status_exclude_any || []).forEach((id) => {
|
||||
const opt = statusOptions.find((o) => String(o.id) === String(id))
|
||||
chips.push({
|
||||
key: `sex-${id}`,
|
||||
label: `Status ausblenden: ${opt?.label ?? id}`,
|
||||
onRemove: () =>
|
||||
setFilters((prev) => ({
|
||||
...prev,
|
||||
status_exclude_any: prev.status_exclude_any.filter((x) => String(x) !== String(id)),
|
||||
})),
|
||||
})
|
||||
})
|
||||
pushCatalogRuleFilterChips(
|
||||
chips,
|
||||
'visibility_rules',
|
||||
filters.visibility_rules,
|
||||
visibilityOptions,
|
||||
'Sichtbarkeit',
|
||||
setFilters
|
||||
)
|
||||
pushCatalogRuleFilterChips(chips, 'status_rules', filters.status_rules, statusOptions, 'Status', setFilters)
|
||||
|
||||
if (filters.exclude_without_focus) {
|
||||
chips.push({
|
||||
@@ -395,6 +389,7 @@ function ExercisesListPage() {
|
||||
skillOptions,
|
||||
visibilityOptions,
|
||||
statusOptions,
|
||||
setFilters,
|
||||
])
|
||||
|
||||
/** Für Browser-/datalist-Vorschläge (aktuelle Treffer-Titel, begrenzt) */
|
||||
@@ -408,36 +403,44 @@ function ExercisesListPage() {
|
||||
const n = (v) => (v === '' || v == null ? undefined : Number(v))
|
||||
const ids = (arr) =>
|
||||
Array.isArray(arr) && arr.length ? arr.map((x) => Number(x)).filter((x) => !Number.isNaN(x)) : undefined
|
||||
const mustInc = []
|
||||
const mustExc = []
|
||||
for (const r of filters.focus_rules || []) {
|
||||
const id = Number(r.focus_area_id)
|
||||
if (!Number.isFinite(id) || id < 1) continue
|
||||
if (r.mode === 'forbid') mustExc.push(id)
|
||||
else mustInc.push(id)
|
||||
}
|
||||
const uniqNums = (arr) => [...new Set(arr)]
|
||||
if (mustInc.length) q.focus_area_must_include_ids = uniqNums(mustInc)
|
||||
if (mustExc.length) q.focus_area_must_exclude_ids = uniqNums(mustExc)
|
||||
const fMn = splitMnCatalogRules(filters.focus_rules)
|
||||
if (fMn.includeIds.length) q.focus_area_must_include_ids = fMn.includeIds
|
||||
if (fMn.excludeIds.length) q.focus_area_must_exclude_ids = fMn.excludeIds
|
||||
if (filters.focus_only_without) q.focus_only_without_focus_areas = true
|
||||
|
||||
const fa = ids(filters.focus_area_ids)
|
||||
if (fa?.length) q.focus_area_ids = fa
|
||||
const sd = ids(filters.style_direction_ids)
|
||||
if (sd?.length) q.style_direction_ids = sd
|
||||
const tt = ids(filters.training_type_ids)
|
||||
if (tt?.length) q.training_type_ids = tt
|
||||
const tg = ids(filters.target_group_ids)
|
||||
if (tg?.length) q.target_group_ids = tg
|
||||
|
||||
const sdMn = splitMnCatalogRules(filters.style_direction_rules)
|
||||
if (sdMn.includeIds.length) q.style_direction_must_include_ids = sdMn.includeIds
|
||||
if (sdMn.excludeIds.length) q.style_direction_must_exclude_ids = sdMn.excludeIds
|
||||
const sdLegacy = ids(filters.style_direction_ids)
|
||||
if (sdLegacy?.length) q.style_direction_ids = sdLegacy
|
||||
|
||||
const ttMn = splitMnCatalogRules(filters.training_type_rules)
|
||||
if (ttMn.includeIds.length) q.training_type_must_include_ids = ttMn.includeIds
|
||||
if (ttMn.excludeIds.length) q.training_type_must_exclude_ids = ttMn.excludeIds
|
||||
const ttLegacy = ids(filters.training_type_ids)
|
||||
if (ttLegacy?.length) q.training_type_ids = ttLegacy
|
||||
|
||||
const tgMn = splitMnCatalogRules(filters.target_group_rules)
|
||||
if (tgMn.includeIds.length) q.target_group_must_include_ids = tgMn.includeIds
|
||||
if (tgMn.excludeIds.length) q.target_group_must_exclude_ids = tgMn.excludeIds
|
||||
const tgLegacy = ids(filters.target_group_ids)
|
||||
if (tgLegacy?.length) q.target_group_ids = tgLegacy
|
||||
|
||||
const visMn = splitScalarCatalogRules(filters.visibility_rules)
|
||||
if (visMn.includeVals.length) q.visibility_any = visMn.includeVals
|
||||
if (visMn.excludeVals.length) q.visibility_exclude_any = visMn.excludeVals
|
||||
|
||||
const stMn = splitScalarCatalogRules(filters.status_rules)
|
||||
if (stMn.includeVals.length) q.status_any = stMn.includeVals
|
||||
if (stMn.excludeVals.length) q.status_exclude_any = stMn.excludeVals
|
||||
|
||||
const sk = ids(filters.skill_ids)
|
||||
if (sk?.length) q.skill_ids = sk
|
||||
if (filters.skill_min_level) q.skill_min_level = n(filters.skill_min_level)
|
||||
if (filters.skill_max_level) q.skill_max_level = n(filters.skill_max_level)
|
||||
if (filters.visibility_any?.length) q.visibility_any = [...filters.visibility_any]
|
||||
if (filters.status_any?.length) q.status_any = [...filters.status_any]
|
||||
if (filters.visibility_exclude_any?.length)
|
||||
q.visibility_exclude_any = [...filters.visibility_exclude_any]
|
||||
if (filters.status_exclude_any?.length) q.status_exclude_any = [...filters.status_exclude_any]
|
||||
if (filters.exclude_without_focus) q.exclude_without_focus = true
|
||||
if (filters.include_archived) q.include_archived = true
|
||||
if (debouncedSearch) q.search = debouncedSearch
|
||||
@@ -896,7 +899,8 @@ function ExercisesListPage() {
|
||||
<p className="muted" style={{ marginTop: 0, marginBottom: '14px' }}>
|
||||
Zwischen den Bereichen gilt <strong>UND</strong>. Fokusbereiche: mehrere „+ mit“ bedeuten alle müssen
|
||||
gesetzt sein; „− ohne“ schließt Übungen aus, die diesen Fokus zusätzlich haben. Stilrichtung /
|
||||
Trainingsstil / Zielgruppe: mehrere Werte pro Feld mit <strong>ODER</strong>.
|
||||
Trainingsstil / Zielgruppe: mehrere „+“ = alle zutreffend (UND); „−“ verbietet die Zuordnung. Unter
|
||||
„Freigabe“: Sichtbarkeit / Status mit „+“ = eine davon (ODER); „−“ blendet aus.
|
||||
</p>
|
||||
|
||||
<section className="exercise-filter-section">
|
||||
@@ -908,34 +912,34 @@ function ExercisesListPage() {
|
||||
legacyFocusAreaIds={filters.focus_area_ids}
|
||||
onPatch={(patch) => setFilters((prev) => ({ ...prev, ...patch }))}
|
||||
/>
|
||||
<div className="exercise-filters-modal-grid" style={{ marginTop: '14px' }}>
|
||||
<div>
|
||||
<label className="form-label">Stilrichtung</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.style_direction_ids}
|
||||
onChange={(v) => setFilters({ ...filters, style_direction_ids: v })}
|
||||
options={styleOptions}
|
||||
placeholder="Stilrichtung suchen …"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="form-label">Trainingsstil</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.training_type_ids}
|
||||
onChange={(v) => setFilters({ ...filters, training_type_ids: v })}
|
||||
options={trainingTypeOptions}
|
||||
placeholder="Trainingsstil suchen …"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="form-label">Zielgruppe</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.target_group_ids}
|
||||
onChange={(v) => setFilters({ ...filters, target_group_ids: v })}
|
||||
options={targetGroupOptions}
|
||||
placeholder="Zielgruppe suchen …"
|
||||
/>
|
||||
</div>
|
||||
<div className="exercise-filters-modal-grid exercise-filters-modal-grid--catalog" style={{ marginTop: '12px' }}>
|
||||
<CatalogRulePicker
|
||||
label="Stilrichtung"
|
||||
hint="+ alle nötig (UND). − verbietet Zuordnung."
|
||||
options={styleOptions}
|
||||
rules={filters.style_direction_rules}
|
||||
rulesFieldName="style_direction_rules"
|
||||
placeholder="Stil …"
|
||||
onPatch={(patch) => setFilters((prev) => ({ ...prev, ...patch }))}
|
||||
/>
|
||||
<CatalogRulePicker
|
||||
label="Trainingsstil"
|
||||
hint="+ alle nötig (UND). − verbietet Zuordnung."
|
||||
options={trainingTypeOptions}
|
||||
rules={filters.training_type_rules}
|
||||
rulesFieldName="training_type_rules"
|
||||
placeholder="Trainingsstil …"
|
||||
onPatch={(patch) => setFilters((prev) => ({ ...prev, ...patch }))}
|
||||
/>
|
||||
<CatalogRulePicker
|
||||
label="Zielgruppe"
|
||||
hint="+ alle nötig (UND). − verbietet Zuordnung."
|
||||
options={targetGroupOptions}
|
||||
rules={filters.target_group_rules}
|
||||
rulesFieldName="target_group_rules"
|
||||
placeholder="Gruppe …"
|
||||
onPatch={(patch) => setFilters((prev) => ({ ...prev, ...patch }))}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -993,31 +997,11 @@ function ExercisesListPage() {
|
||||
</section>
|
||||
|
||||
<section className="exercise-filter-section">
|
||||
<h4 className="exercise-filter-section-title">Ausblenden</h4>
|
||||
<h4 className="exercise-filter-section-title">Ausblenden / Liste</h4>
|
||||
<p className="muted" style={{ marginTop: 0, marginBottom: '12px', fontSize: '13px' }}>
|
||||
Negativlisten schließen Treffer aus (weitere Felder weiterhin mit UND verknüpft).
|
||||
Sichtbarkeit und Status steuern Sie unter „Freigabe“ mit + und −. Hier nur globale Listen-Optionen.
|
||||
</p>
|
||||
<div className="exercise-filters-modal-grid exercise-filters-modal-grid--two">
|
||||
<div>
|
||||
<label className="form-label">Sichtbarkeit nicht anzeigen</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.visibility_exclude_any}
|
||||
onChange={(v) => setFilters({ ...filters, visibility_exclude_any: v })}
|
||||
options={visibilityOptions}
|
||||
placeholder="z. B. Global ausblenden …"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="form-label">Status nicht anzeigen</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.status_exclude_any}
|
||||
onChange={(v) => setFilters({ ...filters, status_exclude_any: v })}
|
||||
options={statusOptions}
|
||||
placeholder="z. B. Entwurf ausblenden …"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: '14px', display: 'flex', flexDirection: 'column', gap: '12px' }}>
|
||||
<div style={{ marginTop: '6px', display: 'flex', flexDirection: 'column', gap: '12px' }}>
|
||||
<label
|
||||
style={{
|
||||
display: 'flex',
|
||||
@@ -1054,25 +1038,28 @@ function ExercisesListPage() {
|
||||
|
||||
<section className="exercise-filter-section exercise-filter-section--last">
|
||||
<h4 className="exercise-filter-section-title">Freigabe</h4>
|
||||
<div className="exercise-filters-modal-grid exercise-filters-modal-grid--two">
|
||||
<div>
|
||||
<label className="form-label">Sichtbarkeit</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.visibility_any}
|
||||
onChange={(v) => setFilters({ ...filters, visibility_any: v })}
|
||||
options={visibilityOptions}
|
||||
placeholder="Sichtbarkeit wählen …"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="form-label">Status</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.status_any}
|
||||
onChange={(v) => setFilters({ ...filters, status_any: v })}
|
||||
options={statusOptions}
|
||||
placeholder="Status wählen …"
|
||||
/>
|
||||
</div>
|
||||
<p className="muted" style={{ marginTop: 0, marginBottom: '10px', fontSize: '12px' }}>
|
||||
Pro Übung nur ein Wert: mehrere „+“ bedeuten „eine davon“ (ODER). „−“ blendet Werte aus.
|
||||
</p>
|
||||
<div className="exercise-filters-modal-grid exercise-filters-modal-grid--two exercise-filters-modal-grid--catalog">
|
||||
<CatalogRulePicker
|
||||
label="Sichtbarkeit"
|
||||
options={visibilityOptions}
|
||||
rules={filters.visibility_rules}
|
||||
rulesFieldName="visibility_rules"
|
||||
idKind="string"
|
||||
placeholder="Sichtbarkeit …"
|
||||
onPatch={(patch) => setFilters((prev) => ({ ...prev, ...patch }))}
|
||||
/>
|
||||
<CatalogRulePicker
|
||||
label="Status"
|
||||
options={statusOptions}
|
||||
rules={filters.status_rules}
|
||||
rulesFieldName="status_rules"
|
||||
idKind="string"
|
||||
placeholder="Status …"
|
||||
onPatch={(patch) => setFilters((prev) => ({ ...prev, ...patch }))}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user