fix(rule): rule pages filter logic is not stable, fixes #313

This commit is contained in:
kunish 2023-09-28 16:53:53 +08:00
parent bd597aa693
commit 1f22147cd1
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430

View File

@ -79,25 +79,36 @@ export default () => {
let scrollElementRef: HTMLDivElement | undefined let scrollElementRef: HTMLDivElement | undefined
const getRuleItemKey = ({ type, payload, proxy }: Rule) =>
`${type}-${payload}-${proxy}`
const ruleVirtualizer = createVirtualizer({ const ruleVirtualizer = createVirtualizer({
get count() { get count() {
return filteredRules().length return filteredRules().length
}, },
getItemKey: (index) => filteredRules()[index].payload, getItemKey: (index) => getRuleItemKey(filteredRules()[index]),
getScrollElement: () => scrollElementRef!, getScrollElement: () => scrollElementRef!,
estimateSize: () => 74, estimateSize: () => 82,
overscan: 5, overscan: 5,
}) })
const ruleVirtualizerItems = ruleVirtualizer.getVirtualItems() const ruleVirtualizerItems = ruleVirtualizer.getVirtualItems()
const getRuleProviderItemKey = ({
type,
name,
vehicleType,
behavior,
}: RuleProvider) => `${type}-${name}-${vehicleType}-${behavior}`
const ruleProviderVirtualizer = createVirtualizer({ const ruleProviderVirtualizer = createVirtualizer({
get count() { get count() {
return filteredRuleProviders().length return filteredRuleProviders().length
}, },
getItemKey: (index) => filteredRuleProviders()[index].name, getItemKey: (index) =>
getRuleProviderItemKey(filteredRuleProviders()[index]),
getScrollElement: () => scrollElementRef!, getScrollElement: () => scrollElementRef!,
estimateSize: () => 74, estimateSize: () => 82,
overscan: 5, overscan: 5,
}) })
@ -157,7 +168,7 @@ export default () => {
> >
{ruleVirtualizerItems.map((virtualizerItem) => { {ruleVirtualizerItems.map((virtualizerItem) => {
const rule = filteredRules().find( const rule = filteredRules().find(
(rule) => rule.payload === virtualizerItem.key, (rule) => getRuleItemKey(rule) === virtualizerItem.key,
)! )!
return ( return (
@ -197,7 +208,8 @@ export default () => {
> >
{ruleProviderVirtualizerItems.map((virtualizerItem) => { {ruleProviderVirtualizerItems.map((virtualizerItem) => {
const ruleProvider = ruleProviders().find( const ruleProvider = ruleProviders().find(
(ruleProvider) => ruleProvider.name === virtualizerItem.key, (ruleProvider) =>
getRuleProviderItemKey(ruleProvider) === virtualizerItem.key,
)! )!
return ( return (