fix: show Update values on the employee details page
This commit is contained in:
parent
5b55bd267b
commit
4612155f6f
@ -223,6 +223,22 @@ export async function fetchEmployeeInstance(instanceId) {
|
|||||||
return rows.find((r) => String(r.instance_id) === String(instanceId)) || null
|
return rows.find((r) => String(r.instance_id) === String(instanceId)) || null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An employee-table row's values under the Update field ids. Update maps every
|
||||||
|
* field into the table, so the row holds what was last saved even though the
|
||||||
|
* workflow views return only the INIT fields.
|
||||||
|
*/
|
||||||
|
function updateValuesFromTable(row) {
|
||||||
|
if (!row) return {}
|
||||||
|
const byLabel = new Map(Object.entries(row).map(([k, v]) => [normLabel(k), v]))
|
||||||
|
const out = {}
|
||||||
|
for (const f of EMPLOYEE_UPDATE_FIELDS) {
|
||||||
|
const v = byLabel.get(normLabel(f.label))
|
||||||
|
if (v !== undefined && v !== null && v !== '') out[f.id] = v
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the latest saved values on the details page.
|
* Show the latest saved values on the details page.
|
||||||
*
|
*
|
||||||
@ -242,7 +258,13 @@ export async function withLatestInstanceValues(view, instanceId) {
|
|||||||
}
|
}
|
||||||
if (!instance) return view
|
if (!instance) return view
|
||||||
|
|
||||||
const record = { ...view.record, ...instance }
|
let tableRow = null
|
||||||
|
try {
|
||||||
|
tableRow = await fetchEmployeeTableRow(instance)
|
||||||
|
} catch {
|
||||||
|
// Keep the instance values.
|
||||||
|
}
|
||||||
|
const record = { ...view.record, ...instance, ...updateValuesFromTable(tableRow) }
|
||||||
const latest = new Map(
|
const latest = new Map(
|
||||||
[...latestByLabel(ALL_EMPLOYEE_FIELDS, record)].map(([label, v]) => [normLabel(label), v]),
|
[...latestByLabel(ALL_EMPLOYEE_FIELDS, record)].map(([label, v]) => [normLabel(label), v]),
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user