feat: update version and enhance exercise filtering features
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 6s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 29s
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 6s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 29s
- Bumped application version to 0.8.40 and updated module versions accordingly. - Introduced new focus area filtering options in the ExercisesListPage, allowing users to include or exclude exercises based on specified focus areas. - Added utility functions for deduplicating and merging focus area IDs to improve filtering logic. - Enhanced the ExercisePickerModal and ExercisesListPage components to support new focus rules and improve user experience with focus area selections.
This commit is contained in:
1 parent
cfd40889ac
commit
518918a6e5
7 files changed
+357
-41
No files matched your search
@@ -0,0 +1,145 @@
|
||||
import React, { useMemo, useState } from 'react'
|
||||
|
||||
function newRuleKey() {
|
||||
if (typeof crypto !== 'undefined' && crypto.randomUUID) return crypto.randomUUID()
|
||||
return `fr-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Fokusbereiche mit „+“ (muss haben) und „−“ (darf nicht haben); optional nur Übungen ohne Fokus-Zuordnung.
|
||||
*/
|
||||
export default function ExerciseFocusRulePicker({
|
||||
focusOptions,
|
||||
focusRules,
|
||||
focusOnlyWithout,
|
||||
excludeWithoutFocus,
|
||||
legacyFocusAreaIds = [],
|
||||
onPatch,
|
||||
}) {
|
||||
const [pendingId, setPendingId] = useState('')
|
||||
|
||||
const legacyWarning = useMemo(
|
||||
() => Array.isArray(legacyFocusAreaIds) && legacyFocusAreaIds.length > 0,
|
||||
[legacyFocusAreaIds]
|
||||
)
|
||||
|
||||
const addRule = (mode) => {
|
||||
const id = String(pendingId || '').trim()
|
||||
if (!id || focusOnlyWithout) return
|
||||
const dup = (focusRules || []).some(
|
||||
(r) => String(r.focus_area_id) === id && r.mode === mode
|
||||
)
|
||||
if (dup) return
|
||||
onPatch({
|
||||
focus_rules: [...(focusRules || []), { key: newRuleKey(), focus_area_id: id, mode }],
|
||||
})
|
||||
setPendingId('')
|
||||
}
|
||||
|
||||
const removeRule = (key) => {
|
||||
onPatch({
|
||||
focus_rules: (focusRules || []).filter((r) => r.key !== key),
|
||||
})
|
||||
}
|
||||
|
||||
const setFocusOnly = (on) => {
|
||||
if (on) {
|
||||
onPatch({
|
||||
focus_only_without: true,
|
||||
exclude_without_focus: false,
|
||||
focus_rules: [],
|
||||
focus_area_ids: [],
|
||||
})
|
||||
setPendingId('')
|
||||
return
|
||||
}
|
||||
onPatch({ focus_only_without: false })
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="exercise-focus-rule-picker">
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: '10px', cursor: 'pointer', marginBottom: '10px' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!focusOnlyWithout}
|
||||
onChange={(e) => setFocusOnly(e.target.checked)}
|
||||
/>
|
||||
<span>Nur Übungen <strong>ohne</strong> Fokusbereich (keine Zuordnung)</span>
|
||||
</label>
|
||||
|
||||
{!focusOnlyWithout ? (
|
||||
<>
|
||||
{legacyWarning ? (
|
||||
<p className="muted" style={{ fontSize: '13px', marginTop: 0, marginBottom: '10px' }}>
|
||||
Es sind noch ältere Fokusfilter (ODER-Liste) aktiv — bitte über die Chips entfernen oder durch Regeln
|
||||
ersetzen.
|
||||
</p>
|
||||
) : null}
|
||||
<label className="form-label">Fokusbereiche (+ mit / − ohne)</label>
|
||||
<p className="muted" style={{ fontSize: '12px', marginTop: 0, marginBottom: '8px' }}>
|
||||
Mehrere „+“: alle müssen gesetzt sein (UND). Mehrere „−“: keiner davon darf gesetzt sein.
|
||||
Kombination z. B. „+ Karate“ und „− Fitness“ = hat Karate, aber nicht zusätzlich Fitness.
|
||||
</p>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'center', marginBottom: '10px' }}>
|
||||
<select
|
||||
className="form-input"
|
||||
style={{ minWidth: '200px', flex: '1 1 180px' }}
|
||||
value={pendingId}
|
||||
onChange={(e) => setPendingId(e.target.value)}
|
||||
aria-label="Fokusbereich wählen"
|
||||
>
|
||||
<option value="">Fokusbereich wählen …</option>
|
||||
{focusOptions.map((o) => (
|
||||
<option key={o.id} value={String(o.id)}>
|
||||
{o.label || o.id}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button type="button" className="btn btn-secondary btn-small" disabled={!pendingId} onClick={() => addRule('require')}>
|
||||
+ Mit
|
||||
</button>
|
||||
<button type="button" className="btn btn-secondary btn-small" disabled={!pendingId} onClick={() => addRule('forbid')}>
|
||||
− Ohne
|
||||
</button>
|
||||
</div>
|
||||
{(focusRules || []).length > 0 ? (
|
||||
<ul style={{ listStyle: 'none', padding: 0, margin: '0 0 12px 0' }}>
|
||||
{(focusRules || []).map((r) => {
|
||||
const opt = focusOptions.find((o) => String(o.id) === String(r.focus_area_id))
|
||||
const name = opt?.label || r.focus_area_id
|
||||
return (
|
||||
<li
|
||||
key={r.key}
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: '8px',
|
||||
padding: '6px 10px',
|
||||
marginBottom: '6px',
|
||||
borderRadius: '8px',
|
||||
border: '1px solid var(--border)',
|
||||
background: 'var(--surface2)',
|
||||
fontSize: '13px',
|
||||
}}
|
||||
>
|
||||
<span>
|
||||
<strong>{r.mode === 'forbid' ? '−' : '+'}</strong> {name}
|
||||
</span>
|
||||
<button type="button" className="btn btn-secondary btn-small" onClick={() => removeRule(r.key)}>
|
||||
Entfernen
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<p className="muted" style={{ fontSize: '13px', marginTop: 0 }}>
|
||||
Solange diese Option aktiv ist, sind Fokus-Regeln und die ODER-Fokusliste deaktiviert.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
mergeExerciseListPrefsFromApi,
|
||||
} from '../constants/exerciseListFilters'
|
||||
import MultiSelectCombo from './MultiSelectCombo'
|
||||
import ExerciseFocusRulePicker from './ExerciseFocusRulePicker'
|
||||
|
||||
const PAGE_SIZE = 100
|
||||
const LEVEL_FILTER_OPTS = SKILL_LEVEL_OPTIONS.filter((o) => o.level != null)
|
||||
@@ -154,6 +155,19 @@ export default function ExercisePickerModal({
|
||||
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)
|
||||
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)
|
||||
@@ -297,18 +311,17 @@ export default function ExercisePickerModal({
|
||||
{filterOpen && (
|
||||
<div style={{ marginTop: '0.35rem', fontSize: '13px', color: 'var(--text2)' }}>
|
||||
<p style={{ margin: '0 0 12px 0' }}>
|
||||
Zwischen den Bereichen gilt <strong>UND</strong>, innerhalb ODER wie in der Übungsübersicht.
|
||||
Zwischen den Bereichen gilt <strong>UND</strong>. Fokus: „+ mit“ / „− ohne“ kombinierbar (mehrere „+“ =
|
||||
alle gesetzt). Sonstige Mehrfachauswahl pro Feld mit <strong>ODER</strong>.
|
||||
</p>
|
||||
<div className="exercise-filters-modal-grid">
|
||||
<div>
|
||||
<label className="form-label">Fokus</label>
|
||||
<MultiSelectCombo
|
||||
value={filters.focus_area_ids}
|
||||
onChange={(v) => setFilters((f) => ({ ...f, focus_area_ids: v }))}
|
||||
options={focusOptions}
|
||||
placeholder="Fokus …"
|
||||
/>
|
||||
</div>
|
||||
<ExerciseFocusRulePicker
|
||||
focusOptions={focusOptions}
|
||||
focusRules={filters.focus_rules}
|
||||
focusOnlyWithout={filters.focus_only_without}
|
||||
legacyFocusAreaIds={filters.focus_area_ids}
|
||||
onPatch={(patch) => setFilters((f) => ({ ...f, ...patch }))}
|
||||
/>
|
||||
<div className="exercise-filters-modal-grid" style={{ marginTop: 12 }}>
|
||||
<div>
|
||||
<label className="form-label">Stilrichtung</label>
|
||||
<MultiSelectCombo
|
||||
@@ -416,11 +429,26 @@ export default function ExercisePickerModal({
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: 12, display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer' }}>
|
||||
<label
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 8,
|
||||
cursor: filters.focus_only_without ? 'not-allowed' : 'pointer',
|
||||
opacity: filters.focus_only_without ? 0.55 : 1,
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled={!!filters.focus_only_without}
|
||||
checked={!!filters.exclude_without_focus}
|
||||
onChange={(e) => setFilters((f) => ({ ...f, exclude_without_focus: e.target.checked }))}
|
||||
onChange={(e) =>
|
||||
setFilters((f) => ({
|
||||
...f,
|
||||
exclude_without_focus: e.target.checked,
|
||||
...(e.target.checked ? { focus_only_without: false } : {}),
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<span>Ohne Fokus ausblenden</span>
|
||||
</label>
|
||||
|
||||
Reference in new issue
Block a user