From 5a42d712790f05f4c7b34cb2674e73b48c97e715 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Thu, 15 Dec 2022 15:55:42 -0500 Subject: [PATCH 1/8] Fix tag picker and add test Signed-off-by: Sarah Medeiros --- .../EntityTagPicker/EntityTagPicker.test.tsx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx index 7da357d806..de7bbb89be 100644 --- a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx +++ b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx @@ -202,4 +202,33 @@ describe('', () => { tags: new EntityTagFilter(['tag2']), }); }); + it('removes tags from filters if there are none available', async () => { + const updateFilters = jest.fn(); + const mockCatalogApiRefNoTags = { + getEntityFacets: async () => ({ + facets: { + 'metadata.tags': {}, + }, + }), + } as unknown as CatalogApi; + + render( + + + + + , + , + ); + await waitFor(() => + expect(updateFilters).toHaveBeenLastCalledWith({ + tags: undefined, + }), + ); + }); }); From 37426f6f5ef206325d1165cacee665240ccbcaf1 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Thu, 15 Dec 2022 15:57:00 -0500 Subject: [PATCH 2/8] Add changeset Signed-off-by: Sarah Medeiros --- .changeset/funny-pianos-grow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/funny-pianos-grow.md diff --git a/.changeset/funny-pianos-grow.md b/.changeset/funny-pianos-grow.md new file mode 100644 index 0000000000..b08b5f0768 --- /dev/null +++ b/.changeset/funny-pianos-grow.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': patch +--- + +Fix filter bug that leaves filters selected when they are not available for the selected kind. From 228f4db4fa541a4a070f8c805ac624f8ca7807d6 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Thu, 15 Dec 2022 15:57:57 -0500 Subject: [PATCH 3/8] Fix tag filter bug Signed-off-by: Sarah Medeiros --- .../src/components/EntityTagPicker/EntityTagPicker.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx index 25f02e8adc..1b7b68cbde 100644 --- a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx +++ b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx @@ -94,9 +94,12 @@ export const EntityTagPicker = (props: EntityTagPickerProps) => { useEffect(() => { updateFilters({ - tags: selectedTags.length ? new EntityTagFilter(selectedTags) : undefined, + tags: + selectedTags.length && Object.keys(availableTags ?? {}).length + ? new EntityTagFilter(selectedTags) + : undefined, }); - }, [selectedTags, updateFilters]); + }, [selectedTags, updateFilters, availableTags]); if (!Object.keys(availableTags ?? {}).length) return null; From 7a7a53138b3a3a13fad970a046a3d6250350eaf5 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Fri, 16 Dec 2022 09:58:18 -0500 Subject: [PATCH 4/8] Update .changeset/funny-pianos-grow.md Co-authored-by: Johan Haals Signed-off-by: Sarah Medeiros --- .changeset/funny-pianos-grow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/funny-pianos-grow.md b/.changeset/funny-pianos-grow.md index b08b5f0768..7823ca82b0 100644 --- a/.changeset/funny-pianos-grow.md +++ b/.changeset/funny-pianos-grow.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-react': patch --- -Fix filter bug that leaves filters selected when they are not available for the selected kind. +Fixed bug in `EntityTagPicker` that filtered on unavailable tags for the selected kind. From 2f45ef5cf275d256885c22b115809e4628776c26 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Fri, 16 Dec 2022 10:34:38 -0500 Subject: [PATCH 5/8] Add changeset for pr #15058 Signed-off-by: Sarah Medeiros --- .changeset/funny-pianos-grow.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changeset/funny-pianos-grow.md b/.changeset/funny-pianos-grow.md index 7823ca82b0..c9241cd818 100644 --- a/.changeset/funny-pianos-grow.md +++ b/.changeset/funny-pianos-grow.md @@ -3,3 +3,7 @@ --- Fixed bug in `EntityTagPicker` that filtered on unavailable tags for the selected kind. + +Fixed bug in `EntityOwnerPicker` that filtered on unavailable tags for the selected kind. + +Fixed bug in `EntityKindPicker` that filtered on unavailable tags for the selected kind. From 2bce511a1084b3088f3ce29a7111d30724a2b8c2 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Fri, 16 Dec 2022 10:35:43 -0500 Subject: [PATCH 6/8] Fix wording Signed-off-by: Sarah Medeiros --- .changeset/funny-pianos-grow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/funny-pianos-grow.md b/.changeset/funny-pianos-grow.md index c9241cd818..17f1d83927 100644 --- a/.changeset/funny-pianos-grow.md +++ b/.changeset/funny-pianos-grow.md @@ -6,4 +6,4 @@ Fixed bug in `EntityTagPicker` that filtered on unavailable tags for the selecte Fixed bug in `EntityOwnerPicker` that filtered on unavailable tags for the selected kind. -Fixed bug in `EntityKindPicker` that filtered on unavailable tags for the selected kind. +Fixed bug in `EntityLifecyclePicker` that filtered on unavailable tags for the selected kind. From c37b9e4c68ab7a0243d9f25bd4a2f3efb27415f6 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Mon, 19 Dec 2022 10:12:29 -0500 Subject: [PATCH 7/8] Clean up ternary Signed-off-by: Sarah Medeiros --- .../src/components/EntityTagPicker/EntityTagPicker.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx index 1b7b68cbde..4a1dc03e96 100644 --- a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx +++ b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx @@ -93,9 +93,10 @@ export const EntityTagPicker = (props: EntityTagPickerProps) => { }, [queryParamTags]); useEffect(() => { + const tags = Object.keys(availableTags ?? {}); updateFilters({ tags: - selectedTags.length && Object.keys(availableTags ?? {}).length + selectedTags.length && tags.length ? new EntityTagFilter(selectedTags) : undefined, }); From 3e174587fcf293ceb00ae96ff92810f667622c33 Mon Sep 17 00:00:00 2001 From: Sarah Medeiros Date: Wed, 21 Dec 2022 10:39:25 -0500 Subject: [PATCH 8/8] Fix changeset Signed-off-by: Sarah Medeiros --- .changeset/funny-pianos-grow.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.changeset/funny-pianos-grow.md b/.changeset/funny-pianos-grow.md index 17f1d83927..7823ca82b0 100644 --- a/.changeset/funny-pianos-grow.md +++ b/.changeset/funny-pianos-grow.md @@ -3,7 +3,3 @@ --- Fixed bug in `EntityTagPicker` that filtered on unavailable tags for the selected kind. - -Fixed bug in `EntityOwnerPicker` that filtered on unavailable tags for the selected kind. - -Fixed bug in `EntityLifecyclePicker` that filtered on unavailable tags for the selected kind.