@spacelift-io/backstage-integration-frontend
Version:
Backstage plugin for integrating Spacelift.io with Backstage
60 lines (57 loc) • 2.4 kB
JavaScript
import { jsxs, jsx } from 'react/jsx-runtime';
import { Page, Header, HeaderLabel, Content } from '@backstage/core-components';
import { useApi, configApiRef } from '@backstage/core-plugin-api';
import { Box, Button } from '@material-ui/core';
import { Alert } from '@material-ui/lab';
import { useFetchStacks } from '../../hooks/useFetchStacks.esm.js';
import { useTriggerRun } from '../../hooks/useTriggerRun.esm.js';
import { SpaceliftStacksTable } from '../SpaceliftStacksTable/SpaceliftStacksTable.esm.js';
const StacksPage = () => {
const config = useApi(configApiRef);
const readOnly = config.getOptionalBoolean("spacelift.readOnly") ?? false;
const { stacks, loading: stacksLoading, error: stacksError, retry: getStacks } = useFetchStacks();
const {
triggerRun,
loading: loadingTriggerRun,
error: errorTriggerRun,
clear: clearTriggerRunError
} = useTriggerRun();
const handleTriggerRun = async (stackId) => {
const res = await triggerRun(stackId);
if (res?.id) {
getStacks();
}
};
const isLoading = stacksLoading || loadingTriggerRun;
return /* @__PURE__ */ jsxs(Page, { themeId: "tool", children: [
/* @__PURE__ */ jsx(Header, { title: "Spacelift", subtitle: "Manage your stacks", children: /* @__PURE__ */ jsx(HeaderLabel, { label: "Stacks", value: "List of stacks" }) }),
/* @__PURE__ */ jsx(Content, { children: /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", style: { gap: "16px" }, children: [
stacksError && /* @__PURE__ */ jsxs(
Alert,
{
variant: "outlined",
severity: "error",
action: /* @__PURE__ */ jsx(Button, { color: "inherit", size: "small", onClick: getStacks, children: "RETRY" }),
children: [
"Failed to load Spacelift stacks: ",
stacksError.message
]
}
),
!stacksError && !readOnly && errorTriggerRun && /* @__PURE__ */ jsxs(Alert, { variant: "outlined", severity: "warning", onClose: clearTriggerRunError, children: [
"Spacelift action failed: ",
errorTriggerRun.message
] }),
/* @__PURE__ */ jsx(
SpaceliftStacksTable,
{
stacks,
loading: isLoading,
triggerRun: readOnly ? void 0 : handleTriggerRun
}
)
] }) })
] });
};
export { StacksPage };
//# sourceMappingURL=Stacks.esm.js.map