From 8ef240565ab7f90e9617ae2435ace2fc99113bda Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 13 Jul 2026 00:48:29 +0100 Subject: [PATCH] Fixed multiselect bug. --- .../Dashboard/common/ObjectSelect.jsx | 79 ++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/src/components/Dashboard/common/ObjectSelect.jsx b/src/components/Dashboard/common/ObjectSelect.jsx index 291e39d..baaf350 100644 --- a/src/components/Dashboard/common/ObjectSelect.jsx +++ b/src/components/Dashboard/common/ObjectSelect.jsx @@ -368,7 +368,9 @@ const ObjectSelect = ({ let selectedObjects = [] if (Array.isArray(value)) { selectedObjects = value - .map((id) => objectList.find((obj) => obj._id === id)) + .map((id) => + objectList.find((obj) => areValuesEqual(obj._id, id)) + ) .filter(Boolean) } setTreeSelectValue(value) @@ -421,7 +423,18 @@ const ObjectSelect = ({ e.preventDefault() e.stopPropagation() - onTreeSelectChange(multiple ? [firstLeaf.value] : firstLeaf.value) + onTreeSelectChange( + multiple + ? [ + ...(Array.isArray(treeSelectValue) ? treeSelectValue : []), + firstLeaf.value + ].filter( + (item, index, values) => + values.findIndex((value) => areValuesEqual(value, item)) === + index + ) + : firstLeaf.value + ) setSearchValue('') onSearch('') }, @@ -429,6 +442,7 @@ const ObjectSelect = ({ treeSelectProps, isSearching, treeData, + treeSelectValue, multiple, onTreeSelectChange, onSearch @@ -450,6 +464,64 @@ const ObjectSelect = ({ useEffect(() => { const handleValue = async () => { + if ( + multiple && + Array.isArray(value) && + getValueIdentity(valueRef.current) !== getValueIdentity(value) && + type != 'unknown' + ) { + valueRef.current = value + const fullValues = await Promise.all( + value.map(fetchFullObjectIfNeeded) + ) + const pathKeys = [] + + if (fullValues.length === 0) { + handleFetchObjectsProperties() + } else { + fullValues.forEach((fullValue) => { + const valueFilter = { ...filter } + const parentKeys = [] + + properties.forEach((prop) => { + if (!Object.prototype.hasOwnProperty.call(fullValue, prop)) return + + const filterValue = fullValue[prop] + let valueString = filterValue + if ( + filterValue && + typeof filterValue === 'object' && + filterValue._id + ) { + valueString = filterValue._id + } else if (filterValue?.name) { + valueString = filterValue.name + } else if (Array.isArray(filterValue)) { + valueString = filterValue.join(',') + } + + valueFilter[prop] = valueString + pathKeys.push( + parentKeys.concat(prop + ':' + valueString).join('-') + ) + parentKeys.push(valueString) + }) + + handleFetchObjectsProperties(valueFilter) + }) + } + + setExpandedKeys([...new Set(pathKeys)]) + setTreeSelectValue( + value + .map((item) => + item && typeof item === 'object' ? item._id : item + ) + .filter((id) => id != null) + ) + setInitialized(true) + return + } if ( value && typeof value === 'object' && @@ -533,7 +605,8 @@ const ObjectSelect = ({ fetchFullObjectIfNeeded, type, connected, - getValueIdentity + getValueIdentity, + multiple ]) const prevValuesRef = useRef({ type, masterFilter })