More object multiselect fixes and improvements.
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-07-13 00:56:24 +01:00
parent 48bd435fb4
commit 5f7fc256e3
2 changed files with 26 additions and 13 deletions

View File

@ -91,7 +91,7 @@
transition: opacity 0.15s ease-in-out; transition: opacity 0.15s ease-in-out;
} }
.ant-select-focused .object-display-tag, .object-select.ant-select-focused .object-display-tag,
.ant-select-focused .object-type-display-tag, .ant-select-focused .object-type-display-tag,
.ant-select-focused .country-display { .ant-select-focused .country-display {
opacity: 0.5; opacity: 0.5;

View File

@ -359,7 +359,7 @@ const ObjectSelect = ({
const onTreeSelectChange = useCallback( const onTreeSelectChange = useCallback(
(value) => { (value) => {
// Mark this as an internal change // Mark this as an internal change
setIsSearching(false) if (!multiple) setIsSearching(false)
isInternalChangeRef.current = true isInternalChangeRef.current = true
// value can be a string (single) or array (multiple) // value can be a string (single) or array (multiple)
@ -368,9 +368,7 @@ const ObjectSelect = ({
let selectedObjects = [] let selectedObjects = []
if (Array.isArray(value)) { if (Array.isArray(value)) {
selectedObjects = value selectedObjects = value
.map((id) => .map((id) => objectList.find((obj) => areValuesEqual(obj._id, id)))
objectList.find((obj) => areValuesEqual(obj._id, id))
)
.filter(Boolean) .filter(Boolean)
} }
setTreeSelectValue(value) setTreeSelectValue(value)
@ -402,14 +400,32 @@ const ObjectSelect = ({
if (requestId !== searchRequestIdRef.current) return if (requestId !== searchRequestIdRef.current) return
if (!Array.isArray(data)) return if (!Array.isArray(data)) return
setTreeData(buildTreeData(data, properties.length)) const searchData =
multiple && Array.isArray(treeSelectValue)
? [
...data,
...objectList.filter((object) =>
treeSelectValue.some((id) => areValuesEqual(object._id, id))
)
].filter(
(object, index, objects) =>
objects.findIndex((item) =>
areValuesEqual(item._id, object._id)
) === index
)
: data
setTreeData(buildTreeData(searchData, properties.length))
}, },
[ [
searchObjects, searchObjects,
type, type,
buildTreeData, buildTreeData,
objectPropertiesTree, objectPropertiesTree,
properties.length properties.length,
multiple,
treeSelectValue,
objectList
] ]
) )
@ -471,9 +487,7 @@ const ObjectSelect = ({
type != 'unknown' type != 'unknown'
) { ) {
valueRef.current = value valueRef.current = value
const fullValues = await Promise.all( const fullValues = await Promise.all(value.map(fetchFullObjectIfNeeded))
value.map(fetchFullObjectIfNeeded)
)
const pathKeys = [] const pathKeys = []
if (fullValues.length === 0) { if (fullValues.length === 0) {
@ -514,9 +528,7 @@ const ObjectSelect = ({
setExpandedKeys([...new Set(pathKeys)]) setExpandedKeys([...new Set(pathKeys)])
setTreeSelectValue( setTreeSelectValue(
value value
.map((item) => .map((item) => (item && typeof item === 'object' ? item._id : item))
item && typeof item === 'object' ? item._id : item
)
.filter((id) => id != null) .filter((id) => id != null)
) )
setInitialized(true) setInitialized(true)
@ -723,6 +735,7 @@ const ObjectSelect = ({
searchValue={searchValue} searchValue={searchValue}
disabled={disabled || type == 'unknown' || type == undefined} disabled={disabled || type == 'unknown' || type == undefined}
style={{ opacity: delayedInitialLoading ? 0 : 1 }} style={{ opacity: delayedInitialLoading ? 0 : 1 }}
className={multiple ? 'object-select-multiple' : 'object-select'}
/> />
{delayedInitialLoading && ( {delayedInitialLoading && (
<TreeSelect <TreeSelect