Add posibility to customize description and title

Signed-off-by: irma12 <irma@roadie.io>
This commit is contained in:
irma12
2022-01-10 14:11:20 +01:00
parent bdf1419d20
commit 34883f5c9e
7 changed files with 49 additions and 7 deletions
+12 -1
View File
@@ -35,13 +35,24 @@ const serviceEntityPage = (
</EntityLayout.Route>
...
<EntityLayout.Route path="/tech-insights" title="Scorecards">
<EntityTechInsightsScorecardContent />
<EntityTechInsightsScorecardContent
title="Customized title for the scorecard"
description="Small description about scorecards"
/>
</EntityLayout.Route>
...
</EntityLayoutWrapper>
);
```
It is not obligatory to pass title and description props to `EntityTechInsightsScorecardContent`. If those are left out, default values from `defaultCheckResultRenderers` in `CheckResultRenderer` will be taken, hence `Boolean scorecard` and `This card represents an overview of default boolean Backstage checks`.
### Customize scorecards overview title and description:
```tsx
// packages/app/src/components/catalog/EntityPage.tsx
## Links
- [The Backstage homepage](https://backstage.io)
```
@@ -38,6 +38,8 @@ export interface TechInsightsApi {
getScorecardsDefinition: (
type: string,
value: CheckResult[],
title?: string,
description?: string,
) => CheckResultRenderer | undefined;
getAllChecks(): Promise<Check[]>;
runChecks(entityParams: EntityName, checks?: Check[]): Promise<CheckResult[]>;
@@ -43,8 +43,14 @@ export class TechInsightsClient implements TechInsightsApi {
getScorecardsDefinition(
type: string,
value: CheckResult[],
title?: string,
description?: string,
): CheckResultRenderer | undefined {
const resultRenderers = defaultCheckResultRenderers(value);
const resultRenderers = defaultCheckResultRenderers(
value,
title,
description,
);
return resultRenderers.find(d => d.type === type);
}
@@ -32,12 +32,15 @@ export type CheckResultRenderer = {
export function defaultCheckResultRenderers(
value: CheckResult[],
title: string,
description: string,
): CheckResultRenderer[] {
return [
{
type: 'json-rules-engine',
title: 'Boolean scorecard',
title: title || 'Boolean scorecard',
description:
description ||
'This card represents an overview of default boolean Backstage checks:',
component: <BooleanCheck checkResult={value} />,
},
@@ -36,9 +36,11 @@ const useStyles = makeStyles((theme: BackstageTheme) => ({
type Checks = {
checks: CheckResult[];
title?: string;
description?: string;
};
export const ChecksOverview = ({ checks }: Checks) => {
export const ChecksOverview = ({ checks, title, description }: Checks) => {
const classes = useStyles();
const api = useApi(techInsightsApiRef);
if (!checks.length) {
@@ -47,6 +49,8 @@ export const ChecksOverview = ({ checks }: Checks) => {
const checkRenderType = api.getScorecardsDefinition(
checks[0].check.type,
checks,
title,
description,
);
if (checkRenderType) {
@@ -23,10 +23,15 @@ import { ChecksOverview } from './ChecksOverview';
import Alert from '@material-ui/lab/Alert';
import { techInsightsApiRef } from '../../api/TechInsightsApi';
export const ScorecardsOverview = () => {
export const ScorecardsOverview = ({
title,
description,
}: {
title?: string;
description?: string;
}) => {
const api = useApi(techInsightsApiRef);
const { namespace, kind, name } = useParams();
const { value, loading, error } = useAsync(
async () => await api.runChecks({ namespace, kind, name }),
);
@@ -37,5 +42,11 @@ export const ScorecardsOverview = () => {
return <Alert severity="error">{error.message}</Alert>;
}
return <ChecksOverview checks={value || []} />;
return (
<ChecksOverview
title={title}
description={description}
checks={value || []}
/>
);
};