refactor: Remove source field handling from activity session metrics logic
Deploy Development / deploy (push) Successful in 54s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Eliminated checks for `source_field` in the `replace_activity_session_metrics` function to streamline EAV row replacement, ensuring consistency with existing logic.
- Updated frontend logic to simplify the filtering of metrics during payload construction, enhancing maintainability.
- Removed outdated unit tests related to `source_field` handling, reflecting the updated logic in the codebase.
This commit is contained in:
Lars committed 2026-04-16 12:35:55 +02:00
1 parent 94bb4a8199
commit 2a26e4fecf
3 files changed
+2 -104

No files matched your search

+2 -39
View File
@@ -96,28 +96,6 @@ const ACTIVITY_LOG_PAYLOAD_KEYS = new Set([
'training_subcategory',
])
/** activity_log-Spalten, die bereits im EntryForm-Kopf bearbeitet werden — kein zweites Feld unter „Weitere Kennwerte“. */
const ENTRY_FORM_SOURCE_COLUMNS = new Set([
'date',
'start_time',
'end_time',
'duration_min',
'kcal_active',
'kcal_resting',
'hr_avg',
'hr_max',
'rpe',
'notes',
])
function schemaRowsForProfileExtras(schemaList) {
return (Array.isArray(schemaList) ? schemaList : []).filter((s) => {
const sf = s && s.source_field
if (!sf || !String(sf).trim()) return true
return !ENTRY_FORM_SOURCE_COLUMNS.has(String(sf).trim())
})
}
function empty() {
return {
date: dayjs().format('YYYY-MM-DD'),
@@ -135,10 +113,6 @@ function empty() {
function buildMetricsPayload(schema, draft) {
const out = []
for (const s of schema) {
const sf = s.source_field
if (sf && String(sf).trim() && ENTRY_FORM_SOURCE_COLUMNS.has(String(sf).trim())) {
continue
}
const raw = draft[s.key]
if (s.data_type === 'boolean') {
if (raw === '' || raw === null || raw === undefined) {
@@ -171,21 +145,10 @@ function buildMetricsPayload(schema, draft) {
}
function SessionMetricsFields({ schema, values, setValues, metrics }) {
const fullSchema = Array.isArray(schema) ? schema : []
const schemaList = schemaRowsForProfileExtras(fullSchema)
const schemaList = Array.isArray(schema) ? schema : []
const metricRows = Array.isArray(metrics) ? metrics : []
const schemaKeys = new Set(schemaList.map((s) => s.key))
const hiddenHeadlineParamKeys = new Set(
fullSchema
.filter((s) => s.source_field && ENTRY_FORM_SOURCE_COLUMNS.has(String(s.source_field).trim()))
.map((s) => s.key)
)
const orphanMetrics = metricRows.filter((row) => {
if (!row || !row.key) return false
if (schemaKeys.has(row.key)) return false
if (hiddenHeadlineParamKeys.has(row.key)) return false
return true
})
const orphanMetrics = metricRows.filter((row) => row && row.key && !schemaKeys.has(row.key))
if (schemaList.length === 0 && orphanMetrics.length === 0) return null
const set = (k, v) => setValues((prev) => ({ ...prev, [k]: v }))