Fixed multiselect bug.
This commit is contained in:
parent
c16a1e8a4e
commit
8ef240565a
@ -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 })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user