Enhance FilterInput and FilterSidebar with property filter support
- Updated FilterInput to include property filter functionality, allowing for more complex filtering expressions. - Introduced new utility functions to convert between filter expressions and values, improving data handling. - Modified FilterSidebar to pass property filter configurations to the FilterInput, enhancing the filtering capabilities. - Improved SimplePropertyFilter to cache options and prevent unnecessary refetching, optimizing performance during interactions.
This commit is contained in:
parent
6b848d392c
commit
18ac93d8e9
@ -1,5 +1,5 @@
|
|||||||
import { useCallback, useContext, useEffect, useRef, useState } from 'react'
|
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { ConfigProvider, Tag, theme } from 'antd'
|
import { ConfigProvider, Popover, Tag, theme } from 'antd'
|
||||||
import { CloseCircleFilled } from '@ant-design/icons'
|
import { CloseCircleFilled } from '@ant-design/icons'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { createRoot } from 'react-dom/client'
|
import { createRoot } from 'react-dom/client'
|
||||||
@ -9,6 +9,8 @@ import useSize from 'antd/es/config-provider/hooks/useSize'
|
|||||||
import { useCompactItemContext } from 'antd/es/space/Compact'
|
import { useCompactItemContext } from 'antd/es/space/Compact'
|
||||||
import useStyle, { useSharedStyle } from 'antd/es/input/style'
|
import useStyle, { useSharedStyle } from 'antd/es/input/style'
|
||||||
import { useThemeContext } from '../context/ThemeContext'
|
import { useThemeContext } from '../context/ThemeContext'
|
||||||
|
import SimplePropertyFilter from './SimplePropertyFilter'
|
||||||
|
import ScrollBox from './ScrollBox'
|
||||||
|
|
||||||
// Longer symbols first so ".." / "<>" / ">=" match before "." / "<" / ">".
|
// Longer symbols first so ".." / "<>" / ">=" match before "." / "<" / ">".
|
||||||
// Wildcards (* ?) and @ stay as plain text — they are not operands.
|
// Wildcards (* ?) and @ stay as plain text — they are not operands.
|
||||||
@ -327,6 +329,25 @@ const chipsHaveLiveRoots = (root, roots) => {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toFilterExpression = (values) => {
|
||||||
|
if (!values?.length) return ''
|
||||||
|
const parts = values.map((value) => {
|
||||||
|
if (value && typeof value === 'object') {
|
||||||
|
return String(value._id ?? value.type ?? JSON.stringify(value))
|
||||||
|
}
|
||||||
|
return String(value)
|
||||||
|
})
|
||||||
|
return parts.length === 1 ? parts[0] : parts.join('|')
|
||||||
|
}
|
||||||
|
|
||||||
|
const fromFilterExpression = (expr) => {
|
||||||
|
if (expr === undefined || expr === null || expr === '') return []
|
||||||
|
if (typeof expr === 'string' && expr.includes('|')) {
|
||||||
|
return expr.split('|').filter((part) => part !== '')
|
||||||
|
}
|
||||||
|
return [expr]
|
||||||
|
}
|
||||||
|
|
||||||
const FilterInput = ({
|
const FilterInput = ({
|
||||||
value = '',
|
value = '',
|
||||||
onChange,
|
onChange,
|
||||||
@ -338,7 +359,8 @@ const FilterInput = ({
|
|||||||
onFocus,
|
onFocus,
|
||||||
onBlur,
|
onBlur,
|
||||||
onPressEnter,
|
onPressEnter,
|
||||||
size
|
size,
|
||||||
|
propertyFilter = null
|
||||||
}) => {
|
}) => {
|
||||||
const { getPrefixCls, direction } = useContext(ConfigProvider.ConfigContext)
|
const { getPrefixCls, direction } = useContext(ConfigProvider.ConfigContext)
|
||||||
const prefixCls = getPrefixCls('input')
|
const prefixCls = getPrefixCls('input')
|
||||||
@ -734,6 +756,46 @@ const FilterInput = ({
|
|||||||
editorRef.current?.focus()
|
editorRef.current?.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const propertyFilterEnabled =
|
||||||
|
!disabled &&
|
||||||
|
propertyFilter?.modelType != null &&
|
||||||
|
propertyFilter?.propertyName != null
|
||||||
|
|
||||||
|
const propertyFilterValue = useMemo(
|
||||||
|
() => fromFilterExpression(internalValue),
|
||||||
|
[internalValue]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handlePropertyFilterChange = useCallback(
|
||||||
|
(keys) => {
|
||||||
|
const next = toFilterExpression(keys)
|
||||||
|
paint(next, focusedRef.current ? next.length : null)
|
||||||
|
emitChange(next)
|
||||||
|
},
|
||||||
|
[emitChange, paint]
|
||||||
|
)
|
||||||
|
|
||||||
|
const propertyFilterContent = propertyFilterEnabled ? (
|
||||||
|
<div
|
||||||
|
onMouseDown={(event) => {
|
||||||
|
// Keep the input focused while interacting with the popover.
|
||||||
|
event.preventDefault()
|
||||||
|
}}
|
||||||
|
style={{ width: 280, height: 220, margin: -4 }}
|
||||||
|
>
|
||||||
|
<ScrollBox inner smallPadding>
|
||||||
|
<div style={{ padding: '12px 16px', minWidth: 0 }}>
|
||||||
|
<SimplePropertyFilter
|
||||||
|
modelType={propertyFilter.modelType}
|
||||||
|
propertyName={propertyFilter.propertyName}
|
||||||
|
value={propertyFilterValue}
|
||||||
|
onChange={handlePropertyFilterChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ScrollBox>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
|
||||||
// Auto-scroll while click-dragging a selection past the visible edges.
|
// Auto-scroll while click-dragging a selection past the visible edges.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let raf = 0
|
let raf = 0
|
||||||
@ -828,146 +890,167 @@ const FilterInput = ({
|
|||||||
? (token.paddingInlineSM ?? token.paddingXS)
|
? (token.paddingInlineSM ?? token.paddingXS)
|
||||||
: (token.paddingInline ?? token.paddingSM)
|
: (token.paddingInline ?? token.paddingSM)
|
||||||
|
|
||||||
|
const input = (
|
||||||
|
<span
|
||||||
|
className={classNames(
|
||||||
|
affixCls,
|
||||||
|
{
|
||||||
|
[`${affixCls}-focused`]: focused,
|
||||||
|
[`${affixCls}-disabled`]: disabled,
|
||||||
|
[`${affixCls}-sm`]: mergedSize === 'small',
|
||||||
|
[`${affixCls}-lg`]: mergedSize === 'large',
|
||||||
|
[`${affixCls}-rtl`]: direction === 'rtl',
|
||||||
|
[`${prefixCls}-outlined`]: true
|
||||||
|
},
|
||||||
|
compactItemClassnames,
|
||||||
|
cssVarCls,
|
||||||
|
rootCls,
|
||||||
|
hashId,
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
cursor: disabled ? 'not-allowed' : 'text',
|
||||||
|
...style,
|
||||||
|
// Affix ::before strut needs inline-flex; display:block stacks it and inflates height.
|
||||||
|
display: 'inline-flex'
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
if (!disabled) editorRef.current?.focus()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<style>{`
|
||||||
|
.filter-input-editor::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
{showPlaceholder && (
|
||||||
|
<span
|
||||||
|
aria-hidden
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
insetInlineStart: placeholderPaddingInline,
|
||||||
|
insetInlineEnd: showClear
|
||||||
|
? placeholderPaddingInline + 22
|
||||||
|
: placeholderPaddingInline,
|
||||||
|
top: 0,
|
||||||
|
bottom: 0,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
color: token.colorTextPlaceholder,
|
||||||
|
pointerEvents: 'none',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
zIndex: 1
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{placeholder}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
ref={editorRef}
|
||||||
|
className={classNames(prefixCls, 'filter-input-editor')}
|
||||||
|
role='textbox'
|
||||||
|
aria-multiline='false'
|
||||||
|
aria-disabled={disabled || undefined}
|
||||||
|
contentEditable={!disabled}
|
||||||
|
suppressContentEditableWarning
|
||||||
|
spellCheck={false}
|
||||||
|
onInput={handleInput}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
onPaste={handlePaste}
|
||||||
|
onCopy={handleCopy}
|
||||||
|
onCut={handleCut}
|
||||||
|
onMouseDown={() => {
|
||||||
|
selectingRef.current = true
|
||||||
|
}}
|
||||||
|
onCompositionStart={() => {
|
||||||
|
composingRef.current = true
|
||||||
|
}}
|
||||||
|
onCompositionEnd={() => {
|
||||||
|
composingRef.current = false
|
||||||
|
syncFromDom()
|
||||||
|
}}
|
||||||
|
onFocus={(event) => {
|
||||||
|
focusedRef.current = true
|
||||||
|
setFocused(true)
|
||||||
|
onFocus?.(event)
|
||||||
|
}}
|
||||||
|
onBlur={(event) => {
|
||||||
|
focusedRef.current = false
|
||||||
|
selectingRef.current = false
|
||||||
|
setFocused(false)
|
||||||
|
const next = normalize(serializeNode(editorRef.current))
|
||||||
|
paint(next)
|
||||||
|
if (next !== valueRef.current) emitChange(next)
|
||||||
|
onBlur?.(event)
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
// Match antd's `> input.ant-input` resets inside affix-wrapper
|
||||||
|
display: 'block',
|
||||||
|
padding: 0,
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: 0,
|
||||||
|
outline: 'none',
|
||||||
|
boxShadow: 'none',
|
||||||
|
background: 'transparent',
|
||||||
|
flex: 'auto',
|
||||||
|
minWidth: 0,
|
||||||
|
width: '100%',
|
||||||
|
fontSize: 'inherit',
|
||||||
|
lineHeight: 'inherit',
|
||||||
|
color: 'inherit',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflowX: 'auto',
|
||||||
|
overflowY: 'hidden',
|
||||||
|
scrollbarWidth: 'none',
|
||||||
|
msOverflowStyle: 'none',
|
||||||
|
wordBreak: 'keep-all',
|
||||||
|
overflowWrap: 'normal',
|
||||||
|
caretColor: token.colorText,
|
||||||
|
cursor: disabled ? 'not-allowed' : 'text'
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{showClear && (
|
||||||
|
<span className={`${prefixCls}-suffix`}>
|
||||||
|
<span
|
||||||
|
className={classNames(
|
||||||
|
`${prefixCls}-clear-icon`,
|
||||||
|
`${prefixCls}-clear-icon-has-value`
|
||||||
|
)}
|
||||||
|
role='button'
|
||||||
|
tabIndex={-1}
|
||||||
|
onMouseDown={handleClear}
|
||||||
|
>
|
||||||
|
<CloseCircleFilled />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
|
||||||
return wrapSharedCSSVar(
|
return wrapSharedCSSVar(
|
||||||
wrapCSSVar(
|
wrapCSSVar(
|
||||||
<span
|
propertyFilterEnabled ? (
|
||||||
className={classNames(
|
<Popover
|
||||||
affixCls,
|
open={focused}
|
||||||
{
|
content={propertyFilterContent}
|
||||||
[`${affixCls}-focused`]: focused,
|
placement='bottomLeft'
|
||||||
[`${affixCls}-disabled`]: disabled,
|
arrow={false}
|
||||||
[`${affixCls}-sm`]: mergedSize === 'small',
|
trigger={[]}
|
||||||
[`${affixCls}-lg`]: mergedSize === 'large',
|
styles={{
|
||||||
[`${affixCls}-rtl`]: direction === 'rtl',
|
body: {
|
||||||
[`${prefixCls}-outlined`]: true
|
padding: 8
|
||||||
},
|
}
|
||||||
compactItemClassnames,
|
|
||||||
cssVarCls,
|
|
||||||
rootCls,
|
|
||||||
hashId,
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
cursor: disabled ? 'not-allowed' : 'text',
|
|
||||||
...style,
|
|
||||||
// Affix ::before strut needs inline-flex; display:block stacks it and inflates height.
|
|
||||||
display: 'inline-flex'
|
|
||||||
}}
|
|
||||||
onClick={() => {
|
|
||||||
if (!disabled) editorRef.current?.focus()
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<style>{`
|
|
||||||
.filter-input-editor::-webkit-scrollbar {
|
|
||||||
display: none;
|
|
||||||
height: 0;
|
|
||||||
}
|
|
||||||
`}</style>
|
|
||||||
{showPlaceholder && (
|
|
||||||
<span
|
|
||||||
aria-hidden
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
insetInlineStart: placeholderPaddingInline,
|
|
||||||
insetInlineEnd: showClear
|
|
||||||
? placeholderPaddingInline + 22
|
|
||||||
: placeholderPaddingInline,
|
|
||||||
top: 0,
|
|
||||||
bottom: 0,
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
color: token.colorTextPlaceholder,
|
|
||||||
pointerEvents: 'none',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
zIndex: 1
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{placeholder}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<div
|
|
||||||
ref={editorRef}
|
|
||||||
className={classNames(prefixCls, 'filter-input-editor')}
|
|
||||||
role='textbox'
|
|
||||||
aria-multiline='false'
|
|
||||||
aria-disabled={disabled || undefined}
|
|
||||||
contentEditable={!disabled}
|
|
||||||
suppressContentEditableWarning
|
|
||||||
spellCheck={false}
|
|
||||||
onInput={handleInput}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
onPaste={handlePaste}
|
|
||||||
onCopy={handleCopy}
|
|
||||||
onCut={handleCut}
|
|
||||||
onMouseDown={() => {
|
|
||||||
selectingRef.current = true
|
|
||||||
}}
|
}}
|
||||||
onCompositionStart={() => {
|
>
|
||||||
composingRef.current = true
|
{input}
|
||||||
}}
|
</Popover>
|
||||||
onCompositionEnd={() => {
|
) : (
|
||||||
composingRef.current = false
|
input
|
||||||
syncFromDom()
|
)
|
||||||
}}
|
|
||||||
onFocus={(event) => {
|
|
||||||
focusedRef.current = true
|
|
||||||
setFocused(true)
|
|
||||||
onFocus?.(event)
|
|
||||||
}}
|
|
||||||
onBlur={(event) => {
|
|
||||||
focusedRef.current = false
|
|
||||||
selectingRef.current = false
|
|
||||||
setFocused(false)
|
|
||||||
const next = normalize(serializeNode(editorRef.current))
|
|
||||||
paint(next)
|
|
||||||
if (next !== valueRef.current) emitChange(next)
|
|
||||||
onBlur?.(event)
|
|
||||||
}}
|
|
||||||
style={{
|
|
||||||
// Match antd's `> input.ant-input` resets inside affix-wrapper
|
|
||||||
display: 'block',
|
|
||||||
padding: 0,
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: 0,
|
|
||||||
outline: 'none',
|
|
||||||
boxShadow: 'none',
|
|
||||||
background: 'transparent',
|
|
||||||
flex: 'auto',
|
|
||||||
minWidth: 0,
|
|
||||||
width: '100%',
|
|
||||||
fontSize: 'inherit',
|
|
||||||
lineHeight: 'inherit',
|
|
||||||
color: 'inherit',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
overflowX: 'auto',
|
|
||||||
overflowY: 'hidden',
|
|
||||||
scrollbarWidth: 'none',
|
|
||||||
msOverflowStyle: 'none',
|
|
||||||
wordBreak: 'keep-all',
|
|
||||||
overflowWrap: 'normal',
|
|
||||||
caretColor: token.colorText,
|
|
||||||
cursor: disabled ? 'not-allowed' : 'text'
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{showClear && (
|
|
||||||
<span className={`${prefixCls}-suffix`}>
|
|
||||||
<span
|
|
||||||
className={classNames(
|
|
||||||
`${prefixCls}-clear-icon`,
|
|
||||||
`${prefixCls}-clear-icon-has-value`
|
|
||||||
)}
|
|
||||||
role='button'
|
|
||||||
tabIndex={-1}
|
|
||||||
onMouseDown={handleClear}
|
|
||||||
>
|
|
||||||
<CloseCircleFilled />
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -983,7 +1066,11 @@ FilterInput.propTypes = {
|
|||||||
onFocus: PropTypes.func,
|
onFocus: PropTypes.func,
|
||||||
onBlur: PropTypes.func,
|
onBlur: PropTypes.func,
|
||||||
onPressEnter: PropTypes.func,
|
onPressEnter: PropTypes.func,
|
||||||
size: PropTypes.oneOf(['small', 'middle', 'large'])
|
size: PropTypes.oneOf(['small', 'middle', 'large']),
|
||||||
|
propertyFilter: PropTypes.shape({
|
||||||
|
modelType: PropTypes.string.isRequired,
|
||||||
|
propertyName: PropTypes.string.isRequired
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FilterInput
|
export default FilterInput
|
||||||
|
|||||||
@ -39,7 +39,17 @@ const FilterSidebar = ({
|
|||||||
if (initialEmptyFields.current.has(k) && v === '') continue
|
if (initialEmptyFields.current.has(k) && v === '') continue
|
||||||
visible[k] = v
|
visible[k] = v
|
||||||
}
|
}
|
||||||
setLocalFilter(visible)
|
setLocalFilter((prev) => {
|
||||||
|
const prevKeys = Object.keys(prev)
|
||||||
|
const nextKeys = Object.keys(visible)
|
||||||
|
if (
|
||||||
|
prevKeys.length === nextKeys.length &&
|
||||||
|
nextKeys.every((key) => prev[key] === visible[key])
|
||||||
|
) {
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
return visible
|
||||||
|
})
|
||||||
}, [filter])
|
}, [filter])
|
||||||
|
|
||||||
const debouncedFilterChange = useCallback(
|
const debouncedFilterChange = useCallback(
|
||||||
@ -167,6 +177,10 @@ const FilterSidebar = ({
|
|||||||
value={row.value}
|
value={row.value}
|
||||||
onChange={(value) => changeValue(row.field, value)}
|
onChange={(value) => changeValue(row.field, value)}
|
||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
|
propertyFilter={{
|
||||||
|
modelType: type,
|
||||||
|
propertyName: row.field
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
icon={<CloseOutlined />}
|
icon={<CloseOutlined />}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useContext, useMemo } from 'react'
|
import { useState, useEffect, useContext, useMemo, useRef } from 'react'
|
||||||
import { Flex, Checkbox, Spin, Typography } from 'antd'
|
import { Flex, Checkbox, Spin, Typography } from 'antd'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { ApiServerContext } from '../context/ApiServerContext'
|
import { ApiServerContext } from '../context/ApiServerContext'
|
||||||
@ -45,6 +45,9 @@ const matchOptions = (options, selected) => {
|
|||||||
return options.filter((option) => selectedKeys.has(getOptionKey(option)))
|
return options.filter((option) => selectedKeys.has(getOptionKey(option)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Survive table reloads / popover remounts without refetching the same property.
|
||||||
|
const optionsCache = new Map()
|
||||||
|
|
||||||
const SimplePropertyFilter = ({
|
const SimplePropertyFilter = ({
|
||||||
modelType,
|
modelType,
|
||||||
propertyName,
|
propertyName,
|
||||||
@ -53,8 +56,17 @@ const SimplePropertyFilter = ({
|
|||||||
search = ''
|
search = ''
|
||||||
}) => {
|
}) => {
|
||||||
const { getModelPropertyValues } = useContext(ApiServerContext)
|
const { getModelPropertyValues } = useContext(ApiServerContext)
|
||||||
const [options, setOptions] = useState([])
|
const getModelPropertyValuesRef = useRef(getModelPropertyValues)
|
||||||
const [loading, setLoading] = useState(false)
|
getModelPropertyValuesRef.current = getModelPropertyValues
|
||||||
|
|
||||||
|
const cacheKey =
|
||||||
|
modelType && propertyName ? `${modelType}:${propertyName}` : null
|
||||||
|
const [options, setOptions] = useState(
|
||||||
|
() => (cacheKey && optionsCache.get(cacheKey)) || []
|
||||||
|
)
|
||||||
|
const [loading, setLoading] = useState(
|
||||||
|
() => !(cacheKey && optionsCache.has(cacheKey))
|
||||||
|
)
|
||||||
const [localChecked, setLocalChecked] = useState(null)
|
const [localChecked, setLocalChecked] = useState(null)
|
||||||
|
|
||||||
const property = useMemo(
|
const property = useMemo(
|
||||||
@ -67,14 +79,30 @@ const SimplePropertyFilter = ({
|
|||||||
let cancelled = false
|
let cancelled = false
|
||||||
|
|
||||||
const loadOptions = async () => {
|
const loadOptions = async () => {
|
||||||
if (!modelType || !propertyName || isDateTimeProperty(property)) return
|
if (!modelType || !propertyName || isDateTimeProperty(property)) {
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = `${modelType}:${propertyName}`
|
||||||
|
const cached = optionsCache.get(key)
|
||||||
|
if (cached) {
|
||||||
|
setOptions(cached)
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const values = await getModelPropertyValues(modelType, propertyName)
|
const values = await getModelPropertyValuesRef.current(
|
||||||
|
modelType,
|
||||||
|
propertyName
|
||||||
|
)
|
||||||
if (cancelled) return
|
if (cancelled) return
|
||||||
const unique = [
|
const unique = [
|
||||||
...new Set((values || []).filter((v) => v != null && v !== ''))
|
...new Set((values || []).filter((v) => v != null && v !== ''))
|
||||||
]
|
]
|
||||||
|
optionsCache.set(key, unique)
|
||||||
setOptions(unique)
|
setOptions(unique)
|
||||||
} finally {
|
} finally {
|
||||||
if (!cancelled) setLoading(false)
|
if (!cancelled) setLoading(false)
|
||||||
@ -85,7 +113,9 @@ const SimplePropertyFilter = ({
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true
|
cancelled = true
|
||||||
}
|
}
|
||||||
}, [modelType, propertyName, getModelPropertyValues, property])
|
// Intentionally omit getModelPropertyValues — context recreates it on every
|
||||||
|
// provider render (e.g. table fetchLoading), which would refetch endlessly.
|
||||||
|
}, [modelType, propertyName, property])
|
||||||
|
|
||||||
const valueKey = useMemo(
|
const valueKey = useMemo(
|
||||||
() => JSON.stringify((value || []).map(getOptionKey)),
|
() => JSON.stringify((value || []).map(getOptionKey)),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user