@backstage/plugin-notifications 0.2.0-next.1 → 0.2.1-next.0

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 +40 -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-ijQzv-25.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 +130 -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 +88 -0
  13. package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js.map +1 -0
  14. package/dist/components/NotificationsTable/BulkActions.esm.js +52 -0
  15. package/dist/components/NotificationsTable/BulkActions.esm.js.map +1 -0
  16. package/dist/components/NotificationsTable/NotificationsTable.esm.js +177 -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 +20 -4
  29. package/dist/index.esm.js +8 -509
  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 +12 -11
  36. package/dist/esm/index-ijQzv-25.esm.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @backstage/plugin-notifications
2
2
 
3
+ ## 0.2.1-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - e6bf85f: Allow overriding `NotificationsPage` page properties
8
+ - a42a19b: Empty descriptions are not rendered to improve the look&feel.
9
+ - 1bc3b86: Fix to show web notifications even when browser is on foreground. Fix duplicate notifications with multiple tabs.
10
+ - f793112: Allow defining `className` and additional properties for `NotificationsSideBarItem`
11
+ - e1c7d6e: Fix infinite loop in the notification title counter
12
+ - fcda449: The rendered size of a notification is limited for very long descriptions.
13
+ - Updated dependencies
14
+ - @backstage/theme@0.5.4-next.0
15
+ - @backstage/core-components@0.14.5-next.0
16
+ - @backstage/core-plugin-api@1.9.2
17
+ - @backstage/errors@1.2.4
18
+ - @backstage/types@1.1.1
19
+ - @backstage/plugin-notifications-common@0.0.3
20
+ - @backstage/plugin-signals-react@0.0.3
21
+
22
+ ## 0.2.0
23
+
24
+ ### Minor Changes
25
+
26
+ - 939b4ec: Notifications-backend URL query parameter changed from `minimal_severity` to `minimumSeverity`.
27
+ - ec40998: On the Notifications page, the user can trigger "Save" or "Mark as read" actions once for multiple selected notifications.
28
+
29
+ ### Patch Changes
30
+
31
+ - abfbcfc: Updated dependency `@testing-library/react` to `^15.0.0`.
32
+ - 9a41a7b: Migrate signals and notifications to the new backend in local development
33
+ - 939b4ec: The severity icons now get their colors from the theme.
34
+ - Updated dependencies
35
+ - @backstage/plugin-notifications-common@0.0.3
36
+ - @backstage/core-components@0.14.4
37
+ - @backstage/core-plugin-api@1.9.2
38
+ - @backstage/theme@0.5.3
39
+ - @backstage/plugin-signals-react@0.0.3
40
+ - @backstage/errors@1.2.4
41
+ - @backstage/types@1.1.1
42
+
3
43
  ## 0.2.0-next.1
4
44
 
5
45
  ### 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;A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A;AAAA,GACxD;AAAA,EAEA,MAAM,oBACJ,OACyB,EAAA;AACzB,IAAO,OAAA,MAAM,IAAK,CAAA,OAAA,CAAwB,QAAU,EAAA;AAAA,MAClD,MAAQ,EAAA,MAAA;AAAA,MACR,IAAA,EAAM,IAAK,CAAA,SAAA,CAAU,OAAO,CAAA;AAAA,MAC5B,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAmB,EAAA;AAAA,KAC/C,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,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/FormControlLabel';
25
- import '@material-ui/core/styles';
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-ijQzv-25.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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AA,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,130 @@
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 { NotificationsTable } from '../NotificationsTable/NotificationsTable.esm.js';
7
+ import { useNotificationsApi } from '../../hooks/useNotificationsApi.esm.js';
8
+ import '../../routes.esm.js';
9
+ import '@backstage/core-plugin-api';
10
+ import 'react-router-dom';
11
+ import { SortByOptions, NotificationsFilters, CreatedAfterOptions } from '../NotificationsFilters/NotificationsFilters.esm.js';
12
+
13
+ const ThrottleDelayMs = 2e3;
14
+ const NotificationsPage = (props) => {
15
+ const {
16
+ title = "Notifications",
17
+ themeId = "tool",
18
+ subtitle,
19
+ tooltip,
20
+ type,
21
+ typeLink
22
+ } = props != null ? props : {};
23
+ const [refresh, setRefresh] = React.useState(false);
24
+ const { lastSignal } = useSignal("notifications");
25
+ const [unreadOnly, setUnreadOnly] = React.useState(true);
26
+ const [saved, setSaved] = React.useState(void 0);
27
+ const [pageNumber, setPageNumber] = React.useState(0);
28
+ const [pageSize, setPageSize] = React.useState(5);
29
+ const [containsText, setContainsText] = React.useState();
30
+ const [createdAfter, setCreatedAfter] = React.useState("lastWeek");
31
+ const [sorting, setSorting] = React.useState(
32
+ SortByOptions.newest.sortBy
33
+ );
34
+ const [severity, setSeverity] = React.useState("low");
35
+ const { error, value, retry, loading } = useNotificationsApi(
36
+ (api) => {
37
+ const options = {
38
+ search: containsText,
39
+ limit: pageSize,
40
+ offset: pageNumber * pageSize,
41
+ minimumSeverity: severity,
42
+ ...sorting || {}
43
+ };
44
+ if (unreadOnly !== void 0) {
45
+ options.read = !unreadOnly;
46
+ }
47
+ if (saved !== void 0) {
48
+ options.saved = saved;
49
+ }
50
+ const createdAfterDate = CreatedAfterOptions[createdAfter].getDate();
51
+ if (createdAfterDate.valueOf() > 0) {
52
+ options.createdAfter = createdAfterDate;
53
+ }
54
+ return api.getNotifications(options);
55
+ },
56
+ [
57
+ containsText,
58
+ unreadOnly,
59
+ createdAfter,
60
+ pageNumber,
61
+ pageSize,
62
+ sorting,
63
+ saved,
64
+ severity
65
+ ]
66
+ );
67
+ const throttledSetRefresh = React.useMemo(
68
+ () => throttle(setRefresh, ThrottleDelayMs),
69
+ [setRefresh]
70
+ );
71
+ useEffect(() => {
72
+ if (refresh && !loading) {
73
+ retry();
74
+ setRefresh(false);
75
+ }
76
+ }, [refresh, setRefresh, retry, loading]);
77
+ useEffect(() => {
78
+ if (lastSignal && lastSignal.action) {
79
+ throttledSetRefresh(true);
80
+ }
81
+ }, [lastSignal, throttledSetRefresh]);
82
+ const onUpdate = () => {
83
+ throttledSetRefresh(true);
84
+ };
85
+ if (error) {
86
+ return /* @__PURE__ */ React.createElement(ResponseErrorPanel, { error });
87
+ }
88
+ return /* @__PURE__ */ React.createElement(
89
+ PageWithHeader,
90
+ {
91
+ title,
92
+ themeId,
93
+ tooltip,
94
+ subtitle,
95
+ type,
96
+ typeLink
97
+ },
98
+ /* @__PURE__ */ React.createElement(Content, null, /* @__PURE__ */ React.createElement(Grid, { container: true }, /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 2 }, /* @__PURE__ */ React.createElement(
99
+ NotificationsFilters,
100
+ {
101
+ unreadOnly,
102
+ onUnreadOnlyChanged: setUnreadOnly,
103
+ createdAfter,
104
+ onCreatedAfterChanged: setCreatedAfter,
105
+ onSortingChanged: setSorting,
106
+ sorting,
107
+ saved,
108
+ onSavedChanged: setSaved,
109
+ severity,
110
+ onSeverityChanged: setSeverity
111
+ }
112
+ )), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 10 }, /* @__PURE__ */ React.createElement(
113
+ NotificationsTable,
114
+ {
115
+ isLoading: loading,
116
+ notifications: value == null ? void 0 : value.notifications,
117
+ onUpdate,
118
+ setContainsText,
119
+ onPageChange: setPageNumber,
120
+ onRowsPerPageChange: setPageSize,
121
+ page: pageNumber,
122
+ pageSize,
123
+ totalCount: value == null ? void 0 : value.totalCount
124
+ }
125
+ ))))
126
+ );
127
+ };
128
+
129
+ export { NotificationsPage };
130
+ //# 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 { 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 } from '../../api';\nimport { NotificationSeverity } from '@backstage/plugin-notifications-common';\n\nconst ThrottleDelayMs = 2000;\n\n/** @public */\nexport type NotificationsPageProps = {\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 } = 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 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 api.getNotifications(options);\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 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 <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 notifications={value?.notifications}\n onUpdate={onUpdate}\n setContainsText={setContainsText}\n onPageChange={setPageNumber}\n onRowsPerPageChange={setPageSize}\n page={pageNumber}\n pageSize={pageSize}\n totalCount={value?.totalCount}\n />\n </Grid>\n </Grid>\n </Content>\n </PageWithHeader>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAqCA,MAAM,eAAkB,GAAA,GAAA,CAAA;AAYX,MAAA,iBAAA,GAAoB,CAAC,KAAmC,KAAA;AACnE,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,GACF,GAAI,wBAAS,EAAC,CAAA;AAEd,EAAA,MAAM,CAAC,OAAS,EAAA,UAAU,CAAI,GAAA,KAAA,CAAM,SAAS,KAAK,CAAA,CAAA;AAClD,EAAA,MAAM,EAAE,UAAA,EAAe,GAAA,SAAA,CAAU,eAAe,CAAA,CAAA;AAChD,EAAA,MAAM,CAAC,UAAY,EAAA,aAAa,CAAI,GAAA,KAAA,CAAM,SAA8B,IAAI,CAAA,CAAA;AAC5E,EAAA,MAAM,CAAC,KAAO,EAAA,QAAQ,CAAI,GAAA,KAAA,CAAM,SAA8B,KAAS,CAAA,CAAA,CAAA;AACvE,EAAA,MAAM,CAAC,UAAY,EAAA,aAAa,CAAI,GAAA,KAAA,CAAM,SAAS,CAAC,CAAA,CAAA;AACpD,EAAA,MAAM,CAAC,QAAU,EAAA,WAAW,CAAI,GAAA,KAAA,CA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AAA,SAAA,EAAS,IACb,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,IAAK,EAAA,EAAA,IAAA,EAAI,IAAC,EAAA,EAAA,EAAI,CACb,EAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,oBAAA;AAAA,MAAA;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,eAAe,KAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAA,aAAA;AAAA,QACtB,QAAA;AAAA,QACA,eAAA;AAAA,QACA,YAAc,EAAA,aAAA;AAAA,QACd,mBAAqB,EAAA,WAAA;AAAA,QACrB,IAAM,EAAA,UAAA;AAAA,QACN,QAAA;AAAA,QACA,YAAY,KAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAA,UAAA;AAAA,OAAA;AAAA,KAEvB,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":""}
@@ -0,0 +1,88 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useNotificationsApi } from '../../hooks/useNotificationsApi.esm.js';
3
+ import { useWebNotifications } from '../../hooks/useWebNotifications.esm.js';
4
+ import { useTitleCounter } from '../../hooks/useTitleCounter.esm.js';
5
+ import { SidebarItem } from '@backstage/core-components';
6
+ import NotificationsIcon from '@material-ui/icons/Notifications';
7
+ import { useApi, useRouteRef } from '@backstage/core-plugin-api';
8
+ import { rootRouteRef } from '../../routes.esm.js';
9
+ import { useSignal } from '@backstage/plugin-signals-react';
10
+ import { notificationsApiRef } from '../../api/NotificationsApi.esm.js';
11
+ import '@backstage/errors';
12
+
13
+ const NotificationsSidebarItem = (props) => {
14
+ const {
15
+ webNotificationsEnabled = false,
16
+ titleCounterEnabled = true,
17
+ icon = NotificationsIcon,
18
+ text = "Notifications",
19
+ ...restProps
20
+ } = props != null ? props : { webNotificationsEnabled: false, titleCounterEnabled: true };
21
+ const { loading, error, value, retry } = useNotificationsApi(
22
+ (api) => api.getStatus()
23
+ );
24
+ const notificationsApi = useApi(notificationsApiRef);
25
+ const [unreadCount, setUnreadCount] = React.useState(0);
26
+ const notificationsRoute = useRouteRef(rootRouteRef);
27
+ const { lastSignal } = useSignal("notifications");
28
+ const { sendWebNotification } = useWebNotifications(webNotificationsEnabled);
29
+ const [refresh, setRefresh] = React.useState(false);
30
+ const { setNotificationCount } = useTitleCounter();
31
+ useEffect(() => {
32
+ if (refresh) {
33
+ retry();
34
+ setRefresh(false);
35
+ }
36
+ }, [refresh, retry]);
37
+ useEffect(() => {
38
+ const handleWebNotification = (signal) => {
39
+ if (!webNotificationsEnabled || signal.action !== "new_notification") {
40
+ return;
41
+ }
42
+ notificationsApi.getNotification(signal.notification_id).then((notification) => {
43
+ var _a;
44
+ if (!notification) {
45
+ return;
46
+ }
47
+ sendWebNotification({
48
+ id: notification.id,
49
+ title: notification.payload.title,
50
+ description: (_a = notification.payload.description) != null ? _a : "",
51
+ link: notification.payload.link
52
+ });
53
+ });
54
+ };
55
+ if (lastSignal && lastSignal.action) {
56
+ handleWebNotification(lastSignal);
57
+ setRefresh(true);
58
+ }
59
+ }, [
60
+ lastSignal,
61
+ sendWebNotification,
62
+ webNotificationsEnabled,
63
+ notificationsApi
64
+ ]);
65
+ useEffect(() => {
66
+ if (!loading && !error && value) {
67
+ setUnreadCount(value.unread);
68
+ }
69
+ }, [loading, error, value]);
70
+ useEffect(() => {
71
+ if (titleCounterEnabled) {
72
+ setNotificationCount(unreadCount);
73
+ }
74
+ }, [titleCounterEnabled, unreadCount, setNotificationCount]);
75
+ return /* @__PURE__ */ React.createElement(
76
+ SidebarItem,
77
+ {
78
+ to: notificationsRoute(),
79
+ hasNotifications: !error && !!unreadCount,
80
+ text,
81
+ icon,
82
+ ...restProps
83
+ }
84
+ );
85
+ };
86
+
87
+ export { NotificationsSidebarItem };
88
+ //# sourceMappingURL=NotificationsSideBarItem.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationsSideBarItem.esm.js","sources":["../../../src/components/NotificationsSideBarItem/NotificationsSideBarItem.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 */\nimport React, { useEffect } from 'react';\nimport { useNotificationsApi } from '../../hooks';\nimport { SidebarItem } from '@backstage/core-components';\nimport NotificationsIcon from '@material-ui/icons/Notifications';\nimport { IconComponent, useApi, useRouteRef } from '@backstage/core-plugin-api';\nimport { rootRouteRef } from '../../routes';\nimport { useSignal } from '@backstage/plugin-signals-react';\nimport { NotificationSignal } from '@backstage/plugin-notifications-common';\nimport { useWebNotifications } from '../../hooks/useWebNotifications';\nimport { useTitleCounter } from '../../hooks/useTitleCounter';\nimport { notificationsApiRef } from '../../api';\n\n/** @public */\nexport const NotificationsSidebarItem = (props?: {\n webNotificationsEnabled?: boolean;\n titleCounterEnabled?: boolean;\n className?: string;\n icon?: IconComponent;\n text?: string;\n disableHighlight?: boolean;\n noTrack?: boolean;\n}) => {\n const {\n webNotificationsEnabled = false,\n titleCounterEnabled = true,\n icon = NotificationsIcon,\n text = 'Notifications',\n ...restProps\n } = props ?? { webNotificationsEnabled: false, titleCounterEnabled: true };\n\n const { loading, error, value, retry } = useNotificationsApi(api =>\n api.getStatus(),\n );\n const notificationsApi = useApi(notificationsApiRef);\n const [unreadCount, setUnreadCount] = React.useState(0);\n const notificationsRoute = useRouteRef(rootRouteRef);\n // TODO: Do we want to add long polling in case signals are not available\n const { lastSignal } = useSignal<NotificationSignal>('notifications');\n const { sendWebNotification } = useWebNotifications(webNotificationsEnabled);\n const [refresh, setRefresh] = React.useState(false);\n const { setNotificationCount } = useTitleCounter();\n\n useEffect(() => {\n if (refresh) {\n retry();\n setRefresh(false);\n }\n }, [refresh, retry]);\n\n useEffect(() => {\n const handleWebNotification = (signal: NotificationSignal) => {\n if (!webNotificationsEnabled || signal.action !== 'new_notification') {\n return;\n }\n\n notificationsApi\n .getNotification(signal.notification_id)\n .then(notification => {\n if (!notification) {\n return;\n }\n sendWebNotification({\n id: notification.id,\n title: notification.payload.title,\n description: notification.payload.description ?? '',\n link: notification.payload.link,\n });\n });\n };\n\n if (lastSignal && lastSignal.action) {\n handleWebNotification(lastSignal);\n setRefresh(true);\n }\n }, [\n lastSignal,\n sendWebNotification,\n webNotificationsEnabled,\n notificationsApi,\n ]);\n\n useEffect(() => {\n if (!loading && !error && value) {\n setUnreadCount(value.unread);\n }\n }, [loading, error, value]);\n\n useEffect(() => {\n if (titleCounterEnabled) {\n setNotificationCount(unreadCount);\n }\n }, [titleCounterEnabled, unreadCount, setNotificationCount]);\n\n // TODO: Figure out if the count can be added to hasNotifications\n return (\n <SidebarItem\n to={notificationsRoute()}\n hasNotifications={!error && !!unreadCount}\n text={text}\n icon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CAAU,MAAM;AACd,IAAA,IAAI,mBAAqB,EAAA;AACvB,MAAA,oBAAA,CAAqB,WAAW,CAAA,CAAA;AAAA,KAClC;AAAA,GACC,EAAA,CAAC,mBAAqB,EAAA,WAAA,EAAa,oBAAoB,CAAC,CAAA,CAAA;AAG3D,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,IAAI,kBAAmB,EAAA;AAAA,MACvB,gBAAkB,EAAA,CAAC,KAAS,IAAA,CAAC,CAAC,WAAA;AAAA,MAC9B,IAAA;AAAA,MACA,IAAA;AAAA,MACC,GAAG,SAAA;AAAA,KAAA;AAAA,GACN,CAAA;AAEJ;;;;"}
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import Grid from '@material-ui/core/Grid';
3
+ import IconButton from '@material-ui/core/IconButton';
4
+ import Tooltip from '@material-ui/core/Tooltip';
5
+ import MarkAsUnreadIcon from '@material-ui/icons/Markunread';
6
+ import MarkAsReadIcon from '@material-ui/icons/CheckCircle';
7
+ import MarkAsUnsavedIcon from '@material-ui/icons/LabelOff';
8
+ import MarkAsSavedIcon from '@material-ui/icons/Label';
9
+
10
+ const BulkActions = ({
11
+ selectedNotifications,
12
+ notifications,
13
+ onSwitchReadStatus,
14
+ onSwitchSavedStatus
15
+ }) => {
16
+ const isDisabled = selectedNotifications.size === 0;
17
+ const bulkNotifications = notifications.filter(
18
+ (notification) => selectedNotifications.has(notification.id)
19
+ );
20
+ const isOneRead = !!bulkNotifications.find(
21
+ (notification) => !!notification.read
22
+ );
23
+ const isOneSaved = !!bulkNotifications.find(
24
+ (notification) => !!notification.saved
25
+ );
26
+ const markAsReadText = isOneRead ? "Return selected among unread" : "Mark selected as read";
27
+ const IconComponent = isOneRead ? MarkAsUnreadIcon : MarkAsReadIcon;
28
+ const markAsSavedText = isOneSaved ? "Undo save for selected" : "Save selected for later";
29
+ const SavedIconComponent = isOneSaved ? MarkAsUnsavedIcon : MarkAsSavedIcon;
30
+ return /* @__PURE__ */ React.createElement(Grid, { container: true, wrap: "nowrap" }, /* @__PURE__ */ React.createElement(Grid, { item: true }, /* @__PURE__ */ React.createElement(Tooltip, { title: markAsSavedText }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
31
+ IconButton,
32
+ {
33
+ disabled: isDisabled,
34
+ onClick: () => {
35
+ onSwitchSavedStatus([...selectedNotifications], !isOneSaved);
36
+ }
37
+ },
38
+ /* @__PURE__ */ React.createElement(SavedIconComponent, { "aria-label": markAsSavedText })
39
+ )))), /* @__PURE__ */ React.createElement(Grid, { item: true }, /* @__PURE__ */ React.createElement(Tooltip, { title: markAsReadText }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
40
+ IconButton,
41
+ {
42
+ disabled: isDisabled,
43
+ onClick: () => {
44
+ onSwitchReadStatus([...selectedNotifications], !isOneRead);
45
+ }
46
+ },
47
+ /* @__PURE__ */ React.createElement(IconComponent, { "aria-label": markAsReadText })
48
+ )))));
49
+ };
50
+
51
+ export { BulkActions };
52
+ //# sourceMappingURL=BulkActions.esm.js.map