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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/api/NotificationsApi.esm.js +8 -0
  3. package/dist/api/NotificationsApi.esm.js.map +1 -0
  4. package/dist/api/NotificationsClient.esm.js +74 -0
  5. package/dist/api/NotificationsClient.esm.js.map +1 -0
  6. package/dist/{esm/index-D44DlZtS.esm.js → components/NotificationsFilters/NotificationsFilters.esm.js} +4 -124
  7. package/dist/components/NotificationsFilters/NotificationsFilters.esm.js.map +1 -0
  8. package/dist/components/NotificationsPage/NotificationsPage.esm.js +138 -0
  9. package/dist/components/NotificationsPage/NotificationsPage.esm.js.map +1 -0
  10. package/dist/components/NotificationsPage/index.esm.js +2 -0
  11. package/dist/components/NotificationsPage/index.esm.js.map +1 -0
  12. package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js +193 -0
  13. package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js.map +1 -0
  14. package/dist/components/NotificationsTable/BulkActions.esm.js +55 -0
  15. package/dist/components/NotificationsTable/BulkActions.esm.js.map +1 -0
  16. package/dist/components/NotificationsTable/NotificationsTable.esm.js +219 -0
  17. package/dist/components/NotificationsTable/NotificationsTable.esm.js.map +1 -0
  18. package/dist/components/NotificationsTable/SelectAll.esm.js +41 -0
  19. package/dist/components/NotificationsTable/SelectAll.esm.js.map +1 -0
  20. package/dist/components/NotificationsTable/SeverityIcon.esm.js +40 -0
  21. package/dist/components/NotificationsTable/SeverityIcon.esm.js.map +1 -0
  22. package/dist/hooks/useNotificationsApi.esm.js +14 -0
  23. package/dist/hooks/useNotificationsApi.esm.js.map +1 -0
  24. package/dist/hooks/useTitleCounter.esm.js +57 -0
  25. package/dist/hooks/useTitleCounter.esm.js.map +1 -0
  26. package/dist/hooks/useWebNotifications.esm.js +44 -0
  27. package/dist/hooks/useWebNotifications.esm.js.map +1 -0
  28. package/dist/index.d.ts +34 -5
  29. package/dist/index.esm.js +8 -524
  30. package/dist/index.esm.js.map +1 -1
  31. package/dist/plugin.esm.js +28 -0
  32. package/dist/plugin.esm.js.map +1 -0
  33. package/dist/routes.esm.js +8 -0
  34. package/dist/routes.esm.js.map +1 -0
  35. package/package.json +9 -6
  36. package/dist/esm/index-D44DlZtS.esm.js.map +0 -1
@@ -0,0 +1,193 @@
1
+ import React, { useCallback, 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, Link } from '@backstage/core-components';
6
+ import NotificationsIcon from '@material-ui/icons/Notifications';
7
+ import { useApi, alertApiRef, 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
+ import { MaterialDesignContent, SnackbarProvider, closeSnackbar, enqueueSnackbar } from 'notistack';
13
+ import { SeverityIcon } from '../NotificationsTable/SeverityIcon.esm.js';
14
+ import OpenInNew from '@material-ui/icons/OpenInNew';
15
+ import MarkAsReadIcon from '@material-ui/icons/CheckCircle';
16
+ import IconButton from '@material-ui/core/IconButton';
17
+ import { styled } from '@material-ui/core/styles';
18
+
19
+ const StyledMaterialDesignContent = styled(MaterialDesignContent)(
20
+ ({ theme }) => ({
21
+ "&.notistack-MuiContent-low": {
22
+ backgroundColor: theme.palette.background.default,
23
+ color: theme.palette.text.primary
24
+ },
25
+ "&.notistack-MuiContent-normal": {
26
+ backgroundColor: theme.palette.background.default,
27
+ color: theme.palette.text.primary
28
+ },
29
+ "&.notistack-MuiContent-high": {
30
+ backgroundColor: theme.palette.background.default,
31
+ color: theme.palette.text.primary
32
+ },
33
+ "&.notistack-MuiContent-critical": {
34
+ backgroundColor: theme.palette.background.default,
35
+ color: theme.palette.text.primary
36
+ }
37
+ })
38
+ );
39
+ const NotificationsSidebarItem = (props) => {
40
+ const {
41
+ webNotificationsEnabled = false,
42
+ titleCounterEnabled = true,
43
+ snackbarEnabled = true,
44
+ icon = NotificationsIcon,
45
+ text = "Notifications",
46
+ ...restProps
47
+ } = props != null ? props : {
48
+ webNotificationsEnabled: false,
49
+ titleCounterEnabled: true,
50
+ snackbarEnabled: true
51
+ };
52
+ const { loading, error, value, retry } = useNotificationsApi(
53
+ (api) => api.getStatus()
54
+ );
55
+ const notificationsApi = useApi(notificationsApiRef);
56
+ const alertApi = useApi(alertApiRef);
57
+ const [unreadCount, setUnreadCount] = React.useState(0);
58
+ const notificationsRoute = useRouteRef(rootRouteRef);
59
+ const { lastSignal } = useSignal("notifications");
60
+ const { sendWebNotification } = useWebNotifications(webNotificationsEnabled);
61
+ const [refresh, setRefresh] = React.useState(false);
62
+ const { setNotificationCount } = useTitleCounter();
63
+ const getSnackbarProperties = useCallback(
64
+ (notification) => {
65
+ const action = (snackBarId) => {
66
+ var _a;
67
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
68
+ IconButton,
69
+ {
70
+ component: Link,
71
+ to: (_a = notification.payload.link) != null ? _a : notificationsRoute(),
72
+ onClick: () => {
73
+ closeSnackbar(snackBarId);
74
+ }
75
+ },
76
+ /* @__PURE__ */ React.createElement(OpenInNew, { fontSize: "small" })
77
+ ), /* @__PURE__ */ React.createElement(
78
+ IconButton,
79
+ {
80
+ onClick: () => {
81
+ notificationsApi.updateNotifications({
82
+ ids: [notification.id],
83
+ read: true
84
+ }).then(() => {
85
+ closeSnackbar(snackBarId);
86
+ }).catch(() => {
87
+ alertApi.post({
88
+ message: "Failed to mark notification as read",
89
+ severity: "error"
90
+ });
91
+ });
92
+ }
93
+ },
94
+ /* @__PURE__ */ React.createElement(MarkAsReadIcon, { fontSize: "small" })
95
+ ));
96
+ };
97
+ return { action };
98
+ },
99
+ [notificationsRoute, notificationsApi, alertApi]
100
+ );
101
+ useEffect(() => {
102
+ if (refresh) {
103
+ retry();
104
+ setRefresh(false);
105
+ }
106
+ }, [refresh, retry]);
107
+ useEffect(() => {
108
+ const handleNotificationSignal = (signal) => {
109
+ if (!webNotificationsEnabled && !snackbarEnabled || signal.action !== "new_notification") {
110
+ return;
111
+ }
112
+ notificationsApi.getNotification(signal.notification_id).then((notification) => {
113
+ var _a;
114
+ if (!notification) {
115
+ return;
116
+ }
117
+ if (webNotificationsEnabled) {
118
+ sendWebNotification({
119
+ id: notification.id,
120
+ title: notification.payload.title,
121
+ description: (_a = notification.payload.description) != null ? _a : "",
122
+ link: notification.payload.link
123
+ });
124
+ }
125
+ if (snackbarEnabled) {
126
+ const { action } = getSnackbarProperties(notification);
127
+ const snackBarText = notification.payload.title.length > 50 ? `${notification.payload.title.substring(0, 50)}...` : notification.payload.title;
128
+ enqueueSnackbar(snackBarText, {
129
+ variant: notification.payload.severity,
130
+ anchorOrigin: { vertical: "bottom", horizontal: "right" },
131
+ action
132
+ });
133
+ }
134
+ }).catch(() => {
135
+ alertApi.post({
136
+ message: "Failed to fetch notification",
137
+ severity: "error"
138
+ });
139
+ });
140
+ };
141
+ if (lastSignal && lastSignal.action) {
142
+ handleNotificationSignal(lastSignal);
143
+ setRefresh(true);
144
+ }
145
+ }, [
146
+ lastSignal,
147
+ sendWebNotification,
148
+ webNotificationsEnabled,
149
+ snackbarEnabled,
150
+ notificationsApi,
151
+ alertApi,
152
+ getSnackbarProperties
153
+ ]);
154
+ useEffect(() => {
155
+ if (!loading && !error && value) {
156
+ setUnreadCount(value.unread);
157
+ }
158
+ }, [loading, error, value]);
159
+ useEffect(() => {
160
+ if (titleCounterEnabled) {
161
+ setNotificationCount(unreadCount);
162
+ }
163
+ }, [titleCounterEnabled, unreadCount, setNotificationCount]);
164
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, snackbarEnabled && /* @__PURE__ */ React.createElement(
165
+ SnackbarProvider,
166
+ {
167
+ iconVariant: {
168
+ normal: /* @__PURE__ */ React.createElement(SeverityIcon, { severity: "normal" }),
169
+ critical: /* @__PURE__ */ React.createElement(SeverityIcon, { severity: "critical" }),
170
+ high: /* @__PURE__ */ React.createElement(SeverityIcon, { severity: "high" }),
171
+ low: /* @__PURE__ */ React.createElement(SeverityIcon, { severity: "low" })
172
+ },
173
+ Components: {
174
+ normal: StyledMaterialDesignContent,
175
+ critical: StyledMaterialDesignContent,
176
+ high: StyledMaterialDesignContent,
177
+ low: StyledMaterialDesignContent
178
+ }
179
+ }
180
+ ), /* @__PURE__ */ React.createElement(
181
+ SidebarItem,
182
+ {
183
+ to: notificationsRoute(),
184
+ hasNotifications: !error && !!unreadCount,
185
+ text,
186
+ icon,
187
+ ...restProps
188
+ }
189
+ ));
190
+ };
191
+
192
+ export { NotificationsSidebarItem };
193
+ //# 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, { 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 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 icon = NotificationsIcon,\n text = 'Notifications',\n ...restProps\n } = props ?? {\n webNotificationsEnabled: false,\n titleCounterEnabled: true,\n snackbarEnabled: true,\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 } 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 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,MA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CAAC,WAAA;AAAA,MAC9B,IAAA;AAAA,MACA,IAAA;AAAA,MACC,GAAG,SAAA;AAAA,KAAA;AAAA,GAER,CAAA,CAAA;AAEJ;;;;"}
@@ -0,0 +1,55 @@
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
+ import MarkAllReadIcon from '@material-ui/icons/DoneAll';
10
+
11
+ const BulkActions = ({
12
+ selectedNotifications,
13
+ notifications,
14
+ isUnread,
15
+ onSwitchReadStatus,
16
+ onSwitchSavedStatus,
17
+ onMarkAllRead
18
+ }) => {
19
+ const isDisabled = selectedNotifications.size === 0;
20
+ const bulkNotifications = notifications.filter(
21
+ (notification) => selectedNotifications.has(notification.id)
22
+ );
23
+ const isOneRead = !!bulkNotifications.find(
24
+ (notification) => !!notification.read
25
+ );
26
+ const isOneSaved = !!bulkNotifications.find(
27
+ (notification) => !!notification.saved
28
+ );
29
+ const markAsReadText = isOneRead ? "Return selected among unread" : "Mark selected as read";
30
+ const IconComponent = isOneRead ? MarkAsUnreadIcon : MarkAsReadIcon;
31
+ const markAsSavedText = isOneSaved ? "Undo save for selected" : "Save selected for later";
32
+ const SavedIconComponent = isOneSaved ? MarkAsUnsavedIcon : MarkAsSavedIcon;
33
+ return /* @__PURE__ */ React.createElement(Grid, { container: true, wrap: "nowrap" }, /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 3 }, onMarkAllRead ? /* @__PURE__ */ React.createElement(Tooltip, { title: "Mark all read" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(IconButton, { disabled: !isUnread, onClick: onMarkAllRead }, /* @__PURE__ */ React.createElement(MarkAllReadIcon, { "aria-label": markAsSavedText })))) : /* @__PURE__ */ React.createElement("div", null)), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 3 }, /* @__PURE__ */ React.createElement(Tooltip, { title: markAsSavedText }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
34
+ IconButton,
35
+ {
36
+ disabled: isDisabled,
37
+ onClick: () => {
38
+ onSwitchSavedStatus([...selectedNotifications], !isOneSaved);
39
+ }
40
+ },
41
+ /* @__PURE__ */ React.createElement(SavedIconComponent, { "aria-label": markAsSavedText })
42
+ )))), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 3 }, /* @__PURE__ */ React.createElement(Tooltip, { title: markAsReadText }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
43
+ IconButton,
44
+ {
45
+ disabled: isDisabled,
46
+ onClick: () => {
47
+ onSwitchReadStatus([...selectedNotifications], !isOneRead);
48
+ }
49
+ },
50
+ /* @__PURE__ */ React.createElement(IconComponent, { "aria-label": markAsReadText })
51
+ )))));
52
+ };
53
+
54
+ export { BulkActions };
55
+ //# sourceMappingURL=BulkActions.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BulkActions.esm.js","sources":["../../../src/components/NotificationsTable/BulkActions.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';\nimport { Notification } from '@backstage/plugin-notifications-common';\nimport Grid from '@material-ui/core/Grid';\nimport IconButton from '@material-ui/core/IconButton';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport MarkAsUnreadIcon from '@material-ui/icons/Markunread' /* TODO: use Drafts and MarkAsUnread once we have mui 5 icons */;\nimport MarkAsReadIcon from '@material-ui/icons/CheckCircle';\nimport MarkAsUnsavedIcon from '@material-ui/icons/LabelOff' /* TODO: use BookmarkRemove and BookmarkAdd once we have mui 5 icons */;\nimport MarkAsSavedIcon from '@material-ui/icons/Label';\nimport MarkAllReadIcon from '@material-ui/icons/DoneAll';\n\nexport const BulkActions = ({\n selectedNotifications,\n notifications,\n isUnread,\n onSwitchReadStatus,\n onSwitchSavedStatus,\n onMarkAllRead,\n}: {\n selectedNotifications: Set<Notification['id']>;\n notifications: Notification[];\n isUnread?: boolean;\n onSwitchReadStatus: (ids: Notification['id'][], newStatus: boolean) => void;\n onSwitchSavedStatus: (ids: Notification['id'][], newStatus: boolean) => void;\n onMarkAllRead?: () => void;\n}) => {\n const isDisabled = selectedNotifications.size === 0;\n const bulkNotifications = notifications.filter(notification =>\n selectedNotifications.has(notification.id),\n );\n\n const isOneRead = !!bulkNotifications.find(\n (notification: Notification) => !!notification.read,\n );\n const isOneSaved = !!bulkNotifications.find(\n (notification: Notification) => !!notification.saved,\n );\n\n const markAsReadText = isOneRead\n ? 'Return selected among unread'\n : 'Mark selected as read';\n const IconComponent = isOneRead ? MarkAsUnreadIcon : MarkAsReadIcon;\n\n const markAsSavedText = isOneSaved\n ? 'Undo save for selected'\n : 'Save selected for later';\n const SavedIconComponent = isOneSaved ? MarkAsUnsavedIcon : MarkAsSavedIcon;\n\n return (\n <Grid container wrap=\"nowrap\">\n <Grid item xs={3}>\n {onMarkAllRead ? (\n <Tooltip title=\"Mark all read\">\n <div>\n {/* The <div> here is a workaround for the Tooltip which does not work for a \"disabled\" child */}\n <IconButton disabled={!isUnread} onClick={onMarkAllRead}>\n <MarkAllReadIcon aria-label={markAsSavedText} />\n </IconButton>\n </div>\n </Tooltip>\n ) : (\n <div />\n )}\n </Grid>\n\n <Grid item xs={3}>\n <Tooltip title={markAsSavedText}>\n <div>\n {/* The <div> here is a workaround for the Tooltip which does not work for a \"disabled\" child */}\n <IconButton\n disabled={isDisabled}\n onClick={() => {\n onSwitchSavedStatus([...selectedNotifications], !isOneSaved);\n }}\n >\n <SavedIconComponent aria-label={markAsSavedText} />\n </IconButton>\n </div>\n </Tooltip>\n </Grid>\n\n <Grid item xs={3}>\n <Tooltip title={markAsReadText}>\n <div>\n <IconButton\n disabled={isDisabled}\n onClick={() => {\n onSwitchReadStatus([...selectedNotifications], !isOneRead);\n }}\n >\n <IconComponent aria-label={markAsReadText} />\n </IconButton>\n </div>\n </Tooltip>\n </Grid>\n </Grid>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;AA0BO,MAAM,cAAc,CAAC;AAAA,EAC1B,qBAAA;AAAA,EACA,aAAA;AAAA,EACA,QAAA;AAAA,EACA,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA,aAAA;AACF,CAOM,KAAA;AACJ,EAAM,MAAA,UAAA,GAAa,sBAAsB,IAAS,KAAA,CAAA,CAAA;AAClD,EAAA,MAAM,oBAAoB,aAAc,CAAA,MAAA;AAAA,IAAO,CAC7C,YAAA,KAAA,qBAAA,CAAsB,GAAI,CAAA,YAAA,CAAa,EAAE,CAAA;AAAA,GAC3C,CAAA;AAEA,EAAM,MAAA,SAAA,GAAY,CAAC,CAAC,iBAAkB,CAAA,IAAA;AAAA,IACpC,CAAC,YAAA,KAA+B,CAAC,CAAC,YAAa,CAAA,IAAA;AAAA,GACjD,CAAA;AACA,EAAM,MAAA,UAAA,GAAa,CAAC,CAAC,iBAAkB,CAAA,IAAA;AAAA,IACrC,CAAC,YAAA,KAA+B,CAAC,CAAC,YAAa,CAAA,KAAA;AAAA,GACjD,CAAA;AAEA,EAAM,MAAA,cAAA,GAAiB,YACnB,8BACA,GAAA,uBAAA,CAAA;AACJ,EAAM,MAAA,aAAA,GAAgB,YAAY,gBAAmB,GAAA,cAAA,CAAA;AAErD,EAAM,MAAA,eAAA,GAAkB,aACpB,wBACA,GAAA,y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AO,EAAA,cAAA,EAAA,sCACb,KACC,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,QAAU,EAAA,UAAA;AAAA,MACV,SAAS,MAAM;AACb,QAAA,kBAAA,CAAmB,CAAC,GAAG,qBAAqB,CAAA,EAAG,CAAC,SAAS,CAAA,CAAA;AAAA,OAC3D;AAAA,KAAA;AAAA,oBAEA,KAAA,CAAA,aAAA,CAAC,aAAc,EAAA,EAAA,YAAA,EAAY,cAAgB,EAAA,CAAA;AAAA,GAE/C,CACF,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
@@ -0,0 +1,219 @@
1
+ import React from 'react';
2
+ import throttle from 'lodash/throttle';
3
+ import RelativeTime from 'react-relative-time';
4
+ import Box from '@material-ui/core/Box';
5
+ import Grid from '@material-ui/core/Grid';
6
+ import Checkbox from '@material-ui/core/Checkbox';
7
+ import Typography from '@material-ui/core/Typography';
8
+ import { makeStyles } from '@material-ui/core/styles';
9
+ import { useConfirm } from 'material-ui-confirm';
10
+ import { useApi, alertApiRef } from '@backstage/core-plugin-api';
11
+ import { Link, Table } from '@backstage/core-components';
12
+ import { notificationsApiRef } from '../../api/NotificationsApi.esm.js';
13
+ import '@backstage/errors';
14
+ import { SeverityIcon } from './SeverityIcon.esm.js';
15
+ import { SelectAll } from './SelectAll.esm.js';
16
+ import { BulkActions } from './BulkActions.esm.js';
17
+
18
+ const ThrottleDelayMs = 1e3;
19
+ const useStyles = makeStyles({
20
+ description: {
21
+ maxHeight: "5rem",
22
+ overflow: "scroll"
23
+ },
24
+ severityItem: {
25
+ alignContent: "center"
26
+ }
27
+ });
28
+ const NotificationsTable = ({
29
+ markAsReadOnLinkOpen,
30
+ isLoading,
31
+ notifications = [],
32
+ isUnread,
33
+ onUpdate,
34
+ setContainsText,
35
+ onPageChange,
36
+ onRowsPerPageChange,
37
+ page,
38
+ pageSize,
39
+ totalCount
40
+ }) => {
41
+ const classes = useStyles();
42
+ const notificationsApi = useApi(notificationsApiRef);
43
+ const alertApi = useApi(alertApiRef);
44
+ const confirm = useConfirm();
45
+ const [selectedNotifications, setSelectedNotifications] = React.useState(
46
+ /* @__PURE__ */ new Set()
47
+ );
48
+ const onNotificationsSelectChange = React.useCallback(
49
+ (ids, checked) => {
50
+ let newSelect;
51
+ if (checked) {
52
+ newSelect = /* @__PURE__ */ new Set([...selectedNotifications, ...ids]);
53
+ } else {
54
+ newSelect = new Set(selectedNotifications);
55
+ ids.forEach((id) => newSelect.delete(id));
56
+ }
57
+ setSelectedNotifications(newSelect);
58
+ },
59
+ [selectedNotifications, setSelectedNotifications]
60
+ );
61
+ const onSwitchReadStatus = React.useCallback(
62
+ (ids, newStatus) => {
63
+ notificationsApi.updateNotifications({
64
+ ids,
65
+ read: newStatus
66
+ }).then(onUpdate);
67
+ },
68
+ [notificationsApi, onUpdate]
69
+ );
70
+ const onSwitchSavedStatus = React.useCallback(
71
+ (ids, newStatus) => {
72
+ notificationsApi.updateNotifications({
73
+ ids,
74
+ saved: newStatus
75
+ }).then(onUpdate);
76
+ },
77
+ [notificationsApi, onUpdate]
78
+ );
79
+ const onMarkAllRead = React.useCallback(() => {
80
+ confirm({
81
+ title: "Are you sure?",
82
+ description: /* @__PURE__ */ React.createElement(React.Fragment, null, "Mark ", /* @__PURE__ */ React.createElement("b", null, "all"), " notifications as ", /* @__PURE__ */ React.createElement("b", null, "read"), "."),
83
+ confirmationText: "Mark All"
84
+ }).then(async () => {
85
+ var _a;
86
+ const ids = (_a = (await notificationsApi.getNotifications({ read: false })).notifications) == null ? void 0 : _a.map((notification) => notification.id);
87
+ return notificationsApi.updateNotifications({
88
+ ids,
89
+ read: true
90
+ }).then(onUpdate);
91
+ }).catch((e) => {
92
+ if (e) {
93
+ alertApi.post({
94
+ message: "Failed to mark all notifications as read",
95
+ severity: "error"
96
+ });
97
+ }
98
+ });
99
+ }, [alertApi, confirm, notificationsApi, onUpdate]);
100
+ const throttledContainsTextHandler = React.useMemo(
101
+ () => throttle(setContainsText, ThrottleDelayMs),
102
+ [setContainsText]
103
+ );
104
+ React.useEffect(() => {
105
+ const allShownIds = new Set(notifications.map((n) => n.id));
106
+ const intersect = [...selectedNotifications].filter(
107
+ (id) => allShownIds.has(id)
108
+ );
109
+ if (selectedNotifications.size !== intersect.length) {
110
+ setSelectedNotifications(new Set(intersect));
111
+ }
112
+ }, [notifications, selectedNotifications]);
113
+ const compactColumns = React.useMemo(
114
+ () => [
115
+ {
116
+ /* selection column */
117
+ width: "1rem",
118
+ title: /* @__PURE__ */ React.createElement(
119
+ SelectAll,
120
+ {
121
+ count: selectedNotifications.size,
122
+ totalCount: notifications.length,
123
+ onSelectAll: () => onNotificationsSelectChange(
124
+ notifications.map((notification) => notification.id),
125
+ selectedNotifications.size !== notifications.length
126
+ )
127
+ }
128
+ ),
129
+ render: (notification) => /* @__PURE__ */ React.createElement(
130
+ Checkbox,
131
+ {
132
+ color: "primary",
133
+ checked: selectedNotifications.has(notification.id),
134
+ onChange: (_, checked) => onNotificationsSelectChange([notification.id], checked)
135
+ }
136
+ )
137
+ },
138
+ {
139
+ /* compact-data column */
140
+ customFilterAndSearch: () => true,
141
+ render: (notification) => {
142
+ var _a;
143
+ return /* @__PURE__ */ React.createElement(Grid, { container: true }, /* @__PURE__ */ React.createElement(Grid, { item: true, className: classes.severityItem }, /* @__PURE__ */ React.createElement(SeverityIcon, { severity: (_a = notification.payload) == null ? void 0 : _a.severity })), /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 11 }, /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Typography, { variant: "subtitle2" }, notification.payload.link ? /* @__PURE__ */ React.createElement(
144
+ Link,
145
+ {
146
+ to: notification.payload.link,
147
+ onClick: () => {
148
+ if (markAsReadOnLinkOpen && !notification.read) {
149
+ onSwitchReadStatus([notification.id], true);
150
+ }
151
+ }
152
+ },
153
+ notification.payload.title
154
+ ) : notification.payload.title), notification.payload.description ? /* @__PURE__ */ React.createElement(Typography, { variant: "body2", className: classes.description }, notification.payload.description) : null, /* @__PURE__ */ React.createElement(Typography, { variant: "caption" }, notification.origin && /* @__PURE__ */ React.createElement(React.Fragment, null, notification.origin, "\xA0\u2022\xA0"), notification.payload.topic && /* @__PURE__ */ React.createElement(React.Fragment, null, notification.payload.topic, "\xA0\u2022\xA0"), notification.created && /* @__PURE__ */ React.createElement(RelativeTime, { value: notification.created })))));
155
+ }
156
+ },
157
+ {
158
+ /* actions column */
159
+ width: "1rem",
160
+ title: /* @__PURE__ */ React.createElement(
161
+ BulkActions,
162
+ {
163
+ notifications,
164
+ selectedNotifications,
165
+ isUnread,
166
+ onSwitchReadStatus,
167
+ onSwitchSavedStatus,
168
+ onMarkAllRead
169
+ }
170
+ ),
171
+ render: (notification) => /* @__PURE__ */ React.createElement(
172
+ BulkActions,
173
+ {
174
+ notifications: [notification],
175
+ selectedNotifications: /* @__PURE__ */ new Set([notification.id]),
176
+ onSwitchReadStatus,
177
+ onSwitchSavedStatus
178
+ }
179
+ )
180
+ }
181
+ ],
182
+ [
183
+ markAsReadOnLinkOpen,
184
+ selectedNotifications,
185
+ notifications,
186
+ isUnread,
187
+ onSwitchReadStatus,
188
+ onSwitchSavedStatus,
189
+ onMarkAllRead,
190
+ onNotificationsSelectChange,
191
+ classes.severityItem,
192
+ classes.description
193
+ ]
194
+ );
195
+ return /* @__PURE__ */ React.createElement(
196
+ Table,
197
+ {
198
+ isLoading,
199
+ options: {
200
+ padding: "dense",
201
+ search: true,
202
+ paging: true,
203
+ pageSize,
204
+ header: true,
205
+ sorting: false
206
+ },
207
+ onPageChange,
208
+ onRowsPerPageChange,
209
+ page,
210
+ totalCount,
211
+ onSearchChange: throttledContainsTextHandler,
212
+ data: notifications,
213
+ columns: compactColumns
214
+ }
215
+ );
216
+ };
217
+
218
+ export { NotificationsTable };
219
+ //# sourceMappingURL=NotificationsTable.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationsTable.esm.js","sources":["../../../src/components/NotificationsTable/NotificationsTable.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 from 'react';\nimport throttle from 'lodash/throttle';\n// @ts-ignore\nimport RelativeTime from 'react-relative-time';\nimport Box from '@material-ui/core/Box';\nimport Grid from '@material-ui/core/Grid';\nimport CheckBox from '@material-ui/core/Checkbox';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport { Notification } from '@backstage/plugin-notifications-common';\nimport { useConfirm } from 'material-ui-confirm';\nimport { alertApiRef, useApi } from '@backstage/core-plugin-api';\nimport {\n Link,\n Table,\n TableColumn,\n TableProps,\n} from '@backstage/core-components';\n\nimport { notificationsApiRef } from '../../api';\n\nimport { SeverityIcon } from './SeverityIcon';\nimport { SelectAll } from './SelectAll';\nimport { BulkActions } from './BulkActions';\n\nconst ThrottleDelayMs = 1000;\n\nconst useStyles = makeStyles({\n description: {\n maxHeight: '5rem',\n overflow: 'scroll',\n },\n severityItem: {\n alignContent: 'center',\n },\n});\n\n/** @public */\nexport type NotificationsTableProps = Pick<\n TableProps,\n 'onPageChange' | 'onRowsPerPageChange' | 'page' | 'totalCount'\n> & {\n markAsReadOnLinkOpen?: boolean;\n isLoading?: boolean;\n isUnread: boolean;\n notifications?: Notification[];\n onUpdate: () => void;\n setContainsText: (search: string) => void;\n pageSize: number;\n};\n\n/** @public */\nexport const NotificationsTable = ({\n markAsReadOnLinkOpen,\n isLoading,\n notifications = [],\n isUnread,\n onUpdate,\n setContainsText,\n onPageChange,\n onRowsPerPageChange,\n page,\n pageSize,\n totalCount,\n}: NotificationsTableProps) => {\n const classes = useStyles();\n const notificationsApi = useApi(notificationsApiRef);\n const alertApi = useApi(alertApiRef);\n const confirm = useConfirm();\n\n const [selectedNotifications, setSelectedNotifications] = React.useState(\n new Set<Notification['id']>(),\n );\n\n const onNotificationsSelectChange = React.useCallback(\n (ids: Notification['id'][], checked: boolean) => {\n let newSelect: Set<Notification['id']>;\n if (checked) {\n newSelect = new Set([...selectedNotifications, ...ids]);\n } else {\n newSelect = new Set(selectedNotifications);\n ids.forEach(id => newSelect.delete(id));\n }\n setSelectedNotifications(newSelect);\n },\n [selectedNotifications, setSelectedNotifications],\n );\n\n const onSwitchReadStatus = React.useCallback(\n (ids: Notification['id'][], newStatus: boolean) => {\n notificationsApi\n .updateNotifications({\n ids,\n read: newStatus,\n })\n .then(onUpdate);\n },\n [notificationsApi, onUpdate],\n );\n\n const onSwitchSavedStatus = React.useCallback(\n (ids: Notification['id'][], newStatus: boolean) => {\n notificationsApi\n .updateNotifications({\n ids,\n saved: newStatus,\n })\n .then(onUpdate);\n },\n [notificationsApi, onUpdate],\n );\n\n const onMarkAllRead = React.useCallback(() => {\n confirm({\n title: 'Are you sure?',\n description: (\n <>\n Mark <b>all</b> notifications as <b>read</b>.\n </>\n ),\n confirmationText: 'Mark All',\n })\n .then(async () => {\n const ids = (\n await notificationsApi.getNotifications({ read: false })\n ).notifications?.map(notification => notification.id);\n\n return notificationsApi\n .updateNotifications({\n ids,\n read: true,\n })\n .then(onUpdate);\n })\n .catch(e => {\n if (e) {\n // if e === undefined, the Cancel button has been hit\n alertApi.post({\n message: 'Failed to mark all notifications as read',\n severity: 'error',\n });\n }\n });\n }, [alertApi, confirm, notificationsApi, onUpdate]);\n\n const throttledContainsTextHandler = React.useMemo(\n () => throttle(setContainsText, ThrottleDelayMs),\n [setContainsText],\n );\n\n React.useEffect(() => {\n const allShownIds = new Set(notifications.map(n => n.id));\n const intersect = [...selectedNotifications].filter(id =>\n allShownIds.has(id),\n );\n if (selectedNotifications.size !== intersect.length) {\n setSelectedNotifications(new Set(intersect));\n }\n }, [notifications, selectedNotifications]);\n\n const compactColumns = React.useMemo(\n (): TableColumn<Notification>[] => [\n {\n /* selection column */\n width: '1rem',\n title: (\n <SelectAll\n count={selectedNotifications.size}\n totalCount={notifications.length}\n onSelectAll={() =>\n onNotificationsSelectChange(\n notifications.map(notification => notification.id),\n selectedNotifications.size !== notifications.length,\n )\n }\n />\n ),\n render: (notification: Notification) => (\n <CheckBox\n color=\"primary\"\n checked={selectedNotifications.has(notification.id)}\n onChange={(_, checked) =>\n onNotificationsSelectChange([notification.id], checked)\n }\n />\n ),\n },\n {\n /* compact-data column */\n customFilterAndSearch: () =>\n true /* Keep sorting&filtering on backend due to pagination. */,\n render: (notification: Notification) => {\n // Compact content\n return (\n <Grid container>\n <Grid item className={classes.severityItem}>\n <SeverityIcon severity={notification.payload?.severity} />\n </Grid>\n <Grid item xs={11}>\n <Box>\n <Typography variant=\"subtitle2\">\n {notification.payload.link ? (\n <Link\n to={notification.payload.link}\n onClick={() => {\n if (markAsReadOnLinkOpen && !notification.read) {\n onSwitchReadStatus([notification.id], true);\n }\n }}\n >\n {notification.payload.title}\n </Link>\n ) : (\n notification.payload.title\n )}\n </Typography>\n {notification.payload.description ? (\n <Typography variant=\"body2\" className={classes.description}>\n {notification.payload.description}\n </Typography>\n ) : null}\n <Typography variant=\"caption\">\n {notification.origin && (\n <>{notification.origin}&nbsp;&bull;&nbsp;</>\n )}\n {notification.payload.topic && (\n <>{notification.payload.topic}&nbsp;&bull;&nbsp;</>\n )}\n {notification.created && (\n <RelativeTime value={notification.created} />\n )}\n </Typography>\n </Box>\n </Grid>\n </Grid>\n );\n },\n },\n {\n /* actions column */\n width: '1rem',\n title: (\n <BulkActions\n notifications={notifications}\n selectedNotifications={selectedNotifications}\n isUnread={isUnread}\n onSwitchReadStatus={onSwitchReadStatus}\n onSwitchSavedStatus={onSwitchSavedStatus}\n onMarkAllRead={onMarkAllRead}\n />\n ),\n render: (notification: Notification) => (\n <BulkActions\n notifications={[notification]}\n selectedNotifications={new Set([notification.id])}\n onSwitchReadStatus={onSwitchReadStatus}\n onSwitchSavedStatus={onSwitchSavedStatus}\n //\n />\n ),\n },\n ],\n [\n markAsReadOnLinkOpen,\n selectedNotifications,\n notifications,\n isUnread,\n onSwitchReadStatus,\n onSwitchSavedStatus,\n onMarkAllRead,\n onNotificationsSelectChange,\n classes.severityItem,\n classes.description,\n ],\n );\n\n return (\n <Table<Notification>\n isLoading={isLoading}\n options={{\n padding: 'dense',\n search: true,\n paging: true,\n pageSize,\n header: true,\n sorting: false,\n }}\n onPageChange={onPageChange}\n onRowsPerPageChange={onRowsPerPageChange}\n page={page}\n totalCount={totalCount}\n onSearchChange={throttledContainsTextHandler}\n data={notifications}\n columns={compactColumns}\n />\n );\n};\n"],"names":["CheckBox"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,MAAM,eAAkB,GAAA,GAAA,CAAA;AAExB,MAAM,YAAY,UAAW,CAAA;AAAA,EAC3B,WAAa,EAAA;AAAA,IACX,SAAW,EAAA,MAAA;AAAA,IACX,QAAU,EAAA,QAAA;AAAA,GACZ;AAAA,EACA,YAAc,EAAA;AAAA,IACZ,YAAc,EAAA,QAAA;AAAA,GAChB;AACF,CAAC,CAAA,CAAA;AAiBM,MAAM,qBAAqB,CAAC;AAAA,EACjC,oBAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAgB,EAAC;AAAA,EACjB,QAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,mBAAA;AAAA,EACA,IAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AACF,CAA+B,KAAA;AAC7B,EAAA,MAAM,UAAU,SAAU,EAAA,CAAA;AAC1B,EAAM,MAAA,gBAAA,GAAmB,OAAO,mBAAmB,CAAA,CAAA;AACnD,EAAM,MAAA,QAAA,GAAW,OAAO,WAAW,CAAA,CAAA;AACnC,EAAA,MAAM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AA;AAAA,WAAA;AAAA,SAEF;AAAA,OAEJ;AAAA,KACF;AAAA,IACA;AAAA,MACE,oBAAA;AAAA,MACA,qBAAA;AAAA,MACA,aAAA;AAAA,MACA,QAAA;AAAA,MACA,kBAAA;AAAA,MACA,mBAAA;AAAA,MACA,aAAA;AAAA,MACA,2BAAA;AAAA,MACA,OAAQ,CAAA,YAAA;AAAA,MACR,OAAQ,CAAA,WAAA;AAAA,KACV;AAAA,GACF,CAAA;AAEA,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,SAAA;AAAA,MACA,OAAS,EAAA;AAAA,QACP,OAAS,EAAA,OAAA;AAAA,QACT,MAAQ,EAAA,IAAA;AAAA,QACR,MAAQ,EAAA,IAAA;AAAA,QACR,QAAA;AAAA,QACA,MAAQ,EAAA,IAAA;AAAA,QACR,OAAS,EAAA,KAAA;AAAA,OACX;AAAA,MACA,YAAA;AAAA,MACA,mBAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAA;AAAA,MACA,cAAgB,EAAA,4BAAA;AAAA,MAChB,IAAM,EAAA,aAAA;AAAA,MACN,OAAS,EAAA,cAAA;AAAA,KAAA;AAAA,GACX,CAAA;AAEJ;;;;"}
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import Checkbox from '@material-ui/core/Checkbox';
3
+ import FormControlLabel from '@material-ui/core/FormControlLabel';
4
+ import { makeStyles } from '@material-ui/core/styles';
5
+
6
+ const useStyles = makeStyles({
7
+ label: {
8
+ marginLeft: "0px",
9
+ maxWidth: "2rem",
10
+ "& span": {
11
+ paddingRight: "0px"
12
+ }
13
+ }
14
+ });
15
+ const SelectAll = ({
16
+ count,
17
+ totalCount,
18
+ onSelectAll
19
+ }) => {
20
+ const classes = useStyles();
21
+ return /* @__PURE__ */ React.createElement(
22
+ FormControlLabel,
23
+ {
24
+ label: count > 0 ? `(${count})` : void 0,
25
+ className: classes.label,
26
+ control: /* @__PURE__ */ React.createElement(
27
+ Checkbox,
28
+ {
29
+ color: "primary",
30
+ disabled: !totalCount,
31
+ checked: count > 0,
32
+ indeterminate: count > 0 && totalCount !== count,
33
+ onChange: onSelectAll
34
+ }
35
+ )
36
+ }
37
+ );
38
+ };
39
+
40
+ export { SelectAll };
41
+ //# sourceMappingURL=SelectAll.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectAll.esm.js","sources":["../../../src/components/NotificationsTable/SelectAll.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';\nimport Checkbox from '@material-ui/core/Checkbox';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport { makeStyles } from '@material-ui/core/styles';\n\nconst useStyles = makeStyles({\n label: {\n marginLeft: '0px',\n maxWidth: '2rem',\n '& span': {\n paddingRight: '0px',\n },\n },\n});\n\nexport const SelectAll = ({\n count,\n totalCount,\n onSelectAll,\n}: {\n count: number;\n totalCount: number;\n onSelectAll: () => void;\n}) => {\n const classes = useStyles();\n\n return (\n <FormControlLabel\n label={count > 0 ? `(${count})` : undefined}\n className={classes.label}\n control={\n <Checkbox\n color=\"primary\"\n disabled={!totalCount}\n checked={count > 0}\n indeterminate={count > 0 && totalCount !== count}\n onChange={onSelectAll}\n />\n }\n />\n );\n};\n"],"names":[],"mappings":";;;;;AAoBA,MAAM,YAAY,UAAW,CAAA;AAAA,EAC3B,KAAO,EAAA;AAAA,IACL,UAAY,EAAA,KAAA;AAAA,IACZ,QAAU,EAAA,MAAA;AAAA,IACV,QAAU,EAAA;AAAA,MACR,YAAc,EAAA,KAAA;AAAA,KAChB;AAAA,GACF;AACF,CAAC,CAAA,CAAA;AAEM,MAAM,YAAY,CAAC;AAAA,EACxB,KAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AACF,CAIM,KAAA;AACJ,EAAA,MAAM,UAAU,SAAU,EAAA,CAAA;AAE1B,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,gBAAA;AAAA,IAAA;AAAA,MACC,KAAO,EAAA,KAAA,GAAQ,CAAI,GAAA,CAAA,CAAA,EAAI,KAAK,CAAM,CAAA,CAAA,GAAA,KAAA,CAAA;AAAA,MAClC,WAAW,OAAQ,CAAA,KAAA;AAAA,MACnB,OACE,kBAAA,KAAA,CAAA,aAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,KAAM,EAAA,SAAA;AAAA,UACN,UAAU,CAAC,UAAA;AAAA,UACX,SAAS,KAAQ,GAAA,CAAA;AAAA,UACjB,aAAA,EAAe,KAAQ,GAAA,CAAA,IAAK,UAAe,KAAA,KAAA;AAAA,UAC3C,QAAU,EAAA,WAAA;AAAA,SAAA;AAAA,OACZ;AAAA,KAAA;AAAA,GAEJ,CAAA;AAEJ;;;;"}
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import NormalIcon from '@material-ui/icons/CheckOutlined';
3
+ import CriticalIcon from '@material-ui/icons/ErrorOutline';
4
+ import HighIcon from '@material-ui/icons/WarningOutlined';
5
+ import LowIcon from '@material-ui/icons/InfoOutlined';
6
+ import { makeStyles } from '@material-ui/core/styles';
7
+
8
+ const useStyles = makeStyles((theme) => ({
9
+ critical: {
10
+ color: theme.palette.status.error
11
+ },
12
+ high: {
13
+ color: theme.palette.status.warning
14
+ },
15
+ normal: {
16
+ color: theme.palette.status.ok
17
+ },
18
+ low: {
19
+ color: theme.palette.status.running
20
+ }
21
+ }));
22
+ const SeverityIcon = ({
23
+ severity
24
+ }) => {
25
+ const classes = useStyles();
26
+ switch (severity) {
27
+ case "critical":
28
+ return /* @__PURE__ */ React.createElement(CriticalIcon, { className: classes.critical });
29
+ case "high":
30
+ return /* @__PURE__ */ React.createElement(HighIcon, { className: classes.high });
31
+ case "low":
32
+ return /* @__PURE__ */ React.createElement(LowIcon, { className: classes.low });
33
+ case "normal":
34
+ default:
35
+ return /* @__PURE__ */ React.createElement(NormalIcon, { className: classes.normal });
36
+ }
37
+ };
38
+
39
+ export { SeverityIcon };
40
+ //# sourceMappingURL=SeverityIcon.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SeverityIcon.esm.js","sources":["../../../src/components/NotificationsTable/SeverityIcon.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';\nimport { NotificationSeverity } from '@backstage/plugin-notifications-common';\nimport NormalIcon from '@material-ui/icons/CheckOutlined';\nimport CriticalIcon from '@material-ui/icons/ErrorOutline';\nimport HighIcon from '@material-ui/icons/WarningOutlined';\nimport LowIcon from '@material-ui/icons/InfoOutlined';\nimport { makeStyles } from '@material-ui/core/styles';\n\nconst useStyles = makeStyles(theme => ({\n critical: {\n color: theme.palette.status.error,\n },\n high: {\n color: theme.palette.status.warning,\n },\n normal: {\n color: theme.palette.status.ok,\n },\n low: {\n color: theme.palette.status.running,\n },\n}));\n\nexport const SeverityIcon = ({\n severity,\n}: {\n severity?: NotificationSeverity;\n}) => {\n const classes = useStyles();\n\n switch (severity) {\n case 'critical':\n return <CriticalIcon className={classes.critical} />;\n case 'high':\n return <HighIcon className={classes.high} />;\n case 'low':\n return <LowIcon className={classes.low} />;\n case 'normal':\n default:\n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