Rollup bug fix.
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2026-03-07 00:10:49 +00:00
parent 545cc0c526
commit 9b3de96be3
2 changed files with 16 additions and 3 deletions

View File

@ -47,6 +47,7 @@ const createSkeletonRows = (rowCount, keyPrefix, keyName) => {
const ObjectChildTable = ({ const ObjectChildTable = ({
maxWidth = '100%', maxWidth = '100%',
name,
properties = [], properties = [],
columns = [], columns = [],
visibleColumns = {}, visibleColumns = {},
@ -264,6 +265,17 @@ const ObjectChildTable = ({
const rollupDataSource = useMemo(() => { const rollupDataSource = useMemo(() => {
if (!rollups || rollups.length === 0) return [] if (!rollups || rollups.length === 0) return []
// Use value from form/props, or fall back to objectData when entering edit mode
// (form may not have populated the field yet)
const itemsForRollup =
value ?? (name && objectData ? objectData[name] : null) ?? []
// Build parent object with children array for rollup functions (e.g. objectData.parts)
const updatedObjectData = { ...objectData }
if (name) {
updatedObjectData[name] = itemsForRollup
}
// Single summary row where each rollup value is placed under // Single summary row where each rollup value is placed under
// the column that matches its `property` field. // the column that matches its `property` field.
const summaryRow = {} const summaryRow = {}
@ -275,8 +287,6 @@ const ObjectChildTable = ({
if (rollup && typeof rollup.value === 'function') { if (rollup && typeof rollup.value === 'function') {
try { try {
const updatedObjectData = { ...objectData }
updatedObjectData[property.name] = value
summaryRow[property.name] = rollup.value(updatedObjectData) summaryRow[property.name] = rollup.value(updatedObjectData)
} catch (e) { } catch (e) {
// Fail quietly but log for debugging // Fail quietly but log for debugging
@ -289,7 +299,7 @@ const ObjectChildTable = ({
}) })
return [summaryRow] return [summaryRow]
}, [properties, rollups, objectData, value]) }, [properties, rollups, objectData, value, name])
const rollupColumns = useMemo(() => { const rollupColumns = useMemo(() => {
const propertyColumns = properties.map((property, index) => { const propertyColumns = properties.map((property, index) => {
@ -455,6 +465,7 @@ const ObjectChildTable = ({
} }
ObjectChildTable.propTypes = { ObjectChildTable.propTypes = {
name: PropTypes.string,
properties: PropTypes.arrayOf( properties: PropTypes.arrayOf(
PropTypes.shape({ PropTypes.shape({
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,

View File

@ -407,6 +407,7 @@ const ObjectProperty = ({
case 'objectChildren': { case 'objectChildren': {
return ( return (
<ObjectChildTable <ObjectChildTable
name={name}
value={value} value={value}
properties={properties} properties={properties}
objectData={objectData} objectData={objectData}
@ -797,6 +798,7 @@ const ObjectProperty = ({
case 'objectChildren': { case 'objectChildren': {
return ( return (
<ObjectChildTable <ObjectChildTable
name={name}
properties={properties} properties={properties}
objectData={objectData} objectData={objectData}
isEditing={true} isEditing={true}