feat: Introduce activity schema headline binding for improved metrics handling
Deploy Development / deploy (push) Successful in 48s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 1s
Build Test / build-frontend (push) Successful in 17s

- Added a new function `activitySchemaHeadlineBinding` to streamline the binding of profile parameters to their corresponding headline columns, enhancing clarity in the metrics display logic.
- Refactored the `SessionMetricsFields` component to utilize the new binding function, simplifying the filtering of schema entries and improving maintainability.
- Updated the logic in `ActivityPage` to leverage the binding function for determining the appropriate column for metrics, ensuring consistent data handling across the application.
This commit is contained in:
Lars committed 2026-04-16 13:15:41 +02:00
1 parent c9d71c0179
commit 2a6c437a08
2 files changed
+202 -15

No files matched your search

+23 -15
View File
@@ -106,6 +106,23 @@ const ENTRY_FORM_ACTIVITY_LOG_COLUMNS = new Set([
'notes',
])
/**
* Bindung Profilparameter ↔ Kopfzeile: Entweder source_field zeigt auf eine Kopfspalte,
* oder der Parameter-key ist selbst eine Kopfspalte (häufig nach Migration / ohne source_field).
* @returns {{ headlineCol: string, parameterKey: string } | null}
*/
function activitySchemaHeadlineBinding(s) {
if (!s || !s.key) return null
const sf = s.source_field != null ? String(s.source_field).trim() : ''
if (sf && ENTRY_FORM_ACTIVITY_LOG_COLUMNS.has(sf)) {
return { headlineCol: sf, parameterKey: s.key }
}
if (ENTRY_FORM_ACTIVITY_LOG_COLUMNS.has(s.key)) {
return { headlineCol: s.key, parameterKey: s.key }
}
return null
}
function empty() {
return {
date: dayjs().format('YYYY-MM-DD'),
@@ -157,18 +174,9 @@ function buildMetricsPayload(schema, draft) {
function SessionMetricsFields({ schema, values, setValues, metrics }) {
const schemaList = Array.isArray(schema) ? schema : []
const headlineDuplicateKeys = new Set(
schemaList
.filter((s) => {
const sf = s.source_field != null ? String(s.source_field).trim() : ''
return sf && ENTRY_FORM_ACTIVITY_LOG_COLUMNS.has(sf)
})
.map((s) => s.key),
schemaList.filter((s) => activitySchemaHeadlineBinding(s) != null).map((s) => s.key),
)
const schemaForDisplay = schemaList.filter((s) => {
const sf = s.source_field != null ? String(s.source_field).trim() : ''
if (!sf) return true
return !ENTRY_FORM_ACTIVITY_LOG_COLUMNS.has(sf)
})
const schemaForDisplay = schemaList.filter((s) => activitySchemaHeadlineBinding(s) == null)
const metricRows = Array.isArray(metrics) ? metrics : []
const schemaKeys = new Set(schemaForDisplay.map((s) => s.key))
const orphanMetrics = metricRows.filter(
@@ -655,10 +663,10 @@ export default function ActivityPage() {
if (sessionDetail?.schema?.length > 0) {
const draftForMetrics = { ...metricDraft }
for (const s of sessionDetail.schema) {
const sf = s.source_field != null ? String(s.source_field).trim() : ''
if (!sf || !ENTRY_FORM_ACTIVITY_LOG_COLUMNS.has(sf)) continue
if (!(s.key in draftForMetrics)) continue
const rawCol = payload[sf] !== undefined ? payload[sf] : editing?.[sf]
const bind = activitySchemaHeadlineBinding(s)
if (!bind || !(s.key in draftForMetrics)) continue
const rawCol =
payload[bind.headlineCol] !== undefined ? payload[bind.headlineCol] : editing?.[bind.headlineCol]
if (rawCol === undefined) continue
if (s.data_type === 'boolean') {
draftForMetrics[s.key] = !!rawCol