UNPKG

@roadiehq/backstage-plugin-github-insights

Version:
63 lines (60 loc) 2.95 kB
import React from 'react'; 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__ */ React.createElement(MissingAnnotationEmptyState, { annotation: GITHUB_INSIGHTS_ANNOTATION }); } if (loading) { return /* @__PURE__ */ React.createElement(Progress, null); } else if (error) { return /* @__PURE__ */ React.createElement(Alert, { severity: "error", className: classes.infoCard }, error.message); } return value?.environments?.length && owner && repo ? /* @__PURE__ */ React.createElement( 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 }, /* @__PURE__ */ React.createElement(List, null, value.environments.map((environment) => /* @__PURE__ */ React.createElement(ListItem, { className: classes.listItem, key: environment.id }, /* @__PURE__ */ React.createElement( Link, { href: environment.html_url, color: "inherit", target: "_blank", rel: "noopener noreferrer" }, /* @__PURE__ */ React.createElement("p", { className: classes.releaseTitle }, environment.name) )))) ) : /* @__PURE__ */ React.createElement(React.Fragment, null); }; const EnvironmentsCard = () => { const { entity } = useEntity(); const hostname = getHostname(entity); return /* @__PURE__ */ React.createElement(GitHubAuthorizationWrapper, { title: "Environments", hostname }, /* @__PURE__ */ React.createElement(EnvironmentsCardContent, null)); }; export { EnvironmentsCard as default }; //# sourceMappingURL=EnvironmentsCard.esm.js.map