UNPKG

@roadiehq/backstage-plugin-github-insights

Version:
78 lines (75 loc) 3.33 kB
import { jsx, jsxs, Fragment } from 'react/jsx-runtime'; 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__ */ 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?.length && owner && repo ? /* @__PURE__ */ jsx( 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, children: /* @__PURE__ */ jsx(List, { children: value.map((release) => /* @__PURE__ */ jsxs(ListItem, { className: classes.listItem, children: [ /* @__PURE__ */ jsxs( Link, { href: release.html_url, color: "inherit", target: "_blank", rel: "noopener noreferrer", children: [ /* @__PURE__ */ jsx("p", { className: classes.releaseTitle, children: release.name }), /* @__PURE__ */ jsx( LocalOfferOutlinedIcon, { fontSize: "inherit", className: classes.releaseTagIcon } ), " ", release.tag_name ] } ), release.prerelease && /* @__PURE__ */ jsx(Chip, { color: "primary", size: "small", label: "Pre-release" }) ] }, release.id)) }) } ) : /* @__PURE__ */ jsx(Fragment, {}); }; const ReleasesCard = () => { const { entity } = useEntity(); const hostname = getHostname(entity); return /* @__PURE__ */ jsx(GitHubAuthorizationWrapper, { title: "Releases", hostname, children: /* @__PURE__ */ jsx(ReleasesCardContent, {}) }); }; export { ReleasesCard as default }; //# sourceMappingURL=ReleasesCard.esm.js.map