UNPKG

@roadiehq/backstage-plugin-github-insights

Version:
73 lines (70 loc) 3.29 kB
import React from 'react'; import { List, ListItem, Link, Chip } from '@material-ui/core'; import LocalOfferOutlinedIcon from '@material-ui/icons/LocalOfferOutlined'; import Alert from '@material-ui/lab/Alert'; 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 ReleasesCardContent = () => { const classes = styles(); const { entity } = useEntity(); const { owner, repo } = useProjectEntity(entity); const { value, loading, error } = useRequest(entity, "releases", 0, 5); 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?.length && owner && repo ? /* @__PURE__ */ React.createElement( InfoCard, { title: "Releases", deepLink: { link: `https://${hostname}/${owner}/${repo}/releases`, title: "Releases", onClick: (e) => { e.preventDefault(); window.open(`https://${hostname}/${owner}/${repo}/releases`); } }, className: classes.infoCard }, /* @__PURE__ */ React.createElement(List, null, value.map((release) => /* @__PURE__ */ React.createElement(ListItem, { className: classes.listItem, key: release.id }, /* @__PURE__ */ React.createElement( Link, { href: release.html_url, color: "inherit", target: "_blank", rel: "noopener noreferrer" }, /* @__PURE__ */ React.createElement("p", { className: classes.releaseTitle }, release.name), /* @__PURE__ */ React.createElement( LocalOfferOutlinedIcon, { fontSize: "inherit", className: classes.releaseTagIcon } ), " ", release.tag_name ), release.prerelease && /* @__PURE__ */ React.createElement(Chip, { color: "primary", size: "small", label: "Pre-release" })))) ) : /* @__PURE__ */ React.createElement(React.Fragment, null); }; const ReleasesCard = () => { const { entity } = useEntity(); const hostname = getHostname(entity); return /* @__PURE__ */ React.createElement(GitHubAuthorizationWrapper, { title: "Releases", hostname }, /* @__PURE__ */ React.createElement(ReleasesCardContent, null)); }; export { ReleasesCard as default }; //# sourceMappingURL=ReleasesCard.esm.js.map