linkDestination can be undefined

Signed-off-by: nikolar <reyna.nikolayev@autodesk.com>
This commit is contained in:
nikolar
2024-12-10 14:19:43 -08:00
parent 0d7097b705
commit d3dc0ec77d
2 changed files with 15 additions and 13 deletions
@@ -45,7 +45,7 @@ const useStyles = makeStyles(
export type InfoCardGridProps = {
entities: Entity[] | undefined;
linkContent?: string | JSX.Element;
linkDestination?: (entity: Entity) => string;
linkDestination?: (entity: Entity) => string | undefined;
};
/**
@@ -58,17 +58,19 @@ export const InfoCardGrid = (props: InfoCardGridProps) => {
const classes = useStyles();
const getRouteToReaderPageFor = useRouteRef(rootDocsRouteRef);
const config = useApi(configApiRef);
const linkRoute = (entity: Entity) =>
typeof linkDestination === 'function'
? linkDestination(entity)
: getRouteToReaderPageFor({
namespace: toLowerMaybe(
entity.metadata.namespace ?? 'default',
config,
),
kind: toLowerMaybe(entity.kind, config),
name: toLowerMaybe(entity.metadata.name, config),
});
const linkRoute = (entity: Entity) => {
if (linkDestination) {
const destination = linkDestination(entity);
if (destination) {
return destination;
}
}
return getRouteToReaderPageFor({
namespace: toLowerMaybe(entity.metadata.namespace ?? 'default', config),
kind: toLowerMaybe(entity.kind, config),
name: toLowerMaybe(entity.metadata.name, config),
});
};
if (!entities) return null;
return (
@@ -72,7 +72,7 @@ export interface PanelProps {
showSupport?: boolean;
options?: TableOptions<DocsTableRow>;
linkContent?: string | JSX.Element;
linkDestination?: (entity: Entity) => string;
linkDestination?: (entity: Entity) => string | undefined;
}
/**