Enhance Maturity Matrix Tools and API Integration
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Failing after 2s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m19s

- Added new functionality for exporting and importing matrix editor data in JSON and CSV formats within the MaturityMatrixToolsAdmin component.
- Updated the API utility functions to support matrix editor exports and imports, enhancing the backend communication for Superadmin tasks.
- Refactored the client API to streamline request handling and improve code clarity.
- Included new UI elements for file upload and download actions, improving user experience in managing matrix data.
This commit is contained in:
Lars committed 2026-05-22 11:12:50 +02:00
1 parent cdeddc7cec
commit d58db3d5dd
6 files changed
+1089 -11

No files matched your search

+22 -6
View File
@@ -13,13 +13,10 @@ export function mergeActiveClubHeader(headers = {}) {
if (cid && /^\d+$/.test(String(cid).trim())) {
return { ...headers, 'X-Active-Club-Id': String(cid).trim() }
}
return { ...headers }
return headers
}
/**
* Generischer API-Aufruf inkl. X-Auth-Token und X-Active-Club-Id.
*/
export async function request(endpoint, options = {}) {
async function _fetchWithAuth(endpoint, options = {}) {
const token = localStorage.getItem('authToken')
const method = (options.method || 'GET').toUpperCase()
@@ -65,7 +62,7 @@ export async function request(endpoint, options = {}) {
throw new Error(snippet ? `HTTP ${response.status}: ${snippet}` : `HTTP ${response.status}`)
}
return response.json()
return response
} catch (e) {
if (e instanceof TypeError && (e.message === 'Failed to fetch' || e.message.includes('fetch'))) {
const hint =
@@ -77,3 +74,22 @@ export async function request(endpoint, options = {}) {
throw e
}
}
/**
* Generischer API-Aufruf inkl. X-Auth-Token und X-Active-Club-Id.
*/
export async function request(endpoint, options = {}) {
const response = await _fetchWithAuth(endpoint, options)
return response.json()
}
/** Text-Download (z. B. CSV-Export) mit gleicher Auth wie request(). */
export async function requestText(endpoint, options = {}) {
const response = await _fetchWithAuth(endpoint, options)
const disposition = response.headers.get('Content-Disposition') || ''
const match = disposition.match(/filename="([^"]+)"/)
return {
text: await response.text(),
filename: match ? match[1] : null,
}
}
@@ -13,6 +13,16 @@ function downloadJson(obj, filename) {
URL.revokeObjectURL(url)
}
function downloadText(text, filename, mime = 'text/csv;charset=utf-8') {
const blob = new Blob([text], { type: mime })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = filename
a.click()
URL.revokeObjectURL(url)
}
function groupModelSkills(model) {
if (!model?.model_skills?.length) return []
const groups = new Map()
@@ -56,6 +66,8 @@ export default function MaturityMatrixToolsAdmin() {
const [stackConfirmText, setStackConfirmText] = useState('')
const [stackLoading, setStackLoading] = useState(false)
const [stackImportLoading, setStackImportLoading] = useState(false)
const [editorLoading, setEditorLoading] = useState(false)
const [editorImportLoading, setEditorImportLoading] = useState(false)
useEffect(() => {
let cancelled = false
@@ -144,6 +156,94 @@ export default function MaturityMatrixToolsAdmin() {
}
}
async function handleExportEditorJson() {
setError('')
setMessage('')
setEditorLoading(true)
try {
const bundle = await api.exportMatrixEditorBundle()
const name = `matrix-editor-${(bundle.bundle_export_id || 'export').slice(0, 8)}.json`
downloadJson(bundle, name)
setMessage('Editor-Export (JSON) heruntergeladen.')
} catch (err) {
setError(err.message || String(err))
} finally {
setEditorLoading(false)
}
}
async function handleExportEditorCsv(part) {
setError('')
setMessage('')
setEditorLoading(true)
try {
const { text, filename } = await api.exportMatrixEditorCsv(part)
downloadText(
text,
filename || (part === 'skills' ? 'faehigkeiten-katalog.csv' : 'faehigkeitsmatrix-zellen.csv')
)
setMessage(part === 'skills' ? 'Katalog-CSV heruntergeladen.' : 'Matrix-CSV heruntergeladen.')
} catch (err) {
setError(err.message || String(err))
} finally {
setEditorLoading(false)
}
}
async function handleImportEditorJson(e) {
const file = e.target.files?.[0]
if (!file) return
setError('')
setMessage('')
setEditorImportLoading(true)
try {
const data = JSON.parse(await file.text())
if (data.kind !== 'shinkan.matrix_editor.v1') {
setError('Erwartet wird kind: shinkan.matrix_editor.v1')
return
}
const res = await api.importMatrixEditorBundle(data)
const w = res.warnings || []
setMessage(
`Import OK: ${res.skills_updated || 0} Fähigkeit(en), ${res.matrix_cells_updated || 0} Matrix-Zelle(n) aktualisiert.` +
(w.length ? ` ${w.length} Hinweis(e) in der Konsole.` : '')
)
if (w.length) console.warn('matrix_editor import warnings', w)
} catch (err) {
setError(err.message || String(err))
} finally {
setEditorImportLoading(false)
e.target.value = ''
}
}
async function handleImportEditorCsv(e, part) {
const file = e.target.files?.[0]
if (!file) return
setError('')
setMessage('')
setEditorImportLoading(true)
try {
const csv_text = await file.text()
const res = await api.importMatrixEditorBundle({
kind: 'shinkan.matrix_editor.csv',
part,
csv_text
})
const w = res.warnings || []
setMessage(
`CSV-Import (${part}) OK: ${res.skills_updated || 0} Fähigkeit(en), ${res.matrix_cells_updated || 0} Matrix-Zelle(n) aktualisiert.` +
(w.length ? ` ${w.length} Hinweis(e) in der Konsole.` : '')
)
if (w.length) console.warn('matrix_editor csv import warnings', w)
} catch (err) {
setError(err.message || String(err))
} finally {
setEditorImportLoading(false)
e.target.value = ''
}
}
async function handleExportStack() {
setError('')
setMessage('')
@@ -234,9 +334,8 @@ export default function MaturityMatrixToolsAdmin() {
return (
<div className="admin-matrix-tools">
<p className="admin-matrix-tools__intro muted">
Matrix nach Kontext auflösen, hierarchisch nach Hauptkategorie und Kategorie darstellen, sowie JSON
exportieren oder importieren (gespeichertes Modell inkl. optional Kontext-Bindings, aufgelöste Matrix, oder{' '}
<strong>Komplett-Stack</strong> mit Fähigkeitskatalog und allen Reifegradmodellen für Test → Prod).
Zentral Beschreibungen und Gewichtungen pflegen (Superadmin), Matrix nach Kontext anzeigen, sowie
vollständige JSON-Stacks für Test → Prod.
</p>
{error ? (
@@ -246,6 +345,76 @@ export default function MaturityMatrixToolsAdmin() {
) : null}
{message ? <p className="muted admin-matrix-tools__msg">{message}</p> : null}
<section className="card admin-matrix-tools__section">
<h2 className="admin-matrix-tools__h2">Zentral bearbeiten (Export / Import)</h2>
<p className="muted admin-matrix-tools__hint">
Flaches Format für Excel oder JSON-Editor: Fähigkeits-Beschreibungen,{' '}
<code className="admin-bindings__code">importance</code> (Gewichtung 1–5), globale Stufen-Texte (
<code className="admin-bindings__code">level_1</code> … <code className="admin-bindings__code">level_5</code>
), Matrix-Zelltexte und Zeilen-Relevanz pro Reifegradmodell. Import aktualisiert bestehende Einträge —
es werden keine neuen Fähigkeiten oder Modelle angelegt.
</p>
<div className="admin-matrix-tools__actions">
<button
type="button"
className="btn btn-primary"
disabled={editorLoading || editorImportLoading}
onClick={handleExportEditorJson}
>
{editorLoading ? 'Export…' : 'JSON exportieren'}
</button>
<button
type="button"
className="btn btn-secondary"
disabled={editorLoading || editorImportLoading}
onClick={() => handleExportEditorCsv('skills')}
>
Katalog als CSV
</button>
<button
type="button"
className="btn btn-secondary"
disabled={editorLoading || editorImportLoading}
onClick={() => handleExportEditorCsv('matrix')}
>
Matrix-Zellen als CSV
</button>
</div>
<div className="admin-matrix-tools__io-grid admin-matrix-tools__io-grid--editor">
<div>
<h3 className="admin-matrix-tools__h3">JSON importieren</h3>
<label className="form-label">Datei (<code className="admin-bindings__code">shinkan.matrix_editor.v1</code>)</label>
<input
type="file"
accept="application/json,.json"
disabled={editorImportLoading}
onChange={handleImportEditorJson}
/>
</div>
<div>
<h3 className="admin-matrix-tools__h3">CSV importieren</h3>
<p className="muted admin-matrix-tools__hint">
Nur geänderte Datei hochladen — Katalog-CSV oder Matrix-CSV getrennt.
</p>
<label className="form-label">Katalog-CSV</label>
<input
type="file"
accept="text/csv,.csv"
disabled={editorImportLoading}
onChange={(e) => handleImportEditorCsv(e, 'skills')}
/>
<label className="form-label admin-matrix-tools__btn-mt">Matrix-CSV</label>
<input
type="file"
accept="text/csv,.csv"
disabled={editorImportLoading}
onChange={(e) => handleImportEditorCsv(e, 'matrix')}
/>
</div>
</div>
{editorImportLoading ? <p className="muted admin-matrix-tools__msg">Import läuft…</p> : null}
</section>
<section className="card admin-matrix-tools__section">
<h2 className="admin-matrix-tools__h2">Kontext und Anzeige</h2>
<div className="admin-matrix-tools__filters">
+21 -1
View File
@@ -4,7 +4,7 @@
* Zentrale API-Kommunikation mit automatischer Token-Injektion
*/
import { request, ACTIVE_CLUB_STORAGE_KEY } from '../api/client.js'
import { request, ACTIVE_CLUB_STORAGE_KEY, requestText } from '../api/client.js'
import * as exercises from '../api/exercises.js'
import * as planning from '../api/planning.js'
import * as skillProfiles from '../api/skillProfiles.js'
@@ -523,6 +523,23 @@ export async function importMatrixStackBundle(payload) {
})
}
/** Superadmin: flacher Export für zentrale Pflege (Beschreibungen, Gewichtungen) */
export async function exportMatrixEditorBundle() {
return request('/api/admin/matrix-editor/export')
}
export async function exportMatrixEditorCsv(part) {
const format = part === 'skills' ? 'csv_skills' : 'csv_matrix'
return requestText(`/api/admin/matrix-editor/export?format=${format}`)
}
export async function importMatrixEditorBundle(payload) {
return request('/api/admin/matrix-editor/import', {
method: 'POST',
body: JSON.stringify(payload)
})
}
// Style Directions (formerly Training Styles)
export async function listStyleDirections(filters = {}) {
const query = new URLSearchParams(filters).toString()
@@ -874,6 +891,9 @@ export const api = {
exportResolvedMaturityBundle,
exportMatrixStackBundle,
importMatrixStackBundle,
exportMatrixEditorBundle,
exportMatrixEditorCsv,
importMatrixEditorBundle,
resolveMaturityModel,
getMaturityModel,
createMaturityModel,