From 38cafdb4a4acaa83aaf6a79cd085fb0918263361 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 27 Dec 2025 13:50:17 +0000 Subject: [PATCH] Bug fix: re-render tree when type, masterFiter etc changes. --- .../Dashboard/common/ObjectSelect.jsx | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/components/Dashboard/common/ObjectSelect.jsx b/src/components/Dashboard/common/ObjectSelect.jsx index ef4f65d..1602c3c 100644 --- a/src/components/Dashboard/common/ObjectSelect.jsx +++ b/src/components/Dashboard/common/ObjectSelect.jsx @@ -47,6 +47,8 @@ const ObjectSelect = ({ const [objectList, setObjectList] = useState([]) const [treeSelectValue, setTreeSelectValue] = useState(null) const [initialLoading, setInitialLoading] = useState(true) + const [expandedKeys, setExpandedKeys] = useState([]) + const [treeVersion, setTreeVersion] = useState(0) const valueRef = useRef(null) // Refs to track value changes @@ -211,6 +213,7 @@ const ObjectSelect = ({ objectType={type} objectData={object} isEditing={false} + showHyperlink={false} style={{ top: '-0.5px' }} /> @@ -246,6 +249,15 @@ const ObjectSelect = ({ value: valueString }) + var nodeChildren = buildTreeData( + children, + pIdx + 1, + parentKeys.concat(valueString), + newFilterPath + ) + if (nodeChildren.length == 0) { + nodeChildren = undefined + } const modelProperty = getModelProperty(type, property) return { title: , @@ -257,12 +269,7 @@ const ObjectSelect = ({ filterPath: newFilterPath, selectable: false, isLeaf: false, - children: buildTreeData( - children, - pIdx + 1, - parentKeys.concat(valueString), - newFilterPath - ) + children: nodeChildren } }) .filter(Boolean) @@ -272,6 +279,7 @@ const ObjectSelect = ({ // --- loadData for async loading on expand --- const loadData = async (node) => { + console.log('loading data for node', node) // node.property is the property name, node.value is the value key if (!node.property) return if (type == 'unknown') return @@ -384,24 +392,39 @@ const ObjectSelect = ({ // console.log('fullValue', fullValue) // Build a new filter from value's properties that are in the properties list const valueFilter = { ...filter } + const pathKeys = [] + const parentKeys = [] properties.forEach((prop) => { if (Object.prototype.hasOwnProperty.call(fullValue, prop)) { const filterValue = fullValue[prop] + let valueString = filterValue if ( filterValue && typeof filterValue === 'object' && filterValue._id ) { valueFilter[prop] = filterValue._id + valueString = filterValue._id } else if (filterValue?.name) { valueFilter[prop] = filterValue.name + valueString = filterValue.name } else if (Array.isArray(filterValue)) { valueFilter[prop] = filterValue.join(',') + valueString = filterValue.join(',') } else { valueFilter[prop] = filterValue + valueString = filterValue } + // Build the path key for this property level + const nodeKey = parentKeys + .concat(prop + ':' + valueString) + .join('-') + pathKeys.push(nodeKey) + parentKeys.push(valueString) } }) + // Expand the path to the object + setExpandedKeys(pathKeys) // Fetch with the new filter handleFetchObjectsProperties(valueFilter) // console.log('setting treeSelectValue', valueRef.current._id) @@ -462,6 +485,8 @@ const ObjectSelect = ({ setObjectPropertiesTree({}) setObjectList([]) setTreeData([]) + setTreeVersion((v) => v + 1) + setExpandedKeys([]) setInitialized(false) onTreeSelectChange(null) setTreeSelectValue(null) @@ -529,8 +554,11 @@ const ObjectSelect = ({ // --- Main TreeSelect UI --- return (