@backstage/plugin-notifications 0.2.0 → 0.2.1-next.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 (36) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/api/NotificationsApi.esm.js +8 -0
  3. package/dist/api/NotificationsApi.esm.js.map +1 -0
  4. package/dist/api/NotificationsClient.esm.js +74 -0
  5. package/dist/api/NotificationsClient.esm.js.map +1 -0
  6. package/dist/{esm/index-D44DlZtS.esm.js → components/NotificationsFilters/NotificationsFilters.esm.js} +4 -124
  7. package/dist/components/NotificationsFilters/NotificationsFilters.esm.js.map +1 -0
  8. package/dist/components/NotificationsPage/NotificationsPage.esm.js +138 -0
  9. package/dist/components/NotificationsPage/NotificationsPage.esm.js.map +1 -0
  10. package/dist/components/NotificationsPage/index.esm.js +2 -0
  11. package/dist/components/NotificationsPage/index.esm.js.map +1 -0
  12. package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js +193 -0
  13. package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js.map +1 -0
  14. package/dist/components/NotificationsTable/BulkActions.esm.js +55 -0
  15. package/dist/components/NotificationsTable/BulkActions.esm.js.map +1 -0
  16. package/dist/components/NotificationsTable/NotificationsTable.esm.js +219 -0
  17. package/dist/components/NotificationsTable/NotificationsTable.esm.js.map +1 -0
  18. package/dist/components/NotificationsTable/SelectAll.esm.js +41 -0
  19. package/dist/components/NotificationsTable/SelectAll.esm.js.map +1 -0
  20. package/dist/components/NotificationsTable/SeverityIcon.esm.js +40 -0
  21. package/dist/components/NotificationsTable/SeverityIcon.esm.js.map +1 -0
  22. package/dist/hooks/useNotificationsApi.esm.js +14 -0
  23. package/dist/hooks/useNotificationsApi.esm.js.map +1 -0
  24. package/dist/hooks/useTitleCounter.esm.js +57 -0
  25. package/dist/hooks/useTitleCounter.esm.js.map +1 -0
  26. package/dist/hooks/useWebNotifications.esm.js +44 -0
  27. package/dist/hooks/useWebNotifications.esm.js.map +1 -0
  28. package/dist/index.d.ts +34 -5
  29. package/dist/index.esm.js +8 -524
  30. package/dist/index.esm.js.map +1 -1
  31. package/dist/plugin.esm.js +28 -0
  32. package/dist/plugin.esm.js.map +1 -0
  33. package/dist/routes.esm.js +8 -0
  34. package/dist/routes.esm.js.map +1 -0
  35. package/package.json +9 -6
  36. package/dist/esm/index-D44DlZtS.esm.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @backstage/plugin-notifications
2
2
 
3
+ ## 0.2.1-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f730c0b: The user can newly mark all unread messages as read at one click.
8
+ - bfcb2f1: Allow showing notifications as snackbars in the UI
9
+ - f6633ca: Add option to set the notification as read automatically when the notification link is opened
10
+ - Updated dependencies
11
+ - @backstage/core-components@0.14.6-next.1
12
+
13
+ ## 0.2.1-next.0
14
+
15
+ ### Patch Changes
16
+
17
+ - e6bf85f: Allow overriding `NotificationsPage` page properties
18
+ - a42a19b: Empty descriptions are not rendered to improve the look&feel.
19
+ - 1bc3b86: Fix to show web notifications even when browser is on foreground. Fix duplicate notifications with multiple tabs.
20
+ - f793112: Allow defining `className` and additional properties for `NotificationsSideBarItem`
21
+ - e1c7d6e: Fix infinite loop in the notification title counter
22
+ - fcda449: The rendered size of a notification is limited for very long descriptions.
23
+ - Updated dependencies
24
+ - @backstage/theme@0.5.4-next.0
25
+ - @backstage/core-components@0.14.5-next.0
26
+ - @backstage/core-plugin-api@1.9.2
27
+ - @backstage/errors@1.2.4
28
+ - @backstage/types@1.1.1
29
+ - @backstage/plugin-notifications-common@0.0.3
30
+ - @backstage/plugin-signals-react@0.0.3
31
+
3
32
  ## 0.2.0
4
33
 
5
34
  ### Minor Changes
@@ -0,0 +1,8 @@
1
+ import { createApiRef } from '@backstage/core-plugin-api';
2
+
3
+ const notificationsApiRef = createApiRef({
4
+ id: "plugin.notifications.service"
5
+ });
6
+
7
+ export { notificationsApiRef };
8
+ //# sourceMappingURL=NotificationsApi.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationsApi.esm.js","sources":["../../src/api/NotificationsApi.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport {\n Notification,\n NotificationSeverity,\n NotificationStatus,\n} from '@backstage/plugin-notifications-common';\n\n/** @public */\nexport const notificationsApiRef = createApiRef<NotificationsApi>({\n id: 'plugin.notifications.service',\n});\n\n/** @public */\nexport type GetNotificationsOptions = {\n offset?: number;\n limit?: number;\n search?: string;\n read?: boolean;\n saved?: boolean;\n createdAfter?: Date;\n sort?: 'created' | 'topic' | 'origin';\n sortOrder?: 'asc' | 'desc';\n minimumSeverity?: NotificationSeverity;\n};\n\n/** @public */\nexport type UpdateNotificationsOptions = {\n ids: string[];\n read?: boolean;\n saved?: boolean;\n};\n\n/** @public */\nexport type GetNotificationsResponse = {\n notifications: Notification[];\n totalCount: number;\n};\n\n/** @public */\nexport interface NotificationsApi {\n getNotifications(\n options?: GetNotificationsOptions,\n ): Promise<GetNotificationsResponse>;\n\n getNotification(id: string): Promise<Notification>;\n\n getStatus(): Promise<NotificationStatus>;\n\n updateNotifications(\n options: UpdateNotificationsOptions,\n ): Promise<Notification[]>;\n}\n"],"names":[],"mappings":";;AAuBO,MAAM,sBAAsB,YAA+B,CAAA;AAAA,EAChE,EAAI,EAAA,8BAAA;AACN,CAAC;;;;"}
@@ -0,0 +1,74 @@
1
+ import { ResponseError } from '@backstage/errors';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => {
6
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ return value;
8
+ };
9
+ class NotificationsClient {
10
+ constructor(options) {
11
+ __publicField(this, "discoveryApi");
12
+ __publicField(this, "fetchApi");
13
+ this.discoveryApi = options.discoveryApi;
14
+ this.fetchApi = options.fetchApi;
15
+ }
16
+ async getNotifications(options) {
17
+ var _a;
18
+ const queryString = new URLSearchParams();
19
+ if ((options == null ? void 0 : options.limit) !== void 0) {
20
+ queryString.append("limit", options.limit.toString(10));
21
+ }
22
+ if ((options == null ? void 0 : options.offset) !== void 0) {
23
+ queryString.append("offset", options.offset.toString(10));
24
+ }
25
+ if ((options == null ? void 0 : options.sort) !== void 0) {
26
+ queryString.append(
27
+ "orderField",
28
+ `${options.sort},${(_a = options == null ? void 0 : options.sortOrder) != null ? _a : "desc"}`
29
+ );
30
+ }
31
+ if (options == null ? void 0 : options.search) {
32
+ queryString.append("search", options.search);
33
+ }
34
+ if ((options == null ? void 0 : options.read) !== void 0) {
35
+ queryString.append("read", options.read ? "true" : "false");
36
+ }
37
+ if ((options == null ? void 0 : options.saved) !== void 0) {
38
+ queryString.append("saved", options.saved ? "true" : "false");
39
+ }
40
+ if ((options == null ? void 0 : options.createdAfter) !== void 0) {
41
+ queryString.append("createdAfter", options.createdAfter.toISOString());
42
+ }
43
+ if ((options == null ? void 0 : options.minimumSeverity) !== void 0) {
44
+ queryString.append("minimumSeverity", options.minimumSeverity);
45
+ }
46
+ const urlSegment = `?${queryString}`;
47
+ return await this.request(urlSegment);
48
+ }
49
+ async getNotification(id) {
50
+ return await this.request(`${id}`);
51
+ }
52
+ async getStatus() {
53
+ return await this.request("status");
54
+ }
55
+ async updateNotifications(options) {
56
+ return await this.request("update", {
57
+ method: "POST",
58
+ body: JSON.stringify(options),
59
+ headers: { "Content-Type": "application/json" }
60
+ });
61
+ }
62
+ async request(path, init) {
63
+ const baseUrl = `${await this.discoveryApi.getBaseUrl("notifications")}/`;
64
+ const url = new URL(path, baseUrl);
65
+ const response = await this.fetchApi.fetch(url.toString(), init);
66
+ if (!response.ok) {
67
+ throw await ResponseError.fromResponse(response);
68
+ }
69
+ return response.json();
70
+ }
71
+ }
72
+
73
+ export { NotificationsClient };
74
+ //# sourceMappingURL=NotificationsClient.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationsClient.esm.js","sources":["../../src/api/NotificationsClient.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n GetNotificationsOptions,\n GetNotificationsResponse,\n NotificationsApi,\n UpdateNotificationsOptions,\n} from './NotificationsApi';\nimport { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';\nimport { ResponseError } from '@backstage/errors';\nimport {\n Notification,\n NotificationStatus,\n} from '@backstage/plugin-notifications-common';\n\n/** @public */\nexport class NotificationsClient implements NotificationsApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n public constructor(options: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n }\n\n async getNotifications(\n options?: GetNotificationsOptions,\n ): Promise<GetNotificationsResponse> {\n const queryString = new URLSearchParams();\n if (options?.limit !== undefined) {\n queryString.append('limit', options.limit.toString(10));\n }\n if (options?.offset !== undefined) {\n queryString.append('offset', options.offset.toString(10));\n }\n if (options?.sort !== undefined) {\n queryString.append(\n 'orderField',\n `${options.sort},${options?.sortOrder ?? 'desc'}`,\n );\n }\n if (options?.search) {\n queryString.append('search', options.search);\n }\n if (options?.read !== undefined) {\n queryString.append('read', options.read ? 'true' : 'false');\n }\n if (options?.saved !== undefined) {\n queryString.append('saved', options.saved ? 'true' : 'false');\n }\n if (options?.createdAfter !== undefined) {\n queryString.append('createdAfter', options.createdAfter.toISOString());\n }\n if (options?.minimumSeverity !== undefined) {\n queryString.append('minimumSeverity', options.minimumSeverity);\n }\n const urlSegment = `?${queryString}`;\n\n return await this.request<GetNotificationsResponse>(urlSegment);\n }\n\n async getNotification(id: string): Promise<Notification> {\n return await this.request<Notification>(`${id}`);\n }\n\n async getStatus(): Promise<NotificationStatus> {\n return await this.request<NotificationStatus>('status');\n }\n\n async updateNotifications(\n options: UpdateNotificationsOptions,\n ): Promise<Notification[]> {\n return await this.request<Notification[]>('update', {\n method: 'POST',\n body: JSON.stringify(options),\n headers: { 'Content-Type': 'application/json' },\n });\n }\n\n private async request<T>(path: string, init?: any): Promise<T> {\n const baseUrl = `${await this.discoveryApi.getBaseUrl('notifications')}/`;\n const url = new URL(path, baseUrl);\n\n const response = await this.fetchApi.fetch(url.toString(), init);\n\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return response.json() as Promise<T>;\n }\n}\n"],"names":[],"mappings":";;;;;;;;AA6BO,MAAM,mBAAgD,CAAA;AAAA,EAIpD,YAAY,OAGhB,EAAA;AANH,IAAiB,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AAMf,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA,CAAA;AAC5B,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA,CAAA;AAAA,GAC1B;AAAA,EAEA,MAAM,iBACJ,OACmC,EAAA;AA3CvC,IAAA,IAAA,EAAA,CAAA;AA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AEA,MAAc,OAAW,CAAA,IAAA,EAAc,IAAwB,EAAA;AAC7D,IAAA,MAAM,UAAU,CAAG,EAAA,MAAM,KAAK,YAAa,CAAA,UAAA,CAAW,eAAe,CAAC,CAAA,CAAA,CAAA,CAAA;AACtE,IAAA,MAAM,GAAM,GAAA,IAAI,GAAI,CAAA,IAAA,EAAM,OAAO,CAAA,CAAA;AAEjC,IAAM,MAAA,QAAA,GAAW,MAAM,IAAK,CAAA,QAAA,CAAS,MAAM,GAAI,CAAA,QAAA,IAAY,IAAI,CAAA,CAAA;AAE/D,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAM,MAAA,MAAM,aAAc,CAAA,YAAA,CAAa,QAAQ,CAAA,CAAA;AAAA,KACjD;AAEA,IAAA,OAAO,SAAS,IAAK,EAAA,CAAA;AAAA,GACvB;AACF;;;;"}
@@ -1,34 +1,11 @@
1
- import React, { useEffect } from 'react';
2
- import throttle from 'lodash/throttle';
3
- import { ResponseErrorPanel, PageWithHeader, Content } from '@backstage/core-components';
4
- import Grid from '@material-ui/core/Grid';
5
- import { useSignal } from '@backstage/plugin-signals-react';
6
- import { useNotificationsApi, NotificationsTable } from '../index.esm.js';
1
+ import React from 'react';
7
2
  import Divider from '@material-ui/core/Divider';
8
3
  import FormControl from '@material-ui/core/FormControl';
4
+ import Grid from '@material-ui/core/Grid';
9
5
  import InputLabel from '@material-ui/core/InputLabel';
10
6
  import MenuItem from '@material-ui/core/MenuItem';
11
7
  import Select from '@material-ui/core/Select';
12
8
  import Typography from '@material-ui/core/Typography';
13
- import '@backstage/core-plugin-api';
14
- import '@backstage/errors';
15
- import 'react-use/esm/useAsyncRetry';
16
- import '@material-ui/icons/Notifications';
17
- import 'react-relative-time';
18
- import '@material-ui/core/Box';
19
- import '@material-ui/core/Checkbox';
20
- import '@material-ui/icons/CheckOutlined';
21
- import '@material-ui/icons/ErrorOutline';
22
- import '@material-ui/icons/WarningOutlined';
23
- import '@material-ui/icons/InfoOutlined';
24
- import '@material-ui/core/styles';
25
- import '@material-ui/core/FormControlLabel';
26
- import '@material-ui/core/IconButton';
27
- import '@material-ui/core/Tooltip';
28
- import '@material-ui/icons/Markunread';
29
- import '@material-ui/icons/CheckCircle';
30
- import '@material-ui/icons/LabelOff';
31
- import '@material-ui/icons/Label';
32
9
 
33
10
  const CreatedAfterOptions = {
34
11
  last24h: {
@@ -184,102 +161,5 @@ const NotificationsFilters = ({
184
161
  )))));
185
162
  };
186
163
 
187
- const ThrottleDelayMs = 2e3;
188
- const NotificationsPage = () => {
189
- const [refresh, setRefresh] = React.useState(false);
190
- const { lastSignal } = useSignal("notifications");
191
- const [unreadOnly, setUnreadOnly] = React.useState(true);
192
- const [saved, setSaved] = React.useState(void 0);
193
- const [pageNumber, setPageNumber] = React.useState(0);
194
- const [pageSize, setPageSize] = React.useState(5);
195
- const [containsText, setContainsText] = React.useState();
196
- const [createdAfter, setCreatedAfter] = React.useState("lastWeek");
197
- const [sorting, setSorting] = React.useState(
198
- SortByOptions.newest.sortBy
199
- );
200
- const [severity, setSeverity] = React.useState("low");
201
- const { error, value, retry, loading } = useNotificationsApi(
202
- (api) => {
203
- const options = {
204
- search: containsText,
205
- limit: pageSize,
206
- offset: pageNumber * pageSize,
207
- minimumSeverity: severity,
208
- ...sorting || {}
209
- };
210
- if (unreadOnly !== void 0) {
211
- options.read = !unreadOnly;
212
- }
213
- if (saved !== void 0) {
214
- options.saved = saved;
215
- }
216
- const createdAfterDate = CreatedAfterOptions[createdAfter].getDate();
217
- if (createdAfterDate.valueOf() > 0) {
218
- options.createdAfter = createdAfterDate;
219
- }
220
- return api.getNotifications(options);
221
- },
222
- [
223
- containsText,
224
- unreadOnly,
225
- createdAfter,
226
- pageNumber,
227
- pageSize,
228
- sorting,
229
- saved,
230
- severity
231
- ]
232
- );
233
- const throttledSetRefresh = React.useMemo(
234
- () => throttle(setRefresh, ThrottleDelayMs),
235
- [setRefresh]
236
- );
237
- useEffect(() => {
238
- if (refresh && !loading) {
239
- retry();
240
- setRefresh(false);
241
- }
242
- }, [refresh, setRefresh, retry, loading]);
243
- useEffect(() => {
244
- if (lastSignal && lastSignal.action) {
245
- throttledSetRefresh(true);
246
- }
247
- }, [lastSignal, throttledSetRefresh]);
248
- const onUpdate = () => {
249
- throttledSetRefresh(true);
250
- };
251
- if (error) {
252
- return /* @__PURE__ */ React.createElement(ResponseErrorPanel, { error });
253
- }
254
- return /* @__PURE__ */ React.createElement(PageWithHeader, { title: "Notifications", themeId: "tool" }, /* @__PURE__ */ React.createElement(Content, null, /* @__PURE__ */ React.createElement(Grid, { container: true }, /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 2 }, /* @__PURE__ */ React.createElement(
255
- NotificationsFilters,
256
- {
257
- unreadOnly,
258
- onUnreadOnlyChanged: setUnreadOnly,
259
- createdAfter,
260
- onCreatedAfterChanged: setCreatedAfter,
261
- onSortingChanged: setSorting,
262
- sorting,
263
- saved,
264
- onSavedChanged: setSaved,
265
- severity,
266
- onSeverityChanged: setSeverity
267
- }
268
- )), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 10 }, /* @__PURE__ */ React.createElement(
269
- NotificationsTable,
270
- {
271
- isLoading: loading,
272
- notifications: value == null ? void 0 : value.notifications,
273
- onUpdate,
274
- setContainsText,
275
- onPageChange: setPageNumber,
276
- onRowsPerPageChange: setPageSize,
277
- page: pageNumber,
278
- pageSize,
279
- totalCount: value == null ? void 0 : value.totalCount
280
- }
281
- )))));
282
- };
283
-
284
- export { NotificationsPage };
285
- //# sourceMappingURL=index-D44DlZtS.esm.js.map
164
+ export { CreatedAfterOptions, NotificationsFilters, SortByOptions };
165
+ //# sourceMappingURL=NotificationsFilters.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationsFilters.esm.js","sources":["../../../src/components/NotificationsFilters/NotificationsFilters.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport Divider from '@material-ui/core/Divider';\nimport FormControl from '@material-ui/core/FormControl';\nimport Grid from '@material-ui/core/Grid';\nimport InputLabel from '@material-ui/core/InputLabel';\nimport MenuItem from '@material-ui/core/MenuItem';\nimport Select from '@material-ui/core/Select';\nimport Typography from '@material-ui/core/Typography';\nimport { GetNotificationsOptions } from '../../api';\nimport { NotificationSeverity } from '@backstage/plugin-notifications-common';\n\nexport type SortBy = Required<\n Pick<GetNotificationsOptions, 'sort' | 'sortOrder'>\n>;\n\nexport type NotificationsFiltersProps = {\n unreadOnly?: boolean;\n onUnreadOnlyChanged: (checked: boolean | undefined) => void;\n createdAfter?: string;\n onCreatedAfterChanged: (value: string) => void;\n sorting: SortBy;\n onSortingChanged: (sortBy: SortBy) => void;\n saved?: boolean;\n onSavedChanged: (checked: boolean | undefined) => void;\n severity: NotificationSeverity;\n onSeverityChanged: (severity: NotificationSeverity) => void;\n};\n\nexport const CreatedAfterOptions: {\n [key: string]: { label: string; getDate: () => Date };\n} = {\n last24h: {\n label: 'Last 24h',\n getDate: () => new Date(Date.now() - 24 * 3600 * 1000),\n },\n lastWeek: {\n label: 'Last week',\n getDate: () => new Date(Date.now() - 7 * 24 * 3600 * 1000),\n },\n all: {\n label: 'Any time',\n getDate: () => new Date(0),\n },\n};\n\nexport const SortByOptions: {\n [key: string]: {\n label: string;\n sortBy: SortBy;\n };\n} = {\n newest: {\n label: 'Newest on top',\n sortBy: {\n sort: 'created',\n sortOrder: 'desc',\n },\n },\n oldest: {\n label: 'Oldest on top',\n sortBy: {\n sort: 'created',\n sortOrder: 'asc',\n },\n },\n topic: {\n label: 'Topic',\n sortBy: {\n sort: 'topic',\n sortOrder: 'asc',\n },\n },\n origin: {\n label: 'Origin',\n sortBy: {\n sort: 'origin',\n sortOrder: 'asc',\n },\n },\n};\n\nconst getSortByText = (sortBy?: SortBy): string => {\n if (sortBy?.sort === 'created' && sortBy?.sortOrder === 'asc') {\n return 'oldest';\n }\n if (sortBy?.sort === 'topic') {\n return 'topic';\n }\n if (sortBy?.sort === 'origin') {\n return 'origin';\n }\n\n return 'newest';\n};\n\nconst AllSeverityOptions: { [key in NotificationSeverity]: string } = {\n critical: 'Critical',\n high: 'High',\n normal: 'Normal',\n low: 'Low',\n};\n\nexport const NotificationsFilters = ({\n sorting,\n onSortingChanged,\n unreadOnly,\n onUnreadOnlyChanged,\n createdAfter,\n onCreatedAfterChanged,\n saved,\n onSavedChanged,\n severity,\n onSeverityChanged,\n}: NotificationsFiltersProps) => {\n const sortByText = getSortByText(sorting);\n\n const handleOnCreatedAfterChanged = (\n event: React.ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n onCreatedAfterChanged(event.target.value as string);\n };\n\n const handleOnViewChanged = (\n event: React.ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n if (event.target.value === 'unread') {\n onUnreadOnlyChanged(true);\n onSavedChanged(undefined);\n } else if (event.target.value === 'read') {\n onUnreadOnlyChanged(false);\n onSavedChanged(undefined);\n } else if (event.target.value === 'saved') {\n onUnreadOnlyChanged(undefined);\n onSavedChanged(true);\n } else {\n // All\n onUnreadOnlyChanged(undefined);\n onSavedChanged(undefined);\n }\n };\n\n const handleOnSortByChanged = (\n event: React.ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const idx = (event.target.value as string) || 'newest';\n const option = SortByOptions[idx];\n onSortingChanged({ ...option.sortBy });\n };\n\n let viewValue = 'all';\n if (saved) {\n viewValue = 'saved';\n } else if (unreadOnly) {\n viewValue = 'unread';\n } else if (unreadOnly === false) {\n viewValue = 'read';\n }\n\n const handleOnSeverityChanged = (\n event: React.ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const value: NotificationSeverity =\n (event.target.value as NotificationSeverity) || 'normal';\n onSeverityChanged(value);\n };\n\n return (\n <>\n <Grid container>\n <Grid item xs={12}>\n <Typography variant=\"h6\">Filters</Typography>\n <Divider variant=\"fullWidth\" />\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-view\">View</InputLabel>\n <Select\n labelId=\"notifications-filter-view\"\n label=\"View\"\n value={viewValue}\n onChange={handleOnViewChanged}\n >\n <MenuItem value=\"unread\">New only</MenuItem>\n <MenuItem value=\"saved\">Saved</MenuItem>\n <MenuItem value=\"read\">Marked as read</MenuItem>\n <MenuItem value=\"all\">All</MenuItem>\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-created\">\n Created after\n </InputLabel>\n\n <Select\n label=\"Created after\"\n labelId=\"notifications-filter-created\"\n placeholder=\"Notifications since\"\n value={createdAfter}\n onChange={handleOnCreatedAfterChanged}\n >\n {Object.keys(CreatedAfterOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {CreatedAfterOptions[key].label}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-sort\">Sort by</InputLabel>\n\n <Select\n label=\"Sort by\"\n labelId=\"notifications-filter-sort\"\n placeholder=\"Field to sort by\"\n value={sortByText}\n onChange={handleOnSortByChanged}\n >\n {Object.keys(SortByOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {SortByOptions[key].label}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-severity\">Severity</InputLabel>\n\n <Select\n label=\"Severity\"\n labelId=\"notifications-filter-severity\"\n value={severity}\n onChange={handleOnSeverityChanged}\n >\n {Object.keys(AllSeverityOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {AllSeverityOptions[key as NotificationSeverity]}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AA4CO,MAAM,mBAET,GAAA;AAAA,EACF,OAAS,EAAA;AAAA,IACP,KAAO,EAAA,UAAA;AAAA,IACP,OAAA,EAAS,MAAM,IAAI,IAAA,CAAK,KAAK,GAAI,EAAA,GAAI,EAAK,GAAA,IAAA,GAAO,GAAI,CAAA;AAAA,GACvD;AAAA,EACA,QAAU,EAAA;AAAA,IACR,KAAO,EAAA,WAAA;AAAA,IACP,OAAA,EAAS,MAAM,IAAI,IAAK,CAAA,IAAA,CAAK,KAAQ,GAAA,CAAA,GAAI,EAAK,GAAA,IAAA,GAAO,GAAI,CAAA;AAAA,GAC3D;AAAA,EACA,GAAK,EAAA;AAAA,IACH,KAAO,EAAA,UAAA;AAAA,IACP,OAAS,EAAA,sBAAU,IAAA,IAAA,CAAK,CAAC,CAAA;AAAA,GAC3B;AACF,EAAA;AAEO,MAAM,aAKT,GAAA;AAAA,EACF,MAAQ,EAAA;AAAA,IACN,KAAO,EAAA,eAAA;AAAA,IACP,MAAQ,EAAA;AAAA,MACN,IAAM,EAAA,SAAA;AAAA,MACN,SAAW,EAAA,MAAA;AAAA,KACb;AAAA,GACF;AAAA,EACA,MAAQ,EAAA;AAAA,IACN,KAAO,EAAA,eAAA;AAAA,IACP,MAAQ,EAAA;AAAA,MACN,IAAM,EAAA,SAAA;AAAA,MACN,SAAW,EAAA,KAAA;AAAA,KACb;AAAA,GACF;AAAA,EACA,KAAO,EAAA;AAAA,IACL,KAAO,EAAA,OAAA;AAAA,IACP,MAAQ,EAAA;AAAA,MACN,IAAM,EAAA,OAAA;AAAA,MACN,SAAW,EAAA,KAAA;AAAA,KACb;AAAA,GACF;AAA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AA,MACC,KAAM,EAAA,SAAA;AAAA,MACN,OAAQ,EAAA,2BAAA;AAAA,MACR,WAAY,EAAA,kBAAA;AAAA,MACZ,KAAO,EAAA,UAAA;AAAA,MACP,QAAU,EAAA,qBAAA;AAAA,KAAA;AAAA,IAET,OAAO,IAAK,CAAA,aAAa,CAAE,CAAA,GAAA,CAAI,CAAC,GAC/B,qBAAA,KAAA,CAAA,aAAA,CAAC,QAAS,EAAA,EAAA,KAAA,EAAO,KAAK,GACnB,EAAA,EAAA,aAAA,CAAc,GAAG,CAAA,CAAE,KACtB,CACD,CAAA;AAAA,GAEL,CACF,CAEA,kBAAA,KAAA,CAAA,aAAA,CAAC,QAAK,IAAI,EAAA,IAAA,EAAC,EAAI,EAAA,EAAA,EAAA,kBACZ,KAAA,CAAA,aAAA,CAAA,WAAA,EAAA,EAAY,WAAS,IAAC,EAAA,OAAA,EAAQ,YAAW,IAAK,EAAA,OAAA,EAAA,sCAC5C,UAAW,EAAA,EAAA,EAAA,EAAG,+BAAgC,EAAA,EAAA,UAAQ,CAEvD,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACC,KAAM,EAAA,UAAA;AAAA,MACN,OAAQ,EAAA,+BAAA;AAAA,MACR,KAAO,EAAA,QAAA;AAAA,MACP,QAAU,EAAA,uBAAA;AAAA,KAAA;AAAA,IAET,MAAO,CAAA,IAAA,CAAK,kBAAkB,CAAA,CAAE,IAAI,CAAC,GAAA,qBACnC,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,EAAS,OAAO,GAAK,EAAA,GAAA,EAAA,EACnB,kBAAmB,CAAA,GAA2B,CACjD,CACD,CAAA;AAAA,GAEL,CACF,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
@@ -0,0 +1,138 @@
1
+ import React, { useEffect } from 'react';
2
+ import throttle from 'lodash/throttle';
3
+ import { ResponseErrorPanel, PageWithHeader, Content } from '@backstage/core-components';
4
+ import Grid from '@material-ui/core/Grid';
5
+ import { ConfirmProvider } from 'material-ui-confirm';
6
+ import { useSignal } from '@backstage/plugin-signals-react';
7
+ import { NotificationsTable } from '../NotificationsTable/NotificationsTable.esm.js';
8
+ import { useNotificationsApi } from '../../hooks/useNotificationsApi.esm.js';
9
+ import '../../routes.esm.js';
10
+ import '@backstage/core-plugin-api';
11
+ import 'react-router-dom';
12
+ import { SortByOptions, NotificationsFilters, CreatedAfterOptions } from '../NotificationsFilters/NotificationsFilters.esm.js';
13
+
14
+ const ThrottleDelayMs = 2e3;
15
+ const NotificationsPage = (props) => {
16
+ var _a, _b, _c;
17
+ const {
18
+ title = "Notifications",
19
+ themeId = "tool",
20
+ subtitle,
21
+ tooltip,
22
+ type,
23
+ typeLink,
24
+ markAsReadOnLinkOpen
25
+ } = props != null ? props : {};
26
+ const [refresh, setRefresh] = React.useState(false);
27
+ const { lastSignal } = useSignal("notifications");
28
+ const [unreadOnly, setUnreadOnly] = React.useState(true);
29
+ const [saved, setSaved] = React.useState(void 0);
30
+ const [pageNumber, setPageNumber] = React.useState(0);
31
+ const [pageSize, setPageSize] = React.useState(5);
32
+ const [containsText, setContainsText] = React.useState();
33
+ const [createdAfter, setCreatedAfter] = React.useState("lastWeek");
34
+ const [sorting, setSorting] = React.useState(
35
+ SortByOptions.newest.sortBy
36
+ );
37
+ const [severity, setSeverity] = React.useState("low");
38
+ const { error, value, retry, loading } = useNotificationsApi(
39
+ (api) => {
40
+ const options = {
41
+ search: containsText,
42
+ limit: pageSize,
43
+ offset: pageNumber * pageSize,
44
+ minimumSeverity: severity,
45
+ ...sorting || {}
46
+ };
47
+ if (unreadOnly !== void 0) {
48
+ options.read = !unreadOnly;
49
+ }
50
+ if (saved !== void 0) {
51
+ options.saved = saved;
52
+ }
53
+ const createdAfterDate = CreatedAfterOptions[createdAfter].getDate();
54
+ if (createdAfterDate.valueOf() > 0) {
55
+ options.createdAfter = createdAfterDate;
56
+ }
57
+ return Promise.all([api.getNotifications(options), api.getStatus()]);
58
+ },
59
+ [
60
+ containsText,
61
+ unreadOnly,
62
+ createdAfter,
63
+ pageNumber,
64
+ pageSize,
65
+ sorting,
66
+ saved,
67
+ severity
68
+ ]
69
+ );
70
+ const throttledSetRefresh = React.useMemo(
71
+ () => throttle(setRefresh, ThrottleDelayMs),
72
+ [setRefresh]
73
+ );
74
+ useEffect(() => {
75
+ if (refresh && !loading) {
76
+ retry();
77
+ setRefresh(false);
78
+ }
79
+ }, [refresh, setRefresh, retry, loading]);
80
+ useEffect(() => {
81
+ if (lastSignal && lastSignal.action) {
82
+ throttledSetRefresh(true);
83
+ }
84
+ }, [lastSignal, throttledSetRefresh]);
85
+ const onUpdate = () => {
86
+ throttledSetRefresh(true);
87
+ };
88
+ if (error) {
89
+ return /* @__PURE__ */ React.createElement(ResponseErrorPanel, { error });
90
+ }
91
+ const notifications = (_a = value == null ? void 0 : value[0]) == null ? void 0 : _a.notifications;
92
+ const totalCount = (_b = value == null ? void 0 : value[0]) == null ? void 0 : _b.totalCount;
93
+ const isUnread = !!((_c = value == null ? void 0 : value[1]) == null ? void 0 : _c.unread);
94
+ return /* @__PURE__ */ React.createElement(
95
+ PageWithHeader,
96
+ {
97
+ title,
98
+ themeId,
99
+ tooltip,
100
+ subtitle,
101
+ type,
102
+ typeLink
103
+ },
104
+ /* @__PURE__ */ React.createElement(Content, null, /* @__PURE__ */ React.createElement(ConfirmProvider, null, /* @__PURE__ */ React.createElement(Grid, { container: true }, /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 2 }, /* @__PURE__ */ React.createElement(
105
+ NotificationsFilters,
106
+ {
107
+ unreadOnly,
108
+ onUnreadOnlyChanged: setUnreadOnly,
109
+ createdAfter,
110
+ onCreatedAfterChanged: setCreatedAfter,
111
+ onSortingChanged: setSorting,
112
+ sorting,
113
+ saved,
114
+ onSavedChanged: setSaved,
115
+ severity,
116
+ onSeverityChanged: setSeverity
117
+ }
118
+ )), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 10 }, /* @__PURE__ */ React.createElement(
119
+ NotificationsTable,
120
+ {
121
+ isLoading: loading,
122
+ isUnread,
123
+ markAsReadOnLinkOpen,
124
+ notifications,
125
+ onUpdate,
126
+ setContainsText,
127
+ onPageChange: setPageNumber,
128
+ onRowsPerPageChange: setPageSize,
129
+ page: pageNumber,
130
+ pageSize,
131
+ totalCount
132
+ }
133
+ )))))
134
+ );
135
+ };
136
+
137
+ export { NotificationsPage };
138
+ //# sourceMappingURL=NotificationsPage.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationsPage.esm.js","sources":["../../../src/components/NotificationsPage/NotificationsPage.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect } from 'react';\nimport throttle from 'lodash/throttle';\nimport {\n Content,\n PageWithHeader,\n ResponseErrorPanel,\n} from '@backstage/core-components';\nimport Grid from '@material-ui/core/Grid';\nimport { ConfirmProvider } from 'material-ui-confirm';\nimport { useSignal } from '@backstage/plugin-signals-react';\n\nimport { NotificationsTable } from '../NotificationsTable';\nimport { useNotificationsApi } from '../../hooks';\nimport {\n CreatedAfterOptions,\n NotificationsFilters,\n SortBy,\n SortByOptions,\n} from '../NotificationsFilters';\nimport { GetNotificationsOptions, GetNotificationsResponse } from '../../api';\nimport {\n NotificationSeverity,\n NotificationStatus,\n} from '@backstage/plugin-notifications-common';\n\nconst ThrottleDelayMs = 2000;\n\n/** @public */\nexport type NotificationsPageProps = {\n /** Mark notification as read when opening the link it contains, defaults to false */\n markAsReadOnLinkOpen?: boolean;\n title?: string;\n themeId?: string;\n subtitle?: string;\n tooltip?: string;\n type?: string;\n typeLink?: string;\n};\n\nexport const NotificationsPage = (props?: NotificationsPageProps) => {\n const {\n title = 'Notifications',\n themeId = 'tool',\n subtitle,\n tooltip,\n type,\n typeLink,\n markAsReadOnLinkOpen,\n } = props ?? {};\n\n const [refresh, setRefresh] = React.useState(false);\n const { lastSignal } = useSignal('notifications');\n const [unreadOnly, setUnreadOnly] = React.useState<boolean | undefined>(true);\n const [saved, setSaved] = React.useState<boolean | undefined>(undefined);\n const [pageNumber, setPageNumber] = React.useState(0);\n const [pageSize, setPageSize] = React.useState(5);\n const [containsText, setContainsText] = React.useState<string>();\n const [createdAfter, setCreatedAfter] = React.useState<string>('lastWeek');\n const [sorting, setSorting] = React.useState<SortBy>(\n SortByOptions.newest.sortBy,\n );\n const [severity, setSeverity] = React.useState<NotificationSeverity>('low');\n\n const { error, value, retry, loading } = useNotificationsApi<\n [GetNotificationsResponse, NotificationStatus]\n >(\n api => {\n const options: GetNotificationsOptions = {\n search: containsText,\n limit: pageSize,\n offset: pageNumber * pageSize,\n minimumSeverity: severity,\n ...(sorting || {}),\n };\n if (unreadOnly !== undefined) {\n options.read = !unreadOnly;\n }\n if (saved !== undefined) {\n options.saved = saved;\n }\n\n const createdAfterDate = CreatedAfterOptions[createdAfter].getDate();\n if (createdAfterDate.valueOf() > 0) {\n options.createdAfter = createdAfterDate;\n }\n\n return Promise.all([api.getNotifications(options), api.getStatus()]);\n },\n [\n containsText,\n unreadOnly,\n createdAfter,\n pageNumber,\n pageSize,\n sorting,\n saved,\n severity,\n ],\n );\n\n const throttledSetRefresh = React.useMemo(\n () => throttle(setRefresh, ThrottleDelayMs),\n [setRefresh],\n );\n\n useEffect(() => {\n if (refresh && !loading) {\n retry();\n setRefresh(false);\n }\n }, [refresh, setRefresh, retry, loading]);\n\n useEffect(() => {\n if (lastSignal && lastSignal.action) {\n throttledSetRefresh(true);\n }\n }, [lastSignal, throttledSetRefresh]);\n\n const onUpdate = () => {\n throttledSetRefresh(true);\n };\n\n if (error) {\n return <ResponseErrorPanel error={error} />;\n }\n\n const notifications = value?.[0]?.notifications;\n const totalCount = value?.[0]?.totalCount;\n const isUnread = !!value?.[1]?.unread;\n\n return (\n <PageWithHeader\n title={title}\n themeId={themeId}\n tooltip={tooltip}\n subtitle={subtitle}\n type={type}\n typeLink={typeLink}\n >\n <Content>\n <ConfirmProvider>\n <Grid container>\n <Grid item xs={2}>\n <NotificationsFilters\n unreadOnly={unreadOnly}\n onUnreadOnlyChanged={setUnreadOnly}\n createdAfter={createdAfter}\n onCreatedAfterChanged={setCreatedAfter}\n onSortingChanged={setSorting}\n sorting={sorting}\n saved={saved}\n onSavedChanged={setSaved}\n severity={severity}\n onSeverityChanged={setSeverity}\n />\n </Grid>\n <Grid item xs={10}>\n <NotificationsTable\n isLoading={loading}\n isUnread={isUnread}\n markAsReadOnLinkOpen={markAsReadOnLinkOpen}\n notifications={notifications}\n onUpdate={onUpdate}\n setContainsText={setContainsText}\n onPageChange={setPageNumber}\n onRowsPerPageChange={setPageSize}\n page={pageNumber}\n pageSize={pageSize}\n totalCount={totalCount}\n />\n </Grid>\n </Grid>\n </ConfirmProvider>\n </Content>\n </PageWithHeader>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAyCA,MAAM,eAAkB,GAAA,GAAA,CAAA;AAcX,MAAA,iBAAA,GAAoB,CAAC,KAAmC,KAAA;AAvDrE,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAwDE,EAAM,MAAA;AAAA,IACJ,KAAQ,GAAA,eAAA;AAAA,IACR,OAAU,GAAA,MAAA;AAAA,IACV,QAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,oBAAA;AAAA,GACF,GAAI,wBAAS,EAAC,CAAA;AAEd,EAAA,MAAM,CAAC,OAAS,EAAA,UAAU,CAAI,GAAA,KAAA,CAAM,SAAS,KAAK,CAAA,CAAA;AAClD,EAAA,MAAM,EA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AAA;AAAA,QACC,UAAA;AAAA,QACA,mBAAqB,EAAA,aAAA;AAAA,QACrB,YAAA;AAAA,QACA,qBAAuB,EAAA,eAAA;AAAA,QACvB,gBAAkB,EAAA,UAAA;AAAA,QAClB,OAAA;AAAA,QACA,KAAA;AAAA,QACA,cAAgB,EAAA,QAAA;AAAA,QAChB,QAAA;AAAA,QACA,iBAAmB,EAAA,WAAA;AAAA,OAAA;AAAA,KAEvB,CACA,kBAAA,KAAA,CAAA,aAAA,CAAC,QAAK,IAAI,EAAA,IAAA,EAAC,IAAI,EACb,EAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,kBAAA;AAAA,MAAA;AAAA,QACC,SAAW,EAAA,OAAA;AAAA,QACX,QAAA;AAAA,QACA,oBAAA;AAAA,QACA,aAAA;AAAA,QACA,QAAA;AAAA,QACA,eAAA;AAAA,QACA,YAAc,EAAA,aAAA;AAAA,QACd,mBAAqB,EAAA,WAAA;AAAA,QACrB,IAAM,EAAA,UAAA;AAAA,QACN,QAAA;AAAA,QACA,UAAA;AAAA,OAAA;AAAA,KAEJ,CACF,CACF,CACF,CAAA;AAAA,GACF,CAAA;AAEJ;;;;"}
@@ -0,0 +1,2 @@
1
+ export { NotificationsPage } from './NotificationsPage.esm.js';
2
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}