@pagerduty/backstage-plugin
Version:
A Backstage plugin that integrates towards PagerDuty
43 lines (40 loc) • 1.74 kB
JavaScript
import React, { useEffect } from 'react';
import { List } 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 Incidents = ({ serviceId, account, refreshIncidents }) => {
const api = useApi(pagerDutyApiRef);
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__ */ React.createElement(IncidentForbiddenState, null);
}
return /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, "Error encountered while fetching information. ", error.message);
}
if (loading) {
return /* @__PURE__ */ React.createElement(Progress, null);
}
if (!incidents?.length) {
return /* @__PURE__ */ React.createElement(IncidentsEmptyState, null);
}
return /* @__PURE__ */ React.createElement(List, { dense: true }, incidents.map((incident, index) => /* @__PURE__ */ React.createElement(IncidentListItem, { key: incident.id + index, incident })));
};
export { Incidents };
//# sourceMappingURL=Incidents.esm.js.map