From dfb920fb6e2c8039f507de227c9e1cfaa11af0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Wed, 20 May 2026 17:28:00 +0200 Subject: [PATCH] fix(catalog-react): prevent EntityKindPicker from double-firing updateFilters on label change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Fredrik Adelöw --- .../EntityKindPicker/EntityKindPicker.test.tsx | 2 +- .../src/components/EntityKindPicker/EntityKindPicker.tsx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx b/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx index 9fa8e6e097..7397c3ee1e 100644 --- a/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx +++ b/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx @@ -140,7 +140,7 @@ describe('', () => { ); expect(updateFilters).toHaveBeenLastCalledWith({ - kind: new EntityKindFilter('group', 'Group'), + kind: new EntityKindFilter('group', 'group'), }); }); diff --git a/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.tsx b/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.tsx index 534b8d03b3..c0565851b0 100644 --- a/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.tsx +++ b/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.tsx @@ -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,