UNPKG

@roadiehq/backstage-plugin-bitbucket-pullrequest

Version:

105 lines (102 loc) 4.03 kB
import React, { useState, useEffect } from 'react'; import { Content, ContentHeader, Table, MarkdownContent, Link } from '@backstage/core-components'; import { DateTime } from 'luxon'; import { useApi } from '@backstage/core-plugin-api'; import { Box } from '@material-ui/core'; import { isBITBUCKETSlugSet } from '../utils/isBITBUCKETSlugSet.esm.js'; import { bitbucketApiRef } from '../api/BitbucketApi.esm.js'; import CheckCircleIcon from '@material-ui/icons/CheckCircle'; import CancelIcon from '@material-ui/icons/Cancel'; import HourglassEmptyIcon from '@material-ui/icons/HourglassEmpty'; import StatusFilter from './StatusFilter.esm.js'; import { useEntity } from '@backstage/plugin-catalog-react'; const PullRequestList = () => { const [pullRequests, setPullRequests] = useState([]); const [stateFilter, setStateFilter] = useState("All"); const { entity } = useEntity(); const PROJECT = isBITBUCKETSlugSet(entity); const bitbucketApi = useApi(bitbucketApiRef); const projectName = PROJECT.split("/")[0]; const repoName = PROJECT.split("/")[1]; useEffect(() => { bitbucketApi.fetchPullRequestList( projectName, repoName, stateFilter !== "All" ? stateFilter : void 0 ).then((data) => setPullRequests(data)).catch((error) => error); }, [stateFilter, projectName, repoName, bitbucketApi]); const GetElapsedTime = ({ start }) => DateTime.fromISO(start).toRelative(); const RenderStateIcon = ({ status }) => { switch (status) { case "OPEN": return /* @__PURE__ */ React.createElement(HourglassEmptyIcon, { color: "primary" }); case "MERGED": return /* @__PURE__ */ React.createElement(CheckCircleIcon, { style: { color: "green" } }); case "DECLINED": return /* @__PURE__ */ React.createElement(CancelIcon, { color: "secondary" }); default: return null; } }; const columns = [ { title: "ID", field: "id", highlight: true, width: "20%", render: (row) => /* @__PURE__ */ React.createElement(Box, { fontWeight: "fontWeightBold" }, /* @__PURE__ */ React.createElement(Link, { to: `${row.url}` }, "#", row.id)) }, { title: "TITLE", field: "title", highlight: true, width: "30%", render: (rowData) => /* @__PURE__ */ React.createElement(Box, { fontWeight: "fontWeightBold" }, rowData.title) }, { title: "STATE", field: "state", highlight: true, width: "10%", render: (rowData) => /* @__PURE__ */ React.createElement(RenderStateIcon, { status: rowData.state }) }, { title: "AUTHOR", field: "author", highlight: true, width: "20%", render: (row) => /* @__PURE__ */ React.createElement(Box, { fontWeight: "fontWeightBold" }, row.author) }, { title: "CREATED", field: "created_on", highlight: true, width: "20%", render: (row) => /* @__PURE__ */ React.createElement(GetElapsedTime, { start: row.created_on }) }, { title: "LAST UPDATED", field: "updated_on", highlight: true, width: "20%", render: (rowData) => /* @__PURE__ */ React.createElement(GetElapsedTime, { start: rowData.updated_on }) } ]; return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Content, null, /* @__PURE__ */ React.createElement(ContentHeader, { title: "Bitbucket Pull Requests" }, /* @__PURE__ */ React.createElement(StatusFilter, { onFilterChange: setStateFilter })), /* @__PURE__ */ React.createElement( Table, { title: PROJECT, columns, data: pullRequests, detailPanel: ({ rowData }) => /* @__PURE__ */ React.createElement(Box, { marginLeft: "14px" }, /* @__PURE__ */ React.createElement( MarkdownContent, { content: rowData.description ?? "_No description provided._", dialect: "gfm" } )) } ))); }; export { PullRequestList as default }; //# sourceMappingURL=PullRequestList.esm.js.map