UNPKG

@pagerduty/backstage-plugin

Version:
54 lines (51 loc) 1.77 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { List, ListSubheader } from '@material-ui/core'; import { EscalationUsersEmptyState } from './EscalationUsersEmptyState.esm.js'; import { EscalationUsersForbiddenState } from './EscalationUsersForbiddenState.esm.js'; import { EscalationUser } from './EscalationUser.esm.js'; import useAsync from 'react-use/lib/useAsync'; 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'; const EscalationPolicy = ({ policyId, policyUrl, policyName, account }) => { const api = useApi(pagerDutyApiRef); const { value: users, loading, error } = useAsync(async () => { return await api.getOnCallByPolicyId(policyId, account); }); if (error) { if (error.message.includes("Forbidden")) { return /* @__PURE__ */ jsx(List, { dense: true, subheader: /* @__PURE__ */ jsx(ListSubheader, { children: "ON CALL" }), children: /* @__PURE__ */ jsx(EscalationUsersForbiddenState, {}) }); } return /* @__PURE__ */ jsxs(Alert, { severity: "error", children: [ "Error encountered while fetching information. ", error.message ] }); } if (loading) { return /* @__PURE__ */ jsx(Progress, { "data-testid": "escalation-progress" }); } if (!users?.length) { return /* @__PURE__ */ jsx(EscalationUsersEmptyState, {}); } return /* @__PURE__ */ jsx(List, { dense: true, children: users.map((user, index) => /* @__PURE__ */ jsx( EscalationUser, { user, policyUrl, policyName }, index )) }); }; export { EscalationPolicy }; //# sourceMappingURL=EscalationPolicy.esm.js.map