feat: add new component EntityTechInsightsScorecardCard
The `EntityTechInsightsScorecardCard` can be used in the overview of the `EntityPage` page or display multiple individual `EntityTechInsightsScorecardCard` in `EntityLayout.Route`. Signed-off-by: David Weber <david.weber@w3tec.ch>
This commit is contained in:
+3
-3
@@ -19,11 +19,11 @@ import { useParams } from 'react-router-dom';
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
import { Progress } from '@backstage/core-components';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { ChecksOverview } from './ChecksOverview';
|
||||
import { ScorecardInfo } from '../ScorecardsInfo';
|
||||
import Alert from '@material-ui/lab/Alert';
|
||||
import { techInsightsApiRef } from '../../api/TechInsightsApi';
|
||||
|
||||
export const ScorecardsOverview = ({
|
||||
export const ScorecardsCard = ({
|
||||
title,
|
||||
description,
|
||||
checksId,
|
||||
@@ -45,7 +45,7 @@ export const ScorecardsOverview = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<ChecksOverview
|
||||
<ScorecardInfo
|
||||
title={title}
|
||||
description={description}
|
||||
checks={value || []}
|
||||
+1
-1
@@ -14,4 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { ScorecardsOverview } from './ScorecardsOverview';
|
||||
export { ScorecardsCard } from './ScorecardsCard';
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
import { Content, Page, Progress } from '@backstage/core-components';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { ScorecardInfo } from '../ScorecardsInfo';
|
||||
import Alert from '@material-ui/lab/Alert';
|
||||
import { techInsightsApiRef } from '../../api/TechInsightsApi';
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
contentScorecards: {
|
||||
paddingLeft: 0,
|
||||
paddingRight: 0,
|
||||
},
|
||||
}));
|
||||
|
||||
export const ScorecardsContent = ({
|
||||
title,
|
||||
description,
|
||||
checksId,
|
||||
}: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
checksId?: string[];
|
||||
}) => {
|
||||
const classes = useStyles();
|
||||
const api = useApi(techInsightsApiRef);
|
||||
const { namespace, kind, name } = useParams();
|
||||
const { value, loading, error } = useAsync(
|
||||
async () => await api.runChecks({ namespace, kind, name }, checksId),
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
return <Progress />;
|
||||
} else if (error) {
|
||||
return <Alert severity="error">{error.message}</Alert>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Page themeId="home">
|
||||
<Content className={classes.contentScorecards}>
|
||||
<ScorecardInfo
|
||||
title={title}
|
||||
description={description}
|
||||
checks={value || []}
|
||||
/>
|
||||
</Content>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { ScorecardsContent } from './ScorecardContent';
|
||||
+33
-22
@@ -17,17 +17,13 @@
|
||||
import React from 'react';
|
||||
import { makeStyles, Grid, Typography } from '@material-ui/core';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { Content, Page, InfoCard } from '@backstage/core-components';
|
||||
import { InfoCard } from '@backstage/core-components';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import { techInsightsApiRef } from '../../api/TechInsightsApi';
|
||||
import { BackstageTheme } from '@backstage/theme';
|
||||
import { Alert } from '@material-ui/lab';
|
||||
|
||||
const useStyles = makeStyles((theme: BackstageTheme) => ({
|
||||
contentScorecards: {
|
||||
paddingLeft: 0,
|
||||
paddingRight: 0,
|
||||
},
|
||||
subheader: {
|
||||
fontWeight: 'bold',
|
||||
paddingLeft: theme.spacing(0.5),
|
||||
@@ -40,12 +36,37 @@ type Checks = {
|
||||
description?: string;
|
||||
};
|
||||
|
||||
export const ChecksOverview = ({ checks, title, description }: Checks) => {
|
||||
const infoCard = (
|
||||
title: Checks['title'],
|
||||
description: Checks['description'],
|
||||
className: string,
|
||||
element: JSX.Element,
|
||||
) => (
|
||||
<Grid item xs={12}>
|
||||
<InfoCard title={title}>
|
||||
<Typography className={className} variant="body1" gutterBottom>
|
||||
{description}
|
||||
</Typography>
|
||||
<Grid item xs={12}>
|
||||
{element}
|
||||
</Grid>
|
||||
</InfoCard>
|
||||
</Grid>
|
||||
);
|
||||
|
||||
export const ScorecardInfo = ({ checks, title, description }: Checks) => {
|
||||
const classes = useStyles();
|
||||
const api = useApi(techInsightsApiRef);
|
||||
|
||||
if (!checks.length) {
|
||||
return <Alert severity="warning">No checks have any data yet.</Alert>;
|
||||
return infoCard(
|
||||
title,
|
||||
description,
|
||||
classes.subheader,
|
||||
<Alert severity="warning">No checks have any data yet.</Alert>,
|
||||
);
|
||||
}
|
||||
|
||||
const checkRenderType = api.getScorecardsDefinition(
|
||||
checks[0].check.type,
|
||||
checks,
|
||||
@@ -54,21 +75,11 @@ export const ChecksOverview = ({ checks, title, description }: Checks) => {
|
||||
);
|
||||
|
||||
if (checkRenderType) {
|
||||
return (
|
||||
<Page themeId="home">
|
||||
<Content className={classes.contentScorecards}>
|
||||
<Grid item xs={12}>
|
||||
<InfoCard title={checkRenderType.title}>
|
||||
<Typography className={classes.subheader} variant="body1">
|
||||
{checkRenderType.description}
|
||||
</Typography>
|
||||
<Grid item xs={11}>
|
||||
{checkRenderType.component}
|
||||
</Grid>
|
||||
</InfoCard>
|
||||
</Grid>
|
||||
</Content>
|
||||
</Page>
|
||||
return infoCard(
|
||||
checkRenderType.title,
|
||||
checkRenderType.description,
|
||||
classes.subheader,
|
||||
checkRenderType.component,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { ScorecardInfo } from './ScorecardInfo';
|
||||
@@ -16,6 +16,7 @@
|
||||
export {
|
||||
techInsightsPlugin,
|
||||
EntityTechInsightsScorecardContent,
|
||||
EntityTechInsightsScorecardCard,
|
||||
} from './plugin';
|
||||
|
||||
export { techInsightsApiRef } from './api/TechInsightsApi';
|
||||
|
||||
@@ -49,7 +49,19 @@ export const EntityTechInsightsScorecardContent = techInsightsPlugin.provide(
|
||||
createRoutableExtension({
|
||||
name: 'EntityTechInsightsScorecardContent',
|
||||
component: () =>
|
||||
import('./components/ScorecardsOverview').then(m => m.ScorecardsOverview),
|
||||
import('./components/ScorecardsContent').then(m => m.ScorecardsContent),
|
||||
mountPoint: rootRouteRef,
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const EntityTechInsightsScorecardCard = techInsightsPlugin.provide(
|
||||
createRoutableExtension({
|
||||
name: 'EntityTechInsightsScorecardCard',
|
||||
component: () =>
|
||||
import('./components/ScorecardsCard').then(m => m.ScorecardsCard),
|
||||
mountPoint: rootRouteRef,
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user