@backstage/plugin-notifications 0.2.4-next.0 → 0.3.0-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.
- package/CHANGELOG.md +18 -0
- package/README.md +2 -29
- package/dist/components/NotificationsPage/NotificationsPage.esm.js +3 -2
- package/dist/components/NotificationsPage/NotificationsPage.esm.js.map +1 -1
- package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js +21 -4
- package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js.map +1 -1
- package/dist/hooks/useTitleCounter.esm.js.map +1 -1
- package/dist/hooks/useWebNotifications.esm.js +14 -9
- package/dist/hooks/useWebNotifications.esm.js.map +1 -1
- package/dist/index.d.ts +8 -23
- package/dist/index.esm.js +4 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @backstage/plugin-notifications
|
|
2
2
|
|
|
3
|
+
## 0.3.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0410fc9: By default, set notification as read when opening snackbar or web notification link
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 80b84f7: Fixed issue with notification reloading on page change
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- @backstage/core-components@0.14.10-next.0
|
|
14
|
+
- @backstage/core-plugin-api@1.9.3
|
|
15
|
+
- @backstage/errors@1.2.4
|
|
16
|
+
- @backstage/theme@0.5.6
|
|
17
|
+
- @backstage/types@1.1.1
|
|
18
|
+
- @backstage/plugin-notifications-common@0.0.5
|
|
19
|
+
- @backstage/plugin-signals-react@0.0.4
|
|
20
|
+
|
|
3
21
|
## 0.2.4-next.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,38 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Welcome to the notifications plugin!
|
|
4
4
|
|
|
5
|
-
_This plugin was created through the Backstage CLI_
|
|
6
|
-
|
|
7
5
|
## Getting started
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
See the documentation for installation instructions.
|
|
11
|
-
|
|
12
|
-
To add the notifications main menu, add the following to your `packages/app/src/components/Root/Root.tsx`:
|
|
13
|
-
|
|
14
|
-
```tsx
|
|
15
|
-
import { NotificationsSidebarItem } from '@backstage/plugin-notifications';
|
|
16
|
-
|
|
17
|
-
<SidebarPage>
|
|
18
|
-
<Sidebar>
|
|
19
|
-
<SidebarGroup>
|
|
20
|
-
// ...
|
|
21
|
-
<NotificationsSidebarItem />
|
|
22
|
-
</SidebarGroup>
|
|
23
|
-
</Sidebar>
|
|
24
|
-
</SidebarPage>;
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Also add the route to notifications to `packages/app/src/App.tsx`:
|
|
28
|
-
|
|
29
|
-
```tsx
|
|
30
|
-
import { NotificationsPage } from '@backstage/plugin-notifications';
|
|
7
|
+
To install, please refer the [Getting Started](https://backstage.io/docs/notifications) Backstage Notifications and Signals documentation section.
|
|
31
8
|
|
|
32
|
-
|
|
33
|
-
// ...
|
|
34
|
-
<Route path="/notifications" element={<NotificationsPage />} />
|
|
35
|
-
</FlatRoutes>;
|
|
36
|
-
```
|
|
9
|
+
Please mind installing the `@backstage/plugin-notifications-backend` and `@backstage/plugin-notifications-node` packages before this frontend plugin.
|
|
37
10
|
|
|
38
11
|
## Real-time notifications
|
|
39
12
|
|
|
@@ -6,9 +6,10 @@ import { ConfirmProvider } from 'material-ui-confirm';
|
|
|
6
6
|
import { useSignal } from '@backstage/plugin-signals-react';
|
|
7
7
|
import { NotificationsTable } from '../NotificationsTable/NotificationsTable.esm.js';
|
|
8
8
|
import { useNotificationsApi } from '../../hooks/useNotificationsApi.esm.js';
|
|
9
|
-
import '../../routes.esm.js';
|
|
10
9
|
import '@backstage/core-plugin-api';
|
|
11
|
-
import '
|
|
10
|
+
import '../../api/NotificationsApi.esm.js';
|
|
11
|
+
import '@backstage/errors';
|
|
12
|
+
import '../../routes.esm.js';
|
|
12
13
|
import '../../hooks/useTitleCounter.esm.js';
|
|
13
14
|
import { SortByOptions, NotificationsFilters, CreatedAfterOptions } from '../NotificationsFilters/NotificationsFilters.esm.js';
|
|
14
15
|
|
|
@@ -1 +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>('all');\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":"
|
|
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>('all');\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,KAA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AA;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,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;;;;"}
|
|
@@ -57,9 +57,11 @@ const NotificationsSidebarItem = (props) => {
|
|
|
57
57
|
const notificationsApi = useApi(notificationsApiRef);
|
|
58
58
|
const alertApi = useApi(alertApiRef);
|
|
59
59
|
const [unreadCount, setUnreadCount] = React.useState(0);
|
|
60
|
-
const notificationsRoute = useRouteRef(rootRouteRef);
|
|
60
|
+
const notificationsRoute = useRouteRef(rootRouteRef)();
|
|
61
61
|
const { lastSignal } = useSignal("notifications");
|
|
62
|
-
const { sendWebNotification } = useWebNotifications(
|
|
62
|
+
const { sendWebNotification, requestUserPermission } = useWebNotifications(
|
|
63
|
+
webNotificationsEnabled
|
|
64
|
+
);
|
|
63
65
|
const [refresh, setRefresh] = React.useState(false);
|
|
64
66
|
const { setNotificationCount } = useTitleCounter();
|
|
65
67
|
const getSnackbarProperties = useCallback(
|
|
@@ -68,8 +70,19 @@ const NotificationsSidebarItem = (props) => {
|
|
|
68
70
|
IconButton,
|
|
69
71
|
{
|
|
70
72
|
component: Link,
|
|
71
|
-
to: notification.payload.link ?? notificationsRoute
|
|
73
|
+
to: notification.payload.link ?? notificationsRoute,
|
|
72
74
|
onClick: () => {
|
|
75
|
+
if (notification.payload.link) {
|
|
76
|
+
notificationsApi.updateNotifications({
|
|
77
|
+
ids: [notification.id],
|
|
78
|
+
read: true
|
|
79
|
+
}).catch(() => {
|
|
80
|
+
alertApi.post({
|
|
81
|
+
message: "Failed to mark notification as read",
|
|
82
|
+
severity: "error"
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
73
86
|
closeSnackbar(snackBarId);
|
|
74
87
|
}
|
|
75
88
|
},
|
|
@@ -124,6 +137,7 @@ const NotificationsSidebarItem = (props) => {
|
|
|
124
137
|
const { action } = getSnackbarProperties(notification);
|
|
125
138
|
const snackBarText = notification.payload.title.length > 50 ? `${notification.payload.title.substring(0, 50)}...` : notification.payload.title;
|
|
126
139
|
enqueueSnackbar(snackBarText, {
|
|
140
|
+
key: notification.id,
|
|
127
141
|
variant: notification.payload.severity,
|
|
128
142
|
anchorOrigin: { vertical: "bottom", horizontal: "right" },
|
|
129
143
|
action,
|
|
@@ -180,7 +194,10 @@ const NotificationsSidebarItem = (props) => {
|
|
|
180
194
|
), /* @__PURE__ */ React.createElement(
|
|
181
195
|
SidebarItem,
|
|
182
196
|
{
|
|
183
|
-
to: notificationsRoute
|
|
197
|
+
to: notificationsRoute,
|
|
198
|
+
onClick: () => {
|
|
199
|
+
requestUserPermission();
|
|
200
|
+
},
|
|
184
201
|
hasNotifications: !error && !!unreadCount,
|
|
185
202
|
text,
|
|
186
203
|
icon,
|
|
@@ -1 +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, { useCallback, useEffect } from 'react';\nimport { useNotificationsApi } from '../../hooks';\nimport { Link, SidebarItem } from '@backstage/core-components';\nimport NotificationsIcon from '@material-ui/icons/Notifications';\nimport {\n alertApiRef,\n IconComponent,\n useApi,\n useRouteRef,\n} from '@backstage/core-plugin-api';\nimport { rootRouteRef } from '../../routes';\nimport { useSignal } from '@backstage/plugin-signals-react';\nimport {\n Notification,\n NotificationSignal,\n} from '@backstage/plugin-notifications-common';\nimport { useWebNotifications } from '../../hooks/useWebNotifications';\nimport { useTitleCounter } from '../../hooks/useTitleCounter';\nimport { notificationsApiRef } from '../../api';\nimport {\n closeSnackbar,\n enqueueSnackbar,\n MaterialDesignContent,\n OptionsWithExtraProps,\n SnackbarKey,\n SnackbarProvider,\n VariantType,\n} from 'notistack';\nimport { SeverityIcon } from '../NotificationsTable/SeverityIcon';\nimport OpenInNew from '@material-ui/icons/OpenInNew';\nimport MarkAsReadIcon from '@material-ui/icons/CheckCircle';\nimport IconButton from '@material-ui/core/IconButton';\nimport { styled } from '@material-ui/core/styles';\n\nconst StyledMaterialDesignContent = styled(MaterialDesignContent)(\n ({ theme }) => ({\n '&.notistack-MuiContent-low': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n '&.notistack-MuiContent-normal': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n '&.notistack-MuiContent-high': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n '&.notistack-MuiContent-critical': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n }),\n);\n\ndeclare module 'notistack' {\n interface VariantOverrides {\n // Custom variants for the snackbar\n low: true;\n normal: true;\n high: true;\n critical: true;\n }\n}\n\n/** @public */\nexport const NotificationsSidebarItem = (props?: {\n webNotificationsEnabled?: boolean;\n titleCounterEnabled?: boolean;\n snackbarEnabled?: boolean;\n snackbarAutoHideDuration?: number | null;\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 snackbarEnabled = true,\n snackbarAutoHideDuration = 10000,\n icon = NotificationsIcon,\n text = 'Notifications',\n ...restProps\n } = props ?? {\n webNotificationsEnabled: false,\n titleCounterEnabled: true,\n snackbarEnabled: true,\n snackbarAutoHideDuration: 10000,\n };\n\n const { loading, error, value, retry } = useNotificationsApi(api =>\n api.getStatus(),\n );\n const notificationsApi = useApi(notificationsApiRef);\n const alertApi = useApi(alertApiRef);\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 const getSnackbarProperties = useCallback(\n (notification: Notification) => {\n const action = (snackBarId: SnackbarKey) => (\n <>\n <IconButton\n component={Link}\n to={notification.payload.link ?? notificationsRoute()}\n onClick={() => {\n closeSnackbar(snackBarId);\n }}\n >\n <OpenInNew fontSize=\"small\" />\n </IconButton>\n <IconButton\n onClick={() => {\n notificationsApi\n .updateNotifications({\n ids: [notification.id],\n read: true,\n })\n .then(() => {\n closeSnackbar(snackBarId);\n })\n .catch(() => {\n alertApi.post({\n message: 'Failed to mark notification as read',\n severity: 'error',\n });\n });\n }}\n >\n <MarkAsReadIcon fontSize=\"small\" />\n </IconButton>\n </>\n );\n\n return { action };\n },\n [notificationsRoute, notificationsApi, alertApi],\n );\n\n useEffect(() => {\n if (refresh) {\n retry();\n setRefresh(false);\n }\n }, [refresh, retry]);\n\n useEffect(() => {\n const handleNotificationSignal = (signal: NotificationSignal) => {\n if (\n (!webNotificationsEnabled && !snackbarEnabled) ||\n signal.action !== 'new_notification'\n ) {\n return;\n }\n\n notificationsApi\n .getNotification(signal.notification_id)\n .then(notification => {\n if (!notification) {\n return;\n }\n if (webNotificationsEnabled) {\n sendWebNotification({\n id: notification.id,\n title: notification.payload.title,\n description: notification.payload.description ?? '',\n link: notification.payload.link,\n });\n }\n if (snackbarEnabled) {\n const { action } = getSnackbarProperties(notification);\n const snackBarText =\n notification.payload.title.length > 50\n ? `${notification.payload.title.substring(0, 50)}...`\n : notification.payload.title;\n enqueueSnackbar(snackBarText, {\n variant: notification.payload.severity,\n anchorOrigin: { vertical: 'bottom', horizontal: 'right' },\n action,\n autoHideDuration: snackbarAutoHideDuration,\n } as OptionsWithExtraProps<VariantType>);\n }\n })\n .catch(() => {\n alertApi.post({\n message: 'Failed to fetch notification',\n severity: 'error',\n });\n });\n };\n\n if (lastSignal && lastSignal.action) {\n handleNotificationSignal(lastSignal);\n setRefresh(true);\n }\n }, [\n lastSignal,\n sendWebNotification,\n webNotificationsEnabled,\n snackbarEnabled,\n snackbarAutoHideDuration,\n notificationsApi,\n alertApi,\n getSnackbarProperties,\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 <>\n {snackbarEnabled && (\n <SnackbarProvider\n iconVariant={{\n normal: <SeverityIcon severity=\"normal\" />,\n critical: <SeverityIcon severity=\"critical\" />,\n high: <SeverityIcon severity=\"high\" />,\n low: <SeverityIcon severity=\"low\" />,\n }}\n Components={{\n normal: StyledMaterialDesignContent,\n critical: StyledMaterialDesignContent,\n high: StyledMaterialDesignContent,\n low: StyledMaterialDesignContent,\n }}\n />\n )}\n <SidebarItem\n to={notificationsRoute()}\n hasNotifications={!error && !!unreadCount}\n text={text}\n icon={icon}\n {...restProps}\n />\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAiDA,MAAM,2BAAA,GAA8B,OAAO,qBAAqB,CAAA;AAAA,EAC9D,CAAC,EAAE,KAAA,EAAa,MAAA;AAAA,IACd,4BAA8B,EAAA;AAAA,MAC5B,eAAA,EAAiB,KAAM,CAAA,OAAA,CAAQ,UAAW,CAAA,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,IAAK,CAAA,OAAA;AAAA,KAC5B;AAAA,IACA,+BAAiC,EAAA;AAAA,MAC/B,eAAA,EAAiB,KAAM,CAAA,OAAA,CAAQ,UAAW,CAAA,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,IAAK,CAAA,OAAA;AAAA,KAC5B;AAAA,IACA,6BAA+B,EAAA;AAAA,MAC7B,eAAA,EAAiB,KAAM,CAAA,OAAA,CAAQ,UAAW,CAAA,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,IAAK,CAAA,OAAA;AAAA,KAC5B;AAAA,IACA,iCAAmC,EAAA;AAAA,MACjC,eAAA,EAAiB,KAAM,CAAA,OAAA,CAAQ,UAAW,CAAA,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,IAAK,CAAA,OAAA;AAAA,KAC5B;AAAA,GACF,CAAA;AACF,CAAA,CAAA;AAaa,MAAA,wBAAA,GAA2B,CAAC,KAUnC,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,uBAA0B,GAAA,KAAA;AAAA,IAC1B,mBAAsB,GAAA,IAAA;AAAA,IACtB,eAAkB,GA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,EAAA,CAAA;AAAA,QAC5C,IAAM,kBAAA,KAAA,CAAA,aAAA,CAAC,YAAa,EAAA,EAAA,QAAA,EAAS,MAAO,EAAA,CAAA;AAAA,QACpC,GAAK,kBAAA,KAAA,CAAA,aAAA,CAAC,YAAa,EAAA,EAAA,QAAA,EAAS,KAAM,EAAA,CAAA;AAAA,OACpC;AAAA,MACA,UAAY,EAAA;AAAA,QACV,MAAQ,EAAA,2BAAA;AAAA,QACR,QAAU,EAAA,2BAAA;AAAA,QACV,IAAM,EAAA,2BAAA;AAAA,QACN,GAAK,EAAA,2BAAA;AAAA,OACP;AAAA,KAAA;AAAA,GAGJ,kBAAA,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,GAER,CAAA,CAAA;AAEJ;;;;"}
|
|
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, { useCallback, useEffect } from 'react';\nimport { useNotificationsApi } from '../../hooks';\nimport { Link, SidebarItem } from '@backstage/core-components';\nimport NotificationsIcon from '@material-ui/icons/Notifications';\nimport {\n alertApiRef,\n IconComponent,\n useApi,\n useRouteRef,\n} from '@backstage/core-plugin-api';\nimport { rootRouteRef } from '../../routes';\nimport { useSignal } from '@backstage/plugin-signals-react';\nimport {\n Notification,\n NotificationSignal,\n} from '@backstage/plugin-notifications-common';\nimport { useWebNotifications } from '../../hooks/useWebNotifications';\nimport { useTitleCounter } from '../../hooks/useTitleCounter';\nimport { notificationsApiRef } from '../../api';\nimport {\n closeSnackbar,\n enqueueSnackbar,\n MaterialDesignContent,\n OptionsWithExtraProps,\n SnackbarKey,\n SnackbarProvider,\n VariantType,\n} from 'notistack';\nimport { SeverityIcon } from '../NotificationsTable/SeverityIcon';\nimport OpenInNew from '@material-ui/icons/OpenInNew';\nimport MarkAsReadIcon from '@material-ui/icons/CheckCircle';\nimport IconButton from '@material-ui/core/IconButton';\nimport { styled } from '@material-ui/core/styles';\n\nconst StyledMaterialDesignContent = styled(MaterialDesignContent)(\n ({ theme }) => ({\n '&.notistack-MuiContent-low': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n '&.notistack-MuiContent-normal': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n '&.notistack-MuiContent-high': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n '&.notistack-MuiContent-critical': {\n backgroundColor: theme.palette.background.default,\n color: theme.palette.text.primary,\n },\n }),\n);\n\ndeclare module 'notistack' {\n interface VariantOverrides {\n // Custom variants for the snackbar\n low: true;\n normal: true;\n high: true;\n critical: true;\n }\n}\n\n/** @public */\nexport const NotificationsSidebarItem = (props?: {\n webNotificationsEnabled?: boolean;\n titleCounterEnabled?: boolean;\n snackbarEnabled?: boolean;\n snackbarAutoHideDuration?: number | null;\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 snackbarEnabled = true,\n snackbarAutoHideDuration = 10000,\n icon = NotificationsIcon,\n text = 'Notifications',\n ...restProps\n } = props ?? {\n webNotificationsEnabled: false,\n titleCounterEnabled: true,\n snackbarEnabled: true,\n snackbarAutoHideDuration: 10000,\n };\n\n const { loading, error, value, retry } = useNotificationsApi(api =>\n api.getStatus(),\n );\n const notificationsApi = useApi(notificationsApiRef);\n const alertApi = useApi(alertApiRef);\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, requestUserPermission } = useWebNotifications(\n webNotificationsEnabled,\n );\n const [refresh, setRefresh] = React.useState(false);\n const { setNotificationCount } = useTitleCounter();\n\n const getSnackbarProperties = useCallback(\n (notification: Notification) => {\n const action = (snackBarId: SnackbarKey) => (\n <>\n <IconButton\n component={Link}\n to={notification.payload.link ?? notificationsRoute}\n onClick={() => {\n if (notification.payload.link) {\n notificationsApi\n .updateNotifications({\n ids: [notification.id],\n read: true,\n })\n .catch(() => {\n alertApi.post({\n message: 'Failed to mark notification as read',\n severity: 'error',\n });\n });\n }\n closeSnackbar(snackBarId);\n }}\n >\n <OpenInNew fontSize=\"small\" />\n </IconButton>\n <IconButton\n onClick={() => {\n notificationsApi\n .updateNotifications({\n ids: [notification.id],\n read: true,\n })\n .then(() => {\n closeSnackbar(snackBarId);\n })\n .catch(() => {\n alertApi.post({\n message: 'Failed to mark notification as read',\n severity: 'error',\n });\n });\n }}\n >\n <MarkAsReadIcon fontSize=\"small\" />\n </IconButton>\n </>\n );\n\n return { action };\n },\n [notificationsRoute, notificationsApi, alertApi],\n );\n\n useEffect(() => {\n if (refresh) {\n retry();\n setRefresh(false);\n }\n }, [refresh, retry]);\n\n useEffect(() => {\n const handleNotificationSignal = (signal: NotificationSignal) => {\n if (\n (!webNotificationsEnabled && !snackbarEnabled) ||\n signal.action !== 'new_notification'\n ) {\n return;\n }\n notificationsApi\n .getNotification(signal.notification_id)\n .then(notification => {\n if (!notification) {\n return;\n }\n if (webNotificationsEnabled) {\n sendWebNotification({\n id: notification.id,\n title: notification.payload.title,\n description: notification.payload.description ?? '',\n link: notification.payload.link,\n });\n }\n if (snackbarEnabled) {\n const { action } = getSnackbarProperties(notification);\n const snackBarText =\n notification.payload.title.length > 50\n ? `${notification.payload.title.substring(0, 50)}...`\n : notification.payload.title;\n enqueueSnackbar(snackBarText, {\n key: notification.id,\n variant: notification.payload.severity,\n anchorOrigin: { vertical: 'bottom', horizontal: 'right' },\n action,\n autoHideDuration: snackbarAutoHideDuration,\n } as OptionsWithExtraProps<VariantType>);\n }\n })\n .catch(() => {\n alertApi.post({\n message: 'Failed to fetch notification',\n severity: 'error',\n });\n });\n };\n\n if (lastSignal && lastSignal.action) {\n handleNotificationSignal(lastSignal);\n setRefresh(true);\n }\n }, [\n lastSignal,\n sendWebNotification,\n webNotificationsEnabled,\n snackbarEnabled,\n snackbarAutoHideDuration,\n notificationsApi,\n alertApi,\n getSnackbarProperties,\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 <>\n {snackbarEnabled && (\n <SnackbarProvider\n iconVariant={{\n normal: <SeverityIcon severity=\"normal\" />,\n critical: <SeverityIcon severity=\"critical\" />,\n high: <SeverityIcon severity=\"high\" />,\n low: <SeverityIcon severity=\"low\" />,\n }}\n Components={{\n normal: StyledMaterialDesignContent,\n critical: StyledMaterialDesignContent,\n high: StyledMaterialDesignContent,\n low: StyledMaterialDesignContent,\n }}\n />\n )}\n <SidebarItem\n to={notificationsRoute}\n onClick={() => {\n requestUserPermission();\n }}\n hasNotifications={!error && !!unreadCount}\n text={text}\n icon={icon}\n {...restProps}\n />\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAiDA,MAAM,2BAAA,GAA8B,OAAO,qBAAqB,CAAA;A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AAa,EAAA,EAAA,QAAA,EAAS,QAAS,EAAA,CAAA;AAAA,QACxC,QAAU,kBAAA,KAAA,CAAA,aAAA,CAAC,YAAa,EAAA,EAAA,QAAA,EAAS,UAAW,EAAA,CAAA;AAAA,QAC5C,IAAM,kBAAA,KAAA,CAAA,aAAA,CAAC,YAAa,EAAA,EAAA,QAAA,EAAS,MAAO,EAAA,CAAA;AAAA,QACpC,GAAK,kBAAA,KAAA,CAAA,aAAA,CAAC,YAAa,EAAA,EAAA,QAAA,EAAS,KAAM,EAAA,CAAA;AAAA,OACpC;AAAA,MACA,UAAY,EAAA;AAAA,QACV,MAAQ,EAAA,2BAAA;AAAA,QACR,QAAU,EAAA,2BAAA;AAAA,QACV,IAAM,EAAA,2BAAA;AAAA,QACN,GAAK,EAAA,2BAAA;AAAA,OACP;AAAA,KAAA;AAAA,GAGJ,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,EAAI,EAAA,kBAAA;AAAA,MACJ,SAAS,MAAM;AACb,QAAsB,qBAAA,EAAA,CAAA;AAAA,OACxB;AAAA,MACA,gBAAkB,EAAA,CAAC,KAAS,IAAA,CAAC,CAAC,WAAA;AAAA,MAC9B,IAAA;AAAA,MACA,IAAA;AAAA,MACC,GAAG,SAAA;AAAA,KAAA;AAAA,GAER,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTitleCounter.esm.js","sources":["../../src/hooks/useTitleCounter.ts"],"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 { useCallback, useEffect, useState } from 'react';\nimport throttle from 'lodash/throttle';\n\nconst getPrefix = (value: number) => (value === 0 ? '' : `(${value}) `);\n\nconst cleanTitle = (currentTitle: string) =>\n currentTitle.replace(/^\\(\\d+\\)\\s/, '');\n\nconst throttledSetTitle = throttle((shownTitle: string) => {\n document.title = shownTitle;\n}, 100);\n\n/** @
|
|
1
|
+
{"version":3,"file":"useTitleCounter.esm.js","sources":["../../src/hooks/useTitleCounter.ts"],"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 { useCallback, useEffect, useState } from 'react';\nimport throttle from 'lodash/throttle';\n\nconst getPrefix = (value: number) => (value === 0 ? '' : `(${value}) `);\n\nconst cleanTitle = (currentTitle: string) =>\n currentTitle.replace(/^\\(\\d+\\)\\s/, '');\n\nconst throttledSetTitle = throttle((shownTitle: string) => {\n document.title = shownTitle;\n}, 100);\n\n/** @internal */\nexport function useTitleCounter() {\n const [title, setTitle] = useState(document.title);\n const [count, setCount] = useState(0);\n\n useEffect(() => {\n const baseTitle = cleanTitle(title);\n const shownTitle = `${getPrefix(count)}${baseTitle}`;\n if (document.title !== shownTitle) {\n throttledSetTitle(shownTitle);\n }\n return () => {\n document.title = cleanTitle(title);\n };\n }, [count, title]);\n\n useEffect(() => {\n const titleElement = document.querySelector('title');\n let observer: MutationObserver | undefined;\n if (titleElement) {\n observer = new MutationObserver(mutations => {\n if (mutations?.[0]?.target?.textContent) {\n setTitle(mutations[0].target.textContent);\n }\n });\n observer.observe(titleElement, {\n characterData: true,\n childList: true,\n });\n }\n return () => {\n if (observer) {\n observer.disconnect();\n }\n };\n }, []);\n\n const setNotificationCount = useCallback(\n (newCount: number) => setCount(newCount),\n [],\n );\n\n return { setNotificationCount };\n}\n"],"names":[],"mappings":";;;AAkBA,MAAM,YAAY,CAAC,KAAA,KAAmB,UAAU,CAAI,GAAA,EAAA,GAAK,IAAI,KAAK,CAAA,EAAA,CAAA,CAAA;AAElE,MAAM,aAAa,CAAC,YAAA,KAClB,YAAa,CAAA,OAAA,CAAQ,cAAc,EAAE,CAAA,CAAA;AAEvC,MAAM,iBAAA,GAAoB,QAAS,CAAA,CAAC,UAAuB,KAAA;AACzD,EAAA,QAAA,CAAS,KAAQ,GAAA,UAAA,CAAA;AACnB,CAAA,EAAG,GAAG,CAAA,CAAA;AAGC,SAAS,eAAkB,GAAA;AAChC,EAAA,MAAM,CAAC,KAAO,EAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,SAAS,KAAK,CAAA,CAAA;AACjD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAS,CAAC,CAAA,CAAA;AAEpC,EAAA,SAAA,CAAU,MAAM;AACd,IAAM,MAAA,SAAA,GAAY,WAAW,KAAK,CAAA,CAAA;AAClC,IAAA,MAAM,aAAa,CAAG,EAAA,SAAA,CAAU,KAAK,CAAC,GAAG,SAAS,CAAA,CAAA,CAAA;AAClD,IAAI,IAAA,QAAA,CAAS,UAAU,UAAY,EAAA;AACjC,MAAA,iBAAA,CAAkB,UAAU,CAAA,CAAA;AAAA,KAC9B;AACA,IAAA,OAAO,MAAM;AACX,MAAS,QAAA,CAAA,KAAA,GAAQ,WAAW,KAAK,CAAA,CAAA;AAAA,KACnC,CAAA;AAAA,GACC,EAAA,CAAC,KAAO,EAAA,KAAK,CAAC,CAAA,CAAA;AAEjB,EAAA,SAAA,CAAU,MAAM;AACd,IAAM,MAAA,YAAA,GAAe,QAAS,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACnD,IAAI,IAAA,QAAA,CAAA;AACJ,IAAA,IAAI,YAAc,EAAA;AAChB,MAAW,QAAA,GAAA,IAAI,iBAAiB,CAAa,SAAA,KAAA;AAC3C,QAAA,IAAI,SAAY,GAAA,CAAC,CAAG,EAAA,MAAA,EAAQ,WAAa,EAAA;AACvC,UAAA,QAAA,CAAS,SAAU,CAAA,CAAC,CAAE,CAAA,MAAA,CAAO,WAAW,CAAA,CAAA;AAAA,SAC1C;AAAA,OACD,CAAA,CAAA;AACD,MAAA,QAAA,CAAS,QAAQ,YAAc,EAAA;AAAA,QAC7B,aAAe,EAAA,IAAA;AAAA,QACf,SAAW,EAAA,IAAA;AAAA,OACZ,CAAA,CAAA;AAAA,KACH;AACA,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,QAAA,CAAS,UAAW,EAAA,CAAA;AAAA,OACtB;AAAA,KACF,CAAA;AAAA,GACF,EAAG,EAAE,CAAA,CAAA;AAEL,EAAA,MAAM,oBAAuB,GAAA,WAAA;AAAA,IAC3B,CAAC,QAAqB,KAAA,QAAA,CAAS,QAAQ,CAAA;AAAA,IACvC,EAAC;AAAA,GACH,CAAA;AAEA,EAAA,OAAO,EAAE,oBAAqB,EAAA,CAAA;AAChC;;;;"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { useState,
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useRouteRef, useApi } from '@backstage/core-plugin-api';
|
|
3
|
+
import { notificationsApiRef } from '../api/NotificationsApi.esm.js';
|
|
4
|
+
import '@backstage/errors';
|
|
2
5
|
import { rootRouteRef } from '../routes.esm.js';
|
|
3
|
-
import { useRouteRef } from '@backstage/core-plugin-api';
|
|
4
|
-
import { useNavigate } from 'react-router-dom';
|
|
5
6
|
|
|
6
7
|
function useWebNotifications(enabled) {
|
|
7
8
|
const [webNotificationPermission, setWebNotificationPermission] = useState("default");
|
|
8
|
-
const notificationsRoute = useRouteRef(rootRouteRef);
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const notificationsRoute = useRouteRef(rootRouteRef)();
|
|
10
|
+
const notificationsApi = useApi(notificationsApiRef);
|
|
11
|
+
const requestUserPermission = useCallback(() => {
|
|
11
12
|
if (enabled && "Notification" in window && webNotificationPermission === "default") {
|
|
12
13
|
window.Notification.requestPermission().then((permission) => {
|
|
13
14
|
setWebNotificationPermission(permission);
|
|
@@ -28,16 +29,20 @@ function useWebNotifications(enabled) {
|
|
|
28
29
|
event.preventDefault();
|
|
29
30
|
if (options.link) {
|
|
30
31
|
window.open(options.link, "_blank");
|
|
32
|
+
notificationsApi.updateNotifications({
|
|
33
|
+
ids: [options.id],
|
|
34
|
+
read: true
|
|
35
|
+
});
|
|
31
36
|
} else {
|
|
32
|
-
|
|
37
|
+
window.open(notificationsRoute);
|
|
33
38
|
}
|
|
34
39
|
notification.close();
|
|
35
40
|
};
|
|
36
41
|
return notification;
|
|
37
42
|
},
|
|
38
|
-
[webNotificationPermission,
|
|
43
|
+
[webNotificationPermission, notificationsApi, notificationsRoute]
|
|
39
44
|
);
|
|
40
|
-
return { sendWebNotification };
|
|
45
|
+
return { sendWebNotification, requestUserPermission };
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
export { useWebNotifications };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWebNotifications.esm.js","sources":["../../src/hooks/useWebNotifications.ts"],"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 { useCallback,
|
|
1
|
+
{"version":3,"file":"useWebNotifications.esm.js","sources":["../../src/hooks/useWebNotifications.ts"],"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 { useCallback, useState } from 'react';\nimport { useApi, useRouteRef } from '@backstage/core-plugin-api';\nimport { notificationsApiRef } from '../api';\nimport { rootRouteRef } from '../routes';\n\n/** @internal */\nexport function useWebNotifications(enabled: boolean) {\n const [webNotificationPermission, setWebNotificationPermission] =\n useState('default');\n const notificationsRoute = useRouteRef(rootRouteRef)();\n const notificationsApi = useApi(notificationsApiRef);\n\n const requestUserPermission = useCallback(() => {\n if (\n enabled &&\n 'Notification' in window &&\n webNotificationPermission === 'default'\n ) {\n window.Notification.requestPermission().then(permission => {\n setWebNotificationPermission(permission);\n });\n }\n }, [enabled, webNotificationPermission]);\n\n const sendWebNotification = useCallback(\n (options: {\n id: string;\n title: string;\n description: string;\n link?: string;\n }) => {\n if (webNotificationPermission !== 'granted') {\n return null;\n }\n\n const notification = new Notification(options.title, {\n body: options.description,\n tag: options.id, // Prevent duplicates from multiple tabs\n });\n\n notification.onclick = event => {\n event.preventDefault();\n if (options.link) {\n window.open(options.link, '_blank');\n notificationsApi.updateNotifications({\n ids: [options.id],\n read: true,\n });\n } else {\n window.open(notificationsRoute);\n }\n notification.close();\n };\n\n return notification;\n },\n [webNotificationPermission, notificationsApi, notificationsRoute],\n );\n\n return { sendWebNotification, requestUserPermission };\n}\n"],"names":[],"mappings":";;;;;;AAqBO,SAAS,oBAAoB,OAAkB,EAAA;AACpD,EAAA,MAAM,CAAC,yBAAA,EAA2B,4BAA4B,CAAA,GAC5D,SAAS,SAAS,CAAA,CAAA;AACpB,EAAM,MAA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,QAAA,YAAA,CAAa,KAAM,EAAA,CAAA;AAAA,OACrB,CAAA;AAEA,MAAO,OAAA,YAAA,CAAA;AAAA,KACT;AAAA,IACA,CAAC,yBAA2B,EAAA,gBAAA,EAAkB,kBAAkB,CAAA;AAAA,GAClE,CAAA;AAEA,EAAO,OAAA,EAAE,qBAAqB,qBAAsB,EAAA,CAAA;AACtD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
5
5
|
import { DiscoveryApi, FetchApi, IconComponent } from '@backstage/core-plugin-api';
|
|
6
|
-
import { NotificationSeverity, Notification
|
|
6
|
+
import { NotificationSeverity, Notification, NotificationStatus } from '@backstage/plugin-notifications-common';
|
|
7
7
|
import { TableProps } from '@backstage/core-components';
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
@@ -47,15 +47,15 @@ type UpdateNotificationsOptions = {
|
|
|
47
47
|
};
|
|
48
48
|
/** @public */
|
|
49
49
|
type GetNotificationsResponse = {
|
|
50
|
-
notifications: Notification
|
|
50
|
+
notifications: Notification[];
|
|
51
51
|
totalCount: number;
|
|
52
52
|
};
|
|
53
53
|
/** @public */
|
|
54
54
|
interface NotificationsApi {
|
|
55
55
|
getNotifications(options?: GetNotificationsOptions): Promise<GetNotificationsResponse>;
|
|
56
|
-
getNotification(id: string): Promise<Notification
|
|
56
|
+
getNotification(id: string): Promise<Notification>;
|
|
57
57
|
getStatus(): Promise<NotificationStatus>;
|
|
58
|
-
updateNotifications(options: UpdateNotificationsOptions): Promise<Notification
|
|
58
|
+
updateNotifications(options: UpdateNotificationsOptions): Promise<Notification[]>;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/** @public */
|
|
@@ -67,9 +67,9 @@ declare class NotificationsClient implements NotificationsApi {
|
|
|
67
67
|
fetchApi: FetchApi;
|
|
68
68
|
});
|
|
69
69
|
getNotifications(options?: GetNotificationsOptions): Promise<GetNotificationsResponse>;
|
|
70
|
-
getNotification(id: string): Promise<Notification
|
|
70
|
+
getNotification(id: string): Promise<Notification>;
|
|
71
71
|
getStatus(): Promise<NotificationStatus>;
|
|
72
|
-
updateNotifications(options: UpdateNotificationsOptions): Promise<Notification
|
|
72
|
+
updateNotifications(options: UpdateNotificationsOptions): Promise<Notification[]>;
|
|
73
73
|
private request;
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -96,21 +96,6 @@ declare function useNotificationsApi<T>(f: (api: NotificationsApi) => Promise<T>
|
|
|
96
96
|
value: T;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
/** @public */
|
|
100
|
-
declare function useWebNotifications(enabled: boolean): {
|
|
101
|
-
sendWebNotification: (options: {
|
|
102
|
-
id: string;
|
|
103
|
-
title: string;
|
|
104
|
-
description: string;
|
|
105
|
-
link?: string;
|
|
106
|
-
}) => Notification | null;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/** @public */
|
|
110
|
-
declare function useTitleCounter(): {
|
|
111
|
-
setNotificationCount: (newCount: number) => void;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
99
|
declare module 'notistack' {
|
|
115
100
|
interface VariantOverrides {
|
|
116
101
|
low: true;
|
|
@@ -137,7 +122,7 @@ type NotificationsTableProps = Pick<TableProps, 'onPageChange' | 'onRowsPerPageC
|
|
|
137
122
|
markAsReadOnLinkOpen?: boolean;
|
|
138
123
|
isLoading?: boolean;
|
|
139
124
|
isUnread: boolean;
|
|
140
|
-
notifications?: Notification
|
|
125
|
+
notifications?: Notification[];
|
|
141
126
|
onUpdate: () => void;
|
|
142
127
|
setContainsText: (search: string) => void;
|
|
143
128
|
pageSize: number;
|
|
@@ -145,4 +130,4 @@ type NotificationsTableProps = Pick<TableProps, 'onPageChange' | 'onRowsPerPageC
|
|
|
145
130
|
/** @public */
|
|
146
131
|
declare const NotificationsTable: ({ markAsReadOnLinkOpen, isLoading, notifications, isUnread, onUpdate, setContainsText, onPageChange, onRowsPerPageChange, page, pageSize, totalCount, }: NotificationsTableProps) => React__default.JSX.Element;
|
|
147
132
|
|
|
148
|
-
export { type GetNotificationsOptions, type GetNotificationsResponse, type NotificationsApi, NotificationsClient, NotificationsPage, type NotificationsPageProps, NotificationsSidebarItem, NotificationsTable, type NotificationsTableProps, type UpdateNotificationsOptions, notificationsApiRef, notificationsPlugin, useNotificationsApi
|
|
133
|
+
export { type GetNotificationsOptions, type GetNotificationsResponse, type NotificationsApi, NotificationsClient, NotificationsPage, type NotificationsPageProps, NotificationsSidebarItem, NotificationsTable, type NotificationsTableProps, type UpdateNotificationsOptions, notificationsApiRef, notificationsPlugin, useNotificationsApi };
|
package/dist/index.esm.js
CHANGED
|
@@ -2,8 +2,10 @@ export { NotificationsPage, notificationsPlugin } from './plugin.esm.js';
|
|
|
2
2
|
export { notificationsApiRef } from './api/NotificationsApi.esm.js';
|
|
3
3
|
export { NotificationsClient } from './api/NotificationsClient.esm.js';
|
|
4
4
|
export { useNotificationsApi } from './hooks/useNotificationsApi.esm.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import 'react';
|
|
6
|
+
import '@backstage/core-plugin-api';
|
|
7
|
+
import './routes.esm.js';
|
|
8
|
+
import './hooks/useTitleCounter.esm.js';
|
|
7
9
|
export { NotificationsSidebarItem } from './components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js';
|
|
8
10
|
export { NotificationsTable } from './components/NotificationsTable/NotificationsTable.esm.js';
|
|
9
11
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-notifications",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-next.1",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "frontend-plugin",
|
|
6
6
|
"pluginId": "notifications",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"react-use": "^17.2.4"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@backstage/cli": "^0.27.0-next.
|
|
60
|
-
"@backstage/core-app-api": "^1.14.
|
|
61
|
-
"@backstage/dev-utils": "^1.0.
|
|
59
|
+
"@backstage/cli": "^0.27.0-next.4",
|
|
60
|
+
"@backstage/core-app-api": "^1.14.2-next.0",
|
|
61
|
+
"@backstage/dev-utils": "^1.0.37-next.3",
|
|
62
62
|
"@backstage/plugin-signals": "^0.0.9-next.0",
|
|
63
|
-
"@backstage/test-utils": "^1.5.
|
|
63
|
+
"@backstage/test-utils": "^1.5.10-next.2",
|
|
64
64
|
"@testing-library/jest-dom": "^6.0.0",
|
|
65
65
|
"@testing-library/react": "^15.0.0",
|
|
66
66
|
"@testing-library/user-event": "^14.0.0",
|