Merge pull request #10702 from angeliski/add-check-id

Add checksId option to EntityTechInsightsScorecardContent component
This commit is contained in:
Fredrik Adelöw
2022-04-09 15:40:55 +02:00
committed by GitHub
6 changed files with 20 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-insights': minor
---
Add checksId option to EntityTechInsightsScorecardContent component
+6
View File
@@ -38,6 +38,10 @@ const serviceEntityPage = (
title="Customized title for the scorecard"
description="Small description about scorecards"
/>
<EntityTechInsightsScorecardContent
title="Show only simpleTestCheck in this card"
checksId={['simpleTestCheck']}
/>
</EntityLayout.Route>
...
</EntityLayoutWrapper>
@@ -46,6 +50,8 @@ const serviceEntityPage = (
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`.
You can pass an array `checksId` as a prop with the [Fact Retrievers ids](../tech-insights-backend#creating-fact-retrievers) to limit which checks you want to show in this card, If you don't pass, the default value is show all checks.
## Boolean Scorecard Example
If you follow the [Backend Example](https://github.com/backstage/backstage/tree/master/plugins/tech-insights-backend#backend-example), once the needed facts have been generated the boolean scorecard will look like this:
+3 -1
View File
@@ -34,9 +34,11 @@ export type CheckResultRenderer = {
export const EntityTechInsightsScorecardContent: ({
title,
description,
checksId,
}: {
title?: string | undefined;
description?: string | undefined;
checksId?: string[] | undefined;
}) => JSX.Element;
// @public
@@ -58,7 +60,7 @@ export interface TechInsightsApi {
// (undocumented)
runChecks(
entityParams: CompoundEntityRef,
checks?: Check[],
checks?: string[],
): Promise<CheckResult[]>;
}
@@ -47,7 +47,7 @@ export interface TechInsightsApi {
getAllChecks(): Promise<Check[]>;
runChecks(
entityParams: CompoundEntityRef,
checks?: Check[],
checks?: string[],
): Promise<CheckResult[]>;
runBulkChecks(
entities: CompoundEntityRef[],
@@ -75,13 +75,12 @@ export class TechInsightsClient implements TechInsightsApi {
async runChecks(
entityParams: CompoundEntityRef,
checks?: Check[],
checks?: string[],
): Promise<CheckResult[]> {
const url = await this.discoveryApi.getBaseUrl('tech-insights');
const { token } = await this.identityApi.getCredentials();
const { namespace, kind, name } = entityParams;
const checkIds = checks ? checks.map(check => check.id) : [];
const requestBody = { checks: checkIds.length > 0 ? checkIds : undefined };
const requestBody = { checks };
const response = await fetch(
`${url}/checks/run/${encodeURIComponent(namespace)}/${encodeURIComponent(
kind,
@@ -26,14 +26,16 @@ import { techInsightsApiRef } from '../../api/TechInsightsApi';
export const ScorecardsOverview = ({
title,
description,
checksId,
}: {
title?: string;
description?: string;
checksId?: string[];
}) => {
const api = useApi(techInsightsApiRef);
const { namespace, kind, name } = useParams();
const { value, loading, error } = useAsync(
async () => await api.runChecks({ namespace, kind, name }),
async () => await api.runChecks({ namespace, kind, name }, checksId),
);
if (loading) {