fix(catalog-react): prevent EntityKindPicker from double-firing updateFilters on label change
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -140,7 +140,7 @@ describe('<EntityKindPicker/>', () => {
|
||||
);
|
||||
|
||||
expect(updateFilters).toHaveBeenLastCalledWith({
|
||||
kind: new EntityKindFilter('group', 'Group'),
|
||||
kind: new EntityKindFilter('group', 'group'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import { Select } from '@backstage/core-components';
|
||||
import { alertApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
import Box from '@material-ui/core/Box';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { EntityKindFilter } from '../../filters';
|
||||
import { useEntityList } from '../../hooks';
|
||||
import { filterKinds, useAllKinds } from './kindFilterUtils';
|
||||
@@ -65,13 +65,16 @@ function useEntityKindFilter(opts: { initialFilter: string }): {
|
||||
const { allKinds, loading, error } = useAllKinds();
|
||||
const selectedKindLabel = allKinds.get(selectedKind) || selectedKind;
|
||||
|
||||
const kindLabelRef = useRef(selectedKindLabel);
|
||||
kindLabelRef.current = selectedKindLabel;
|
||||
|
||||
useEffect(() => {
|
||||
updateFilters({
|
||||
kind: selectedKind
|
||||
? new EntityKindFilter(selectedKind, selectedKindLabel)
|
||||
? new EntityKindFilter(selectedKind, kindLabelRef.current)
|
||||
: undefined,
|
||||
});
|
||||
}, [selectedKind, selectedKindLabel, updateFilters]);
|
||||
}, [selectedKind, updateFilters]);
|
||||
|
||||
return {
|
||||
loading,
|
||||
|
||||
Reference in New Issue
Block a user