From aa66ae0a7f2373d10b81d3793548bac24c182f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20R=C3=A4ntil=C3=A4?= Date: Fri, 15 Mar 2024 09:53:37 +0100 Subject: [PATCH 1/4] feat: Added 'onlyFailed' prop to ScorecardsCard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gustaf Räntilä --- .changeset/twelve-doors-speak.md | 5 ++++ .../components/BooleanCheck/BooleanCheck.tsx | 6 +++++ .../src/components/BooleanCheck/index.ts | 2 +- .../src/components/CheckResultRenderer.tsx | 4 +++- .../ScorecardsCard/ScorecardsCard.tsx | 24 ++++++++++++++++--- .../ScorecardsInfo/ScorecardInfo.tsx | 13 +++++++++- 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .changeset/twelve-doors-speak.md diff --git a/.changeset/twelve-doors-speak.md b/.changeset/twelve-doors-speak.md new file mode 100644 index 0000000000..f3bf806f7b --- /dev/null +++ b/.changeset/twelve-doors-speak.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-tech-insights': minor +--- + +Added 'onlyFailed' prop to ScorecardsCard, and 'isFailed' to each check type. diff --git a/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx b/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx index 17758e8ee4..5729387372 100644 --- a/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx +++ b/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx @@ -29,3 +29,9 @@ export const BooleanCheck = (props: { checkResult: CheckResult }) => { ); }; + +/** + * @public + */ +export const isBooleanCheckFailed = (checkResult: CheckResult) => + !checkResult.result; diff --git a/plugins/tech-insights/src/components/BooleanCheck/index.ts b/plugins/tech-insights/src/components/BooleanCheck/index.ts index 729ab4d62e..accb43f464 100644 --- a/plugins/tech-insights/src/components/BooleanCheck/index.ts +++ b/plugins/tech-insights/src/components/BooleanCheck/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { BooleanCheck } from './BooleanCheck'; +export { BooleanCheck, isBooleanCheckFailed } from './BooleanCheck'; diff --git a/plugins/tech-insights/src/components/CheckResultRenderer.tsx b/plugins/tech-insights/src/components/CheckResultRenderer.tsx index 7db3c72c02..8dc0a13517 100644 --- a/plugins/tech-insights/src/components/CheckResultRenderer.tsx +++ b/plugins/tech-insights/src/components/CheckResultRenderer.tsx @@ -16,7 +16,7 @@ import { CheckResult } from '@backstage/plugin-tech-insights-common'; import React from 'react'; -import { BooleanCheck } from './BooleanCheck'; +import { BooleanCheck, isBooleanCheckFailed } from './BooleanCheck'; /** * Defines a react component that is responsible for rendering a result of a given type. @@ -27,6 +27,7 @@ export type CheckResultRenderer = { type: string; component: (check: CheckResult) => React.ReactElement; description?: (check: CheckResult) => string | React.ReactElement; + isFailed?: (check: CheckResult) => boolean; }; /** @@ -39,4 +40,5 @@ export const jsonRulesEngineCheckResultRenderer: CheckResultRenderer = { component: (checkResult: CheckResult) => ( ), + isFailed: isBooleanCheckFailed, }; diff --git a/plugins/tech-insights/src/components/ScorecardsCard/ScorecardsCard.tsx b/plugins/tech-insights/src/components/ScorecardsCard/ScorecardsCard.tsx index 4bbc283829..7f69b9432d 100644 --- a/plugins/tech-insights/src/components/ScorecardsCard/ScorecardsCard.tsx +++ b/plugins/tech-insights/src/components/ScorecardsCard/ScorecardsCard.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import React from 'react'; +import React, { useMemo } from 'react'; import useAsync from 'react-use/lib/useAsync'; import { ErrorPanel, Progress } from '@backstage/core-components'; import { useApi } from '@backstage/core-plugin-api'; @@ -27,8 +27,9 @@ export const ScorecardsCard = (props: { title: string; description?: string; checksId?: string[]; + onlyFailed?: boolean; }) => { - const { title, description, checksId } = props; + const { title, description, checksId, onlyFailed } = props; const api = useApi(techInsightsApiRef); const { entity } = useEntity(); const { value, loading, error } = useAsync( @@ -36,17 +37,34 @@ export const ScorecardsCard = (props: { [api, entity, JSON.stringify(checksId)], ); + const checkResultRenderers = useMemo(() => { + if (!onlyFailed || !value) return {}; + + const types = [...new Set(value.map(({ check }) => check.type))]; + const renderers = api.getCheckResultRenderers(types); + return Object.fromEntries( + renderers.map(renderer => [renderer.type, renderer]), + ); + }, [api, value, onlyFailed]); + if (loading) { return ; } else if (error) { return ; } + const filteredValue = !onlyFailed + ? value || [] + : (value || []).filter(val => + checkResultRenderers[val.check.type]?.isFailed?.(val), + ); + return ( ); }; diff --git a/plugins/tech-insights/src/components/ScorecardsInfo/ScorecardInfo.tsx b/plugins/tech-insights/src/components/ScorecardsInfo/ScorecardInfo.tsx index cfff074368..66c149ba3c 100644 --- a/plugins/tech-insights/src/components/ScorecardsInfo/ScorecardInfo.tsx +++ b/plugins/tech-insights/src/components/ScorecardsInfo/ScorecardInfo.tsx @@ -52,11 +52,22 @@ export const ScorecardInfo = (props: { checkResults: CheckResult[]; title: string; description?: string; + noWarning?: boolean; }) => { - const { checkResults, title, description } = props; + const { checkResults, title, description, noWarning } = props; const classes = useStyles(); if (!checkResults.length) { + if (noWarning) { + return infoCard( + title, + description, + classes.subheader, + + All checks passed, or no checks have been performed yet + , + ); + } return infoCard( title, description, From 6f83727f8242762964fe317957913141ded08796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20R=C3=A4ntil=C3=A4?= Date: Mon, 18 Mar 2024 14:04:47 +0100 Subject: [PATCH 2/4] api report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gustaf Räntilä --- plugins/tech-insights/api-report.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/tech-insights/api-report.md b/plugins/tech-insights/api-report.md index 1e07c0fc69..5544299bf2 100644 --- a/plugins/tech-insights/api-report.md +++ b/plugins/tech-insights/api-report.md @@ -39,6 +39,7 @@ export type CheckResultRenderer = { type: string; component: (check: CheckResult) => React_2.ReactElement; description?: (check: CheckResult) => string | React_2.ReactElement; + isFailed?: (check: CheckResult) => boolean; }; // @public (undocumented) @@ -46,6 +47,7 @@ export const EntityTechInsightsScorecardCard: (props: { title: string; description?: string | undefined; checksId?: string[] | undefined; + onlyFailed?: boolean | undefined; }) => JSX_2.Element; // @public (undocumented) @@ -73,6 +75,7 @@ export const ScorecardInfo: (props: { checkResults: CheckResult[]; title: string; description?: string | undefined; + noWarning?: boolean | undefined; }) => JSX_2.Element; // @public (undocumented) From 9c1e3678d02de49720f6827a40d649a7ae7160cc Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Tue, 19 Mar 2024 10:17:37 +0100 Subject: [PATCH 3/4] Update twelve-doors-speak.md Signed-off-by: blam --- .changeset/twelve-doors-speak.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/twelve-doors-speak.md b/.changeset/twelve-doors-speak.md index f3bf806f7b..83c5a7656e 100644 --- a/.changeset/twelve-doors-speak.md +++ b/.changeset/twelve-doors-speak.md @@ -2,4 +2,4 @@ '@backstage/plugin-tech-insights': minor --- -Added 'onlyFailed' prop to ScorecardsCard, and 'isFailed' to each check type. +Added `onlyFailed` prop to `ScorecardsCard`, and `isFailed` to each check type. From 21d1c53287ffa99130a6734ac17c918c30e13d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20R=C3=A4ntil=C3=A4?= Date: Tue, 19 Mar 2024 12:16:21 +0100 Subject: [PATCH 4/4] changeset: use patch, not minor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gustaf Räntilä --- .changeset/twelve-doors-speak.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/twelve-doors-speak.md b/.changeset/twelve-doors-speak.md index 83c5a7656e..ac88bf561a 100644 --- a/.changeset/twelve-doors-speak.md +++ b/.changeset/twelve-doors-speak.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-tech-insights': minor +'@backstage/plugin-tech-insights': patch --- Added `onlyFailed` prop to `ScorecardsCard`, and `isFailed` to each check type.