From f24207eb6c1a1b1dc977bb1b14616d1a05b92de5 Mon Sep 17 00:00:00 2001 From: GoFightNguyen Date: Sun, 24 Dec 2023 22:08:15 +0000 Subject: [PATCH 1/7] catalog: export defaultColumnsFunc Signed-off-by: GoFightNguyen --- plugins/catalog/api-report.md | 3 +++ .../catalog/src/components/CatalogTable/CatalogTable.tsx | 6 +++++- plugins/catalog/src/components/CatalogTable/index.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index bef24b50d8..e2225f5ba6 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -245,6 +245,9 @@ export interface DefaultCatalogPageProps { tableOptions?: TableProps['options']; } +// @public (undocumented) +export const defaultColumnsFunc: CatalogTableColumnsFunc; + // @public export class DefaultEntityPresentationApi implements EntityPresentationApi { static create( diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index 006210bb1d..c68e1b06a6 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -77,7 +77,11 @@ const refCompare = (a: Entity, b: Entity) => { return toRef(a).localeCompare(toRef(b)); }; -const defaultColumnsFunc: CatalogTableColumnsFunc = ({ filters, entities }) => { +/** @public */ +export const defaultColumnsFunc: CatalogTableColumnsFunc = ({ + filters, + entities, +}) => { const showTypeColumn = filters.type === undefined; return [ diff --git a/plugins/catalog/src/components/CatalogTable/index.ts b/plugins/catalog/src/components/CatalogTable/index.ts index f5d1ca1bb7..e1d96a6f8f 100644 --- a/plugins/catalog/src/components/CatalogTable/index.ts +++ b/plugins/catalog/src/components/CatalogTable/index.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export { CatalogTable } from './CatalogTable'; +export { CatalogTable, defaultColumnsFunc } from './CatalogTable'; export type { CatalogTableProps } from './CatalogTable'; export type { CatalogTableRow, CatalogTableColumnsFunc } from './types'; From 9f734489937f13fb6ea080b5001b31c8c87045e4 Mon Sep 17 00:00:00 2001 From: GoFightNguyen Date: Sun, 24 Dec 2023 22:17:42 +0000 Subject: [PATCH 2/7] catalog: rename to defaultCatalogTableColumnsFunc from defaultColumnsFunc Signed-off-by: GoFightNguyen --- plugins/catalog/api-report.md | 2 +- plugins/catalog/src/components/CatalogTable/CatalogTable.tsx | 4 ++-- plugins/catalog/src/components/CatalogTable/index.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index e2225f5ba6..718e974302 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -246,7 +246,7 @@ export interface DefaultCatalogPageProps { } // @public (undocumented) -export const defaultColumnsFunc: CatalogTableColumnsFunc; +export const defaultCatalogTableColumnsFunc: CatalogTableColumnsFunc; // @public export class DefaultEntityPresentationApi implements EntityPresentationApi { diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index c68e1b06a6..fe79607a0c 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -78,7 +78,7 @@ const refCompare = (a: Entity, b: Entity) => { }; /** @public */ -export const defaultColumnsFunc: CatalogTableColumnsFunc = ({ +export const defaultCatalogTableColumnsFunc: CatalogTableColumnsFunc = ({ filters, entities, }) => { @@ -126,7 +126,7 @@ export const defaultColumnsFunc: CatalogTableColumnsFunc = ({ /** @public */ export const CatalogTable = (props: CatalogTableProps) => { const { - columns = defaultColumnsFunc, + columns = defaultCatalogTableColumnsFunc, tableOptions, subtitle, emptyContent, diff --git a/plugins/catalog/src/components/CatalogTable/index.ts b/plugins/catalog/src/components/CatalogTable/index.ts index e1d96a6f8f..a33cc4a9b5 100644 --- a/plugins/catalog/src/components/CatalogTable/index.ts +++ b/plugins/catalog/src/components/CatalogTable/index.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export { CatalogTable, defaultColumnsFunc } from './CatalogTable'; +export { CatalogTable, defaultCatalogTableColumnsFunc } from './CatalogTable'; export type { CatalogTableProps } from './CatalogTable'; export type { CatalogTableRow, CatalogTableColumnsFunc } from './types'; From ebc733e67774e1ddbd94321bc3fd7857f72e123b Mon Sep 17 00:00:00 2001 From: GoFightNguyen Date: Sun, 24 Dec 2023 22:28:52 +0000 Subject: [PATCH 3/7] catalog: extract defaultCatalogTableColumnsFunc to separate file Signed-off-by: GoFightNguyen --- .../components/CatalogTable/CatalogTable.tsx | 47 +------------- .../defaultCatalogTableColumnsFunc.tsx | 65 +++++++++++++++++++ .../src/components/CatalogTable/index.ts | 3 +- 3 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index fe79607a0c..d21cca27c6 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -47,6 +47,7 @@ import React, { ReactNode, useMemo } from 'react'; import { columnFactories } from './columns'; import { CatalogTableColumnsFunc, CatalogTableRow } from './types'; import { PaginatedCatalogTable } from './PaginatedCatalogTable'; +import { defaultCatalogTableColumnsFunc } from './defaultCatalogTableColumnsFunc'; /** * Props for {@link CatalogTable}. @@ -77,52 +78,6 @@ const refCompare = (a: Entity, b: Entity) => { return toRef(a).localeCompare(toRef(b)); }; -/** @public */ -export const defaultCatalogTableColumnsFunc: CatalogTableColumnsFunc = ({ - filters, - entities, -}) => { - const showTypeColumn = filters.type === undefined; - - return [ - columnFactories.createTitleColumn({ hidden: true }), - columnFactories.createNameColumn({ defaultKind: filters.kind?.value }), - ...createEntitySpecificColumns(), - columnFactories.createMetadataDescriptionColumn(), - columnFactories.createTagsColumn(), - ]; - - function createEntitySpecificColumns(): TableColumn[] { - const baseColumns = [ - columnFactories.createSystemColumn(), - columnFactories.createOwnerColumn(), - columnFactories.createSpecTypeColumn({ hidden: !showTypeColumn }), - columnFactories.createSpecLifecycleColumn(), - ]; - switch (filters.kind?.value) { - case 'user': - return []; - case 'domain': - case 'system': - return [columnFactories.createOwnerColumn()]; - case 'group': - case 'template': - return [ - columnFactories.createSpecTypeColumn({ hidden: !showTypeColumn }), - ]; - case 'location': - return [ - columnFactories.createSpecTypeColumn({ hidden: !showTypeColumn }), - columnFactories.createSpecTargetsColumn(), - ]; - default: - return entities.every(entity => entity.metadata.namespace === 'default') - ? baseColumns - : [...baseColumns, columnFactories.createNamespaceColumn()]; - } - } -}; - /** @public */ export const CatalogTable = (props: CatalogTableProps) => { const { diff --git a/plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx b/plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx new file mode 100644 index 0000000000..5948dedee6 --- /dev/null +++ b/plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx @@ -0,0 +1,65 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TableColumn } from '@backstage/core-components'; +import { columnFactories } from './columns'; +import { CatalogTableColumnsFunc, CatalogTableRow } from './types'; + +/** @public */ +export const defaultCatalogTableColumnsFunc: CatalogTableColumnsFunc = ({ + filters, + entities, +}) => { + const showTypeColumn = filters.type === undefined; + + return [ + columnFactories.createTitleColumn({ hidden: true }), + columnFactories.createNameColumn({ defaultKind: filters.kind?.value }), + ...createEntitySpecificColumns(), + columnFactories.createMetadataDescriptionColumn(), + columnFactories.createTagsColumn(), + ]; + + function createEntitySpecificColumns(): TableColumn[] { + const baseColumns = [ + columnFactories.createSystemColumn(), + columnFactories.createOwnerColumn(), + columnFactories.createSpecTypeColumn({ hidden: !showTypeColumn }), + columnFactories.createSpecLifecycleColumn(), + ]; + switch (filters.kind?.value) { + case 'user': + return []; + case 'domain': + case 'system': + return [columnFactories.createOwnerColumn()]; + case 'group': + case 'template': + return [ + columnFactories.createSpecTypeColumn({ hidden: !showTypeColumn }), + ]; + case 'location': + return [ + columnFactories.createSpecTypeColumn({ hidden: !showTypeColumn }), + columnFactories.createSpecTargetsColumn(), + ]; + default: + return entities.every(entity => entity.metadata.namespace === 'default') + ? baseColumns + : [...baseColumns, columnFactories.createNamespaceColumn()]; + } + } +}; diff --git a/plugins/catalog/src/components/CatalogTable/index.ts b/plugins/catalog/src/components/CatalogTable/index.ts index a33cc4a9b5..d69ed0b3a2 100644 --- a/plugins/catalog/src/components/CatalogTable/index.ts +++ b/plugins/catalog/src/components/CatalogTable/index.ts @@ -14,6 +14,7 @@ * limitations under the License. */ -export { CatalogTable, defaultCatalogTableColumnsFunc } from './CatalogTable'; +export { CatalogTable } from './CatalogTable'; +export { defaultCatalogTableColumnsFunc } from './defaultCatalogTableColumnsFunc'; export type { CatalogTableProps } from './CatalogTable'; export type { CatalogTableRow, CatalogTableColumnsFunc } from './types'; From e541c0ec551cee11c12278ea865830f5c29c5f5a Mon Sep 17 00:00:00 2001 From: GoFightNguyen Date: Sun, 24 Dec 2023 23:25:19 +0000 Subject: [PATCH 4/7] catalog: changeset Signed-off-by: GoFightNguyen --- .changeset/seven-dots-serve.md | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .changeset/seven-dots-serve.md diff --git a/.changeset/seven-dots-serve.md b/.changeset/seven-dots-serve.md new file mode 100644 index 0000000000..79f8f62abb --- /dev/null +++ b/.changeset/seven-dots-serve.md @@ -0,0 +1,35 @@ +--- +'@backstage/plugin-catalog': minor +--- + +Exported `defaultCatalogTableColumnsFunc` to create a seam for defining the columns in [CatalogTable](https://github.com/backstage/backstage/blob/master/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx) of some Kinds while using the default columns for the others. +This is useful for defining the columns of a custom Kind or to redefine the columns for a built-in Kind. + +```diff +// packages/app/src/App.tsx + +import { + CatalogEntityPage, + CatalogIndexPage, + catalogPlugin, ++ CatalogTable, ++ CatalogTableColumnsFunc, ++ defaultCatalogTableColumnsFunc, +} from '@backstage/plugin-catalog'; + ++ const myColumnsFunc: CatalogTableColumnsFunc = (entityListContext) => { ++ if (entityListContext.filters.kind?.value === 'MyKind') { ++ return [ ++ CatalogTable.columns.createNameColumn(), ++ CatalogTable.columns.createOwnerColumn() ++ ]; ++ } ++ ++ return defaultCatalogTableColumnsFunc(entityListContext); ++ }; + +... + +- } /> ++ } /> +``` From 93ce28dfa3d153942d7bc0c8dbc24052eb7f5844 Mon Sep 17 00:00:00 2001 From: Jason Nguyen Date: Sun, 24 Dec 2023 17:10:39 -0700 Subject: [PATCH 5/7] remove relative URL from changeset Signed-off-by: Jason Nguyen --- .changeset/seven-dots-serve.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/seven-dots-serve.md b/.changeset/seven-dots-serve.md index 79f8f62abb..1518fb20cc 100644 --- a/.changeset/seven-dots-serve.md +++ b/.changeset/seven-dots-serve.md @@ -2,7 +2,7 @@ '@backstage/plugin-catalog': minor --- -Exported `defaultCatalogTableColumnsFunc` to create a seam for defining the columns in [CatalogTable](https://github.com/backstage/backstage/blob/master/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx) of some Kinds while using the default columns for the others. +Exported `defaultCatalogTableColumnsFunc` to create a seam for defining the columns in `` of some Kinds while using the default columns for the others. This is useful for defining the columns of a custom Kind or to redefine the columns for a built-in Kind. ```diff From 7db77f9487244c1c27f805d998cb66c80e3860e6 Mon Sep 17 00:00:00 2001 From: GoFightNguyen Date: Tue, 26 Dec 2023 21:09:38 +0000 Subject: [PATCH 6/7] catalog: export defaultCatalogTableColumnsFunc through CatalogTable.defaultColumnsFunc instead of directly Signed-off-by: GoFightNguyen --- .changeset/seven-dots-serve.md | 5 ++--- plugins/catalog/api-report.md | 4 +--- plugins/catalog/src/components/CatalogTable/CatalogTable.tsx | 1 + .../CatalogTable/defaultCatalogTableColumnsFunc.tsx | 2 ++ plugins/catalog/src/components/CatalogTable/index.ts | 1 - 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.changeset/seven-dots-serve.md b/.changeset/seven-dots-serve.md index 1518fb20cc..f48ab1f19c 100644 --- a/.changeset/seven-dots-serve.md +++ b/.changeset/seven-dots-serve.md @@ -2,7 +2,7 @@ '@backstage/plugin-catalog': minor --- -Exported `defaultCatalogTableColumnsFunc` to create a seam for defining the columns in `` of some Kinds while using the default columns for the others. +Exported `CatalogTable.defaultColumnsFunc` to create a seam for defining the columns in `` of some Kinds while using the default columns for the others. This is useful for defining the columns of a custom Kind or to redefine the columns for a built-in Kind. ```diff @@ -14,7 +14,6 @@ import { catalogPlugin, + CatalogTable, + CatalogTableColumnsFunc, -+ defaultCatalogTableColumnsFunc, } from '@backstage/plugin-catalog'; + const myColumnsFunc: CatalogTableColumnsFunc = (entityListContext) => { @@ -25,7 +24,7 @@ import { + ]; + } + -+ return defaultCatalogTableColumnsFunc(entityListContext); ++ return CatalogTable.defaultColumnsFunc(entityListContext); + }; ... diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index 718e974302..feda3fd70d 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -182,6 +182,7 @@ export const CatalogTable: { ): TableColumn; createNamespaceColumn(): TableColumn; }>; + defaultColumnsFunc: CatalogTableColumnsFunc; }; // @public @@ -245,9 +246,6 @@ export interface DefaultCatalogPageProps { tableOptions?: TableProps['options']; } -// @public (undocumented) -export const defaultCatalogTableColumnsFunc: CatalogTableColumnsFunc; - // @public export class DefaultEntityPresentationApi implements EntityPresentationApi { static create( diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index d21cca27c6..7da12d7138 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -226,6 +226,7 @@ export const CatalogTable = (props: CatalogTableProps) => { }; CatalogTable.columns = columnFactories; +CatalogTable.defaultColumnsFunc = defaultCatalogTableColumnsFunc; function toEntityRow(entity: Entity) { const partOfSystemRelations = getEntityRelations(entity, RELATION_PART_OF, { diff --git a/plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx b/plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx index 5948dedee6..85f44d3f51 100644 --- a/plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx +++ b/plugins/catalog/src/components/CatalogTable/defaultCatalogTableColumnsFunc.tsx @@ -18,6 +18,8 @@ import { TableColumn } from '@backstage/core-components'; import { columnFactories } from './columns'; import { CatalogTableColumnsFunc, CatalogTableRow } from './types'; +// The defaultCatalogTableColumnsFunc symbol is not directly exported, but through the +// CatalogTable.defaultColumnsFunc field. /** @public */ export const defaultCatalogTableColumnsFunc: CatalogTableColumnsFunc = ({ filters, diff --git a/plugins/catalog/src/components/CatalogTable/index.ts b/plugins/catalog/src/components/CatalogTable/index.ts index d69ed0b3a2..f5d1ca1bb7 100644 --- a/plugins/catalog/src/components/CatalogTable/index.ts +++ b/plugins/catalog/src/components/CatalogTable/index.ts @@ -15,6 +15,5 @@ */ export { CatalogTable } from './CatalogTable'; -export { defaultCatalogTableColumnsFunc } from './defaultCatalogTableColumnsFunc'; export type { CatalogTableProps } from './CatalogTable'; export type { CatalogTableRow, CatalogTableColumnsFunc } from './types'; From 326f556251a6611ac1914416f494a62c7c431675 Mon Sep 17 00:00:00 2001 From: Jason Nguyen Date: Fri, 19 Jan 2024 07:56:51 -0700 Subject: [PATCH 7/7] simplify changeset Signed-off-by: Jason Nguyen --- .changeset/seven-dots-serve.md | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/.changeset/seven-dots-serve.md b/.changeset/seven-dots-serve.md index f48ab1f19c..80919b5d28 100644 --- a/.changeset/seven-dots-serve.md +++ b/.changeset/seven-dots-serve.md @@ -2,33 +2,4 @@ '@backstage/plugin-catalog': minor --- -Exported `CatalogTable.defaultColumnsFunc` to create a seam for defining the columns in `` of some Kinds while using the default columns for the others. -This is useful for defining the columns of a custom Kind or to redefine the columns for a built-in Kind. - -```diff -// packages/app/src/App.tsx - -import { - CatalogEntityPage, - CatalogIndexPage, - catalogPlugin, -+ CatalogTable, -+ CatalogTableColumnsFunc, -} from '@backstage/plugin-catalog'; - -+ const myColumnsFunc: CatalogTableColumnsFunc = (entityListContext) => { -+ if (entityListContext.filters.kind?.value === 'MyKind') { -+ return [ -+ CatalogTable.columns.createNameColumn(), -+ CatalogTable.columns.createOwnerColumn() -+ ]; -+ } -+ -+ return CatalogTable.defaultColumnsFunc(entityListContext); -+ }; - -... - -- } /> -+ } /> -``` +Exported `CatalogTable.defaultColumnsFunc` for defining the columns in `` of some Kinds while using the default columns for the others.