From 67276652e6404809c995e3e6c410b69c08d68080 Mon Sep 17 00:00:00 2001 From: Boris Bera Date: Sun, 25 Feb 2024 11:18:11 -0500 Subject: [PATCH 1/2] Make `spec.target` searchable in catalog table for location Signed-off-by: Boris Bera --- .changeset/wet-sheep-reply.md | 5 +++++ .../catalog/src/components/CatalogTable/columns.tsx | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/wet-sheep-reply.md diff --git a/.changeset/wet-sheep-reply.md b/.changeset/wet-sheep-reply.md new file mode 100644 index 0000000000..27635b133e --- /dev/null +++ b/.changeset/wet-sheep-reply.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': patch +--- + +Allow the `spec.target` field to be searchable in the catalog table for locations. Previously, only the `spec.targets` field was be searchable. This makes locations generated by providers such as the `GithubEntityProvider` searchable in the catalog table. [#23098](https://github.com/backstage/backstage/issues/23098) diff --git a/plugins/catalog/src/components/CatalogTable/columns.tsx b/plugins/catalog/src/components/CatalogTable/columns.tsx index 4260a0c26b..a191befe59 100644 --- a/plugins/catalog/src/components/CatalogTable/columns.tsx +++ b/plugins/catalog/src/components/CatalogTable/columns.tsx @@ -86,6 +86,18 @@ export const columnFactories = Object.freeze({ return { title: 'Targets', field: 'entity.spec.targets', + customFilterAndSearch: (query, row) => { + const targets = []; + if (Array.isArray(row.entity?.spec?.targets)) { + targets.push(...row.entity?.spec?.targets); + } else if (row.entity?.spec?.target) { + targets.push(row.entity?.spec?.target); + } + return targets + .join(', ') + .toLocaleUpperCase('en-US') + .includes(query.toLocaleUpperCase('en-US')); + }, render: ({ entity }) => ( <> {(entity?.spec?.targets || entity?.spec?.target) && ( From 1b2dc6c815c298bea792f3d9a1e0fd88d52a0578 Mon Sep 17 00:00:00 2001 From: Boris Bera Date: Mon, 26 Feb 2024 16:03:46 -0500 Subject: [PATCH 2/2] Appease typescript Signed-off-by: Boris Bera --- .../catalog/src/components/CatalogTable/columns.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/catalog/src/components/CatalogTable/columns.tsx b/plugins/catalog/src/components/CatalogTable/columns.tsx index a191befe59..a955aaadb9 100644 --- a/plugins/catalog/src/components/CatalogTable/columns.tsx +++ b/plugins/catalog/src/components/CatalogTable/columns.tsx @@ -87,11 +87,14 @@ export const columnFactories = Object.freeze({ title: 'Targets', field: 'entity.spec.targets', customFilterAndSearch: (query, row) => { - const targets = []; - if (Array.isArray(row.entity?.spec?.targets)) { - targets.push(...row.entity?.spec?.targets); + let targets: JsonArray = []; + if ( + row.entity?.spec?.targets && + Array.isArray(row.entity?.spec?.targets) + ) { + targets = row.entity?.spec?.targets; } else if (row.entity?.spec?.target) { - targets.push(row.entity?.spec?.target); + targets = [row.entity?.spec?.target]; } return targets .join(', ')