@pagerduty/backstage-plugin 0.12.1-next.98 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/api/client.esm.js +151 -0
  2. package/dist/api/client.esm.js.map +1 -0
  3. package/dist/components/ChangeEvents/ChangeEventEmptyState.esm.js +17 -0
  4. package/dist/components/ChangeEvents/ChangeEventEmptyState.esm.js.map +1 -0
  5. package/dist/components/ChangeEvents/ChangeEventForbiddenState.esm.js +17 -0
  6. package/dist/components/ChangeEvents/ChangeEventForbiddenState.esm.js.map +1 -0
  7. package/dist/components/ChangeEvents/ChangeEventListItem.esm.js +70 -0
  8. package/dist/components/ChangeEvents/ChangeEventListItem.esm.js.map +1 -0
  9. package/dist/components/ChangeEvents/ChangeEvents.esm.js +45 -0
  10. package/dist/components/ChangeEvents/ChangeEvents.esm.js.map +1 -0
  11. package/dist/components/EntityPagerDutyCard/index.esm.js +29 -0
  12. package/dist/components/EntityPagerDutyCard/index.esm.js.map +1 -0
  13. package/dist/components/EntityPagerDutySmallCard/index.esm.js +29 -0
  14. package/dist/components/EntityPagerDutySmallCard/index.esm.js.map +1 -0
  15. package/dist/components/Errors/ForbiddenError.esm.js +24 -0
  16. package/dist/components/Errors/ForbiddenError.esm.js.map +1 -0
  17. package/dist/components/Errors/MissingTokenError.esm.js +24 -0
  18. package/dist/components/Errors/MissingTokenError.esm.js.map +1 -0
  19. package/dist/components/Errors/ServiceNotFoundError.esm.js +24 -0
  20. package/dist/components/Errors/ServiceNotFoundError.esm.js.map +1 -0
  21. package/dist/components/Escalation/EscalationPolicy.esm.js +64 -0
  22. package/dist/components/Escalation/EscalationPolicy.esm.js.map +1 -0
  23. package/dist/components/Escalation/EscalationUser.esm.js +98 -0
  24. package/dist/components/Escalation/EscalationUser.esm.js.map +1 -0
  25. package/dist/components/Escalation/EscalationUsersEmptyState.esm.js +20 -0
  26. package/dist/components/Escalation/EscalationUsersEmptyState.esm.js.map +1 -0
  27. package/dist/components/Escalation/EscalationUsersForbiddenState.esm.js +20 -0
  28. package/dist/components/Escalation/EscalationUsersForbiddenState.esm.js.map +1 -0
  29. package/dist/components/HomePagePagerDutyCard/Content.esm.js +9 -0
  30. package/dist/components/HomePagePagerDutyCard/Content.esm.js.map +1 -0
  31. package/dist/components/HomePagePagerDutyCard/index.esm.js +2 -0
  32. package/dist/components/HomePagePagerDutyCard/index.esm.js.map +1 -0
  33. package/dist/components/Incident/IncidentEmptyState.esm.js +27 -0
  34. package/dist/components/Incident/IncidentEmptyState.esm.js.map +1 -0
  35. package/dist/components/Incident/IncidentForbiddenState.esm.js +17 -0
  36. package/dist/components/Incident/IncidentForbiddenState.esm.js.map +1 -0
  37. package/dist/components/Incident/IncidentListItem.esm.js +114 -0
  38. package/dist/components/Incident/IncidentListItem.esm.js.map +1 -0
  39. package/dist/components/Incident/Incidents.esm.js +41 -0
  40. package/dist/components/Incident/Incidents.esm.js.map +1 -0
  41. package/dist/components/PagerDutyCard/index.esm.js +193 -0
  42. package/dist/components/PagerDutyCard/index.esm.js.map +1 -0
  43. package/dist/components/PagerDutyCardCommon/InsightsCard.esm.js +35 -0
  44. package/dist/components/PagerDutyCardCommon/InsightsCard.esm.js.map +1 -0
  45. package/dist/components/PagerDutyCardCommon/OpenServiceButton.esm.js +42 -0
  46. package/dist/components/PagerDutyCardCommon/OpenServiceButton.esm.js.map +1 -0
  47. package/dist/components/PagerDutyCardCommon/ServiceStandardsCard.esm.js +95 -0
  48. package/dist/components/PagerDutyCardCommon/ServiceStandardsCard.esm.js.map +1 -0
  49. package/dist/components/PagerDutyCardCommon/StatusCard.esm.js +102 -0
  50. package/dist/components/PagerDutyCardCommon/StatusCard.esm.js.map +1 -0
  51. package/dist/components/PagerDutyCardCommon/TriggerIncidentButton.esm.js +59 -0
  52. package/dist/components/PagerDutyCardCommon/TriggerIncidentButton.esm.js.map +1 -0
  53. package/dist/components/PagerDutySmallCard/index.esm.js +209 -0
  54. package/dist/components/PagerDutySmallCard/index.esm.js.map +1 -0
  55. package/dist/components/TriggerButton/index.esm.js +48 -0
  56. package/dist/components/TriggerButton/index.esm.js.map +1 -0
  57. package/dist/components/TriggerDialog/TriggerDialog.esm.js +94 -0
  58. package/dist/components/TriggerDialog/TriggerDialog.esm.js.map +1 -0
  59. package/dist/components/constants.esm.js +5 -0
  60. package/dist/components/constants.esm.js.map +1 -0
  61. package/dist/components/pagerDutyEntity.esm.js +13 -0
  62. package/dist/components/pagerDutyEntity.esm.js.map +1 -0
  63. package/dist/deprecated.esm.js +10 -0
  64. package/dist/deprecated.esm.js.map +1 -0
  65. package/dist/hooks/index.esm.js +10 -0
  66. package/dist/hooks/index.esm.js.map +1 -0
  67. package/dist/index.d.ts +2 -1
  68. package/dist/index.esm.js +6 -30
  69. package/dist/index.esm.js.map +1 -1
  70. package/dist/plugin.esm.js +71 -0
  71. package/dist/plugin.esm.js.map +1 -0
  72. package/package.json +12 -10
  73. package/dist/esm/index-b1b65bd2.esm.js +0 -37
  74. package/dist/esm/index-b1b65bd2.esm.js.map +0 -1
  75. package/dist/esm/index-b56f9c4b.esm.js +0 -1595
  76. package/dist/esm/index-b56f9c4b.esm.js.map +0 -1
@@ -1,1595 +0,0 @@
1
- import { createApiRef, createRouteRef, createPlugin, createApiFactory, discoveryApiRef, configApiRef, fetchApiRef, createComponentExtension, useApi, alertApiRef, identityApiRef } from '@backstage/core-plugin-api';
2
- import { NotFoundError } from '@backstage/errors';
3
- import { createCardExtension } from '@backstage/plugin-home-react';
4
- import React, { useEffect, useState, useCallback } from 'react';
5
- import { useEntity } from '@backstage/plugin-catalog-react';
6
- import { makeStyles, ListItem, ListItemText, Chip, Typography, ListItemSecondaryAction, Tooltip, IconButton, Grid, List, ListItemIcon, createStyles, ListSubheader, Button, Card, withStyles, LinearProgress, Dialog, DialogTitle, DialogContent, TextField, DialogActions, CircularProgress, CardHeader, Divider, CardContent, Accordion, AccordionSummary, AccordionDetails } from '@material-ui/core';
7
- import { DateTime, Duration } from 'luxon';
8
- import OpenInBrowserIcon from '@material-ui/icons/OpenInBrowser';
9
- import { Link, Progress, StatusWarning, StatusError, EmptyState, TabbedCard, CardTab, InfoCard } from '@backstage/core-components';
10
- import EmptyStateImage from '../assets/emptystate.svg';
11
- import useAsyncFn from 'react-use/lib/useAsyncFn';
12
- import { Alert } from '@material-ui/lab';
13
- import ForbiddenStateImage from '../assets/forbiddenstate.svg';
14
- import Avatar from '@material-ui/core/Avatar';
15
- import NotificationsIcon from '@material-ui/icons/Notifications';
16
- import useAsync from 'react-use/lib/useAsync';
17
- import LinkIcon from '@material-ui/icons/Link';
18
- import PDGreenImage from '../assets/PD-Green.svg';
19
- import PDWhiteImage from '../assets/PD-White.svg';
20
- import validateColor from 'validate-color';
21
- import InfoIcon from '@material-ui/icons/Info';
22
- import CheckCircle from '@material-ui/icons/CheckCircle';
23
- import RadioButtonUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked';
24
- import { makeStyles as makeStyles$1, createStyles as createStyles$1, useTheme } from '@material-ui/core/styles';
25
- import { useAsyncFn as useAsyncFn$1 } from 'react-use';
26
- import Alert$1 from '@material-ui/lab/Alert/Alert';
27
- import { parseEntityRef, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
28
- import AddAlert from '@material-ui/icons/AddAlert';
29
- import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
30
-
31
- const PAGERDUTY_INTEGRATION_KEY = "pagerduty.com/integration-key";
32
- const PAGERDUTY_SERVICE_ID = "pagerduty.com/service-id";
33
-
34
- function getPagerDutyEntity(entity) {
35
- const {
36
- [PAGERDUTY_INTEGRATION_KEY]: integrationKey,
37
- [PAGERDUTY_SERVICE_ID]: serviceId
38
- } = entity.metadata.annotations || {};
39
- const name = entity.metadata.name;
40
- return { integrationKey, serviceId, name };
41
- }
42
-
43
- class UnauthorizedError extends Error {
44
- }
45
- class ForbiddenError$1 extends Error {
46
- }
47
- const pagerDutyApiRef = createApiRef({
48
- id: "plugin.pagerduty.api"
49
- });
50
- class PagerDutyClient {
51
- constructor(config) {
52
- this.config = config;
53
- }
54
- static fromConfig(configApi, dependencies) {
55
- var _a;
56
- const { discoveryApi, fetchApi } = dependencies;
57
- const eventsBaseUrl = (_a = configApi.getOptionalString("pagerDuty.eventsBaseUrl")) != null ? _a : "https://events.pagerduty.com/v2";
58
- return new PagerDutyClient({
59
- eventsBaseUrl,
60
- discoveryApi,
61
- fetchApi
62
- });
63
- }
64
- async getServiceByPagerDutyEntity(pagerDutyEntity) {
65
- const { integrationKey, serviceId } = pagerDutyEntity;
66
- let response;
67
- let url;
68
- if (integrationKey) {
69
- url = `${await this.config.discoveryApi.getBaseUrl(
70
- "pagerduty"
71
- )}/services?integration_key=${integrationKey}`;
72
- const serviceResponse = await this.findByUrl(url);
73
- if (serviceResponse.service === void 0)
74
- throw new NotFoundError();
75
- response = serviceResponse;
76
- } else if (serviceId) {
77
- url = `${await this.config.discoveryApi.getBaseUrl(
78
- "pagerduty"
79
- )}/services/${serviceId}`;
80
- response = await this.findByUrl(url);
81
- } else {
82
- throw new NotFoundError();
83
- }
84
- return response;
85
- }
86
- async getServiceByEntity(entity) {
87
- return await this.getServiceByPagerDutyEntity(getPagerDutyEntity(entity));
88
- }
89
- async getServiceById(serviceId) {
90
- const url = `${await this.config.discoveryApi.getBaseUrl(
91
- "pagerduty"
92
- )}/services/${serviceId}`;
93
- return await this.findByUrl(url);
94
- }
95
- async getIncidentsByServiceId(serviceId) {
96
- const url = `${await this.config.discoveryApi.getBaseUrl(
97
- "pagerduty"
98
- )}/services/${serviceId}/incidents`;
99
- return await this.findByUrl(url);
100
- }
101
- async getChangeEventsByServiceId(serviceId) {
102
- const url = `${await this.config.discoveryApi.getBaseUrl(
103
- "pagerduty"
104
- )}/services/${serviceId}/change-events`;
105
- return await this.findByUrl(url);
106
- }
107
- async getServiceStandardsByServiceId(serviceId) {
108
- const url = `${await this.config.discoveryApi.getBaseUrl(
109
- "pagerduty"
110
- )}/services/${serviceId}/standards`;
111
- return await this.findByUrl(url);
112
- }
113
- async getServiceMetricsByServiceId(serviceId) {
114
- const url = `${await this.config.discoveryApi.getBaseUrl(
115
- "pagerduty"
116
- )}/services/${serviceId}/metrics`;
117
- return await this.findByUrl(url);
118
- }
119
- async getOnCallByPolicyId(policyId) {
120
- const params = `escalation_policy_ids[]=${policyId}`;
121
- const url = `${await this.config.discoveryApi.getBaseUrl(
122
- "pagerduty"
123
- )}/oncall-users?${params}`;
124
- const response = await this.findByUrl(url);
125
- return response.users;
126
- }
127
- triggerAlarm(request) {
128
- var _a;
129
- const { integrationKey, source, description, userName } = request;
130
- const body = JSON.stringify({
131
- event_action: "trigger",
132
- routing_key: integrationKey,
133
- client: "Backstage",
134
- client_url: source,
135
- payload: {
136
- summary: description,
137
- source,
138
- severity: "error",
139
- class: "manual trigger",
140
- custom_details: {
141
- user: userName
142
- }
143
- }
144
- });
145
- const options = {
146
- method: "POST",
147
- headers: {
148
- "Content-Type": "application/json; charset=UTF-8",
149
- Accept: "application/json, text/plain, */*"
150
- },
151
- body
152
- };
153
- const url = (_a = this.config.eventsBaseUrl) != null ? _a : "https://events.pagerduty.com/v2";
154
- return this.request(`${url}/enqueue`, options);
155
- }
156
- async findByUrl(url) {
157
- const options = {
158
- method: "GET",
159
- headers: {
160
- Accept: "application/vnd.pagerduty+json;version=2",
161
- "Content-Type": "application/json"
162
- }
163
- };
164
- const response = await this.request(url, options);
165
- return response.json();
166
- }
167
- async request(url, options) {
168
- const response = await this.config.fetchApi.fetch(url, options);
169
- if (response.status === 401) {
170
- throw new UnauthorizedError("Unauthorized: You don't have access to this resource");
171
- }
172
- if (response.status === 403) {
173
- throw new ForbiddenError$1("Forbidden: You are not allowed to perform this action");
174
- }
175
- if (response.status === 404) {
176
- throw new NotFoundError("Not Found: Resource not found");
177
- }
178
- if (!response.ok) {
179
- const payload = await response.json();
180
- const errors = payload.errors.map((error) => error).join(" ");
181
- const message = `Request failed with ${response.status}, ${errors}`;
182
- throw new Error(message);
183
- }
184
- return response;
185
- }
186
- }
187
-
188
- createRouteRef({
189
- id: "pagerduty"
190
- });
191
- const pagerDutyPlugin = createPlugin({
192
- id: "pagerduty",
193
- apis: [
194
- createApiFactory({
195
- api: pagerDutyApiRef,
196
- deps: {
197
- discoveryApi: discoveryApiRef,
198
- configApi: configApiRef,
199
- fetchApi: fetchApiRef
200
- },
201
- factory: ({ configApi, discoveryApi, fetchApi }) => PagerDutyClient.fromConfig(configApi, { discoveryApi, fetchApi })
202
- })
203
- ]
204
- });
205
- const EntityPagerDutyCard$1 = pagerDutyPlugin.provide(
206
- createComponentExtension({
207
- name: "EntityPagerDutyCard",
208
- component: {
209
- lazy: () => Promise.resolve().then(function () { return index$1; }).then(
210
- (m) => m.EntityPagerDutyCard
211
- )
212
- }
213
- })
214
- );
215
- const EntityPagerDutySmallCard$1 = pagerDutyPlugin.provide(
216
- createComponentExtension({
217
- name: "EntityPagerDutySmallCard",
218
- component: {
219
- lazy: () => Promise.resolve().then(function () { return index; }).then(
220
- (m) => m.EntityPagerDutySmallCard
221
- )
222
- }
223
- })
224
- );
225
- const HomePagePagerDutyCard = pagerDutyPlugin.provide(
226
- createCardExtension({
227
- name: "HomePagePagerDutyCard",
228
- title: "PagerDuty Homepage Card",
229
- components: () => import('./index-b1b65bd2.esm.js'),
230
- settings: {
231
- schema: {
232
- title: "PagerDuty",
233
- type: "object",
234
- properties: {
235
- integrationKey: {
236
- title: "PagerDuty integration key",
237
- type: "string"
238
- },
239
- serviceId: {
240
- title: "PagerDuty service id",
241
- type: "string"
242
- },
243
- name: {
244
- title: "PagerDuty service name",
245
- type: "string"
246
- }
247
- }
248
- }
249
- }
250
- })
251
- );
252
-
253
- const useStyles$8 = makeStyles((theme) => ({
254
- denseListIcon: {
255
- marginRight: 0,
256
- display: "flex",
257
- flexDirection: "column",
258
- alignItems: "center",
259
- justifyContent: "center"
260
- },
261
- listItemPrimary: {
262
- fontWeight: "bold"
263
- },
264
- warning: {
265
- borderColor: theme.palette.warning.main,
266
- color: "#fff",
267
- backgroundColor: theme.palette.warning.main,
268
- boxShadow: "0 4px 4px 0 rgba(0,0,0,0.2)",
269
- textTransform: "uppercase",
270
- "& *": {
271
- color: "#fff"
272
- }
273
- },
274
- error: {
275
- borderColor: theme.palette.error.main,
276
- color: "#fff",
277
- backgroundColor: theme.palette.error.main,
278
- boxShadow: "0 4px 4px 0 rgba(0,0,0,0.2)",
279
- textTransform: "uppercase",
280
- "& *": {
281
- color: "#fff"
282
- }
283
- },
284
- lowUrgency: {
285
- borderColor: theme.palette.warning.main,
286
- color: theme.palette.warning.main,
287
- backgroundColor: "#fff",
288
- boxShadow: "0 4px 4px 0 rgba(0,0,0,0.2)",
289
- textTransform: "uppercase",
290
- "& *": {
291
- color: theme.palette.warning.main
292
- }
293
- },
294
- highUrgency: {
295
- borderColor: theme.palette.error.main,
296
- color: theme.palette.error.main,
297
- backgroundColor: "#fff",
298
- boxShadow: "0 4px 4px 0 rgba(0,0,0,0.2)",
299
- textTransform: "uppercase",
300
- "& *": {
301
- color: theme.palette.error.main
302
- }
303
- },
304
- textContainer: {
305
- display: "flex",
306
- alignItems: "baseline"
307
- },
308
- smallIconStyle: {
309
- color: theme.palette.text.primary,
310
- marginRight: "-20px"
311
- }
312
- }));
313
- const IncidentListItem = ({ incident }) => {
314
- var _a, _b, _c;
315
- const classes = useStyles$8();
316
- const duration = (/* @__PURE__ */ new Date()).getTime() - new Date(incident.created_at).getTime();
317
- const createdAt = DateTime.local().minus(Duration.fromMillis(duration)).toRelative({ locale: "en" });
318
- const user = (_a = incident.assignments[0]) == null ? void 0 : _a.assignee;
319
- return /* @__PURE__ */ React.createElement(ListItem, { dense: true, key: incident.id }, /* @__PURE__ */ React.createElement(
320
- ListItemText,
321
- {
322
- primary: /* @__PURE__ */ React.createElement("div", { className: classes.textContainer }, /* @__PURE__ */ React.createElement(
323
- Chip,
324
- {
325
- "data-testid": `chip-${incident.status}`,
326
- label: incident.status,
327
- size: "small",
328
- variant: "outlined",
329
- className: incident.status === "triggered" ? classes.error : classes.warning
330
- }
331
- ), /* @__PURE__ */ React.createElement(
332
- Chip,
333
- {
334
- "data-testid": `chip-${incident.urgency}`,
335
- label: `${incident.urgency} urgency`,
336
- size: "small",
337
- variant: "outlined",
338
- className: incident.urgency === "high" ? classes.highUrgency : classes.lowUrgency
339
- }
340
- ), incident.title),
341
- primaryTypographyProps: {
342
- variant: "body1",
343
- className: classes.listItemPrimary
344
- },
345
- secondary: /* @__PURE__ */ React.createElement(Typography, { noWrap: true, variant: "body2", color: "textSecondary" }, "Created ", createdAt, " and assigned to", " ", /* @__PURE__ */ React.createElement(Link, { to: (_b = user == null ? void 0 : user.html_url) != null ? _b : "#" }, (_c = user == null ? void 0 : user.summary) != null ? _c : "nobody"))
346
- }
347
- ), /* @__PURE__ */ React.createElement(ListItemSecondaryAction, null, /* @__PURE__ */ React.createElement(Tooltip, { title: "View in PagerDuty", placement: "top" }, /* @__PURE__ */ React.createElement(
348
- IconButton,
349
- {
350
- href: incident.html_url,
351
- target: "_blank",
352
- rel: "noopener noreferrer",
353
- className: classes.smallIconStyle
354
- },
355
- /* @__PURE__ */ React.createElement(OpenInBrowserIcon, null)
356
- ))));
357
- };
358
-
359
- const IncidentsEmptyState = () => {
360
- return /* @__PURE__ */ React.createElement(
361
- Grid,
362
- {
363
- container: true,
364
- justifyContent: "center",
365
- direction: "column",
366
- alignItems: "center"
367
- },
368
- /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(Typography, { variant: "h5" }, "Nice! No incidents found!")),
369
- /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(
370
- "img",
371
- {
372
- src: EmptyStateImage,
373
- alt: "EmptyState",
374
- "data-testid": "emptyStateImg"
375
- }
376
- ))
377
- );
378
- };
379
-
380
- const IncidentForbiddenState = () => {
381
- return /* @__PURE__ */ React.createElement(Grid, { container: true, justifyContent: "center", direction: "column", alignItems: "center" }, /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(Typography, { variant: "h5" }, "Feature not available with your account or token.")), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(
382
- "img",
383
- {
384
- src: ForbiddenStateImage,
385
- alt: "ForbiddenState",
386
- "data-testid": "forbiddenStateImg"
387
- }
388
- )));
389
- };
390
-
391
- const Incidents = ({ serviceId, refreshIncidents }) => {
392
- const api = useApi(pagerDutyApiRef);
393
- const [{ value: incidents, loading, error }, getIncidents] = useAsyncFn(
394
- async () => {
395
- const { incidents: foundIncidents } = await api.getIncidentsByServiceId(
396
- serviceId
397
- );
398
- return foundIncidents;
399
- }
400
- );
401
- useEffect(() => {
402
- getIncidents();
403
- }, [refreshIncidents, getIncidents]);
404
- if (error) {
405
- if (error.message.includes("Forbidden")) {
406
- return /* @__PURE__ */ React.createElement(IncidentForbiddenState, null);
407
- }
408
- return /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, "Error encountered while fetching information. ", error.message);
409
- }
410
- if (loading) {
411
- return /* @__PURE__ */ React.createElement(Progress, null);
412
- }
413
- if (!(incidents == null ? void 0 : incidents.length)) {
414
- return /* @__PURE__ */ React.createElement(IncidentsEmptyState, null);
415
- }
416
- return /* @__PURE__ */ React.createElement(List, { dense: true }, incidents.map((incident, index) => /* @__PURE__ */ React.createElement(IncidentListItem, { key: incident.id + index, incident })));
417
- };
418
-
419
- const useStyles$7 = makeStyles({
420
- denseListIcon: {
421
- marginRight: 0,
422
- display: "flex",
423
- flexDirection: "column",
424
- alignItems: "center",
425
- justifyContent: "center"
426
- }
427
- });
428
- const EscalationUsersEmptyState = () => {
429
- const classes = useStyles$7();
430
- return /* @__PURE__ */ React.createElement(ListItem, null, /* @__PURE__ */ React.createElement(ListItemIcon, null, /* @__PURE__ */ React.createElement("div", { className: classes.denseListIcon }, /* @__PURE__ */ React.createElement(StatusWarning, null))), /* @__PURE__ */ React.createElement(ListItemText, { primary: "No one is on-call. Update the escalation policy." }));
431
- };
432
-
433
- const useStyles$6 = makeStyles({
434
- denseListIcon: {
435
- marginRight: 0,
436
- display: "flex",
437
- flexDirection: "column",
438
- alignItems: "center",
439
- justifyContent: "center"
440
- }
441
- });
442
- const EscalationUsersForbiddenState = () => {
443
- const classes = useStyles$6();
444
- return /* @__PURE__ */ React.createElement(ListItem, null, /* @__PURE__ */ React.createElement(ListItemIcon, null, /* @__PURE__ */ React.createElement("div", { className: classes.denseListIcon }, /* @__PURE__ */ React.createElement(StatusError, null))), /* @__PURE__ */ React.createElement(ListItemText, { primary: "You don't permissions to list on-calls. Check your OAuth token permissions." }));
445
- };
446
-
447
- const useStyles$5 = makeStyles((theme) => ({
448
- listItemPrimary: {
449
- fontWeight: "bold"
450
- },
451
- listItemSecondary: {
452
- fontWeight: "normal",
453
- textDecoration: "underline",
454
- marginTop: "-5px"
455
- },
456
- buttonStyle: {
457
- marginLeft: "-11px",
458
- marginTop: "-10px",
459
- fontSize: "15px",
460
- color: theme.palette.text.primary,
461
- "&:hover": {
462
- backgroundColor: "transparent",
463
- textDecoration: "underline"
464
- }
465
- },
466
- userTextButtonStyle: {
467
- marginLeft: "-11px",
468
- marginTop: "-10px",
469
- marginBottom: "-10px",
470
- fontSize: "15px",
471
- color: theme.palette.text.primary,
472
- "&:hover": {
473
- backgroundColor: "transparent",
474
- textDecoration: "underline"
475
- }
476
- },
477
- containerStyle: {
478
- display: "flex",
479
- alignItems: "center",
480
- fontWeight: "bold"
481
- },
482
- iconStyle: {
483
- fontSize: "25px",
484
- marginLeft: "-4px",
485
- color: theme.palette.text.primary
486
- },
487
- smallIconStyle: {
488
- color: theme.palette.text.primary
489
- },
490
- avatarStyle: {
491
- marginTop: "-20px"
492
- }
493
- }));
494
- function navigateToUrl(url) {
495
- window.open(url, "_blank");
496
- }
497
- const EscalationUser = ({ user, policyUrl, policyName }) => {
498
- const classes = useStyles$5();
499
- return /* @__PURE__ */ React.createElement(ListItem, null, /* @__PURE__ */ React.createElement(ListItemIcon, null, /* @__PURE__ */ React.createElement(
500
- Avatar,
501
- {
502
- alt: user.name,
503
- src: user.avatar_url,
504
- className: classes.avatarStyle
505
- }
506
- )), /* @__PURE__ */ React.createElement(
507
- ListItemText,
508
- {
509
- primary: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Tooltip, { title: "Open user in PagerDuty", placement: "top" }, /* @__PURE__ */ React.createElement(
510
- IconButton,
511
- {
512
- "aria-label": "open-user-in-browser",
513
- onClick: () => navigateToUrl(user.html_url),
514
- className: classes.userTextButtonStyle
515
- },
516
- /* @__PURE__ */ React.createElement("span", { className: classes.containerStyle }, user.name)
517
- )), /* @__PURE__ */ React.createElement(
518
- Typography,
519
- {
520
- className: classes.listItemSecondary,
521
- color: "textSecondary"
522
- },
523
- user.email
524
- )),
525
- secondary: /* @__PURE__ */ React.createElement(
526
- IconButton,
527
- {
528
- "aria-label": "open-escalation-policy-in-browser",
529
- onClick: () => navigateToUrl(policyUrl),
530
- className: classes.buttonStyle
531
- },
532
- /* @__PURE__ */ React.createElement("span", { className: classes.containerStyle }, /* @__PURE__ */ React.createElement(NotificationsIcon, { className: classes.iconStyle }), policyName)
533
- )
534
- }
535
- ));
536
- };
537
-
538
- const useStyles$4 = makeStyles(
539
- () => createStyles({
540
- listStyle: {
541
- marginLeft: "-15px"
542
- }
543
- })
544
- );
545
- const EscalationPolicy = ({
546
- policyId,
547
- policyUrl,
548
- policyName
549
- }) => {
550
- const api = useApi(pagerDutyApiRef);
551
- const classes = useStyles$4();
552
- const {
553
- value: users,
554
- loading,
555
- error
556
- } = useAsync(async () => {
557
- return await api.getOnCallByPolicyId(policyId);
558
- });
559
- if (error) {
560
- if (error.message.includes("Forbidden")) {
561
- return /* @__PURE__ */ React.createElement(List, { dense: true, subheader: /* @__PURE__ */ React.createElement(ListSubheader, null, "ON CALL") }, /* @__PURE__ */ React.createElement(EscalationUsersForbiddenState, null));
562
- }
563
- return /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, "Error encountered while fetching information. ", error.message);
564
- }
565
- if (loading) {
566
- return /* @__PURE__ */ React.createElement(Progress, null);
567
- }
568
- if (!(users == null ? void 0 : users.length)) {
569
- return /* @__PURE__ */ React.createElement(EscalationUsersEmptyState, null);
570
- }
571
- return /* @__PURE__ */ React.createElement(
572
- List,
573
- {
574
- dense: true,
575
- className: classes.listStyle
576
- },
577
- users.map((user, index) => /* @__PURE__ */ React.createElement(
578
- EscalationUser,
579
- {
580
- key: index,
581
- user,
582
- policyUrl,
583
- policyName
584
- }
585
- ))
586
- );
587
- };
588
-
589
- const MissingTokenError = () => /* @__PURE__ */ React.createElement(
590
- EmptyState,
591
- {
592
- missing: "info",
593
- title: "Missing or invalid PagerDuty Token",
594
- description: "The request to fetch data needs a valid token. See README for more details.",
595
- action: /* @__PURE__ */ React.createElement(
596
- Button,
597
- {
598
- color: "primary",
599
- variant: "contained",
600
- href: "https://pagerduty.github.io/backstage-plugin-docs/getting-started/pagerduty/"
601
- },
602
- "Read More"
603
- )
604
- }
605
- );
606
-
607
- const ServiceNotFoundError = () => /* @__PURE__ */ React.createElement(
608
- EmptyState,
609
- {
610
- missing: "data",
611
- title: "PagerDuty Service Not Found",
612
- description: "A service could not be found within PagerDuty based on the provided service id. Please verify your configuration.",
613
- action: /* @__PURE__ */ React.createElement(
614
- Button,
615
- {
616
- color: "primary",
617
- variant: "contained",
618
- href: "https://pagerduty.github.io/backstage-plugin-docs/getting-started/pagerduty/"
619
- },
620
- "Read More"
621
- )
622
- }
623
- );
624
-
625
- const useStyles$3 = makeStyles((theme) => ({
626
- denseListIcon: {
627
- marginRight: 0,
628
- display: "flex",
629
- flexDirection: "column",
630
- alignItems: "center",
631
- justifyContent: "center"
632
- },
633
- listItemPrimary: {
634
- fontWeight: "bold"
635
- },
636
- smallExternalLinkIconStyle: {
637
- color: theme.palette.text.primary
638
- },
639
- smallExternalLinkWithoutMarginIconStyle: {
640
- color: theme.palette.text.primary,
641
- marginRight: "-20px"
642
- },
643
- smallIconStyle: {
644
- color: theme.palette.text.primary,
645
- marginRight: "-20px"
646
- }
647
- }));
648
- const ChangeEventListItem = ({ changeEvent }) => {
649
- const classes = useStyles$3();
650
- const duration = (/* @__PURE__ */ new Date()).getTime() - new Date(changeEvent.timestamp).getTime();
651
- const changedAt = DateTime.local().minus(Duration.fromMillis(duration)).toRelative({ locale: "en" });
652
- let externalLinkElem;
653
- if (changeEvent.links.length > 0) {
654
- const text = changeEvent.links[0].text;
655
- externalLinkElem = /* @__PURE__ */ React.createElement(Tooltip, { title: text, placement: "top" }, /* @__PURE__ */ React.createElement(
656
- IconButton,
657
- {
658
- component: Link,
659
- to: changeEvent.links[0].href,
660
- className: changeEvent.html_url === void 0 ? classes.smallExternalLinkWithoutMarginIconStyle : classes.smallExternalLinkIconStyle
661
- },
662
- /* @__PURE__ */ React.createElement(LinkIcon, null)
663
- ));
664
- }
665
- return /* @__PURE__ */ React.createElement(ListItem, { dense: true, key: changeEvent.id }, /* @__PURE__ */ React.createElement(
666
- ListItemText,
667
- {
668
- primary: /* @__PURE__ */ React.createElement(React.Fragment, null, changeEvent.summary),
669
- primaryTypographyProps: {
670
- variant: "body1",
671
- className: classes.listItemPrimary
672
- },
673
- secondary: /* @__PURE__ */ React.createElement(Typography, { variant: "body2", color: "textSecondary" }, "Triggered from ", changeEvent.source, " ", changedAt, ".")
674
- }
675
- ), /* @__PURE__ */ React.createElement(ListItemSecondaryAction, null, externalLinkElem, changeEvent.html_url === void 0 ? null : /* @__PURE__ */ React.createElement(Tooltip, { title: "View in PagerDuty", placement: "top" }, /* @__PURE__ */ React.createElement(
676
- IconButton,
677
- {
678
- component: Link,
679
- to: changeEvent.html_url,
680
- className: classes.smallIconStyle
681
- },
682
- /* @__PURE__ */ React.createElement(OpenInBrowserIcon, null)
683
- ))));
684
- };
685
-
686
- const ChangeEventEmptyState = () => {
687
- return /* @__PURE__ */ React.createElement(Grid, { container: true, justifyContent: "center", direction: "column", alignItems: "center" }, /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(Typography, { variant: "h5" }, "No change events to display yet.")), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(
688
- "img",
689
- {
690
- src: EmptyStateImage,
691
- alt: "EmptyState",
692
- "data-testid": "emptyStateImg"
693
- }
694
- )));
695
- };
696
-
697
- const ChangeEventForbiddenState = () => {
698
- return /* @__PURE__ */ React.createElement(Grid, { container: true, justifyContent: "center", direction: "column", alignItems: "center" }, /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(Typography, { variant: "h5" }, "Feature not available with your account or token.")), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React.createElement(
699
- "img",
700
- {
701
- src: ForbiddenStateImage,
702
- alt: "ForbiddenState",
703
- "data-testid": "forbiddenStateImg"
704
- }
705
- )));
706
- };
707
-
708
- const ChangeEvents = ({ serviceId, refreshEvents }) => {
709
- const api = useApi(pagerDutyApiRef);
710
- const [{ value: changeEvents, loading, error }, getChangeEvents] = useAsyncFn(
711
- async () => {
712
- const { change_events } = await api.getChangeEventsByServiceId(serviceId);
713
- return change_events;
714
- }
715
- );
716
- useEffect(() => {
717
- getChangeEvents();
718
- }, [refreshEvents, getChangeEvents]);
719
- if (error) {
720
- if (error.message.includes("Forbidden")) {
721
- return /* @__PURE__ */ React.createElement(ChangeEventForbiddenState, null);
722
- }
723
- return /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, "Error encountered while fetching information. ", error.message);
724
- }
725
- if (loading) {
726
- return /* @__PURE__ */ React.createElement(Progress, null);
727
- }
728
- if (!(changeEvents == null ? void 0 : changeEvents.length)) {
729
- return /* @__PURE__ */ React.createElement(ChangeEventEmptyState, null);
730
- }
731
- return /* @__PURE__ */ React.createElement(List, { dense: true }, changeEvents.map((changeEvent, index) => /* @__PURE__ */ React.createElement(
732
- ChangeEventListItem,
733
- {
734
- key: changeEvent.id + index,
735
- changeEvent
736
- }
737
- )));
738
- };
739
-
740
- const ForbiddenError = () => /* @__PURE__ */ React.createElement(
741
- EmptyState,
742
- {
743
- missing: "info",
744
- title: "Unauthorized",
745
- description: "You don't have the required permissions to perform this action. See README for more details.",
746
- action: /* @__PURE__ */ React.createElement(
747
- Button,
748
- {
749
- color: "primary",
750
- variant: "contained",
751
- href: "https://pagerduty.github.io/backstage-plugin-docs/getting-started/pagerduty/"
752
- },
753
- "Read More"
754
- )
755
- }
756
- );
757
-
758
- function IncidentCounterCard({ count, label, color, compact }) {
759
- const textColor = color && validateColor(color) ? color : "black";
760
- const useStyles = makeStyles(() => ({
761
- cardStyle: {
762
- marginRight: "10px",
763
- height: compact !== true ? "120px" : "80px",
764
- display: "flex",
765
- alignItems: "center",
766
- justifyContent: "center",
767
- backgroundColor: "rgba(0, 0, 0, 0.03)"
768
- },
769
- largeTextStyle: {
770
- color: textColor,
771
- fontSize: "30px",
772
- marginTop: "-10px"
773
- },
774
- smallTextStyle: {
775
- color: textColor,
776
- fontWeight: "bold",
777
- fontSize: "10px",
778
- marginTop: "-5px",
779
- textTransform: "uppercase",
780
- flexWrap: "wrap"
781
- }
782
- }));
783
- const { cardStyle, largeTextStyle, smallTextStyle } = useStyles();
784
- return /* @__PURE__ */ React.createElement(Card, { className: cardStyle }, count !== void 0 ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { className: largeTextStyle }, count), /* @__PURE__ */ React.createElement(Typography, { className: smallTextStyle }, label)) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { className: largeTextStyle }, "-"), /* @__PURE__ */ React.createElement(Typography, { className: smallTextStyle }, label)));
785
- }
786
-
787
- function OpenServiceButton({ serviceUrl, compact }) {
788
- const useStyles = makeStyles((theme) => ({
789
- buttonStyle: {
790
- color: theme.palette.text.primary,
791
- "&:hover": {
792
- backgroundColor: "transparent",
793
- textDecoration: "underline"
794
- }
795
- },
796
- containerStyle: {
797
- fontSize: compact !== true ? "12px" : "10px",
798
- width: compact !== true ? "85px" : "70px"
799
- },
800
- iconStyle: {
801
- fontSize: "30px",
802
- marginBottom: "-10px"
803
- },
804
- textStyle: {
805
- marginBottom: "-10px"
806
- }
807
- }));
808
- const { buttonStyle, containerStyle, iconStyle, textStyle } = useStyles();
809
- function navigateToService() {
810
- window.open(serviceUrl, "_blank");
811
- }
812
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
813
- IconButton,
814
- {
815
- "aria-label": "open-service-in-browser",
816
- onClick: navigateToService,
817
- className: buttonStyle
818
- },
819
- /* @__PURE__ */ React.createElement("div", { className: containerStyle }, /* @__PURE__ */ React.createElement(OpenInBrowserIcon, { className: iconStyle }), /* @__PURE__ */ React.createElement("p", { className: textStyle }, "Open service in PagerDuty"))
820
- ));
821
- }
822
-
823
- function colorFromPercentage(theme, percentage) {
824
- if (percentage < 0.5) {
825
- return theme.palette.error.main;
826
- } else if (percentage < 0.8) {
827
- return theme.palette.warning.main;
828
- }
829
- return theme.palette.success.main;
830
- }
831
- function ServiceStandardsCard({ total, completed, standards, compact }) {
832
- const useStyles = makeStyles((theme) => ({
833
- cardStyle: {
834
- height: compact !== true ? "120px" : "80px",
835
- display: "grid",
836
- gridTemplateRows: "1fr auto auto",
837
- backgroundColor: "rgba(0, 0, 0, 0.03)"
838
- },
839
- containerStyle: {
840
- display: "flex",
841
- justifyContent: "center",
842
- marginTop: compact !== true ? "-100px" : "-50px"
843
- },
844
- largeTextStyle: {
845
- fontSize: compact !== true ? "50px" : "40px",
846
- color: completed !== void 0 && total !== void 0 ? colorFromPercentage(theme, completed / total) : colorFromPercentage(theme, 0),
847
- alignSelf: "center",
848
- justifyContent: "center"
849
- },
850
- smallTextStyle: {
851
- color: theme.palette.textSubtle,
852
- fontSize: compact !== true ? "14px" : "12px",
853
- fontWeight: "bold",
854
- alignSelf: "center",
855
- justifyContent: "center",
856
- marginLeft: "-2px",
857
- marginTop: compact !== true ? "25px" : "20px"
858
- },
859
- tooltipContainer: {},
860
- tooltipIcon: {
861
- marginRight: "5px"
862
- },
863
- standardItem: {
864
- display: "flex",
865
- alignItems: "center"
866
- }
867
- }));
868
- const BorderLinearProgress = withStyles((theme) => ({
869
- root: {
870
- height: 10,
871
- borderRadius: 5,
872
- margin: 5
873
- },
874
- colorPrimary: {
875
- backgroundColor: theme.palette.grey[theme.palette.type === "light" ? 200 : 700]
876
- },
877
- bar: {
878
- borderRadius: 5,
879
- backgroundColor: completed !== void 0 && total !== void 0 ? colorFromPercentage(theme, completed / total) : colorFromPercentage(theme, 0)
880
- }
881
- }))(LinearProgress);
882
- const {
883
- cardStyle,
884
- containerStyle,
885
- largeTextStyle,
886
- smallTextStyle,
887
- tooltipContainer,
888
- tooltipIcon,
889
- standardItem
890
- } = useStyles();
891
- if (standards === void 0 || completed === void 0 || total === void 0) {
892
- return /* @__PURE__ */ React.createElement(Card, { className: cardStyle }, /* @__PURE__ */ React.createElement("div", { className: containerStyle }, /* @__PURE__ */ React.createElement(Typography, { className: smallTextStyle }, "Unable to retrieve Scores")));
893
- }
894
- return /* @__PURE__ */ React.createElement(Card, { className: cardStyle }, completed !== void 0 && total !== void 0 ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: tooltipContainer }, /* @__PURE__ */ React.createElement(IconButton, null, /* @__PURE__ */ React.createElement(
895
- Tooltip,
896
- {
897
- interactive: true,
898
- title: /* @__PURE__ */ React.createElement(React.Fragment, null, standards == null ? void 0 : standards.map((standard, key) => /* @__PURE__ */ React.createElement("p", { key }, standard.pass ? /* @__PURE__ */ React.createElement("span", { className: standardItem }, /* @__PURE__ */ React.createElement(CheckCircle, { className: tooltipIcon }), " ", standard.name) : /* @__PURE__ */ React.createElement("span", { className: standardItem }, /* @__PURE__ */ React.createElement(RadioButtonUncheckedIcon, { className: tooltipIcon }), " ", standard.name))))
899
- },
900
- /* @__PURE__ */ React.createElement(InfoIcon, null)
901
- ))), /* @__PURE__ */ React.createElement("div", { className: containerStyle }, /* @__PURE__ */ React.createElement(Typography, { className: largeTextStyle }, completed), /* @__PURE__ */ React.createElement(Typography, { className: smallTextStyle }, "/", total)), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
902
- BorderLinearProgress,
903
- {
904
- variant: "determinate",
905
- value: completed / total * 100
906
- }
907
- ))) : /* @__PURE__ */ React.createElement("div", { className: containerStyle }, /* @__PURE__ */ React.createElement(Typography, { className: smallTextStyle }, "Unable to retrieve Scores")));
908
- }
909
-
910
- function labelFromStatus(status) {
911
- let label;
912
- switch (status) {
913
- case "active":
914
- label = "OK";
915
- break;
916
- case "warning":
917
- label = "ACTIVE";
918
- break;
919
- case "critical":
920
- label = "ALARM";
921
- break;
922
- case "maintenance":
923
- label = "MAINTENANCE";
924
- break;
925
- case "disabled":
926
- label = "DISABLED";
927
- break;
928
- default:
929
- label = "OK";
930
- break;
931
- }
932
- return label;
933
- }
934
- function colorFromStatus(theme, status) {
935
- let color;
936
- switch (status) {
937
- case "active":
938
- color = theme.palette.success.main;
939
- break;
940
- case "warning":
941
- color = theme.palette.warningBackground;
942
- break;
943
- case "critical":
944
- color = theme.palette.error.main;
945
- break;
946
- case "maintenance":
947
- color = "#ebdc00";
948
- break;
949
- case "disabled":
950
- color = "#A9A9A9";
951
- break;
952
- default:
953
- color = theme.palette.success.main;
954
- break;
955
- }
956
- return color;
957
- }
958
- function StatusCard({ serviceId, refreshStatus, compact }) {
959
- const api = useApi(pagerDutyApiRef);
960
- const [{ value: status, loading, error }, getStatus] = useAsyncFn$1(
961
- async () => {
962
- const { service: foundService } = await api.getServiceById(serviceId);
963
- return foundService.status;
964
- }
965
- );
966
- const useStyles = makeStyles$1((theme) => ({
967
- cardStyle: {
968
- height: compact !== true ? "120px" : "80px",
969
- display: "flex",
970
- alignItems: "center",
971
- justifyContent: "center",
972
- backgroundColor: status !== void 0 ? colorFromStatus(theme, status) : colorFromStatus(theme, "active"),
973
- marginRight: "10px"
974
- },
975
- largeTextStyle: {
976
- color: "white",
977
- fontWeight: "bold",
978
- fontSize: "20px",
979
- wordWrap: "break-word"
980
- }
981
- }));
982
- const { cardStyle, largeTextStyle } = useStyles();
983
- useEffect(() => {
984
- getStatus();
985
- }, [refreshStatus, getStatus]);
986
- if (error) {
987
- if (error.message.includes("Forbidden")) {
988
- return /* @__PURE__ */ React.createElement("p", null, "forbidden");
989
- }
990
- return /* @__PURE__ */ React.createElement(Alert$1, { severity: "error" }, "Error encountered while fetching information. ", error.message);
991
- }
992
- if (loading) {
993
- return /* @__PURE__ */ React.createElement(Progress, null);
994
- }
995
- if (!status) {
996
- return /* @__PURE__ */ React.createElement("p", null, "not found");
997
- }
998
- return /* @__PURE__ */ React.createElement(Card, { className: cardStyle }, status !== void 0 ? /* @__PURE__ */ React.createElement(Typography, { className: largeTextStyle }, labelFromStatus(status)) : /* @__PURE__ */ React.createElement(Typography, { className: largeTextStyle }, "Unable to get status"));
999
- }
1000
-
1001
- const TriggerDialog = ({
1002
- showDialog,
1003
- handleDialog,
1004
- onIncidentCreated,
1005
- serviceName,
1006
- integrationKey
1007
- }) => {
1008
- const alertApi = useApi(alertApiRef);
1009
- const identityApi = useApi(identityApiRef);
1010
- const api = useApi(pagerDutyApiRef);
1011
- const [description, setDescription] = useState("");
1012
- const [{ value, loading, error }, handleTriggerAlarm] = useAsyncFn(
1013
- async (descriptions) => {
1014
- const { userEntityRef } = await identityApi.getBackstageIdentity();
1015
- const { name: userName } = parseEntityRef(userEntityRef, {
1016
- defaultKind: "User",
1017
- defaultNamespace: DEFAULT_NAMESPACE
1018
- });
1019
- return await api.triggerAlarm({
1020
- integrationKey,
1021
- source: window.location.toString(),
1022
- description: descriptions,
1023
- userName
1024
- });
1025
- }
1026
- );
1027
- const descriptionChanged = (event) => {
1028
- setDescription(event.target.value);
1029
- };
1030
- useEffect(() => {
1031
- if (value) {
1032
- (async () => {
1033
- alertApi.post({
1034
- message: `Alarm successfully triggered`
1035
- });
1036
- handleDialog();
1037
- await new Promise((resolve) => setTimeout(resolve, 1e3));
1038
- onIncidentCreated == null ? void 0 : onIncidentCreated();
1039
- })();
1040
- }
1041
- }, [value, alertApi, handleDialog, onIncidentCreated]);
1042
- if (error) {
1043
- alertApi.post({
1044
- message: `Failed to trigger alarm. ${error.message}`,
1045
- severity: "error"
1046
- });
1047
- }
1048
- return /* @__PURE__ */ React.createElement(Dialog, { maxWidth: "md", open: showDialog, onClose: handleDialog, fullWidth: true }, /* @__PURE__ */ React.createElement(DialogTitle, null, "This action will trigger an incident for ", /* @__PURE__ */ React.createElement("strong", null, '"', serviceName, '"'), "."), /* @__PURE__ */ React.createElement(DialogContent, null, /* @__PURE__ */ React.createElement(Alert, { severity: "info" }, /* @__PURE__ */ React.createElement(Typography, { variant: "body1", align: "justify" }, `If the issue you are seeing does not need urgent attention, please get in touch with the responsible team using their preferred communications channel. You can find information about the owner of this entity in the "About" card. If the issue is urgent, please don't hesitate to trigger the alert.`)), /* @__PURE__ */ React.createElement(
1049
- Typography,
1050
- {
1051
- variant: "body1",
1052
- style: { marginTop: "1em" },
1053
- gutterBottom: true,
1054
- align: "justify"
1055
- },
1056
- "Please describe the problem you want to report. Be as descriptive as possible. Your signed in user and a reference to the current page will automatically be amended to the alarm so that the receiver can reach out to you if necessary."
1057
- ), /* @__PURE__ */ React.createElement(
1058
- TextField,
1059
- {
1060
- inputProps: { "data-testid": "trigger-input" },
1061
- id: "description",
1062
- multiline: true,
1063
- fullWidth: true,
1064
- minRows: 4,
1065
- margin: "normal",
1066
- label: "Problem description",
1067
- variant: "outlined",
1068
- onChange: descriptionChanged
1069
- }
1070
- )), /* @__PURE__ */ React.createElement(DialogActions, null, /* @__PURE__ */ React.createElement(
1071
- Button,
1072
- {
1073
- "data-testid": "trigger-button",
1074
- id: "trigger",
1075
- color: "secondary",
1076
- disabled: !description || loading,
1077
- variant: "contained",
1078
- onClick: () => handleTriggerAlarm(description),
1079
- endIcon: loading && /* @__PURE__ */ React.createElement(CircularProgress, { size: 16 })
1080
- },
1081
- "Trigger Incident"
1082
- ), /* @__PURE__ */ React.createElement(Button, { id: "close", color: "primary", onClick: handleDialog }, "Close")));
1083
- };
1084
-
1085
- function TriggerIncidentButton({ integrationKey, entityName, compact, handleRefresh }) {
1086
- const useStyles = makeStyles((theme) => ({
1087
- buttonStyle: {
1088
- color: theme.palette.text.primary,
1089
- "&:hover": {
1090
- backgroundColor: "transparent",
1091
- textDecoration: "underline"
1092
- }
1093
- },
1094
- containerStyle: {
1095
- fontSize: compact !== true ? "12px" : "10px",
1096
- width: compact !== true ? "80px" : "60px",
1097
- marginRight: "-10px"
1098
- },
1099
- iconStyle: {
1100
- fontSize: "30px",
1101
- marginBottom: "-10px"
1102
- },
1103
- textStyle: {
1104
- marginBottom: "-10px"
1105
- }
1106
- }));
1107
- const { buttonStyle, containerStyle, iconStyle, textStyle } = useStyles();
1108
- const [dialogShown, setDialogShown] = useState(false);
1109
- const showDialog = useCallback(() => {
1110
- setDialogShown(true);
1111
- }, [setDialogShown]);
1112
- const hideDialog = useCallback(() => {
1113
- setDialogShown(false);
1114
- }, [setDialogShown]);
1115
- const disabled = !integrationKey;
1116
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
1117
- IconButton,
1118
- {
1119
- "aria-label": "create-incident",
1120
- onClick: showDialog,
1121
- className: disabled ? "" : buttonStyle,
1122
- disabled
1123
- },
1124
- /* @__PURE__ */ React.createElement("div", { className: containerStyle }, /* @__PURE__ */ React.createElement(AddAlert, { className: iconStyle }), /* @__PURE__ */ React.createElement("p", { className: textStyle }, "Create new incident"))
1125
- ), integrationKey && /* @__PURE__ */ React.createElement(
1126
- TriggerDialog,
1127
- {
1128
- showDialog: dialogShown,
1129
- handleDialog: hideDialog,
1130
- integrationKey,
1131
- serviceName: entityName,
1132
- onIncidentCreated: handleRefresh
1133
- }
1134
- ));
1135
- }
1136
-
1137
- const useStyles$2 = makeStyles$1(
1138
- (theme) => createStyles$1({
1139
- overviewHeaderTextStyle: {
1140
- fontSize: "14px",
1141
- fontWeight: 500,
1142
- color: theme.palette.type === "light" ? "rgba(0, 0, 0, 0.54)" : "rgba(255, 255, 255, 0.7)"
1143
- },
1144
- oncallHeaderTextStyle: {
1145
- fontSize: "14px",
1146
- fontWeight: 500,
1147
- marginTop: "10px",
1148
- color: theme.palette.type === "light" ? "rgba(0, 0, 0, 0.54)" : "rgba(255, 255, 255, 0.7)"
1149
- },
1150
- headerStyle: {
1151
- marginBottom: "0px",
1152
- fontSize: "0px"
1153
- },
1154
- overviewHeaderContainerStyle: {
1155
- display: "flex",
1156
- margin: "15px",
1157
- marginBottom: "20px"
1158
- },
1159
- headerWithSubheaderContainerStyle: {
1160
- display: "flex",
1161
- alignItems: "center"
1162
- },
1163
- subheaderTextStyle: {
1164
- fontSize: "10px",
1165
- marginLeft: "5px"
1166
- },
1167
- overviewCardsContainerStyle: {
1168
- display: "flex",
1169
- margin: "15px",
1170
- marginTop: "-15px"
1171
- },
1172
- incidentMetricsContainerStyle: {
1173
- display: "flex",
1174
- height: "100%",
1175
- justifyContent: "center",
1176
- columnSpan: "all"
1177
- }
1178
- })
1179
- );
1180
- const BasicCard$1 = ({ children }) => /* @__PURE__ */ React.createElement(InfoCard, { title: "PagerDuty" }, children);
1181
- const PagerDutyCard$1 = (props) => {
1182
- var _a, _b, _c, _d, _e, _f, _g, _h;
1183
- const classes = useStyles$2();
1184
- const theme = useTheme();
1185
- const { readOnly, disableChangeEvents, disableOnCall } = props;
1186
- const api = useApi(pagerDutyApiRef);
1187
- const [refreshIncidents, setRefreshIncidents] = useState(false);
1188
- const [refreshChangeEvents, setRefreshChangeEvents] = useState(false);
1189
- const [refreshStatus, setRefreshStatus] = useState(false);
1190
- const handleRefresh = useCallback(() => {
1191
- setRefreshIncidents((x) => !x);
1192
- setRefreshChangeEvents((x) => !x);
1193
- setRefreshStatus((x) => !x);
1194
- }, []);
1195
- const {
1196
- value: service,
1197
- loading,
1198
- error
1199
- } = useAsync(async () => {
1200
- const { service: foundService } = await api.getServiceByPagerDutyEntity(
1201
- props
1202
- );
1203
- const serviceStandards = await api.getServiceStandardsByServiceId(
1204
- foundService.id
1205
- );
1206
- const serviceMetrics = await api.getServiceMetricsByServiceId(
1207
- foundService.id
1208
- );
1209
- const result = {
1210
- id: foundService.id,
1211
- name: foundService.name,
1212
- url: foundService.html_url,
1213
- policyId: foundService.escalation_policy.id,
1214
- policyLink: foundService.escalation_policy.html_url,
1215
- policyName: foundService.escalation_policy.name,
1216
- status: foundService.status,
1217
- standards: serviceStandards !== void 0 ? serviceStandards.standards : void 0,
1218
- metrics: serviceMetrics !== void 0 ? serviceMetrics.metrics : void 0
1219
- };
1220
- return result;
1221
- }, [props]);
1222
- if (error) {
1223
- let errorNode;
1224
- switch (error.constructor) {
1225
- case UnauthorizedError:
1226
- errorNode = /* @__PURE__ */ React.createElement(MissingTokenError, null);
1227
- break;
1228
- case NotFoundError:
1229
- errorNode = /* @__PURE__ */ React.createElement(ServiceNotFoundError, null);
1230
- break;
1231
- default:
1232
- errorNode = /* @__PURE__ */ React.createElement(ForbiddenError, null);
1233
- }
1234
- return /* @__PURE__ */ React.createElement(BasicCard$1, null, errorNode);
1235
- }
1236
- if (loading) {
1237
- return /* @__PURE__ */ React.createElement(BasicCard$1, null, /* @__PURE__ */ React.createElement(Progress, null));
1238
- }
1239
- return /* @__PURE__ */ React.createElement(Card, { "data-testid": "pagerduty-card" }, /* @__PURE__ */ React.createElement(
1240
- CardHeader,
1241
- {
1242
- className: classes.headerStyle,
1243
- title: theme.palette.type === "dark" ? /* @__PURE__ */ React.createElement("img", { src: PDWhiteImage, alt: "PagerDuty", height: "35" }) : /* @__PURE__ */ React.createElement("img", { src: PDGreenImage, alt: "PagerDuty", height: "35" }),
1244
- action: !readOnly && props.integrationKey ? /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
1245
- TriggerIncidentButton,
1246
- {
1247
- "data-testid": "trigger-incident-button",
1248
- integrationKey: props.integrationKey,
1249
- entityName: props.name,
1250
- handleRefresh
1251
- }
1252
- ), /* @__PURE__ */ React.createElement(OpenServiceButton, { serviceUrl: service.url })) : /* @__PURE__ */ React.createElement(OpenServiceButton, { serviceUrl: service.url })
1253
- }
1254
- ), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 12, className: classes.overviewHeaderContainerStyle }, /* @__PURE__ */ React.createElement(Grid, { item: true, md: 3 }, /* @__PURE__ */ React.createElement(Typography, { className: classes.overviewHeaderTextStyle }, "STATUS")), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 6 }, /* @__PURE__ */ React.createElement("span", { className: classes.headerWithSubheaderContainerStyle }, /* @__PURE__ */ React.createElement(Typography, { className: classes.overviewHeaderTextStyle }, "INSIGHTS"), /* @__PURE__ */ React.createElement(Typography, { className: classes.subheaderTextStyle }, "(last 30 days)"))), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 3 }, /* @__PURE__ */ React.createElement(Typography, { className: classes.overviewHeaderTextStyle }, "STANDARDS"))), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 12, className: classes.overviewCardsContainerStyle }, /* @__PURE__ */ React.createElement(Grid, { item: true, md: 3 }, /* @__PURE__ */ React.createElement(StatusCard, { serviceId: service.id, refreshStatus })), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 6, className: classes.incidentMetricsContainerStyle }, /* @__PURE__ */ React.createElement(Grid, { item: true, md: 4 }, /* @__PURE__ */ React.createElement(
1255
- IncidentCounterCard,
1256
- {
1257
- count: (service == null ? void 0 : service.metrics) !== void 0 && service.metrics.length > 0 ? service == null ? void 0 : service.metrics[0].total_interruptions : void 0,
1258
- label: "interruptions",
1259
- color: theme.palette.textSubtle
1260
- }
1261
- )), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 4 }, /* @__PURE__ */ React.createElement(
1262
- IncidentCounterCard,
1263
- {
1264
- count: (service == null ? void 0 : service.metrics) !== void 0 && service.metrics.length > 0 ? service == null ? void 0 : service.metrics[0].total_high_urgency_incidents : void 0,
1265
- label: "high urgency",
1266
- color: theme.palette.warning.main
1267
- }
1268
- )), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 4 }, /* @__PURE__ */ React.createElement(
1269
- IncidentCounterCard,
1270
- {
1271
- count: (service == null ? void 0 : service.metrics) !== void 0 && ((_a = service == null ? void 0 : service.metrics) == null ? void 0 : _a.length) > 0 ? service == null ? void 0 : service.metrics[0].total_incident_count : void 0,
1272
- label: "incidents",
1273
- color: theme.palette.error.main
1274
- }
1275
- ))), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 3 }, /* @__PURE__ */ React.createElement(
1276
- ServiceStandardsCard,
1277
- {
1278
- total: ((_b = service == null ? void 0 : service.standards) == null ? void 0 : _b.score) !== void 0 ? (_d = (_c = service == null ? void 0 : service.standards) == null ? void 0 : _c.score) == null ? void 0 : _d.total : void 0,
1279
- completed: ((_e = service == null ? void 0 : service.standards) == null ? void 0 : _e.score) !== void 0 ? (_g = (_f = service == null ? void 0 : service.standards) == null ? void 0 : _f.score) == null ? void 0 : _g.passing : void 0,
1280
- standards: (service == null ? void 0 : service.standards) !== void 0 ? (_h = service == null ? void 0 : service.standards) == null ? void 0 : _h.standards : void 0
1281
- }
1282
- ))), /* @__PURE__ */ React.createElement(Divider, null), /* @__PURE__ */ React.createElement(CardContent, null, /* @__PURE__ */ React.createElement(TabbedCard, null, /* @__PURE__ */ React.createElement(CardTab, { label: "Incidents" }, /* @__PURE__ */ React.createElement(
1283
- Incidents,
1284
- {
1285
- serviceId: service.id,
1286
- refreshIncidents
1287
- }
1288
- )), disableChangeEvents !== true ? /* @__PURE__ */ React.createElement(CardTab, { label: "Change Events" }, /* @__PURE__ */ React.createElement(
1289
- ChangeEvents,
1290
- {
1291
- "data-testid": "change-events",
1292
- serviceId: service.id,
1293
- refreshEvents: refreshChangeEvents
1294
- }
1295
- )) : /* @__PURE__ */ React.createElement(React.Fragment, null)), disableOnCall !== true ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { className: classes.oncallHeaderTextStyle }, "ON CALL"), /* @__PURE__ */ React.createElement(
1296
- EscalationPolicy,
1297
- {
1298
- "data-testid": "oncall-card",
1299
- policyId: service.policyId,
1300
- policyUrl: service.policyLink,
1301
- policyName: service.policyName
1302
- }
1303
- )) : /* @__PURE__ */ React.createElement(React.Fragment, null)));
1304
- };
1305
-
1306
- const isPluginApplicableToEntity$1 = (entity) => {
1307
- var _a, _b;
1308
- return Boolean(
1309
- ((_a = entity.metadata.annotations) == null ? void 0 : _a[PAGERDUTY_INTEGRATION_KEY]) || ((_b = entity.metadata.annotations) == null ? void 0 : _b[PAGERDUTY_SERVICE_ID])
1310
- );
1311
- };
1312
- const EntityPagerDutyCard = (props) => {
1313
- const { readOnly, disableChangeEvents, disableOnCall } = props;
1314
- const { entity } = useEntity();
1315
- const pagerDutyEntity = getPagerDutyEntity(entity);
1316
- return /* @__PURE__ */ React.createElement(
1317
- PagerDutyCard$1,
1318
- {
1319
- ...pagerDutyEntity,
1320
- readOnly,
1321
- disableChangeEvents,
1322
- disableOnCall
1323
- }
1324
- );
1325
- };
1326
-
1327
- var index$1 = /*#__PURE__*/Object.freeze({
1328
- __proto__: null,
1329
- isPluginApplicableToEntity: isPluginApplicableToEntity$1,
1330
- EntityPagerDutyCard: EntityPagerDutyCard
1331
- });
1332
-
1333
- const useStyles$1 = makeStyles$1(
1334
- (theme) => createStyles$1({
1335
- overviewHeaderTextStyle: {
1336
- fontSize: "14px",
1337
- fontWeight: 500,
1338
- color: theme.palette.type === "light" ? "rgba(0, 0, 0, 0.54)" : "rgba(255, 255, 255, 0.7)"
1339
- },
1340
- headerStyle: {
1341
- marginBottom: "0px",
1342
- fontSize: "0px"
1343
- },
1344
- overviewHeaderContainerStyle: {
1345
- display: "flex",
1346
- margin: "0px",
1347
- padding: "15px",
1348
- marginBottom: "5px"
1349
- },
1350
- headerWithSubheaderContainerStyle: {
1351
- display: "flex",
1352
- alignItems: "center"
1353
- },
1354
- subheaderTextStyle: {
1355
- fontSize: "10px",
1356
- marginLeft: "5px"
1357
- },
1358
- overviewCardsContainerStyle: {
1359
- display: "flex",
1360
- margin: "15px",
1361
- marginTop: "-15px"
1362
- },
1363
- onCallAccordionDetails: {
1364
- display: "flex",
1365
- width: "100%",
1366
- marginTop: "-25px",
1367
- marginBottom: "-15px"
1368
- },
1369
- incidentMetricsContainerStyle: {
1370
- display: "flex",
1371
- height: "100%",
1372
- justifyContent: "center",
1373
- columnSpan: "all",
1374
- margin: "15px",
1375
- marginTop: "-15px"
1376
- }
1377
- })
1378
- );
1379
- const BasicCard = ({ children }) => /* @__PURE__ */ React.createElement(InfoCard, { title: "PagerDuty" }, children);
1380
- const PagerDutySmallCard = (props) => {
1381
- var _a, _b, _c, _d, _e, _f, _g, _h;
1382
- const classes = useStyles$1();
1383
- const theme = useTheme();
1384
- const { readOnly, disableInsights, disableOnCall } = props;
1385
- const api = useApi(pagerDutyApiRef);
1386
- const [refreshStatus, setRefreshStatus] = useState(false);
1387
- const handleRefresh = useCallback(() => {
1388
- setRefreshStatus((x) => !x);
1389
- }, []);
1390
- const {
1391
- value: service,
1392
- loading,
1393
- error
1394
- } = useAsync(async () => {
1395
- const { service: foundService } = await api.getServiceByPagerDutyEntity(
1396
- props
1397
- );
1398
- const serviceStandards = await api.getServiceStandardsByServiceId(
1399
- foundService.id
1400
- );
1401
- const serviceMetrics = await api.getServiceMetricsByServiceId(
1402
- foundService.id
1403
- );
1404
- const result = {
1405
- id: foundService.id,
1406
- name: foundService.name,
1407
- url: foundService.html_url,
1408
- policyId: foundService.escalation_policy.id,
1409
- policyLink: foundService.escalation_policy.html_url,
1410
- policyName: foundService.escalation_policy.name,
1411
- status: foundService.status,
1412
- standards: serviceStandards !== void 0 ? serviceStandards.standards : void 0,
1413
- metrics: serviceMetrics !== void 0 ? serviceMetrics.metrics : void 0
1414
- };
1415
- return result;
1416
- }, [props]);
1417
- if (error) {
1418
- let errorNode;
1419
- switch (error.constructor) {
1420
- case UnauthorizedError:
1421
- errorNode = /* @__PURE__ */ React.createElement(MissingTokenError, null);
1422
- break;
1423
- case NotFoundError:
1424
- errorNode = /* @__PURE__ */ React.createElement(ServiceNotFoundError, null);
1425
- break;
1426
- default:
1427
- errorNode = /* @__PURE__ */ React.createElement(ForbiddenError, null);
1428
- }
1429
- return /* @__PURE__ */ React.createElement(BasicCard, null, errorNode);
1430
- }
1431
- if (loading) {
1432
- return /* @__PURE__ */ React.createElement(BasicCard, null, /* @__PURE__ */ React.createElement(Progress, null));
1433
- }
1434
- return /* @__PURE__ */ React.createElement(Card, { "data-testid": "pagerduty-card" }, /* @__PURE__ */ React.createElement(
1435
- CardHeader,
1436
- {
1437
- className: classes.headerStyle,
1438
- title: theme.palette.type === "dark" ? /* @__PURE__ */ React.createElement("img", { src: PDWhiteImage, alt: "PagerDuty", height: "25" }) : /* @__PURE__ */ React.createElement("img", { src: PDGreenImage, alt: "PagerDuty", height: "25" }),
1439
- action: !readOnly && props.integrationKey ? /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
1440
- TriggerIncidentButton,
1441
- {
1442
- compact: true,
1443
- "data-testid": "trigger-incident-button",
1444
- integrationKey: props.integrationKey,
1445
- entityName: props.name,
1446
- handleRefresh
1447
- }
1448
- ), /* @__PURE__ */ React.createElement(OpenServiceButton, { compact: true, serviceUrl: service.url })) : /* @__PURE__ */ React.createElement(OpenServiceButton, { compact: true, serviceUrl: service.url })
1449
- }
1450
- ), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 12, className: classes.overviewHeaderContainerStyle }, /* @__PURE__ */ React.createElement(Grid, { item: true, md: 6 }, /* @__PURE__ */ React.createElement(Typography, { className: classes.overviewHeaderTextStyle }, "STATUS")), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 6 }, /* @__PURE__ */ React.createElement(Typography, { className: classes.overviewHeaderTextStyle }, "STANDARDS"))), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 12, className: classes.overviewCardsContainerStyle }, /* @__PURE__ */ React.createElement(Grid, { item: true, md: 6 }, /* @__PURE__ */ React.createElement(StatusCard, { compact: true, serviceId: service.id, refreshStatus })), /* @__PURE__ */ React.createElement(Grid, { item: true, md: 6 }, /* @__PURE__ */ React.createElement(
1451
- ServiceStandardsCard,
1452
- {
1453
- compact: true,
1454
- total: ((_a = service == null ? void 0 : service.standards) == null ? void 0 : _a.score) !== void 0 ? (_c = (_b = service == null ? void 0 : service.standards) == null ? void 0 : _b.score) == null ? void 0 : _c.total : void 0,
1455
- completed: ((_d = service == null ? void 0 : service.standards) == null ? void 0 : _d.score) !== void 0 ? (_f = (_e = service == null ? void 0 : service.standards) == null ? void 0 : _e.score) == null ? void 0 : _f.passing : void 0,
1456
- standards: (service == null ? void 0 : service.standards) !== void 0 ? (_g = service == null ? void 0 : service.standards) == null ? void 0 : _g.standards : void 0
1457
- }
1458
- ))), disableInsights !== true ? /* @__PURE__ */ React.createElement(Accordion, null, /* @__PURE__ */ React.createElement(
1459
- AccordionSummary,
1460
- {
1461
- expandIcon: /* @__PURE__ */ React.createElement(ExpandMoreIcon, null),
1462
- "aria-controls": "panel1a-content",
1463
- id: "panel1a-header"
1464
- },
1465
- /* @__PURE__ */ React.createElement("span", { className: classes.headerWithSubheaderContainerStyle }, /* @__PURE__ */ React.createElement(Typography, { className: classes.overviewHeaderTextStyle }, "INSIGHTS"), /* @__PURE__ */ React.createElement(Typography, { className: classes.subheaderTextStyle }, "(last 30 days)"))
1466
- ), /* @__PURE__ */ React.createElement(AccordionDetails, null, /* @__PURE__ */ React.createElement(
1467
- Grid,
1468
- {
1469
- item: true,
1470
- md: 12,
1471
- className: classes.incidentMetricsContainerStyle
1472
- },
1473
- /* @__PURE__ */ React.createElement(Grid, { item: true, md: 4 }, /* @__PURE__ */ React.createElement(
1474
- IncidentCounterCard,
1475
- {
1476
- compact: true,
1477
- count: (service == null ? void 0 : service.metrics) !== void 0 && service.metrics.length > 0 ? service == null ? void 0 : service.metrics[0].total_interruptions : void 0,
1478
- label: "interruptions",
1479
- color: theme.palette.textSubtle
1480
- }
1481
- )),
1482
- /* @__PURE__ */ React.createElement(Grid, { item: true, md: 4 }, /* @__PURE__ */ React.createElement(
1483
- IncidentCounterCard,
1484
- {
1485
- compact: true,
1486
- count: (service == null ? void 0 : service.metrics) !== void 0 && service.metrics.length > 0 ? service == null ? void 0 : service.metrics[0].total_high_urgency_incidents : void 0,
1487
- label: "high urgency",
1488
- color: theme.palette.warning.main
1489
- }
1490
- )),
1491
- /* @__PURE__ */ React.createElement(Grid, { item: true, md: 4 }, /* @__PURE__ */ React.createElement(
1492
- IncidentCounterCard,
1493
- {
1494
- compact: true,
1495
- count: (service == null ? void 0 : service.metrics) !== void 0 && ((_h = service == null ? void 0 : service.metrics) == null ? void 0 : _h.length) > 0 ? service == null ? void 0 : service.metrics[0].total_incident_count : void 0,
1496
- label: "incidents",
1497
- color: theme.palette.error.main
1498
- }
1499
- ))
1500
- ))) : /* @__PURE__ */ React.createElement(React.Fragment, null), disableOnCall !== true ? /* @__PURE__ */ React.createElement(Accordion, null, /* @__PURE__ */ React.createElement(
1501
- AccordionSummary,
1502
- {
1503
- expandIcon: /* @__PURE__ */ React.createElement(ExpandMoreIcon, null),
1504
- "aria-controls": "panel1a-content",
1505
- id: "panel1a-header"
1506
- },
1507
- /* @__PURE__ */ React.createElement(Typography, { className: classes.overviewHeaderTextStyle }, "ON CALL")
1508
- ), /* @__PURE__ */ React.createElement(AccordionDetails, { className: classes.onCallAccordionDetails }, /* @__PURE__ */ React.createElement(
1509
- EscalationPolicy,
1510
- {
1511
- "data-testid": "oncall-card",
1512
- policyId: service.policyId,
1513
- policyUrl: service.policyLink,
1514
- policyName: service.policyName
1515
- }
1516
- ))) : /* @__PURE__ */ React.createElement(React.Fragment, null));
1517
- };
1518
-
1519
- const isPluginApplicableToEntity = (entity) => {
1520
- var _a, _b;
1521
- return Boolean(
1522
- ((_a = entity.metadata.annotations) == null ? void 0 : _a[PAGERDUTY_INTEGRATION_KEY]) || ((_b = entity.metadata.annotations) == null ? void 0 : _b[PAGERDUTY_SERVICE_ID])
1523
- );
1524
- };
1525
- const EntityPagerDutySmallCard = (props) => {
1526
- const { readOnly, disableInsights, disableOnCall } = props;
1527
- const { entity } = useEntity();
1528
- const pagerDutyEntity = getPagerDutyEntity(entity);
1529
- return /* @__PURE__ */ React.createElement(
1530
- PagerDutySmallCard,
1531
- {
1532
- ...pagerDutyEntity,
1533
- readOnly,
1534
- disableInsights,
1535
- disableOnCall
1536
- }
1537
- );
1538
- };
1539
-
1540
- var index = /*#__PURE__*/Object.freeze({
1541
- __proto__: null,
1542
- isPluginApplicableToEntity: isPluginApplicableToEntity,
1543
- EntityPagerDutySmallCard: EntityPagerDutySmallCard
1544
- });
1545
-
1546
- function usePagerdutyEntity() {
1547
- const { entity } = useEntity();
1548
- return getPagerDutyEntity(entity);
1549
- }
1550
-
1551
- const useStyles = makeStyles((theme) => ({
1552
- buttonStyle: {
1553
- backgroundColor: theme.palette.error.main,
1554
- color: theme.palette.error.contrastText,
1555
- "&:hover": {
1556
- backgroundColor: theme.palette.error.dark
1557
- }
1558
- }
1559
- }));
1560
- function TriggerButton(props) {
1561
- var _a;
1562
- const { buttonStyle } = useStyles();
1563
- const { integrationKey, name } = usePagerdutyEntity();
1564
- const [dialogShown, setDialogShown] = useState(false);
1565
- const showDialog = useCallback(() => {
1566
- setDialogShown(true);
1567
- }, [setDialogShown]);
1568
- const hideDialog = useCallback(() => {
1569
- setDialogShown(false);
1570
- }, [setDialogShown]);
1571
- const disabled = !integrationKey;
1572
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
1573
- Button,
1574
- {
1575
- onClick: showDialog,
1576
- variant: "contained",
1577
- className: disabled ? "" : buttonStyle,
1578
- disabled
1579
- },
1580
- integrationKey ? (_a = props.children) != null ? _a : "Create new incident" : "Missing integration key"
1581
- ), integrationKey && /* @__PURE__ */ React.createElement(
1582
- TriggerDialog,
1583
- {
1584
- showDialog: dialogShown,
1585
- handleDialog: hideDialog,
1586
- integrationKey,
1587
- serviceName: name
1588
- }
1589
- ));
1590
- }
1591
-
1592
- const PagerDutyCard = EntityPagerDutyCard;
1593
-
1594
- export { EntityPagerDutyCard$1 as E, HomePagePagerDutyCard as H, PagerDutyCard$1 as P, TriggerButton as T, UnauthorizedError as U, EntityPagerDutySmallCard$1 as a, isPluginApplicableToEntity as b, PagerDutyClient as c, pagerDutyApiRef as d, PagerDutyCard as e, isPluginApplicableToEntity$1 as i, pagerDutyPlugin as p };
1595
- //# sourceMappingURL=index-b56f9c4b.esm.js.map