@pagerduty/backstage-plugin 0.13.0-next.3 → 0.13.0-next.31

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.
@@ -0,0 +1,213 @@
1
+ import React, { useState, useMemo } from 'react';
2
+ import { useMaterialReactTable, MRT_EditActionButtons, MaterialReactTable } from 'material-react-table';
3
+ import { Typography, Box, DialogTitle, DialogContent, DialogActions, Tooltip, IconButton } from '@material-ui/core';
4
+ import { QueryClient, QueryClientProvider, useMutation } from '@tanstack/react-query';
5
+ import { Edit, OpenInBrowser } from '@mui/icons-material';
6
+ import { useApi } from '@backstage/core-plugin-api';
7
+ import { pagerDutyApiRef } from '../../api/client.esm.js';
8
+
9
+ function getColorFromStatus(status) {
10
+ switch (status) {
11
+ case "InSync":
12
+ return "green";
13
+ case "OutOfSync":
14
+ return "red";
15
+ case "NotMapped":
16
+ return "orange";
17
+ default:
18
+ return "gray";
19
+ }
20
+ }
21
+ function makeReadable(status) {
22
+ switch (status) {
23
+ case "InSync":
24
+ return "In Sync";
25
+ case "OutOfSync":
26
+ return "Out of Sync";
27
+ case "NotMapped":
28
+ return "Not Mapped";
29
+ default:
30
+ return "Refresh to Update";
31
+ }
32
+ }
33
+ const MappingTable = ({
34
+ mappings,
35
+ catalogEntities
36
+ }) => {
37
+ const DenseTable = () => {
38
+ const [validationErrors, setValidationErrors] = useState({});
39
+ const pagerDutyApi = useApi(pagerDutyApiRef);
40
+ const columns = useMemo(
41
+ () => [
42
+ {
43
+ accessorKey: "serviceId",
44
+ header: "Service ID",
45
+ visibleInShowHideMenu: false,
46
+ enableEditing: false,
47
+ Edit: () => null,
48
+ Cell: ({ cell }) => /* @__PURE__ */ React.createElement(Typography, { variant: "body1", style: { fontWeight: 600 } }, cell.getValue())
49
+ },
50
+ {
51
+ accessorKey: "serviceName",
52
+ header: "PagerDuty Service",
53
+ enableEditing: false
54
+ },
55
+ {
56
+ accessorKey: "team",
57
+ header: "Team",
58
+ enableEditing: false
59
+ },
60
+ {
61
+ accessorKey: "escalationPolicy",
62
+ header: "Escalation Policy",
63
+ enableEditing: false
64
+ },
65
+ {
66
+ accessorKey: "entityRef",
67
+ header: "Mapping",
68
+ visibleInShowHideMenu: false,
69
+ editVariant: "select",
70
+ editSelectOptions: getCatalogEntityOptions(),
71
+ muiEditTextFieldProps: {
72
+ select: true,
73
+ error: !!(validationErrors == null ? void 0 : validationErrors.state),
74
+ helperText: validationErrors == null ? void 0 : validationErrors.state
75
+ }
76
+ },
77
+ {
78
+ accessorKey: "entityName",
79
+ header: "Mapped Entity Name",
80
+ enableEditing: false,
81
+ Edit: () => null
82
+ },
83
+ {
84
+ accessorKey: "status",
85
+ header: "Status",
86
+ enableEditing: false,
87
+ Edit: () => null,
88
+ Cell: ({ cell }) => /* @__PURE__ */ React.createElement(
89
+ Box,
90
+ {
91
+ component: "span",
92
+ bgcolor: getColorFromStatus(cell.getValue()),
93
+ borderRadius: "0.25rem",
94
+ color: "white",
95
+ p: "0.25rem"
96
+ },
97
+ makeReadable(cell.getValue())
98
+ )
99
+ },
100
+ {
101
+ accessorKey: "serviceUrl",
102
+ header: "Service URL",
103
+ visibleInShowHideMenu: false,
104
+ enableEditing: false,
105
+ Edit: () => null
106
+ }
107
+ ],
108
+ [validationErrors]
109
+ );
110
+ function useUpdateMapping() {
111
+ return useMutation({
112
+ mutationFn: async (mapping) => {
113
+ return await pagerDutyApi.storeServiceMapping(
114
+ mapping.serviceId,
115
+ mapping.entityRef
116
+ );
117
+ }
118
+ // client side optimistic update
119
+ // onMutate: (newMappingInfo: PagerDutyEntityMapping) => {
120
+ // queryClient.setQueryData(["updateMappings"], (prevMappings: any) =>
121
+ // prevMappings?.map((prevMapping: PagerDutyEntityMapping) => {
122
+ // if (prevMapping.serviceId === newMappingInfo.serviceId) {
123
+ // newMappingInfo.entityName =
124
+ // fetchedCatalogEntities.find(
125
+ // (entity) => entity.id === newMappingInfo.entityRef
126
+ // )?.name || "";
127
+ // return newMappingInfo;
128
+ // }
129
+ // return prevMapping;
130
+ // })
131
+ // );
132
+ // },
133
+ });
134
+ }
135
+ const { mutateAsync: updateMapping, isPending: isUpdatingMapping } = useUpdateMapping();
136
+ const handleSaveMapping = async ({ values, table }) => {
137
+ var _a;
138
+ setValidationErrors({});
139
+ values.entityName = ((_a = catalogEntities.find((entity) => entity.id === values.entityRef)) == null ? void 0 : _a.name) || "";
140
+ values.status = "RefreshToUpdate";
141
+ await updateMapping(values);
142
+ table.setEditingRow(null);
143
+ };
144
+ const openInBrowser = (url) => {
145
+ window.open(url, "_blank", "noreferrer");
146
+ };
147
+ const dataTable = useMaterialReactTable({
148
+ columns,
149
+ data: mappings,
150
+ editDisplayMode: "modal",
151
+ // default ('row', 'cell', 'table', and 'custom' are also available)
152
+ enableEditing: true,
153
+ positionActionsColumn: "last",
154
+ enableStickyHeader: true,
155
+ enableFilters: true,
156
+ getRowId: (row) => row.serviceId,
157
+ muiToolbarAlertBannerProps: mappings === void 0 ? {
158
+ color: "error",
159
+ children: "Error loading data"
160
+ } : void 0,
161
+ muiTableContainerProps: {
162
+ sx: {
163
+ minHeight: "500px"
164
+ }
165
+ },
166
+ onEditingRowCancel: () => setValidationErrors({}),
167
+ onEditingRowSave: handleSaveMapping,
168
+ // optionally customize modal content
169
+ renderEditRowDialogContent: ({ table, row, internalEditComponents }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DialogTitle, null, "Edit Mapping"), /* @__PURE__ */ React.createElement(DialogContent, null, internalEditComponents, " "), /* @__PURE__ */ React.createElement(DialogActions, null, /* @__PURE__ */ React.createElement(MRT_EditActionButtons, { variant: "text", table, row }))),
170
+ renderRowActions: ({ row, table }) => /* @__PURE__ */ React.createElement(Box, { sx: { display: "flex" } }, /* @__PURE__ */ React.createElement(Tooltip, { title: "Edit" }, /* @__PURE__ */ React.createElement(IconButton, { onClick: () => table.setEditingRow(row) }, /* @__PURE__ */ React.createElement(Edit, null))), /* @__PURE__ */ React.createElement(Tooltip, { title: "Open in PagerDuty" }, /* @__PURE__ */ React.createElement(
171
+ IconButton,
172
+ {
173
+ onClick: () => openInBrowser(row.getValue("serviceUrl"))
174
+ },
175
+ /* @__PURE__ */ React.createElement(OpenInBrowser, null)
176
+ ))),
177
+ state: {
178
+ isLoading: mappings.length === 0 || catalogEntities.length === 0,
179
+ isSaving: isUpdatingMapping,
180
+ showAlertBanner: mappings === void 0 || catalogEntities === void 0,
181
+ showProgressBars: mappings.length === 0 || catalogEntities.length === 0,
182
+ columnVisibility: {
183
+ serviceId: false,
184
+ entityRef: false,
185
+ serviceUrl: false
186
+ }
187
+ }
188
+ });
189
+ function getCatalogEntityOptions() {
190
+ const options = [];
191
+ options.push({ value: "", label: "None" });
192
+ catalogEntities.forEach((entity) => {
193
+ const foundMapping = mappings.find(
194
+ (item) => item.entityRef === entity.id
195
+ );
196
+ const foundServiceAnnotation = entity.annotations["pagerduty.com/service-id"];
197
+ if (!foundMapping && !foundServiceAnnotation || foundServiceAnnotation && foundServiceAnnotation === (foundMapping == null ? void 0 : foundMapping.serviceId) && !foundMapping) {
198
+ options.push({
199
+ value: entity.id,
200
+ label: entity.name
201
+ });
202
+ }
203
+ });
204
+ return options;
205
+ }
206
+ return /* @__PURE__ */ React.createElement(MaterialReactTable, { table: dataTable });
207
+ };
208
+ const queryClient = new QueryClient();
209
+ return /* @__PURE__ */ React.createElement(QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React.createElement(DenseTable, null));
210
+ };
211
+
212
+ export { MappingTable };
213
+ //# sourceMappingURL=MappingTable.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MappingTable.esm.js","sources":["../../../src/components/PagerDutyPage/MappingTable.tsx"],"sourcesContent":["import React, { useMemo, useState } from \"react\";\nimport { PagerDutyEntityMapping } from \"@pagerduty/backstage-plugin-common\";\nimport {\n MRT_ColumnDef,\n MRT_EditActionButtons,\n MRT_TableOptions,\n MaterialReactTable,\n useMaterialReactTable,\n} from \"material-react-table\";\nimport {\n Box,\n DialogActions,\n DialogContent,\n DialogTitle,\n IconButton,\n Tooltip,\n Typography,\n} from \"@material-ui/core\";\nimport {\n QueryClient,\n QueryClientProvider,\n useMutation,\n} from \"@tanstack/react-query\";\nimport { Edit, OpenInBrowser } from \"@mui/icons-material\";\nimport { useApi } from \"@backstage/core-plugin-api\";\nimport { pagerDutyApiRef } from \"../../api\";\n\ntype BackstageEntity = {\n name: string; // \"Ads\"\n id: string; // \"QWe1j283n12j132\"\n system: string; // \"Production\"\n owner: string; // \"Mapped\"\n lifecycle: string; // \"Ads\"\n annotations: Annotations;\n};\n\nexport type Annotations = {\n \"pagerduty.com/integration-key\": string;\n \"pagerduty.com/service-id\": string;\n};\n\nfunction getColorFromStatus(status?: string) {\n switch (status) {\n case \"InSync\":\n return \"green\";\n case \"OutOfSync\":\n return \"red\";\n case \"NotMapped\":\n return \"orange\";\n default:\n return \"gray\";\n }\n}\n\nfunction makeReadable(status?: string) {\n switch (status) {\n case \"InSync\":\n return \"In Sync\";\n case \"OutOfSync\":\n return \"Out of Sync\";\n case \"NotMapped\":\n return \"Not Mapped\";\n default:\n return \"Refresh to Update\";\n }\n}\n\ntype CatalogEntityOptions = {\n value: string;\n label: string;\n};\n\ntype MappingTableProps = {\n mappings: PagerDutyEntityMapping[];\n catalogEntities: BackstageEntity[];\n};\n\nexport const MappingTable = ({\n mappings,\n catalogEntities,\n}: MappingTableProps) => {\n const DenseTable = () => {\n const [validationErrors, setValidationErrors] = useState<\n Record<string, string | undefined>\n >({});\n\n const pagerDutyApi = useApi(pagerDutyApiRef);\n\n const columns = useMemo<MRT_ColumnDef<PagerDutyEntityMapping>[]>(\n () => [\n {\n accessorKey: \"serviceId\",\n header: \"Service ID\",\n visibleInShowHideMenu: false,\n enableEditing: false,\n Edit: () => null,\n Cell: ({ cell }) => (\n <Typography variant=\"body1\" style={{ fontWeight: 600 }}>\n {cell.getValue<string>()}\n </Typography>\n ),\n },\n {\n accessorKey: \"serviceName\",\n header: \"PagerDuty Service\",\n enableEditing: false,\n },\n {\n accessorKey: \"team\",\n header: \"Team\",\n enableEditing: false,\n },\n {\n accessorKey: \"escalationPolicy\",\n header: \"Escalation Policy\",\n enableEditing: false,\n },\n {\n accessorKey: \"entityRef\",\n header: \"Mapping\",\n visibleInShowHideMenu: false,\n editVariant: \"select\",\n editSelectOptions: getCatalogEntityOptions(),\n muiEditTextFieldProps: {\n select: true,\n error: !!validationErrors?.state,\n helperText: validationErrors?.state,\n },\n },\n {\n accessorKey: \"entityName\",\n header: \"Mapped Entity Name\",\n enableEditing: false,\n Edit: () => null,\n },\n {\n accessorKey: \"status\",\n header: \"Status\",\n enableEditing: false,\n Edit: () => null,\n Cell: ({ cell }) => (\n <Box\n component=\"span\"\n bgcolor={getColorFromStatus(cell.getValue<string>())}\n borderRadius=\"0.25rem\"\n color=\"white\"\n p=\"0.25rem\"\n >\n {makeReadable(cell.getValue<string>())}\n </Box>\n ),\n },\n {\n accessorKey: \"serviceUrl\",\n header: \"Service URL\",\n visibleInShowHideMenu: false,\n enableEditing: false,\n Edit: () => null,\n },\n ],\n [validationErrors]\n );\n\n // UPDATE hook (put mapping in api)\n function useUpdateMapping() {\n // const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (mapping: PagerDutyEntityMapping) => {\n return await pagerDutyApi.storeServiceMapping(\n mapping.serviceId,\n mapping.entityRef\n );\n },\n // client side optimistic update\n // onMutate: (newMappingInfo: PagerDutyEntityMapping) => {\n // queryClient.setQueryData([\"updateMappings\"], (prevMappings: any) =>\n // prevMappings?.map((prevMapping: PagerDutyEntityMapping) => {\n // if (prevMapping.serviceId === newMappingInfo.serviceId) {\n // newMappingInfo.entityName =\n // fetchedCatalogEntities.find(\n // (entity) => entity.id === newMappingInfo.entityRef\n // )?.name || \"\";\n\n // return newMappingInfo;\n // }\n // return prevMapping;\n // })\n // );\n // },\n });\n }\n\n // call UPDATE hook\n const { mutateAsync: updateMapping, isPending: isUpdatingMapping } =\n useUpdateMapping();\n\n // UPDATE action\n const handleSaveMapping: MRT_TableOptions<PagerDutyEntityMapping>[\"onEditingRowSave\"] =\n async ({ values, table }) => {\n setValidationErrors({});\n values.entityName =\n catalogEntities.find((entity) => entity.id === values.entityRef)\n ?.name || \"\";\n values.status = \"RefreshToUpdate\";\n await updateMapping(values);\n table.setEditingRow(null); // exit editing mode\n };\n\n const openInBrowser = (url: string) => {\n window.open(url, \"_blank\", \"noreferrer\");\n };\n\n const dataTable = useMaterialReactTable({\n columns,\n data: mappings,\n editDisplayMode: \"modal\", // default ('row', 'cell', 'table', and 'custom' are also available)\n enableEditing: true,\n positionActionsColumn: \"last\",\n enableStickyHeader: true,\n enableFilters: true,\n getRowId: (row) => row.serviceId,\n muiToolbarAlertBannerProps:\n mappings === undefined\n ? {\n color: \"error\",\n children: \"Error loading data\",\n }\n : undefined,\n muiTableContainerProps: {\n sx: {\n minHeight: \"500px\",\n },\n },\n onEditingRowCancel: () => setValidationErrors({}),\n onEditingRowSave: handleSaveMapping,\n // optionally customize modal content\n renderEditRowDialogContent: ({ table, row, internalEditComponents }) => (\n <>\n <DialogTitle>Edit Mapping</DialogTitle>\n <DialogContent>{internalEditComponents} </DialogContent>\n <DialogActions>\n <MRT_EditActionButtons variant=\"text\" table={table} row={row} />\n </DialogActions>\n </>\n ),\n renderRowActions: ({ row, table }) => (\n <Box sx={{ display: \"flex\" }}>\n <Tooltip title=\"Edit\">\n <IconButton onClick={() => table.setEditingRow(row)}>\n <Edit />\n </IconButton>\n </Tooltip>\n <Tooltip title=\"Open in PagerDuty\">\n <IconButton\n onClick={() => openInBrowser(row.getValue(\"serviceUrl\"))}\n >\n <OpenInBrowser />\n </IconButton>\n </Tooltip>\n </Box>\n ),\n state: {\n isLoading: mappings.length === 0 || catalogEntities.length === 0,\n isSaving: isUpdatingMapping,\n showAlertBanner:\n mappings === undefined || catalogEntities === undefined,\n showProgressBars: mappings.length === 0 || catalogEntities.length === 0,\n columnVisibility: {\n serviceId: false,\n entityRef: false,\n serviceUrl: false,\n },\n },\n });\n\n function getCatalogEntityOptions(): CatalogEntityOptions[] {\n const options: CatalogEntityOptions[] = [];\n // if (entityOptions.length === 0) {\n // initialize with empty object\n options.push({ value: \"\", label: \"None\" });\n // }\n\n catalogEntities.forEach((entity) => {\n // find entity with entity.id in entityMappings array\n const foundMapping = mappings.find(\n (item) => item.entityRef === entity.id\n );\n\n const foundServiceAnnotation =\n entity.annotations[\"pagerduty.com/service-id\"];\n\n if (\n (!foundMapping && !foundServiceAnnotation) ||\n (foundServiceAnnotation &&\n foundServiceAnnotation === foundMapping?.serviceId &&\n !foundMapping)\n ) {\n options.push({\n value: entity.id,\n label: entity.name,\n });\n }\n });\n\n return options;\n }\n\n return <MaterialReactTable table={dataTable} />;\n };\n\n const queryClient = new QueryClient();\n\n return (\n <QueryClientProvider client={queryClient}>\n <DenseTable />\n </QueryClientProvider>\n );\n};\n"],"names":[],"mappings":";;;;;;;;AAyCA,SAAS,mBAAmB,MAAiB,EAAA;AAC3C,EAAA,QAAQ,MAAQ;AAAA,IACd,KAAK,QAAA;AACH,MAAO,OAAA,OAAA,CAAA;AAAA,IACT,KAAK,WAAA;AACH,MAAO,OAAA,KAAA,CAAA;AAAA,IACT,KAAK,WAAA;AACH,MAAO,OAAA,QAAA,CAAA;AAAA,IACT;AACE,MAAO,OAAA,MAAA,CAAA;AAAA,GACX;AACF,CAAA;AAEA,SAAS,aAAa,MAAiB,EAAA;AACrC,EAAA,QAAQ,MAAQ;AAAA,IACd,KAAK,QAAA;AACH,MAAO,OAAA,SAAA,CAAA;AAAA,IACT,KAAK,WAAA;AACH,MAAO,OAAA,aAAA,CAAA;AAAA,IACT,KAAK,WAAA;AACH,MAAO,OAAA,YAAA,CAAA;AAAA,IACT;AACE,MAAO,OAAA,mBAAA,CAAA;AAAA,GACX;AACF,CAAA;AAYO,MAAM,eAAe,CAAC;AAAA,EAC3B,QAAA;AAAA,EACA,eAAA;AACF,CAAyB,KAAA;AACvB,EAAA,MAA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AAA;AAAA,YACX,OAAO,MAAO,CAAA,EAAA;AAAA,YACd,OAAO,MAAO,CAAA,IAAA;AAAA,WACf,CAAA,CAAA;AAAA,SACH;AAAA,OACD,CAAA,CAAA;AAED,MAAO,OAAA,OAAA,CAAA;AAAA,KACT;AAEA,IAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,kBAAmB,EAAA,EAAA,KAAA,EAAO,SAAW,EAAA,CAAA,CAAA;AAAA,GAC/C,CAAA;AAEA,EAAM,MAAA,WAAA,GAAc,IAAI,WAAY,EAAA,CAAA;AAEpC,EAAA,2CACG,mBAAoB,EAAA,EAAA,MAAA,EAAQ,WAC3B,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,gBAAW,CACd,CAAA,CAAA;AAEJ;;;;"}
@@ -1,263 +1,46 @@
1
- import React, { useState, useMemo } from 'react';
2
- import { Typography, Box, DialogTitle, DialogContent, DialogActions, Tooltip, IconButton } from '@material-ui/core';
3
- import EditIcon from '@mui/icons-material/Edit';
1
+ import React, { useState, useEffect } from 'react';
4
2
  import { useApi } from '@backstage/core-plugin-api';
5
3
  import { pagerDutyApiRef } from '../../api/client.esm.js';
6
- import { QueryClient, QueryClientProvider, useQuery, useMutation } from '@tanstack/react-query';
7
- import { useMaterialReactTable, MRT_EditActionButtons, MaterialReactTable } from 'material-react-table';
8
4
  import { catalogApiRef } from '@backstage/plugin-catalog-react';
9
- import OpenInBrowserIcon from '@material-ui/icons/OpenInBrowser';
5
+ import { MappingTable } from './MappingTable.esm.js';
10
6
 
11
- function getColorFromStatus(status) {
12
- switch (status) {
13
- case "InSync":
14
- return "green";
15
- case "OutOfSync":
16
- return "red";
17
- case "NotMapped":
18
- return "orange";
19
- default:
20
- return "gray";
21
- }
22
- }
23
- function makeReadable(status) {
24
- switch (status) {
25
- case "InSync":
26
- return "In Sync";
27
- case "OutOfSync":
28
- return "Out of Sync";
29
- case "NotMapped":
30
- return "Not Mapped";
31
- default:
32
- return "Refresh to Update";
33
- }
34
- }
35
7
  const ServiceMappingComponent = () => {
36
8
  const [entityMappings, setEntityMappings] = useState([]);
37
9
  const [catalogEntities, setCatalogEntities] = useState([]);
38
10
  const pagerDutyApi = useApi(pagerDutyApiRef);
39
11
  const catalogApi = useApi(catalogApiRef);
40
- async function fetchCatalogEntities() {
41
- const result = await catalogApi.getEntities({
42
- filter: { kind: "Component" }
43
- });
44
- const entities = [];
45
- result.items.forEach((entity) => {
46
- var _a, _b, _c, _d, _e, _f;
47
- entities.push({
48
- name: (_a = entity.metadata) == null ? void 0 : _a.name,
49
- id: (_c = (_b = entity.metadata) == null ? void 0 : _b.uid) != null ? _c : "",
50
- system: JSON.stringify((_d = entity.spec) == null ? void 0 : _d.system) || "",
51
- owner: JSON.stringify((_e = entity.spec) == null ? void 0 : _e.owner) || "",
52
- lifecycle: JSON.stringify((_f = entity.spec) == null ? void 0 : _f.lifecycle) || ""
12
+ useEffect(() => {
13
+ function fetchMappings() {
14
+ pagerDutyApi.getEntityMappings().then((result) => {
15
+ setEntityMappings(result.mappings);
53
16
  });
54
- });
55
- setCatalogEntities(entities);
56
- return entities;
57
- }
58
- function getCatalogEntityOptions() {
59
- const options = [];
60
- options.push({ value: "", label: "None" });
61
- catalogEntities.forEach((entity) => {
62
- const foundEntity = entityMappings.find(
63
- (item) => item.entityRef === entity.id
64
- );
65
- if (!foundEntity) {
66
- options.push({
67
- value: entity.id,
68
- label: entity.name
17
+ }
18
+ function fetchCatalogEntities() {
19
+ catalogApi.getEntities({
20
+ filter: { kind: "Component" }
21
+ }).then((result) => {
22
+ const entities = [];
23
+ result.items.forEach((entity) => {
24
+ var _a, _b, _c, _d, _e, _f;
25
+ const annotations = JSON.parse(
26
+ JSON.stringify(entity.metadata.annotations)
27
+ );
28
+ entities.push({
29
+ name: (_a = entity.metadata) == null ? void 0 : _a.name,
30
+ id: (_c = (_b = entity.metadata) == null ? void 0 : _b.uid) != null ? _c : "",
31
+ system: JSON.stringify((_d = entity.spec) == null ? void 0 : _d.system) || "",
32
+ owner: JSON.stringify((_e = entity.spec) == null ? void 0 : _e.owner) || "",
33
+ lifecycle: JSON.stringify((_f = entity.spec) == null ? void 0 : _f.lifecycle) || "",
34
+ annotations
35
+ });
69
36
  });
70
- }
71
- });
72
- return options;
73
- }
74
- function useGetMappings() {
75
- return useQuery({
76
- queryKey: ["mappings"],
77
- queryFn: async () => {
78
- const { mappings: foundMappings } = await pagerDutyApi.getEntityMappings();
79
- setEntityMappings(foundMappings);
80
- return foundMappings;
81
- },
82
- refetchOnWindowFocus: false
83
- });
84
- }
85
- function useGetCatalogEntities() {
86
- return useQuery({
87
- queryKey: ["entities"],
88
- queryFn: async () => fetchCatalogEntities(),
89
- refetchOnMount: false
90
- });
91
- }
92
- function useUpdateMapping() {
93
- return useMutation({
94
- mutationFn: async (mapping) => {
95
- return await pagerDutyApi.storeServiceMapping(
96
- mapping.serviceId,
97
- mapping.entityRef
98
- );
99
- }
100
- // client side optimistic update
101
- // onMutate: (newMappingInfo: PagerDutyEntityMapping) => {
102
- // queryClient.setQueryData(["updateMappings"], (prevMappings: any) =>
103
- // prevMappings?.map((prevMapping: PagerDutyEntityMapping) => {
104
- // if (prevMapping.serviceId === newMappingInfo.serviceId) {
105
- // newMappingInfo.entityName =
106
- // fetchedCatalogEntities.find(
107
- // (entity) => entity.id === newMappingInfo.entityRef
108
- // )?.name || "";
109
- // return newMappingInfo;
110
- // }
111
- // return prevMapping;
112
- // })
113
- // );
114
- // },
115
- });
116
- }
117
- const DenseTable = () => {
118
- const [validationErrors, setValidationErrors] = useState({});
119
- const columns = useMemo(
120
- () => [
121
- {
122
- accessorKey: "serviceId",
123
- header: "Service ID",
124
- visibleInShowHideMenu: false,
125
- enableEditing: false,
126
- Edit: () => null,
127
- Cell: ({ cell }) => /* @__PURE__ */ React.createElement(Typography, { variant: "body1", style: { fontWeight: 600 } }, cell.getValue())
128
- },
129
- {
130
- accessorKey: "serviceName",
131
- header: "PagerDuty Service",
132
- enableEditing: false
133
- },
134
- {
135
- accessorKey: "team",
136
- header: "Team",
137
- enableEditing: false
138
- },
139
- {
140
- accessorKey: "escalationPolicy",
141
- header: "Escalation Policy",
142
- enableEditing: false
143
- },
144
- {
145
- accessorKey: "entityRef",
146
- header: "Mapping",
147
- visibleInShowHideMenu: false,
148
- editVariant: "select",
149
- editSelectOptions: getCatalogEntityOptions(),
150
- muiEditTextFieldProps: {
151
- select: true,
152
- error: !!(validationErrors == null ? void 0 : validationErrors.state),
153
- helperText: validationErrors == null ? void 0 : validationErrors.state
154
- }
155
- },
156
- {
157
- accessorKey: "entityName",
158
- header: "Mapped Entity Name",
159
- enableEditing: false,
160
- Edit: () => null
161
- },
162
- {
163
- accessorKey: "status",
164
- header: "Status",
165
- enableEditing: false,
166
- Edit: () => null,
167
- Cell: ({ cell }) => /* @__PURE__ */ React.createElement(
168
- Box,
169
- {
170
- component: "span",
171
- bgcolor: getColorFromStatus(cell.getValue()),
172
- borderRadius: "0.25rem",
173
- color: "white",
174
- p: "0.25rem"
175
- },
176
- makeReadable(cell.getValue())
177
- )
178
- },
179
- {
180
- accessorKey: "serviceUrl",
181
- header: "Service URL",
182
- visibleInShowHideMenu: false,
183
- enableEditing: false,
184
- Edit: () => null
185
- }
186
- ],
187
- [validationErrors]
188
- );
189
- const {
190
- data: fetchedMappings = [],
191
- isError: isLoadingMappingsError,
192
- isFetching: isFetchingMappings,
193
- isLoading: isLoadingMappings
194
- } = useGetMappings();
195
- const {
196
- data: fetchedCatalogEntities = [],
197
- isError: isLoadingCatalogEntitiesError,
198
- isFetching: isFetchingCatalogEntities,
199
- isLoading: isLoadingCatalogEntities
200
- } = useGetCatalogEntities();
201
- const { mutateAsync: updateMapping, isPending: isUpdatingMapping } = useUpdateMapping();
202
- const handleSaveMapping = async ({ values, table }) => {
203
- var _a;
204
- setValidationErrors({});
205
- values.entityName = ((_a = fetchedCatalogEntities.find(
206
- (entity) => entity.id === values.entityRef
207
- )) == null ? void 0 : _a.name) || "";
208
- values.status = "RefreshToUpdate";
209
- await updateMapping(values);
210
- table.setEditingRow(null);
211
- };
212
- const openInBrowser = (url) => {
213
- window.open(url, "_blank", "noreferrer");
214
- };
215
- const dataTable = useMaterialReactTable({
216
- columns,
217
- data: fetchedMappings,
218
- editDisplayMode: "modal",
219
- // default ('row', 'cell', 'table', and 'custom' are also available)
220
- enableEditing: true,
221
- positionActionsColumn: "last",
222
- enableStickyHeader: true,
223
- enableFilters: true,
224
- getRowId: (row) => row.serviceId,
225
- muiToolbarAlertBannerProps: isLoadingMappingsError ? {
226
- color: "error",
227
- children: "Error loading data"
228
- } : void 0,
229
- muiTableContainerProps: {
230
- sx: {
231
- minHeight: "500px"
232
- }
233
- },
234
- onEditingRowCancel: () => setValidationErrors({}),
235
- onEditingRowSave: handleSaveMapping,
236
- // optionally customize modal content
237
- renderEditRowDialogContent: ({ table, row, internalEditComponents }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DialogTitle, null, "Edit Mapping"), /* @__PURE__ */ React.createElement(DialogContent, null, internalEditComponents, " "), /* @__PURE__ */ React.createElement(DialogActions, null, /* @__PURE__ */ React.createElement(MRT_EditActionButtons, { variant: "text", table, row }))),
238
- renderRowActions: ({ row, table }) => /* @__PURE__ */ React.createElement(Box, { sx: { display: "flex" } }, /* @__PURE__ */ React.createElement(Tooltip, { title: "Edit" }, /* @__PURE__ */ React.createElement(IconButton, { onClick: () => table.setEditingRow(row) }, /* @__PURE__ */ React.createElement(EditIcon, null))), /* @__PURE__ */ React.createElement(Tooltip, { title: "Open in PagerDuty" }, /* @__PURE__ */ React.createElement(
239
- IconButton,
240
- {
241
- onClick: () => openInBrowser(row.getValue("serviceUrl"))
242
- },
243
- /* @__PURE__ */ React.createElement(OpenInBrowserIcon, null)
244
- ))),
245
- state: {
246
- isLoading: isLoadingMappings || isLoadingCatalogEntities,
247
- isSaving: isUpdatingMapping,
248
- showAlertBanner: isLoadingMappingsError || isLoadingCatalogEntitiesError,
249
- showProgressBars: isFetchingMappings || isFetchingCatalogEntities,
250
- columnVisibility: {
251
- serviceId: false,
252
- entityRef: false,
253
- serviceUrl: false
254
- }
255
- }
256
- });
257
- return /* @__PURE__ */ React.createElement(MaterialReactTable, { table: dataTable });
258
- };
259
- const queryClient = new QueryClient();
260
- return /* @__PURE__ */ React.createElement(QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React.createElement(DenseTable, null));
37
+ setCatalogEntities(entities);
38
+ });
39
+ }
40
+ fetchMappings();
41
+ fetchCatalogEntities();
42
+ }, [catalogApi, pagerDutyApi]);
43
+ return /* @__PURE__ */ React.createElement(MappingTable, { mappings: entityMappings, catalogEntities });
261
44
  };
262
45
 
263
46
  export { ServiceMappingComponent };
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceMappingComponent.esm.js","sources":["../../../src/components/PagerDutyPage/ServiceMappingComponent.tsx"],"sourcesContent":["import React, { useMemo, useState } from \"react\";\nimport {\n Box,\n DialogActions,\n DialogContent,\n DialogTitle,\n IconButton,\n Tooltip,\n Typography,\n} from \"@material-ui/core\";\nimport EditIcon from \"@mui/icons-material/Edit\";\nimport { PagerDutyEntityMapping } from \"@pagerduty/backstage-plugin-common\";\nimport { useApi } from \"@backstage/core-plugin-api\";\nimport { pagerDutyApiRef } from \"../../api\";\nimport {\n QueryClient,\n QueryClientProvider,\n useMutation,\n useQuery,\n} from \"@tanstack/react-query\";\nimport {\n MRT_ColumnDef,\n MRT_EditActionButtons,\n MRT_TableOptions,\n MaterialReactTable,\n useMaterialReactTable,\n} from \"material-react-table\";\nimport { catalogApiRef } from \"@backstage/plugin-catalog-react\";\nimport OpenInBrowser from \"@material-ui/icons/OpenInBrowser\";\n\ntype Service = {\n name: string; // \"Ads\"\n id: string; // \"QWe1j283n12j132\"\n system: string; // \"Production\"\n owner: string; // \"Mapped\"\n lifecycle: string; // \"Ads\"\n};\n\nfunction getColorFromStatus(status?: string) {\n switch (status) {\n case \"InSync\":\n return \"green\";\n case \"OutOfSync\":\n return \"red\";\n case \"NotMapped\":\n return \"orange\";\n default:\n return \"gray\";\n }\n}\n\nfunction makeReadable(status?: string) {\n switch (status) {\n case \"InSync\":\n return \"In Sync\";\n case \"OutOfSync\":\n return \"Out of Sync\";\n case \"NotMapped\":\n return \"Not Mapped\";\n default:\n return \"Refresh to Update\";\n }\n}\n\nexport const ServiceMappingComponent = () => {\n const [entityMappings, setEntityMappings] = useState<\n PagerDutyEntityMapping[]\n >([]);\n const [catalogEntities, setCatalogEntities] = useState<Service[]>([]);\n // const [entityOptions, setEntityOptions] = useState<CatalogEntityOptions[]>([]);\n\n const pagerDutyApi = useApi(pagerDutyApiRef);\n const catalogApi = useApi(catalogApiRef);\n\n // function fetchCatalogEntities() {\n\n // catalogApi\n // .getEntities({\n // filter: { kind: \"Component\" },\n // })\n // .then((result) => {\n // const entities: Service[] = [];\n // result.items.forEach((entity: any) => {\n // entities.push({\n // name: entity.metadata?.name,\n // id: entity.metadata?.uid ?? \"\",\n // system: JSON.stringify(entity.spec?.system) || \"\",\n // owner: JSON.stringify(entity.spec?.owner) || \"\",\n // lifecycle: JSON.stringify(entity.spec?.lifecycle) || \"\",\n // });\n // });\n\n // setCatalogEntities(entities);\n // });\n // }\n\n async function fetchCatalogEntities(): Promise<Service[]> {\n const result = await catalogApi.getEntities({\n filter: { kind: \"Component\" },\n });\n\n const entities: Service[] = [];\n result.items.forEach((entity: any) => {\n entities.push({\n name: entity.metadata?.name,\n id: entity.metadata?.uid ?? \"\",\n system: JSON.stringify(entity.spec?.system) || \"\",\n owner: JSON.stringify(entity.spec?.owner) || \"\",\n lifecycle: JSON.stringify(entity.spec?.lifecycle) || \"\",\n });\n });\n\n setCatalogEntities(entities);\n\n return entities;\n }\n\n type CatalogEntityOptions = {\n value: string;\n label: string;\n };\n\n function getCatalogEntityOptions(): CatalogEntityOptions[] {\n const options: CatalogEntityOptions[] = [];\n // if (entityOptions.length === 0) {\n // initialize with empty object\n options.push({ value: \"\", label: \"None\" });\n // }\n\n catalogEntities.forEach((entity) => {\n // find entity with entity.id in entityMappings array\n const foundEntity = entityMappings.find(\n (item) => item.entityRef === entity.id\n );\n\n if (!foundEntity) {\n options.push({\n value: entity.id,\n label: entity.name,\n });\n }\n });\n\n // setEntityOptions(options);\n\n return options;\n } \n\n // READ hook (get mappings from api)\n function useGetMappings() {\n return useQuery<PagerDutyEntityMapping[]>({\n queryKey: [\"mappings\"],\n queryFn: async () => {\n // send api request here\n const { mappings: foundMappings } =\n await pagerDutyApi.getEntityMappings();\n\n setEntityMappings(foundMappings);\n\n return foundMappings;\n },\n refetchOnWindowFocus: false,\n });\n }\n\n // READ hook (get catalog entities from api)\n function useGetCatalogEntities() {\n return useQuery<Service[]>({\n queryKey: [\"entities\"],\n queryFn: async () => fetchCatalogEntities(),\n refetchOnMount: false,\n });\n }\n\n // UPDATE hook (put mapping in api)\n function useUpdateMapping() {\n // const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (mapping: PagerDutyEntityMapping) => {\n return await pagerDutyApi.storeServiceMapping(\n mapping.serviceId,\n mapping.entityRef\n );\n },\n // client side optimistic update\n // onMutate: (newMappingInfo: PagerDutyEntityMapping) => {\n // queryClient.setQueryData([\"updateMappings\"], (prevMappings: any) =>\n // prevMappings?.map((prevMapping: PagerDutyEntityMapping) => {\n // if (prevMapping.serviceId === newMappingInfo.serviceId) {\n // newMappingInfo.entityName =\n // fetchedCatalogEntities.find(\n // (entity) => entity.id === newMappingInfo.entityRef\n // )?.name || \"\";\n\n // return newMappingInfo;\n // }\n // return prevMapping;\n // })\n // );\n // },\n });\n }\n\n const DenseTable = () => {\n const [validationErrors, setValidationErrors] = useState<\n Record<string, string | undefined>\n >({});\n\n const columns = useMemo<MRT_ColumnDef<PagerDutyEntityMapping>[]>(\n () => [\n {\n accessorKey: \"serviceId\",\n header: \"Service ID\",\n visibleInShowHideMenu: false,\n enableEditing: false,\n Edit: () => null,\n Cell: ({ cell }) => (\n <Typography variant=\"body1\" style={{ fontWeight: 600 }}>\n {cell.getValue<string>()}\n </Typography>\n ),\n },\n {\n accessorKey: \"serviceName\",\n header: \"PagerDuty Service\",\n enableEditing: false,\n },\n {\n accessorKey: \"team\",\n header: \"Team\",\n enableEditing: false,\n },\n {\n accessorKey: \"escalationPolicy\",\n header: \"Escalation Policy\",\n enableEditing: false,\n },\n {\n accessorKey: \"entityRef\",\n header: \"Mapping\",\n visibleInShowHideMenu: false,\n editVariant: \"select\",\n editSelectOptions: getCatalogEntityOptions(),\n muiEditTextFieldProps: {\n select: true,\n error: !!validationErrors?.state,\n helperText: validationErrors?.state,\n },\n },\n {\n accessorKey: \"entityName\",\n header: \"Mapped Entity Name\",\n enableEditing: false,\n Edit: () => null,\n },\n {\n accessorKey: \"status\",\n header: \"Status\",\n enableEditing: false,\n Edit: () => null,\n Cell: ({ cell }) => (\n <Box\n component=\"span\"\n bgcolor={getColorFromStatus(cell.getValue<string>())}\n borderRadius=\"0.25rem\"\n color=\"white\"\n p=\"0.25rem\"\n >\n {makeReadable(cell.getValue<string>())}\n </Box>\n ),\n },\n {\n accessorKey: \"serviceUrl\",\n header: \"Service URL\",\n visibleInShowHideMenu: false,\n enableEditing: false,\n Edit: () => null,\n },\n ],\n [validationErrors]\n );\n\n // call READ hook\n const {\n data: fetchedMappings = [],\n isError: isLoadingMappingsError,\n isFetching: isFetchingMappings,\n isLoading: isLoadingMappings,\n } = useGetMappings();\n\n // call READ hook\n const {\n data: fetchedCatalogEntities = [],\n isError: isLoadingCatalogEntitiesError,\n isFetching: isFetchingCatalogEntities,\n isLoading: isLoadingCatalogEntities,\n } = useGetCatalogEntities();\n\n // call UPDATE hook\n const { mutateAsync: updateMapping, isPending: isUpdatingMapping } =\n useUpdateMapping();\n\n // UPDATE action\n const handleSaveMapping: MRT_TableOptions<PagerDutyEntityMapping>[\"onEditingRowSave\"] =\n async ({ values, table }) => {\n setValidationErrors({});\n values.entityName =\n fetchedCatalogEntities.find(\n (entity) => entity.id === values.entityRef\n )?.name || \"\";\n values.status = \"RefreshToUpdate\";\n await updateMapping(values);\n table.setEditingRow(null); // exit editing mode\n };\n\n const openInBrowser = (url: string) => {\n window.open(url, \"_blank\", \"noreferrer\");\n };\n\n const dataTable = useMaterialReactTable({\n columns,\n data: fetchedMappings,\n editDisplayMode: \"modal\", // default ('row', 'cell', 'table', and 'custom' are also available)\n enableEditing: true,\n positionActionsColumn: \"last\",\n enableStickyHeader: true,\n enableFilters: true,\n getRowId: (row) => row.serviceId,\n muiToolbarAlertBannerProps: isLoadingMappingsError\n ? {\n color: \"error\",\n children: \"Error loading data\",\n }\n : undefined,\n muiTableContainerProps: {\n sx: {\n minHeight: \"500px\",\n },\n },\n onEditingRowCancel: () => setValidationErrors({}),\n onEditingRowSave: handleSaveMapping,\n // optionally customize modal content\n renderEditRowDialogContent: ({ table, row, internalEditComponents }) => (\n <>\n <DialogTitle>Edit Mapping</DialogTitle>\n <DialogContent>{internalEditComponents} </DialogContent>\n <DialogActions>\n <MRT_EditActionButtons variant=\"text\" table={table} row={row} />\n </DialogActions>\n </>\n ),\n renderRowActions: ({ row, table }) => (\n <Box sx={{ display: \"flex\" }}>\n <Tooltip title=\"Edit\">\n <IconButton onClick={() => table.setEditingRow(row)}>\n <EditIcon />\n </IconButton>\n </Tooltip>\n <Tooltip title=\"Open in PagerDuty\">\n <IconButton\n onClick={() => openInBrowser(row.getValue(\"serviceUrl\"))}\n >\n <OpenInBrowser />\n </IconButton>\n </Tooltip>\n </Box>\n ),\n state: {\n isLoading: isLoadingMappings || isLoadingCatalogEntities,\n isSaving: isUpdatingMapping,\n showAlertBanner: isLoadingMappingsError || isLoadingCatalogEntitiesError,\n showProgressBars: isFetchingMappings || isFetchingCatalogEntities,\n columnVisibility: {\n serviceId: false,\n entityRef: false,\n serviceUrl: false,\n },\n },\n });\n\n return <MaterialReactTable table={dataTable} />;\n };\n\n const queryClient = new QueryClient();\n\n return (\n <QueryClientProvider client={queryClient}>\n <DenseTable />\n </QueryClientProvider>\n );\n};\n"],"names":["OpenInBrowser"],"mappings":";;;;;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ACF,CAAA;AAAA,MAEF,KAAO,EAAA;AAAA,QACL,WAAW,iBAAqB,IAAA,wBAAA;AAAA,QAChC,QAAU,EAAA,iBAAA;AAAA,QACV,iBAAiB,sBAA0B,IAAA,6BAAA;AAAA,QAC3C,kBAAkB,kBAAsB,IAAA,yBAAA;AAAA,QACxC,gBAAkB,EAAA;AAAA,UAChB,SAAW,EAAA,KAAA;AAAA,UACX,SAAW,EAAA,KAAA;AAAA,UACX,UAAY,EAAA,KAAA;AAAA,SACd;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAED,IAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,kBAAmB,EAAA,EAAA,KAAA,EAAO,SAAW,EAAA,CAAA,CAAA;AAAA,GAC/C,CAAA;AAEA,EAAM,MAAA,WAAA,GAAc,IAAI,WAAY,EAAA,CAAA;AAEpC,EAAA,2CACG,mBAAoB,EAAA,EAAA,MAAA,EAAQ,WAC3B,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,gBAAW,CACd,CAAA,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"ServiceMappingComponent.esm.js","sources":["../../../src/components/PagerDutyPage/ServiceMappingComponent.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { PagerDutyEntityMapping } from \"@pagerduty/backstage-plugin-common\";\nimport { useApi } from \"@backstage/core-plugin-api\";\nimport { pagerDutyApiRef } from \"../../api\";\nimport { catalogApiRef } from \"@backstage/plugin-catalog-react\";\nimport { MappingTable } from \"./MappingTable\";\n\ntype BackstageEntity = {\n name: string; // \"Ads\"\n id: string; // \"QWe1j283n12j132\"\n system: string; // \"Production\"\n owner: string; // \"Mapped\"\n lifecycle: string; // \"Ads\"\n annotations: Annotations;\n};\n\nexport type Annotations = {\n \"pagerduty.com/integration-key\": string;\n \"pagerduty.com/service-id\": string;\n};\n\n\nexport const ServiceMappingComponent = () => {\n const [entityMappings, setEntityMappings] = useState<\n PagerDutyEntityMapping[]\n >([]);\n const [catalogEntities, setCatalogEntities] = useState<BackstageEntity[]>([]);\n\n const pagerDutyApi = useApi(pagerDutyApiRef);\n const catalogApi = useApi(catalogApiRef);\n\n // call fetchMappings() and fetchCatalogEntities() on useEffect hook\n useEffect(() => {\n function fetchMappings() {\n pagerDutyApi.getEntityMappings().then((result) => {\n setEntityMappings(result.mappings);\n });\n }\n\n function fetchCatalogEntities() {\n catalogApi\n .getEntities({\n filter: { kind: \"Component\" },\n })\n .then((result) => {\n const entities: BackstageEntity[] = [];\n result.items.forEach((entity: any) => {\n const annotations: Annotations = JSON.parse(\n JSON.stringify(entity.metadata.annotations)\n );\n\n entities.push({\n name: entity.metadata?.name,\n id: entity.metadata?.uid ?? \"\",\n system: JSON.stringify(entity.spec?.system) || \"\",\n owner: JSON.stringify(entity.spec?.owner) || \"\",\n lifecycle: JSON.stringify(entity.spec?.lifecycle) || \"\",\n annotations: annotations,\n });\n });\n\n setCatalogEntities(entities);\n });\n }\n\n fetchMappings();\n fetchCatalogEntities();\n }, [catalogApi, pagerDutyApi]);\n\n \n return (\n <MappingTable mappings={entityMappings} catalogEntities={catalogEntities} />\n );\n};\n"],"names":[],"mappings":";;;;;;AAsBO,MAAM,0BAA0B,MAAM;AAC3C,EAAA,MAAM,CAAC,cAAgB,EAAA,iBAAiB,CAAI,GAAA,QAAA,CAE1C,EAAE,CAAA,CAAA;AACJ,EAAA,MAAM,CAAC,eAAiB,EAAA,kBAAkB,CAAI,GAAA,QAAA,CAA4B,EAAE,CAAA,CAAA;AAE5E,EAAM,MAAA,YAAA,GAAe,OAAO,eAAe,CAAA,CAAA;AAC3C,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA,CAAA;AAGvC,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,SAAS,aAAgB,GAAA;AACvB,MAAA,YAAA,CAAa,iBAAkB,EAAA,CAAE,IAAK,CAAA,CAAC,MAAW,KAAA;AAChD,QAAA,iBAAA,CAAkB,OAAO,QAAQ,CAAA,CAAA;AAAA,OACl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,SAAS,CAAK,IAAA,EAAA;AAAA,YACrD,WAAA;AAAA,WACD,CAAA,CAAA;AAAA,SACF,CAAA,CAAA;AAED,QAAA,kBAAA,CAAmB,QAAQ,CAAA,CAAA;AAAA,OAC5B,CAAA,CAAA;AAAA,KACP;AAEA,IAAc,aAAA,EAAA,CAAA;AACd,IAAqB,oBAAA,EAAA,CAAA;AAAA,GACpB,EAAA,CAAC,UAAY,EAAA,YAAY,CAAC,CAAA,CAAA;AAG7B,EAAA,uBACK,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA,EAAa,QAAU,EAAA,cAAA,EAAgB,eAAmC,EAAA,CAAA,CAAA;AAEjF;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import * as _backstage_plugin_home_react from '@backstage/plugin-home-react';
2
3
  import { Entity } from '@backstage/catalog-model';
3
4
  import * as react from 'react';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagerduty/backstage-plugin",
3
3
  "description": "A Backstage plugin that integrates towards PagerDuty",
4
- "version": "0.13.0-next.3",
4
+ "version": "0.13.0-next.31",
5
5
  "main": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",