feat: Update activity session metrics handling to skip source field inserts
Deploy Development / deploy (push) Successful in 55s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

- Modified the `replace_activity_session_metrics` function to skip EAV inserts for parameters with a defined `source_field`, aligning with the existing logic in `upsert_session_metrics_from_csv_mapped`.
- Enhanced the frontend logic to filter out metrics associated with `source_field` during payload construction, improving data integrity and user experience.
- Added unit tests to validate the new behavior, ensuring that metrics with `source_field` are correctly excluded from inserts.
This commit is contained in:
Lars committed 2026-04-16 12:29:01 +02:00
1 parent fd7a2dac6d
commit 94bb4a8199
3 files changed
+104 -2

No files matched your search

+39 -2
View File
@@ -96,6 +96,28 @@ 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'),
@@ -113,6 +135,10 @@ 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) {
@@ -145,10 +171,21 @@ function buildMetricsPayload(schema, draft) {
}
function SessionMetricsFields({ schema, values, setValues, metrics }) {
const schemaList = Array.isArray(schema) ? schema : []
const fullSchema = Array.isArray(schema) ? schema : []
const schemaList = schemaRowsForProfileExtras(fullSchema)
const metricRows = Array.isArray(metrics) ? metrics : []
const schemaKeys = new Set(schemaList.map((s) => s.key))
const orphanMetrics = metricRows.filter((row) => row && row.key && !schemaKeys.has(row.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
})
if (schemaList.length === 0 && orphanMetrics.length === 0) return null
const set = (k, v) => setValues((prev) => ({ ...prev, [k]: v }))