@roadiehq/backstage-plugin-github-insights
Version:
69 lines (66 loc) • 3.34 kB
JavaScript
import React from 'react';
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__ */ React.createElement(MissingAnnotationEmptyState, { annotation: GITHUB_INSIGHTS_ANNOTATION });
}
if (loading || licenseLoading) {
return /* @__PURE__ */ React.createElement(Progress, null);
} else if (error || licenseError) {
return /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, "Error occurred while fetching data for the compliance card:", " ", error?.message);
}
return /* @__PURE__ */ React.createElement(InfoCard, { title: "Compliance report", className: classes.infoCard }, /* @__PURE__ */ React.createElement(
StructuredMetadataTable,
{
metadata: {
"Protected branches": branches?.length && owner && repo ? /* @__PURE__ */ React.createElement(List, { className: classes.listStyle }, branches.map((branch) => /* @__PURE__ */ React.createElement(ListItem, { key: branch.name }, branch.name))) : /* @__PURE__ */ React.createElement(Box, { display: "flex", alignItems: "center" }, /* @__PURE__ */ React.createElement(
WarningIcon,
{
style: {
color: "orange",
marginRight: "5px",
flexShrink: 0
}
}
), /* @__PURE__ */ React.createElement("span", null, "None")),
License: license === NO_LICENSE_MSG ? /* @__PURE__ */ React.createElement(Box, { display: "flex", alignItems: "center" }, /* @__PURE__ */ React.createElement(
WarningIcon,
{
style: {
color: "orange",
marginRight: "5px",
flexShrink: 0
}
}
), /* @__PURE__ */ React.createElement("span", null, "None")) : license
}
}
));
};
const ComplianceCard = () => {
const { entity } = useEntity();
const hostname = getHostname(entity);
return /* @__PURE__ */ React.createElement(GitHubAuthorizationWrapper, { title: "Compliance", hostname }, /* @__PURE__ */ React.createElement(ComplianceCardContent, null));
};
export { ComplianceCard as default };
//# sourceMappingURL=ComplianceCard.esm.js.map