@roadiehq/backstage-plugin-bitbucket-pullrequest
Version:
112 lines (109 loc) • 3.95 kB
JavaScript
import { jsx, jsxs } from 'react/jsx-runtime';
import { 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__ */ jsx(HourglassEmptyIcon, { color: "primary" });
case "MERGED":
return /* @__PURE__ */ jsx(CheckCircleIcon, { style: { color: "green" } });
case "DECLINED":
return /* @__PURE__ */ jsx(CancelIcon, { color: "secondary" });
default:
return null;
}
};
const columns = [
{
title: "ID",
field: "id",
highlight: true,
width: "20%",
render: (row) => /* @__PURE__ */ jsx(Box, { fontWeight: "fontWeightBold", children: /* @__PURE__ */ jsxs(Link, { to: `${row.url}`, children: [
"#",
row.id
] }) })
},
{
title: "TITLE",
field: "title",
highlight: true,
width: "30%",
render: (rowData) => /* @__PURE__ */ jsx(Box, { fontWeight: "fontWeightBold", children: rowData.title })
},
{
title: "STATE",
field: "state",
highlight: true,
width: "10%",
render: (rowData) => /* @__PURE__ */ jsx(RenderStateIcon, { status: rowData.state })
},
{
title: "AUTHOR",
field: "author",
highlight: true,
width: "20%",
render: (row) => /* @__PURE__ */ jsx(Box, { fontWeight: "fontWeightBold", children: row.author })
},
{
title: "CREATED",
field: "created_on",
highlight: true,
width: "20%",
render: (row) => /* @__PURE__ */ jsx(GetElapsedTime, { start: row.created_on })
},
{
title: "LAST UPDATED",
field: "updated_on",
highlight: true,
width: "20%",
render: (rowData) => /* @__PURE__ */ jsx(GetElapsedTime, { start: rowData.updated_on })
}
];
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(Content, { children: [
/* @__PURE__ */ jsx(ContentHeader, { title: "Bitbucket Pull Requests", children: /* @__PURE__ */ jsx(StatusFilter, { onFilterChange: setStateFilter }) }),
/* @__PURE__ */ jsx(
Table,
{
title: PROJECT,
columns,
data: pullRequests,
detailPanel: ({ rowData }) => /* @__PURE__ */ jsx(Box, { marginLeft: "14px", children: /* @__PURE__ */ jsx(
MarkdownContent,
{
content: rowData.description ?? "_No description provided._",
dialect: "gfm"
}
) })
}
)
] }) });
};
export { PullRequestList as default };
//# sourceMappingURL=PullRequestList.esm.js.map