@roadiehq/backstage-plugin-github-insights
Version:
63 lines (60 loc) • 2.87 kB
JavaScript
import { jsx, Fragment } from 'react/jsx-runtime';
import { List, ListItem, Link } from '@material-ui/core';
import { Alert } from '@material-ui/lab';
import { MissingAnnotationEmptyState, Progress, InfoCard } from '@backstage/core-components';
import { useRequest } from '../../../hooks/useRequest.esm.js';
import { useEntityGithubScmIntegration } from '../../../hooks/useEntityGithubScmIntegration.esm.js';
import { useProjectEntity } from '../../../hooks/useProjectEntity.esm.js';
import { isGithubInsightsAvailable, GITHUB_INSIGHTS_ANNOTATION } from '../../utils/isGithubInsightsAvailable.esm.js';
import { useEntity } from '@backstage/plugin-catalog-react';
import { styles } from '../../utils/styles.esm.js';
import { getHostname } from '../../utils/githubUtils.esm.js';
import { GitHubAuthorizationWrapper } from '@roadiehq/github-auth-utils-react';
const EnvironmentsCardContent = () => {
const classes = styles();
const { entity } = useEntity();
const { owner, repo } = useProjectEntity(entity);
const { value, loading, error } = useRequest(entity, "environments", 0, 0);
const { hostname } = useEntityGithubScmIntegration(entity);
const projectAlert = isGithubInsightsAvailable(entity);
if (!projectAlert) {
return /* @__PURE__ */ jsx(MissingAnnotationEmptyState, { annotation: GITHUB_INSIGHTS_ANNOTATION });
}
if (loading) {
return /* @__PURE__ */ jsx(Progress, {});
} else if (error) {
return /* @__PURE__ */ jsx(Alert, { severity: "error", className: classes.infoCard, children: error.message });
}
return value?.environments?.length && owner && repo ? /* @__PURE__ */ jsx(
InfoCard,
{
title: "Environments",
deepLink: {
link: `https://${hostname}/${owner}/${repo}/deployments`,
title: "Environments",
onClick: (e) => {
e.preventDefault();
window.open(`https://${hostname}/${owner}/${repo}/deployments`);
}
},
className: classes.infoCard,
children: /* @__PURE__ */ jsx(List, { children: value.environments.map((environment) => /* @__PURE__ */ jsx(ListItem, { className: classes.listItem, children: /* @__PURE__ */ jsx(
Link,
{
href: environment.html_url,
color: "inherit",
target: "_blank",
rel: "noopener noreferrer",
children: /* @__PURE__ */ jsx("p", { className: classes.releaseTitle, children: environment.name })
}
) }, environment.id)) })
}
) : /* @__PURE__ */ jsx(Fragment, {});
};
const EnvironmentsCard = () => {
const { entity } = useEntity();
const hostname = getHostname(entity);
return /* @__PURE__ */ jsx(GitHubAuthorizationWrapper, { title: "Environments", hostname, children: /* @__PURE__ */ jsx(EnvironmentsCardContent, {}) });
};
export { EnvironmentsCard as default };
//# sourceMappingURL=EnvironmentsCard.esm.js.map