Merge pull request #9656 from backstage/rugvip/switchprops

catalog: added EntitySwitchProps
This commit is contained in:
Patrik Oldsberg
2022-02-18 14:14:53 +01:00
committed by GitHub
4 changed files with 27 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---
Added `EntitySwitchProps` type for `EntitySwitch`.
+9 -2
View File
@@ -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';
@@ -313,14 +314,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,
@@ -330,6 +331,12 @@ export interface EntitySwitchCaseProps {
) => boolean | Promise<boolean>;
}
// @public
export interface EntitySwitchProps {
// (undocumented)
children: ReactNode;
}
// @public (undocumented)
export function FilterContainer(props: {
children: React_2.ReactNode;
@@ -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<boolean>;
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<SwitchCaseResult>((element: React.ReactElement) => {
.flatMap<SwitchCaseResult>((element: ReactElement) => {
const { if: condition, children: elementsChildren } =
element.props as EntitySwitchCase;
return [
@@ -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';