UNPKG

@roadiehq/backstage-plugin-github-insights

Version:
79 lines (76 loc) 3.33 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { List, ListItem, Box } from '@material-ui/core'; import Alert from '@material-ui/lab/Alert'; import { MissingAnnotationEmptyState, Progress, InfoCard, StructuredMetadataTable } from '@backstage/core-components'; import { useProtectedBranches, useRepoLicence, NO_LICENSE_MSG } from '../../../hooks/useComplianceHooks.esm.js'; import { useProjectEntity } from '../../../hooks/useProjectEntity.esm.js'; import { isGithubInsightsAvailable, GITHUB_INSIGHTS_ANNOTATION } from '../../utils/isGithubInsightsAvailable.esm.js'; import WarningIcon from '@material-ui/icons/ErrorOutline'; import { styles } from '../../utils/styles.esm.js'; import { useEntity } from '@backstage/plugin-catalog-react'; import { getHostname } from '../../utils/githubUtils.esm.js'; import { GitHubAuthorizationWrapper } from '@roadiehq/github-auth-utils-react'; const ComplianceCardContent = () => { const { entity } = useEntity(); const { branches, loading, error } = useProtectedBranches(entity); const { license, loading: licenseLoading, error: licenseError } = useRepoLicence(entity); const classes = styles(); const { owner, repo } = useProjectEntity(entity); const projectAlert = isGithubInsightsAvailable(entity); if (!projectAlert) { return /* @__PURE__ */ jsx(MissingAnnotationEmptyState, { annotation: GITHUB_INSIGHTS_ANNOTATION }); } if (loading || licenseLoading) { return /* @__PURE__ */ jsx(Progress, {}); } else if (error || licenseError) { return /* @__PURE__ */ jsxs(Alert, { severity: "error", children: [ "Error occurred while fetching data for the compliance card:", " ", error?.message ] }); } return /* @__PURE__ */ jsx(InfoCard, { title: "Compliance report", className: classes.infoCard, children: /* @__PURE__ */ jsx( StructuredMetadataTable, { metadata: { "Protected branches": branches?.length && owner && repo ? /* @__PURE__ */ jsx(List, { className: classes.listStyle, children: branches.map((branch) => /* @__PURE__ */ jsx(ListItem, { children: branch.name }, branch.name)) }) : /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", children: [ /* @__PURE__ */ jsx( WarningIcon, { style: { color: "orange", marginRight: "5px", flexShrink: 0 } } ), /* @__PURE__ */ jsx("span", { children: "None" }) ] }), License: license === NO_LICENSE_MSG ? /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", children: [ /* @__PURE__ */ jsx( WarningIcon, { style: { color: "orange", marginRight: "5px", flexShrink: 0 } } ), /* @__PURE__ */ jsx("span", { children: "None" }) ] }) : license } } ) }); }; const ComplianceCard = () => { const { entity } = useEntity(); const hostname = getHostname(entity); return /* @__PURE__ */ jsx(GitHubAuthorizationWrapper, { title: "Compliance", hostname, children: /* @__PURE__ */ jsx(ComplianceCardContent, {}) }); }; export { ComplianceCard as default }; //# sourceMappingURL=ComplianceCard.esm.js.map