UNPKG

@backstage-community/plugin-sonarqube

Version:
141 lines (138 loc) 5.24 kB
import { jsxs, jsx, Fragment } from 'react/jsx-runtime'; import { useEntity, MissingAnnotationEmptyState } from '@backstage/plugin-catalog-react'; import { sonarQubeApiRef, useProjectInfo, SONARQUBE_PROJECT_KEY_ANNOTATION } from '@backstage-community/plugin-sonarqube-react'; import Grid from '@material-ui/core/Grid'; import { makeStyles } from '@material-ui/core/styles'; import useAsync from 'react-use/esm/useAsync'; import { InfoCard, Progress, EmptyState } from '@backstage/core-components'; import { useApi } from '@backstage/core-plugin-api'; import { QualityBadge, BugReportRatingCard, VulnerabilitiesRatingCard, CodeSmellsRatingCard, HotspotsReviewed, CoverageRatingCard, DuplicationsRatingCard, LastAnalyzedRatingCard } from './MetricInsights.esm.js'; import { useTranslationRef } from '@backstage/frontend-plugin-api'; import { sonarqubeTranslationRef } from '../../translation.esm.js'; const useStyles = makeStyles((theme) => ({ header: { padding: theme.spacing(2, 2, 2, 2.5) }, action: { margin: 0 }, lastAnalyzed: { color: theme.palette.text.secondary } })); const SonarQubeCard = (props) => { const { variant = "gridItem", missingAnnotationReadMoreUrl } = props; const { entity } = useEntity(); const sonarQubeApi = useApi(sonarQubeApiRef); const { t } = useTranslationRef(sonarqubeTranslationRef); const { projectKey: projectTitle, projectInstance } = useProjectInfo(entity); const { value: summaryFinding, loading } = useAsync( async () => sonarQubeApi.getFindingSummary({ componentKey: projectTitle, projectInstance }), [sonarQubeApi, projectTitle] ); const deepLink = !loading && summaryFinding?.metrics ? { title: t("sonarQubeCard.deepLinkTitle"), link: summaryFinding.projectUrl } : void 0; const classes = useStyles(); return /* @__PURE__ */ jsxs( InfoCard, { title: t("sonarQubeCard.title"), deepLink, variant, headerProps: { action: !loading && summaryFinding?.metrics && /* @__PURE__ */ jsx(QualityBadge, { value: summaryFinding }), classes: { root: classes.header, action: classes.action } }, children: [ loading && /* @__PURE__ */ jsx(Progress, {}), !loading && !projectTitle && /* @__PURE__ */ jsx( MissingAnnotationEmptyState, { annotation: SONARQUBE_PROJECT_KEY_ANNOTATION, readMoreUrl: missingAnnotationReadMoreUrl } ), !loading && projectTitle && !summaryFinding?.metrics && /* @__PURE__ */ jsx( EmptyState, { missing: "info", title: t("sonarQubeCard.emptyState.title"), description: t("sonarQubeCard.emptyState.description", { projectTitle }) } ), !loading && summaryFinding?.metrics && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs( Grid, { item: true, container: true, direction: "column", justifyContent: "space-between", alignItems: "center", style: { height: "100%" }, spacing: 0, children: [ /* @__PURE__ */ jsxs(Grid, { item: true, container: true, justifyContent: "space-around", children: [ /* @__PURE__ */ jsx( BugReportRatingCard, { value: summaryFinding, title: t("sonarQubeCard.bugReportRatingCardTitle") } ), /* @__PURE__ */ jsx( VulnerabilitiesRatingCard, { value: summaryFinding, title: t("sonarQubeCard.vulnerabilitiesRatingCardTitle") } ), /* @__PURE__ */ jsx( CodeSmellsRatingCard, { value: summaryFinding, title: t("sonarQubeCard.codeSmellsRatingCardTitle") } ), /* @__PURE__ */ jsx( HotspotsReviewed, { value: summaryFinding, title: t("sonarQubeCard.hotspotsReviewedTitle") } ), /* @__PURE__ */ jsx("div", { style: { width: "100%" } }), /* @__PURE__ */ jsx( CoverageRatingCard, { value: summaryFinding, title: t("sonarQubeCard.coverageRatingCardTitle") } ), /* @__PURE__ */ jsx( DuplicationsRatingCard, { value: summaryFinding, title: t("sonarQubeCard.duplicationsRatingCard") } ) ] }), /* @__PURE__ */ jsx(Grid, { item: true, className: classes.lastAnalyzed, children: /* @__PURE__ */ jsx(LastAnalyzedRatingCard, { value: summaryFinding }) }) ] } ) }) ] } ); }; export { SonarQubeCard }; //# sourceMappingURL=SonarQubeCard.esm.js.map