@pagerduty/backstage-plugin
Version:
A Backstage plugin that integrates towards PagerDuty
55 lines (52 loc) • 1.99 kB
JavaScript
import { jsx, jsxs } from 'react/jsx-runtime';
import { useEffect } from 'react';
import { makeStyles, List, createStyles } from '@material-ui/core';
import { IncidentListItem } from './IncidentListItem.esm.js';
import { IncidentsEmptyState } from './IncidentEmptyState.esm.js';
import useAsyncFn from 'react-use/lib/useAsyncFn';
import { pagerDutyApiRef } from '../../api/client.esm.js';
import { Alert } from '@material-ui/lab';
import { useApi } from '@backstage/core-plugin-api';
import { Progress } from '@backstage/core-components';
import { IncidentForbiddenState } from './IncidentForbiddenState.esm.js';
const useStyles = makeStyles(
() => createStyles({
loadingStyles: {
height: "253px"
}
})
);
const Incidents = ({ serviceId, account, refreshIncidents, serviceURL }) => {
const api = useApi(pagerDutyApiRef);
const { loadingStyles } = useStyles();
const [{ value: incidents, loading, error }, getIncidents] = useAsyncFn(
async () => {
const { incidents: foundIncidents } = await api.getIncidentsByServiceId(
serviceId,
account
);
return foundIncidents;
}
);
useEffect(() => {
getIncidents();
}, [refreshIncidents, getIncidents]);
if (error) {
if (error.message.includes("Forbidden")) {
return /* @__PURE__ */ jsx(IncidentForbiddenState, {});
}
return /* @__PURE__ */ jsxs(Alert, { severity: "error", children: [
"Error encountered while fetching information. ",
error.message
] });
}
if (loading) {
return /* @__PURE__ */ jsx("div", { className: loadingStyles, children: /* @__PURE__ */ jsx(Progress, {}) });
}
if (!incidents?.length) {
return /* @__PURE__ */ jsx(IncidentsEmptyState, { serviceURL });
}
return /* @__PURE__ */ jsx(List, { dense: true, children: incidents.map((incident, index) => /* @__PURE__ */ jsx(IncidentListItem, { incident }, incident.id + index)) });
};
export { Incidents };
//# sourceMappingURL=Incidents.esm.js.map