UNPKG

@roadiehq/backstage-plugin-argo-cd

Version:
98 lines (95 loc) 3.62 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { Table } from '@backstage/core-components'; import { useApi, configApiRef } from '@backstage/core-plugin-api'; import { Link, List, ListItem } from '@material-ui/core'; import SyncIcon from '@material-ui/icons/Sync'; import { DateTime } from 'luxon'; const ArgoCDHistoryTable = ({ data, retry }) => { const configApi = useApi(configApiRef); const namespaced = configApi.getOptionalBoolean("argocd.namespacedApps") ?? false; const baseUrl = configApi.getOptionalString("argocd.baseUrl"); const supportsMultipleArgoInstances = Boolean( configApi.getOptionalConfigArray("argocd.appLocatorMethods")?.length ); const linkUrl = (row) => { if (supportsMultipleArgoInstances && !baseUrl) { const instanceConfig = configApi.getConfigArray("argocd.appLocatorMethods").find((value) => value.getOptionalString("type") === "config")?.getOptionalConfigArray("instances")?.find((value) => value.getOptionalString("name") === row?.instance); return instanceConfig?.getOptionalString("frontendUrl") ?? instanceConfig?.getOptionalString("url"); } return baseUrl; }; const columns = [ { title: "Name", field: "name", render: (row) => linkUrl ? /* @__PURE__ */ jsx( Link, { href: `${linkUrl(row)}/applications/${namespaced ? `${row.appNamespace}/${row.app}` : row.app}`, target: "_blank", rel: "noopener", children: row.app } ) : row.app }, { title: "Deploy Details", defaultSort: "desc", field: "deployedAt", render: (row) => /* @__PURE__ */ jsxs(List, { dense: true, style: { padding: "0px" }, children: [ /* @__PURE__ */ jsx(ListItem, { style: { paddingLeft: "0px" }, children: row.deployedAt ? `Deployed at ${DateTime.fromISO(row.deployedAt).toLocal().toFormat("dd MMM yyyy, HH:mm:ss")}` : null }), /* @__PURE__ */ jsx(ListItem, { style: { paddingLeft: "0px" }, children: row.deployStartedAt ? `Run ${DateTime.fromISO(row.deployStartedAt).toLocal().toRelative()}` : null }), /* @__PURE__ */ jsx(ListItem, { style: { paddingLeft: "0px" }, children: row.deployedAt && row.deployStartedAt ? `Took ${DateTime.fromISO(row.deployStartedAt).diff(DateTime.fromISO(row.deployedAt)).toFormat("hh:mm:ss")}` : null }) ] }) }, { title: "Author", field: "revisionDetails.author", render: (row) => /* @__PURE__ */ jsx("div", { children: row.revisionDetails?.author || "Loading..." }) }, { title: "Message", field: "revisionDetails.message", render: (row) => /* @__PURE__ */ jsx("div", { children: row.revisionDetails?.message || "Loading..." }) }, { title: "Revision", field: "revision", render: (row) => /* @__PURE__ */ jsx("div", { children: row.revision }) } ]; if (supportsMultipleArgoInstances) { columns.splice(1, 0, { title: "Instance", field: "instance", render: (row) => row.metadata?.instance?.name ? row.metadata?.instance?.name : row.instance }); } return /* @__PURE__ */ jsx( Table, { title: "ArgoCD history", options: { paging: true, search: false, draggable: false, padding: "dense" }, data, columns, actions: [ { icon: () => /* @__PURE__ */ jsx(SyncIcon, {}), tooltip: "Refresh", isFreeAction: true, onClick: () => retry() } ] } ); }; export { ArgoCDHistoryTable }; //# sourceMappingURL=ArgoCDHistoryTable.esm.js.map