feat: Implement reference value types reordering and confidence level sorting
- Added a new API endpoint for reordering reference value types based on user-defined order. - Updated the AdminReferenceValueTypesPage to allow users to reorder types using up/down buttons. - Introduced a consistent confidence level sorting mechanism across the application. - Refactored related components to remove unused sort order fields and improve user experience.
This commit is contained in:
1 parent
45e4e64f15
commit
296e79c3b3
7 files changed
+149
-31
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Gauge, Plus, Pencil, Trash2, Save, X } from 'lucide-react'
|
||||
import { Gauge, Plus, Pencil, Trash2, Save, X, ChevronUp, ChevronDown } from 'lucide-react'
|
||||
import { api } from '../utils/api'
|
||||
import { VALUE_DATA_TYPE_LABELS } from '../utils/referenceValueMeta'
|
||||
|
||||
@@ -47,7 +47,6 @@ const emptyForm = () => ({
|
||||
vr_max_length: '',
|
||||
vr_not_empty: true,
|
||||
vr_enum_list: '',
|
||||
sort_order: 0,
|
||||
active: true,
|
||||
metadata_json: '{}',
|
||||
})
|
||||
@@ -55,6 +54,7 @@ const emptyForm = () => ({
|
||||
export default function AdminReferenceValueTypesPage() {
|
||||
const [rows, setRows] = useState([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [reorderBusy, setReorderBusy] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
const [toast, setToast] = useState(null)
|
||||
const [editingId, setEditingId] = useState(null)
|
||||
@@ -106,7 +106,6 @@ export default function AdminReferenceValueTypesPage() {
|
||||
vr_max_length: vr.max_length != null ? String(vr.max_length) : '',
|
||||
vr_not_empty: vr.not_empty !== false,
|
||||
vr_enum_list: allowed,
|
||||
sort_order: r.sort_order ?? 0,
|
||||
active: !!r.active,
|
||||
metadata_json: r.metadata && typeof r.metadata === 'object' ? JSON.stringify(r.metadata, null, 2) : '{}',
|
||||
})
|
||||
@@ -155,7 +154,6 @@ export default function AdminReferenceValueTypesPage() {
|
||||
default_unit: form.default_unit.trim(),
|
||||
value_data_type: form.value_data_type,
|
||||
validation_rules,
|
||||
sort_order: Number(form.sort_order) || 0,
|
||||
active: !!form.active,
|
||||
metadata,
|
||||
}
|
||||
@@ -201,6 +199,24 @@ export default function AdminReferenceValueTypesPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const moveRow = async (index, dir) => {
|
||||
const j = dir === 'up' ? index - 1 : index + 1
|
||||
if (j < 0 || j >= rows.length) return
|
||||
setReorderBusy(true)
|
||||
setError(null)
|
||||
const next = [...rows]
|
||||
;[next[index], next[j]] = [next[j], next[index]]
|
||||
try {
|
||||
await api.adminReorderReferenceValueTypes(next.map((r) => r.id))
|
||||
setRows(next)
|
||||
} catch (e) {
|
||||
setError(e.message || 'Reihenfolge konnte nicht gespeichert werden')
|
||||
await load()
|
||||
} finally {
|
||||
setReorderBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const plausibilisierungBlock = () => {
|
||||
const t = form.value_data_type
|
||||
if (t === 'integer' || t === 'decimal' || t === 'percentage') {
|
||||
@@ -450,18 +466,6 @@ export default function AdminReferenceValueTypesPage() {
|
||||
placeholder="bpm, %, Stufe, …"
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-admin-sort">
|
||||
Sortierung
|
||||
</label>
|
||||
<input
|
||||
id="ref-admin-sort"
|
||||
type="number"
|
||||
className="form-input"
|
||||
value={form.sort_order}
|
||||
onChange={(e) => setForm((f) => ({ ...f, sort_order: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<span className="settings-page__field-label">Sichtbarkeit</span>
|
||||
<label
|
||||
@@ -515,23 +519,52 @@ export default function AdminReferenceValueTypesPage() {
|
||||
|
||||
<div className="card">
|
||||
<div className="card-title">Alle Typen ({rows.length})</div>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', marginTop: 0, marginBottom: 12, lineHeight: 1.5 }}>
|
||||
Reihenfolge in der Liste und in den Nutzer-Dropdowns: Zeile mit <strong>hoch/runter</strong> verschieben.
|
||||
</p>
|
||||
<div style={{ overflowX: 'auto' }}>
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
|
||||
<thead>
|
||||
<tr style={{ textAlign: 'left', borderBottom: '1px solid var(--border)', color: 'var(--text2)' }}>
|
||||
<th style={{ padding: '8px 4px', width: 44 }} aria-label="Reihenfolge" title="Reihenfolge" />
|
||||
<th style={{ padding: '8px 6px' }}>Key</th>
|
||||
<th style={{ padding: '8px 6px' }}>Name</th>
|
||||
<th style={{ padding: '8px 6px' }}>Kategorie</th>
|
||||
<th style={{ padding: '8px 6px' }}>Typ</th>
|
||||
<th style={{ padding: '8px 6px' }}>Einheit</th>
|
||||
<th style={{ padding: '8px 6px' }}>Sort.</th>
|
||||
<th style={{ padding: '8px 6px' }}>Aktiv</th>
|
||||
<th style={{ padding: '8px 6px' }} />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
{rows.map((r, i) => (
|
||||
<tr key={r.id} style={{ borderBottom: '1px solid var(--border)' }}>
|
||||
<td style={{ padding: '6px 4px', verticalAlign: 'middle' }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ padding: '4px 6px', minHeight: 0, lineHeight: 1 }}
|
||||
disabled={reorderBusy || i === 0}
|
||||
title="Nach oben"
|
||||
onClick={() => moveRow(i, 'up')}
|
||||
aria-label="Nach oben"
|
||||
>
|
||||
<ChevronUp size={16} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ padding: '4px 6px', minHeight: 0, lineHeight: 1 }}
|
||||
disabled={reorderBusy || i === rows.length - 1}
|
||||
title="Nach unten"
|
||||
onClick={() => moveRow(i, 'down')}
|
||||
aria-label="Nach unten"
|
||||
>
|
||||
<ChevronDown size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
<td style={{ padding: '10px 6px', fontFamily: 'monospace', fontSize: 13 }}>{r.key}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{r.label}</td>
|
||||
<td style={{ padding: '10px 6px', color: 'var(--text2)' }}>{r.category || '–'}</td>
|
||||
@@ -539,7 +572,6 @@ export default function AdminReferenceValueTypesPage() {
|
||||
{VALUE_DATA_TYPE_LABELS[r.value_data_type] || r.value_data_type || '–'}
|
||||
</td>
|
||||
<td style={{ padding: '10px 6px', color: 'var(--text2)' }}>{r.default_unit || '–'}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{r.sort_order}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{r.active ? '✓' : '–'}</td>
|
||||
<td style={{ padding: '6px', textAlign: 'right', whiteSpace: 'nowrap' }}>
|
||||
<button
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
labelMethod,
|
||||
labelConfidence,
|
||||
VALUE_DATA_TYPE_LABELS,
|
||||
sortConfidenceKeys,
|
||||
} from '../utils/referenceValueMeta'
|
||||
|
||||
const DEFAULT_FORM_META = {
|
||||
@@ -462,7 +463,7 @@ export default function ProfileReferenceValuesPage() {
|
||||
value={form.confidence}
|
||||
onChange={(e) => setForm((f) => ({ ...f, confidence: e.target.value }))}
|
||||
>
|
||||
{(metaEnums.confidence_levels || []).map((k) => (
|
||||
{sortConfidenceKeys(metaEnums.confidence_levels || []).map((k) => (
|
||||
<option key={k} value={k}>
|
||||
{labelConfidence(k)}
|
||||
</option>
|
||||
|
||||
Reference in new issue
Block a user