From 18c7f12f398247bdc45c5cfe347b0007c82fc388 Mon Sep 17 00:00:00 2001 From: Alex McKay Date: Fri, 29 Mar 2024 14:04:02 -0400 Subject: [PATCH] Add isApiType function Signed-off-by: Alex McKay --- .changeset/witty-kings-smoke.md | 5 +++++ plugins/catalog/api-report.md | 5 +++++ plugins/catalog/src/components/EntitySwitch/conditions.ts | 8 ++++++++ plugins/catalog/src/components/EntitySwitch/index.ts | 1 + 4 files changed, 19 insertions(+) create mode 100644 .changeset/witty-kings-smoke.md diff --git a/.changeset/witty-kings-smoke.md b/.changeset/witty-kings-smoke.md new file mode 100644 index 0000000000..d59716eeff --- /dev/null +++ b/.changeset/witty-kings-smoke.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': minor +--- + +Add `isApiType()` to EntitySwitch routing functions. diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index 8766b983ca..a26099d613 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -559,6 +559,11 @@ export interface HasSystemsCardProps { variant?: InfoCardVariants; } +// @public +export function isApiType( + types: string | string[], +): (entity: Entity) => boolean; + // @public export function isComponentType( types: string | string[], diff --git a/plugins/catalog/src/components/EntitySwitch/conditions.ts b/plugins/catalog/src/components/EntitySwitch/conditions.ts index f834804141..890bcdac9c 100644 --- a/plugins/catalog/src/components/EntitySwitch/conditions.ts +++ b/plugins/catalog/src/components/EntitySwitch/conditions.ts @@ -60,6 +60,14 @@ export function isResourceType(types: string | string[]) { return isEntityWith({ kind: 'resource', type: types }); } +/** + * For use in EntitySwitch.Case. Matches if the entity is an API of a given spec.type. + * @public + */ +export function isApiType(types: string | string[]) { + return isEntityWith({ kind: 'api', type: types }); +} + /** * For use in EntitySwitch.Case. Matches if the entity is the specified kind and type (if present). * @public diff --git a/plugins/catalog/src/components/EntitySwitch/index.ts b/plugins/catalog/src/components/EntitySwitch/index.ts index 8848f98866..a4e46c0b77 100644 --- a/plugins/catalog/src/components/EntitySwitch/index.ts +++ b/plugins/catalog/src/components/EntitySwitch/index.ts @@ -22,5 +22,6 @@ export { isNamespace, isComponentType, isResourceType, + isApiType, isEntityWith, } from './conditions';