Add option to override description in result renderer

Signed-off-by: ivgo <ivgo@spreadgroup.com>
This commit is contained in:
ivgo
2023-04-13 14:50:52 +02:00
parent 7dc55a8b5b
commit 22963209d2
5 changed files with 58 additions and 15 deletions
@@ -26,6 +26,7 @@ import { BooleanCheck } from './BooleanCheck';
export type CheckResultRenderer = {
type: string;
component: (check: CheckResult) => React.ReactElement;
description?: (check: CheckResult) => string | React.ReactElement;
};
/**
@@ -38,21 +38,29 @@ export const ScorecardsList = (props: { checkResults: CheckResult[] }) => {
return (
<List>
{checkResults.map((result, index) => (
<ListItem key={result.check.id}>
<ListItemText
key={index}
primary={result.check.name}
secondary={result.check.description}
className={classes.listItemText}
/>
{checkResultRenderers
.find(({ type }) => type === result.check.type)
?.component(result) ?? (
<Alert severity="error">Unknown type.</Alert>
)}
</ListItem>
))}
{checkResults.map((result, index) => {
const description = checkResultRenderers.find(
renderer => renderer.type === result.check.type,
)?.description;
return (
<ListItem key={result.check.id}>
<ListItemText
key={index}
primary={result.check.name}
secondary={
description ? description(result) : result.check.description
}
className={classes.listItemText}
/>
{checkResultRenderers
.find(({ type }) => type === result.check.type)
?.component(result) ?? (
<Alert severity="error">Unknown type.</Alert>
)}
</ListItem>
);
})}
</List>
);
};