Incorporated the feedback

Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
bnechyporenko
2022-09-19 18:19:22 +02:00
parent 7939e743f5
commit f4c67c3eca
2 changed files with 23 additions and 14 deletions
+1 -1
View File
@@ -285,7 +285,7 @@ export function EntityRefLinks(props: EntityRefLinksProps): JSX.Element;
export type EntityRefLinksProps = {
entityRefs: (string | Entity | CompoundEntityRef)[];
defaultKind?: string;
titleFn?: (r: string | Entity | CompoundEntityRef) => string;
getTitle?: (cer: CompoundEntityRef) => string;
} & Omit<LinkProps, 'to'>;
// @public
@@ -26,7 +26,7 @@ import { LinkProps } from '@backstage/core-components';
export type EntityRefLinksProps = {
entityRefs: (string | Entity | CompoundEntityRef)[];
defaultKind?: string;
titleFn?: (r: string | Entity | CompoundEntityRef) => string;
getTitle?: (cer: CompoundEntityRef) => string;
} & Omit<LinkProps, 'to'>;
/**
@@ -35,20 +35,29 @@ export type EntityRefLinksProps = {
* @public
*/
export function EntityRefLinks(props: EntityRefLinksProps) {
const { entityRefs, defaultKind, titleFn, ...linkProps } = props;
const { entityRefs, defaultKind, getTitle, ...linkProps } = props;
return (
<>
{entityRefs.map((r, i) => (
<React.Fragment key={i}>
{i > 0 && ', '}
<EntityRefLink
{...linkProps}
entityRef={r}
defaultKind={defaultKind}
title={titleFn ? titleFn(r) : undefined}
/>
</React.Fragment>
))}
{entityRefs.map((r, i) => {
const isCompoundEntityRef =
getTitle && typeof r !== 'string' && !('metadata' in r && getTitle);
const title = isCompoundEntityRef
? getTitle(r as CompoundEntityRef)
: undefined;
return (
<React.Fragment key={i}>
{i > 0 && ', '}
<EntityRefLink
{...linkProps}
entityRef={r}
defaultKind={defaultKind}
title={title}
/>
</React.Fragment>
);
})}
</>
);
}