Rollup bug fix.
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit
This commit is contained in:
parent
545cc0c526
commit
9b3de96be3
@ -47,6 +47,7 @@ const createSkeletonRows = (rowCount, keyPrefix, keyName) => {
|
||||
|
||||
const ObjectChildTable = ({
|
||||
maxWidth = '100%',
|
||||
name,
|
||||
properties = [],
|
||||
columns = [],
|
||||
visibleColumns = {},
|
||||
@ -264,6 +265,17 @@ const ObjectChildTable = ({
|
||||
const rollupDataSource = useMemo(() => {
|
||||
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
|
||||
// the column that matches its `property` field.
|
||||
const summaryRow = {}
|
||||
@ -275,8 +287,6 @@ const ObjectChildTable = ({
|
||||
|
||||
if (rollup && typeof rollup.value === 'function') {
|
||||
try {
|
||||
const updatedObjectData = { ...objectData }
|
||||
updatedObjectData[property.name] = value
|
||||
summaryRow[property.name] = rollup.value(updatedObjectData)
|
||||
} catch (e) {
|
||||
// Fail quietly but log for debugging
|
||||
@ -289,7 +299,7 @@ const ObjectChildTable = ({
|
||||
})
|
||||
|
||||
return [summaryRow]
|
||||
}, [properties, rollups, objectData, value])
|
||||
}, [properties, rollups, objectData, value, name])
|
||||
|
||||
const rollupColumns = useMemo(() => {
|
||||
const propertyColumns = properties.map((property, index) => {
|
||||
@ -455,6 +465,7 @@ const ObjectChildTable = ({
|
||||
}
|
||||
|
||||
ObjectChildTable.propTypes = {
|
||||
name: PropTypes.string,
|
||||
properties: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
name: PropTypes.string.isRequired,
|
||||
|
||||
@ -407,6 +407,7 @@ const ObjectProperty = ({
|
||||
case 'objectChildren': {
|
||||
return (
|
||||
<ObjectChildTable
|
||||
name={name}
|
||||
value={value}
|
||||
properties={properties}
|
||||
objectData={objectData}
|
||||
@ -797,6 +798,7 @@ const ObjectProperty = ({
|
||||
case 'objectChildren': {
|
||||
return (
|
||||
<ObjectChildTable
|
||||
name={name}
|
||||
properties={properties}
|
||||
objectData={objectData}
|
||||
isEditing={true}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user