From 852d5ff758310ee9b80cd17cc68d9843d986089b Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 18 Feb 2022 13:20:15 +0100 Subject: [PATCH] catalog: added EntitySwitchProps Signed-off-by: Patrik Oldsberg --- .changeset/five-apes-rest.md | 5 +++++ plugins/catalog/api-report.md | 11 +++++++++-- .../src/components/EntitySwitch/EntitySwitch.tsx | 16 ++++++++++++---- .../catalog/src/components/EntitySwitch/index.ts | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 .changeset/five-apes-rest.md diff --git a/.changeset/five-apes-rest.md b/.changeset/five-apes-rest.md new file mode 100644 index 0000000000..d4704d2014 --- /dev/null +++ b/.changeset/five-apes-rest.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': patch +--- + +Added `EntitySwitchProps` type for `EntitySwitch`. diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index e2cc0c8ba6..15e88de8d4 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -15,6 +15,7 @@ import { IndexableDocument } from '@backstage/search-common'; import { InfoCardVariants } from '@backstage/core-components'; import { Overrides } from '@material-ui/core/styles/overrides'; import { default as React_2 } from 'react'; +import { ReactNode } from 'react'; import { RouteRef } from '@backstage/core-plugin-api'; import { StyleRules } from '@material-ui/core/styles/withStyles'; import { TableColumn } from '@backstage/core-components'; @@ -307,14 +308,14 @@ export function EntityProcessingErrorsPanel(): JSX.Element | null; // @public (undocumented) export const EntitySwitch: { - (props: { children: React_2.ReactNode }): JSX.Element | null; + (props: EntitySwitchProps): JSX.Element | null; Case: (_props: EntitySwitchCaseProps) => null; }; // @public (undocumented) export interface EntitySwitchCaseProps { // (undocumented) - children: React_2.ReactNode; + children: ReactNode; // (undocumented) if?: ( entity: Entity, @@ -324,6 +325,12 @@ export interface EntitySwitchCaseProps { ) => boolean | Promise; } +// @public +export interface EntitySwitchProps { + // (undocumented) + children: ReactNode; +} + // @public (undocumented) export function FilterContainer(props: { children: React_2.ReactNode; diff --git a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx index c919cdf805..4433517247 100644 --- a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx +++ b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx @@ -16,7 +16,7 @@ import { Entity } from '@backstage/catalog-model'; import { useEntity } from '@backstage/plugin-catalog-react'; -import React from 'react'; +import React, { ReactNode, ReactElement } from 'react'; import { attachComponentData, useApiHolder, @@ -33,7 +33,7 @@ export interface EntitySwitchCaseProps { entity: Entity, context: { apis: ApiHolder }, ) => boolean | Promise; - children: React.ReactNode; + children: ReactNode; } const EntitySwitchCaseComponent = (_props: EntitySwitchCaseProps) => null; @@ -53,8 +53,16 @@ type SwitchCaseResult = { children: JSX.Element; }; +/** + * Props for the {@link EntitySwitch} component. + * @public + */ +export interface EntitySwitchProps { + children: ReactNode; +} + /** @public */ -export const EntitySwitch = (props: { children: React.ReactNode }) => { +export const EntitySwitch = (props: EntitySwitchProps) => { const { entity } = useEntity(); const apis = useApiHolder(); const results = useElementFilter( @@ -66,7 +74,7 @@ export const EntitySwitch = (props: { children: React.ReactNode }) => { withStrictError: 'Child of EntitySwitch is not an EntitySwitch.Case', }) .getElements() - .flatMap((element: React.ReactElement) => { + .flatMap((element: ReactElement) => { const { if: condition, children: elementsChildren } = element.props as EntitySwitchCase; return [ diff --git a/plugins/catalog/src/components/EntitySwitch/index.ts b/plugins/catalog/src/components/EntitySwitch/index.ts index 0e2852b223..6cccf4be6e 100644 --- a/plugins/catalog/src/components/EntitySwitch/index.ts +++ b/plugins/catalog/src/components/EntitySwitch/index.ts @@ -15,5 +15,5 @@ */ export { EntitySwitch } from './EntitySwitch'; -export type { EntitySwitchCaseProps } from './EntitySwitch'; +export type { EntitySwitchProps, EntitySwitchCaseProps } from './EntitySwitch'; export { isKind, isNamespace, isComponentType } from './conditions';