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:
Fredrik Adelöw
2026-05-20 17:28:00 +02:00
parent 813608335f
commit dfb920fb6e
2 changed files with 7 additions and 4 deletions
@@ -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,