@backstage/plugin-notifications 0.5.12 → 0.5.13
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 +16 -0
- package/dist/alpha.d.ts +65 -3
- package/dist/alpha.esm.js +1 -0
- package/dist/alpha.esm.js.map +1 -1
- package/dist/components/NotificationsFilters/NotificationsFilters.esm.js +38 -33
- package/dist/components/NotificationsFilters/NotificationsFilters.esm.js.map +1 -1
- package/dist/components/NotificationsPage/NotificationsPage.esm.js +22 -8
- package/dist/components/NotificationsPage/NotificationsPage.esm.js.map +1 -1
- package/dist/components/NotificationsSideBarItem/NotificationsSideBarItem.esm.js.map +1 -1
- package/dist/components/NotificationsTable/BulkActions.esm.js +7 -3
- package/dist/components/NotificationsTable/BulkActions.esm.js.map +1 -1
- package/dist/components/NotificationsTable/NotificationsTable.esm.js +17 -1
- package/dist/components/NotificationsTable/NotificationsTable.esm.js.map +1 -1
- package/dist/components/UserNotificationSettingsCard/UserNotificationSettingsCard.esm.js +7 -6
- package/dist/components/UserNotificationSettingsCard/UserNotificationSettingsCard.esm.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/package.json.esm.js +1 -1
- package/dist/translation.esm.js +104 -0
- package/dist/translation.esm.js.map +1 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @backstage/plugin-notifications
|
|
2
2
|
|
|
3
|
+
## 0.5.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4452d15: Added i18n support.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/frontend-plugin-api@0.13.3
|
|
10
|
+
- @backstage/core-components@0.18.5
|
|
11
|
+
|
|
12
|
+
## 0.5.13-next.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @backstage/core-components@0.18.5-next.0
|
|
18
|
+
|
|
3
19
|
## 0.5.12
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/alpha.d.ts
CHANGED
|
@@ -1,7 +1,69 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
|
|
3
3
|
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
4
4
|
|
|
5
|
+
/** @alpha */
|
|
6
|
+
declare const notificationsTranslationRef: _backstage_frontend_plugin_api.TranslationRef<"plugin.notifications", {
|
|
7
|
+
readonly "table.errors.markAllReadFailed": "Failed to mark all notifications as read";
|
|
8
|
+
readonly "table.pagination.firstTooltip": "First Page";
|
|
9
|
+
readonly "table.pagination.labelDisplayedRows": "{from}-{to} of {count}";
|
|
10
|
+
readonly "table.pagination.labelRowsSelect": "rows";
|
|
11
|
+
readonly "table.pagination.lastTooltip": "Last Page";
|
|
12
|
+
readonly "table.pagination.nextTooltip": "Next Page";
|
|
13
|
+
readonly "table.pagination.previousTooltip": "Previous Page";
|
|
14
|
+
readonly "table.emptyMessage": "No records to display";
|
|
15
|
+
readonly "table.bulkActions.markAllRead": "Mark all read";
|
|
16
|
+
readonly "table.bulkActions.markSelectedAsRead": "Mark selected as read";
|
|
17
|
+
readonly "table.bulkActions.returnSelectedAmongUnread": "Return selected among unread";
|
|
18
|
+
readonly "table.bulkActions.saveSelectedForLater": "Save selected for later";
|
|
19
|
+
readonly "table.bulkActions.undoSaveForSelected": "Undo save for selected";
|
|
20
|
+
readonly "table.confirmDialog.title": "Are you sure?";
|
|
21
|
+
readonly "table.confirmDialog.markAllReadDescription": "Mark <b>all</b> notifications as <b>read</b>.";
|
|
22
|
+
readonly "table.confirmDialog.markAllReadConfirmation": "Mark All";
|
|
23
|
+
readonly "filters.view.all": "All";
|
|
24
|
+
readonly "filters.view.label": "View";
|
|
25
|
+
readonly "filters.view.read": "Read notifications";
|
|
26
|
+
readonly "filters.view.saved": "Saved";
|
|
27
|
+
readonly "filters.view.unread": "Unread notifications";
|
|
28
|
+
readonly "filters.title": "Filters";
|
|
29
|
+
readonly "filters.severity.normal": "Normal";
|
|
30
|
+
readonly "filters.severity.high": "High";
|
|
31
|
+
readonly "filters.severity.low": "Low";
|
|
32
|
+
readonly "filters.severity.label": "Min severity";
|
|
33
|
+
readonly "filters.severity.critical": "Critical";
|
|
34
|
+
readonly "filters.topic.label": "Topic";
|
|
35
|
+
readonly "filters.topic.anyTopic": "Any topic";
|
|
36
|
+
readonly "filters.createdAfter.label": "Sent out";
|
|
37
|
+
readonly "filters.createdAfter.placeholder": "Notifications since";
|
|
38
|
+
readonly "filters.createdAfter.last24h": "Last 24h";
|
|
39
|
+
readonly "filters.createdAfter.lastWeek": "Last week";
|
|
40
|
+
readonly "filters.createdAfter.anyTime": "Any time";
|
|
41
|
+
readonly "filters.sortBy.origin": "Origin";
|
|
42
|
+
readonly "filters.sortBy.label": "Sort by";
|
|
43
|
+
readonly "filters.sortBy.placeholder": "Field to sort by";
|
|
44
|
+
readonly "filters.sortBy.newest": "Newest on top";
|
|
45
|
+
readonly "filters.sortBy.oldest": "Oldest on top";
|
|
46
|
+
readonly "filters.sortBy.topic": "Topic";
|
|
47
|
+
readonly "settings.table.origin": "Origin";
|
|
48
|
+
readonly "settings.table.topic": "Topic";
|
|
49
|
+
readonly "settings.title": "Notification settings";
|
|
50
|
+
readonly "settings.errors.useNotificationFormat": "useNotificationFormat must be used within a NotificationFormatProvider";
|
|
51
|
+
readonly "settings.errorTitle": "Failed to load settings";
|
|
52
|
+
readonly "settings.noSettingsAvailable": "No notification settings available, check back later";
|
|
53
|
+
readonly "sidebar.title": "Notifications";
|
|
54
|
+
readonly "sidebar.errors.markAsReadFailed": "Failed to mark notification as read";
|
|
55
|
+
readonly "sidebar.errors.fetchNotificationFailed": "Failed to fetch notification";
|
|
56
|
+
readonly "notificationsPage.title": "Notifications";
|
|
57
|
+
readonly "notificationsPage.tableTitle.all_one": "All notifications ({{count}})";
|
|
58
|
+
readonly "notificationsPage.tableTitle.all_other": "All notifications ({{count}})";
|
|
59
|
+
readonly "notificationsPage.tableTitle.saved_one": "Saved notifications ({{count}})";
|
|
60
|
+
readonly "notificationsPage.tableTitle.saved_other": "Saved notifications ({{count}})";
|
|
61
|
+
readonly "notificationsPage.tableTitle.unread_one": "Unread notifications ({{count}})";
|
|
62
|
+
readonly "notificationsPage.tableTitle.unread_other": "Unread notifications ({{count}})";
|
|
63
|
+
readonly "notificationsPage.tableTitle.read_one": "Read notifications ({{count}})";
|
|
64
|
+
readonly "notificationsPage.tableTitle.read_other": "Read notifications ({{count}})";
|
|
65
|
+
}>;
|
|
66
|
+
|
|
5
67
|
/** @alpha */
|
|
6
68
|
declare const _default: _backstage_frontend_plugin_api.OverridableFrontendPlugin<{
|
|
7
69
|
root: _backstage_core_plugin_api.RouteRef<undefined>;
|
|
@@ -24,7 +86,7 @@ declare const _default: _backstage_frontend_plugin_api.OverridableFrontendPlugin
|
|
|
24
86
|
configInput: {
|
|
25
87
|
path?: string | undefined;
|
|
26
88
|
};
|
|
27
|
-
output: _backstage_frontend_plugin_api.ExtensionDataRef<string, "core.routing.path", {}> | _backstage_frontend_plugin_api.ExtensionDataRef<
|
|
89
|
+
output: _backstage_frontend_plugin_api.ExtensionDataRef<string, "core.routing.path", {}> | _backstage_frontend_plugin_api.ExtensionDataRef<react.JSX.Element, "core.reactElement", {}> | _backstage_frontend_plugin_api.ExtensionDataRef<_backstage_frontend_plugin_api.RouteRef<_backstage_frontend_plugin_api.AnyRouteRefParams>, "core.routing.ref", {
|
|
28
90
|
optional: true;
|
|
29
91
|
}>;
|
|
30
92
|
inputs: {};
|
|
@@ -37,4 +99,4 @@ declare const _default: _backstage_frontend_plugin_api.OverridableFrontendPlugin
|
|
|
37
99
|
}>;
|
|
38
100
|
}>;
|
|
39
101
|
|
|
40
|
-
export { _default as default };
|
|
102
|
+
export { _default as default, notificationsTranslationRef };
|
package/dist/alpha.esm.js
CHANGED
|
@@ -3,6 +3,7 @@ import { PageBlueprint, ApiBlueprint, fetchApiRef, discoveryApiRef, createFronte
|
|
|
3
3
|
import { rootRouteRef } from './routes.esm.js';
|
|
4
4
|
import { notificationsApiRef } from './api/NotificationsApi.esm.js';
|
|
5
5
|
import { NotificationsClient } from './api/NotificationsClient.esm.js';
|
|
6
|
+
export { notificationsTranslationRef } from './translation.esm.js';
|
|
6
7
|
|
|
7
8
|
const page = PageBlueprint.make({
|
|
8
9
|
params: {
|
package/dist/alpha.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alpha.esm.js","sources":["../src/alpha.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 {\n ApiBlueprint,\n PageBlueprint,\n createFrontendPlugin,\n discoveryApiRef,\n fetchApiRef,\n} from '@backstage/frontend-plugin-api';\nimport { rootRouteRef } from './routes';\nimport { NotificationsClient, notificationsApiRef } from './api';\n\nconst page = PageBlueprint.make({\n params: {\n path: '/notifications',\n routeRef: rootRouteRef,\n loader: () =>\n import('./components/NotificationsPage').then(m => (\n <m.NotificationsPage />\n )),\n },\n});\n\nconst api = ApiBlueprint.make({\n params: defineParams =>\n defineParams({\n api: notificationsApiRef,\n deps: { discoveryApi: discoveryApiRef, fetchApi: fetchApiRef },\n factory: ({ discoveryApi, fetchApi }) =>\n new NotificationsClient({ discoveryApi, fetchApi }),\n }),\n});\n\n/** @alpha */\nexport default createFrontendPlugin({\n pluginId: 'notifications',\n info: { packageJson: () => import('../package.json') },\n routes: {\n root: rootRouteRef,\n },\n // TODO(Rugvip): Nav item (i.e. NotificationsSidebarItem) currently needs to be installed manually\n extensions: [page, api],\n});\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"alpha.esm.js","sources":["../src/alpha.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 {\n ApiBlueprint,\n PageBlueprint,\n createFrontendPlugin,\n discoveryApiRef,\n fetchApiRef,\n} from '@backstage/frontend-plugin-api';\nimport { rootRouteRef } from './routes';\nimport { NotificationsClient, notificationsApiRef } from './api';\n\nconst page = PageBlueprint.make({\n params: {\n path: '/notifications',\n routeRef: rootRouteRef,\n loader: () =>\n import('./components/NotificationsPage').then(m => (\n <m.NotificationsPage />\n )),\n },\n});\n\nconst api = ApiBlueprint.make({\n params: defineParams =>\n defineParams({\n api: notificationsApiRef,\n deps: { discoveryApi: discoveryApiRef, fetchApi: fetchApiRef },\n factory: ({ discoveryApi, fetchApi }) =>\n new NotificationsClient({ discoveryApi, fetchApi }),\n }),\n});\n\n/** @alpha */\nexport default createFrontendPlugin({\n pluginId: 'notifications',\n info: { packageJson: () => import('../package.json') },\n routes: {\n root: rootRouteRef,\n },\n // TODO(Rugvip): Nav item (i.e. NotificationsSidebarItem) currently needs to be installed manually\n extensions: [page, api],\n});\n\nexport { notificationsTranslationRef } from './translation';\n"],"names":[],"mappings":";;;;;;;AA0BA,MAAM,IAAA,GAAO,cAAc,IAAA,CAAK;AAAA,EAC9B,MAAA,EAAQ;AAAA,IACN,IAAA,EAAM,gBAAA;AAAA,IACN,QAAA,EAAU,YAAA;AAAA,IACV,MAAA,EAAQ,MACN,OAAO,6CAAgC,CAAA,CAAE,IAAA,CAAK,CAAA,CAAA,qBAC5C,GAAA,CAAC,CAAA,CAAE,iBAAA,EAAF,EAAoB,CACtB;AAAA;AAEP,CAAC,CAAA;AAED,MAAM,GAAA,GAAM,aAAa,IAAA,CAAK;AAAA,EAC5B,MAAA,EAAQ,kBACN,YAAA,CAAa;AAAA,IACX,GAAA,EAAK,mBAAA;AAAA,IACL,IAAA,EAAM,EAAE,YAAA,EAAc,eAAA,EAAiB,UAAU,WAAA,EAAY;AAAA,IAC7D,OAAA,EAAS,CAAC,EAAE,YAAA,EAAc,QAAA,EAAS,KACjC,IAAI,mBAAA,CAAoB,EAAE,YAAA,EAAc,QAAA,EAAU;AAAA,GACrD;AACL,CAAC,CAAA;AAGD,YAAe,oBAAA,CAAqB;AAAA,EAClC,QAAA,EAAU,eAAA;AAAA,EACV,MAAM,EAAE,WAAA,EAAa,MAAM,OAAO,uBAAiB,CAAA,EAAE;AAAA,EACrD,MAAA,EAAQ;AAAA,IACN,IAAA,EAAM;AAAA,GACR;AAAA;AAAA,EAEA,UAAA,EAAY,CAAC,IAAA,EAAM,GAAG;AACxB,CAAC,CAAA;;;;"}
|
|
@@ -1,49 +1,53 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import FormControl from '@material-ui/core/FormControl';
|
|
3
|
+
import Divider from '@material-ui/core/Divider';
|
|
3
4
|
import Grid from '@material-ui/core/Grid';
|
|
4
5
|
import InputLabel from '@material-ui/core/InputLabel';
|
|
5
6
|
import MenuItem from '@material-ui/core/MenuItem';
|
|
6
7
|
import Select from '@material-ui/core/Select';
|
|
8
|
+
import Typography from '@material-ui/core/Typography';
|
|
9
|
+
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
10
|
+
import { notificationsTranslationRef } from '../../translation.esm.js';
|
|
7
11
|
|
|
8
12
|
const ALL = "___all___";
|
|
9
13
|
const CreatedAfterOptions = {
|
|
10
14
|
last24h: {
|
|
11
|
-
|
|
15
|
+
labelKey: "filters.createdAfter.last24h",
|
|
12
16
|
getDate: () => new Date(Date.now() - 24 * 3600 * 1e3)
|
|
13
17
|
},
|
|
14
18
|
lastWeek: {
|
|
15
|
-
|
|
19
|
+
labelKey: "filters.createdAfter.lastWeek",
|
|
16
20
|
getDate: () => new Date(Date.now() - 7 * 24 * 3600 * 1e3)
|
|
17
21
|
},
|
|
18
22
|
all: {
|
|
19
|
-
|
|
23
|
+
labelKey: "filters.createdAfter.anyTime",
|
|
20
24
|
getDate: () => /* @__PURE__ */ new Date(0)
|
|
21
25
|
}
|
|
22
26
|
};
|
|
23
27
|
const SortByOptions = {
|
|
24
28
|
newest: {
|
|
25
|
-
|
|
29
|
+
labelKey: "filters.sortBy.newest",
|
|
26
30
|
sortBy: {
|
|
27
31
|
sort: "created",
|
|
28
32
|
sortOrder: "desc"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
oldest: {
|
|
32
|
-
|
|
36
|
+
labelKey: "filters.sortBy.oldest",
|
|
33
37
|
sortBy: {
|
|
34
38
|
sort: "created",
|
|
35
39
|
sortOrder: "asc"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
topic: {
|
|
39
|
-
|
|
43
|
+
labelKey: "filters.sortBy.topic",
|
|
40
44
|
sortBy: {
|
|
41
45
|
sort: "topic",
|
|
42
46
|
sortOrder: "asc"
|
|
43
47
|
}
|
|
44
48
|
},
|
|
45
49
|
origin: {
|
|
46
|
-
|
|
50
|
+
labelKey: "filters.sortBy.origin",
|
|
47
51
|
sortBy: {
|
|
48
52
|
sort: "origin",
|
|
49
53
|
sortOrder: "asc"
|
|
@@ -62,12 +66,6 @@ const getSortByText = (sortBy) => {
|
|
|
62
66
|
}
|
|
63
67
|
return "newest";
|
|
64
68
|
};
|
|
65
|
-
const AllSeverityOptions = {
|
|
66
|
-
critical: "Critical",
|
|
67
|
-
high: "High",
|
|
68
|
-
normal: "Normal",
|
|
69
|
-
low: "Low"
|
|
70
|
-
};
|
|
71
69
|
const NotificationsFilters = ({
|
|
72
70
|
sorting,
|
|
73
71
|
onSortingChanged,
|
|
@@ -83,6 +81,7 @@ const NotificationsFilters = ({
|
|
|
83
81
|
onTopicChanged,
|
|
84
82
|
allTopics
|
|
85
83
|
}) => {
|
|
84
|
+
const { t } = useTranslationRef(notificationsTranslationRef);
|
|
86
85
|
const sortByText = getSortByText(sorting);
|
|
87
86
|
const handleOnCreatedAfterChanged = (event) => {
|
|
88
87
|
onCreatedAfterChanged(event.target.value);
|
|
@@ -125,76 +124,82 @@ const NotificationsFilters = ({
|
|
|
125
124
|
};
|
|
126
125
|
const sortedAllTopics = (allTopics || []).sort((a, b) => a.localeCompare(b));
|
|
127
126
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Grid, { container: true, children: [
|
|
127
|
+
/* @__PURE__ */ jsxs(Grid, { item: true, xs: 12, children: [
|
|
128
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h6", children: t("filters.title") }),
|
|
129
|
+
/* @__PURE__ */ jsx(Divider, { variant: "fullWidth" })
|
|
130
|
+
] }),
|
|
128
131
|
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsxs(FormControl, { fullWidth: true, variant: "outlined", size: "small", children: [
|
|
129
|
-
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-view", children: "
|
|
132
|
+
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-view", children: t("filters.view.label") }),
|
|
130
133
|
/* @__PURE__ */ jsxs(
|
|
131
134
|
Select,
|
|
132
135
|
{
|
|
133
136
|
labelId: "notifications-filter-view",
|
|
134
|
-
label: "
|
|
137
|
+
label: t("filters.view.label"),
|
|
135
138
|
value: viewValue,
|
|
136
139
|
onChange: handleOnViewChanged,
|
|
137
140
|
children: [
|
|
138
|
-
/* @__PURE__ */ jsx(MenuItem, { value: "unread", children: "
|
|
139
|
-
/* @__PURE__ */ jsx(MenuItem, { value: "read", children: "
|
|
140
|
-
/* @__PURE__ */ jsx(MenuItem, { value: "saved", children: "
|
|
141
|
-
/* @__PURE__ */ jsx(MenuItem, { value: "all", children: "
|
|
141
|
+
/* @__PURE__ */ jsx(MenuItem, { value: "unread", children: t("filters.view.unread") }),
|
|
142
|
+
/* @__PURE__ */ jsx(MenuItem, { value: "read", children: t("filters.view.read") }),
|
|
143
|
+
/* @__PURE__ */ jsx(MenuItem, { value: "saved", children: t("filters.view.saved") }),
|
|
144
|
+
/* @__PURE__ */ jsx(MenuItem, { value: "all", children: t("filters.view.all") })
|
|
142
145
|
]
|
|
143
146
|
}
|
|
144
147
|
)
|
|
145
148
|
] }) }),
|
|
146
149
|
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsxs(FormControl, { fullWidth: true, variant: "outlined", size: "small", children: [
|
|
147
|
-
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-created", children: "
|
|
150
|
+
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-created", children: t("filters.createdAfter.label") }),
|
|
148
151
|
/* @__PURE__ */ jsx(
|
|
149
152
|
Select,
|
|
150
153
|
{
|
|
151
|
-
label: "
|
|
154
|
+
label: t("filters.createdAfter.label"),
|
|
152
155
|
labelId: "notifications-filter-created",
|
|
153
|
-
placeholder: "
|
|
156
|
+
placeholder: t("filters.createdAfter.placeholder"),
|
|
154
157
|
value: createdAfter,
|
|
155
158
|
onChange: handleOnCreatedAfterChanged,
|
|
156
|
-
children: Object.keys(CreatedAfterOptions).map((key) => /* @__PURE__ */ jsx(MenuItem, { value: key, children:
|
|
159
|
+
children: Object.keys(CreatedAfterOptions).map((key) => /* @__PURE__ */ jsx(MenuItem, { value: key, children: t(
|
|
160
|
+
CreatedAfterOptions[key].labelKey
|
|
161
|
+
) }, key))
|
|
157
162
|
}
|
|
158
163
|
)
|
|
159
164
|
] }) }),
|
|
160
165
|
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsxs(FormControl, { fullWidth: true, variant: "outlined", size: "small", children: [
|
|
161
|
-
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-sort", children: "
|
|
166
|
+
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-sort", children: t("filters.sortBy.label") }),
|
|
162
167
|
/* @__PURE__ */ jsx(
|
|
163
168
|
Select,
|
|
164
169
|
{
|
|
165
|
-
label: "
|
|
170
|
+
label: t("filters.sortBy.label"),
|
|
166
171
|
labelId: "notifications-filter-sort",
|
|
167
|
-
placeholder: "
|
|
172
|
+
placeholder: t("filters.sortBy.placeholder"),
|
|
168
173
|
value: sortByText,
|
|
169
174
|
onChange: handleOnSortByChanged,
|
|
170
|
-
children: Object.keys(SortByOptions).map((key) => /* @__PURE__ */ jsx(MenuItem, { value: key, children: SortByOptions[key].
|
|
175
|
+
children: Object.keys(SortByOptions).map((key) => /* @__PURE__ */ jsx(MenuItem, { value: key, children: t(SortByOptions[key].labelKey) }, key))
|
|
171
176
|
}
|
|
172
177
|
)
|
|
173
178
|
] }) }),
|
|
174
179
|
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsxs(FormControl, { fullWidth: true, variant: "outlined", size: "small", children: [
|
|
175
|
-
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-severity", children: "
|
|
180
|
+
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-severity", children: t("filters.severity.label") }),
|
|
176
181
|
/* @__PURE__ */ jsx(
|
|
177
182
|
Select,
|
|
178
183
|
{
|
|
179
|
-
label: "
|
|
184
|
+
label: t("filters.severity.label"),
|
|
180
185
|
labelId: "notifications-filter-severity",
|
|
181
186
|
value: severity,
|
|
182
187
|
onChange: handleOnSeverityChanged,
|
|
183
|
-
children:
|
|
188
|
+
children: ["critical", "high", "normal", "low"].map((key) => /* @__PURE__ */ jsx(MenuItem, { value: key, children: t(`filters.severity.${key}`) }, key))
|
|
184
189
|
}
|
|
185
190
|
)
|
|
186
191
|
] }) }),
|
|
187
192
|
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsxs(FormControl, { fullWidth: true, variant: "outlined", size: "small", children: [
|
|
188
|
-
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-topic", children: "
|
|
193
|
+
/* @__PURE__ */ jsx(InputLabel, { id: "notifications-filter-topic", children: t("filters.topic.label") }),
|
|
189
194
|
/* @__PURE__ */ jsxs(
|
|
190
195
|
Select,
|
|
191
196
|
{
|
|
192
|
-
label: "
|
|
197
|
+
label: t("filters.topic.label"),
|
|
193
198
|
labelId: "notifications-filter-topic",
|
|
194
199
|
value: topic ?? ALL,
|
|
195
200
|
onChange: handleOnTopicChanged,
|
|
196
201
|
children: [
|
|
197
|
-
/* @__PURE__ */ jsx(MenuItem, { value: ALL, children: "
|
|
202
|
+
/* @__PURE__ */ jsx(MenuItem, { value: ALL, children: t("filters.topic.anyTopic") }, ALL),
|
|
198
203
|
sortedAllTopics.map((item) => /* @__PURE__ */ jsx(MenuItem, { value: item, children: item }, item))
|
|
199
204
|
]
|
|
200
205
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsFilters.esm.js","sources":["../../../src/components/NotificationsFilters/NotificationsFilters.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ChangeEvent } from 'react';\nimport FormControl from '@material-ui/core/FormControl';\nimport Grid from '@material-ui/core/Grid';\nimport InputLabel from '@material-ui/core/InputLabel';\nimport MenuItem from '@material-ui/core/MenuItem';\nimport Select from '@material-ui/core/Select';\nimport { GetNotificationsOptions } from '../../api';\nimport { NotificationSeverity } from '@backstage/plugin-notifications-common';\n\nexport type SortBy = Required<\n Pick<GetNotificationsOptions, 'sort' | 'sortOrder'>\n>;\n\nexport type NotificationsFiltersProps = {\n unreadOnly?: boolean;\n onUnreadOnlyChanged: (checked: boolean | undefined) => void;\n createdAfter?: string;\n onCreatedAfterChanged: (value: string) => void;\n sorting: SortBy;\n onSortingChanged: (sortBy: SortBy) => void;\n saved?: boolean;\n onSavedChanged: (checked: boolean | undefined) => void;\n severity: NotificationSeverity;\n onSeverityChanged: (severity: NotificationSeverity) => void;\n topic?: string;\n onTopicChanged: (value: string | undefined) => void;\n allTopics?: string[];\n};\n\nconst ALL = '___all___';\n\nexport const CreatedAfterOptions: {\n [key: string]: { label: string; getDate: () => Date };\n} = {\n last24h: {\n label: 'Last 24h',\n getDate: () => new Date(Date.now() - 24 * 3600 * 1000),\n },\n lastWeek: {\n label: 'Last week',\n getDate: () => new Date(Date.now() - 7 * 24 * 3600 * 1000),\n },\n all: {\n label: 'Any time',\n getDate: () => new Date(0),\n },\n};\n\nexport const SortByOptions: {\n [key: string]: {\n label: string;\n sortBy: SortBy;\n };\n} = {\n newest: {\n label: 'Newest on top',\n sortBy: {\n sort: 'created',\n sortOrder: 'desc',\n },\n },\n oldest: {\n label: 'Oldest on top',\n sortBy: {\n sort: 'created',\n sortOrder: 'asc',\n },\n },\n topic: {\n label: 'Topic',\n sortBy: {\n sort: 'topic',\n sortOrder: 'asc',\n },\n },\n origin: {\n label: 'Origin',\n sortBy: {\n sort: 'origin',\n sortOrder: 'asc',\n },\n },\n};\n\nconst getSortByText = (sortBy?: SortBy): string => {\n if (sortBy?.sort === 'created' && sortBy?.sortOrder === 'asc') {\n return 'oldest';\n }\n if (sortBy?.sort === 'topic') {\n return 'topic';\n }\n if (sortBy?.sort === 'origin') {\n return 'origin';\n }\n\n return 'newest';\n};\n\nconst AllSeverityOptions: { [key in NotificationSeverity]: string } = {\n critical: 'Critical',\n high: 'High',\n normal: 'Normal',\n low: 'Low',\n};\n\nexport const NotificationsFilters = ({\n sorting,\n onSortingChanged,\n unreadOnly,\n onUnreadOnlyChanged,\n createdAfter,\n onCreatedAfterChanged,\n saved,\n onSavedChanged,\n severity,\n onSeverityChanged,\n topic,\n onTopicChanged,\n allTopics,\n}: NotificationsFiltersProps) => {\n const sortByText = getSortByText(sorting);\n\n const handleOnCreatedAfterChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n onCreatedAfterChanged(event.target.value as string);\n };\n\n const handleOnViewChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n if (event.target.value === 'unread') {\n onUnreadOnlyChanged(true);\n onSavedChanged(undefined);\n } else if (event.target.value === 'read') {\n onUnreadOnlyChanged(false);\n onSavedChanged(undefined);\n } else if (event.target.value === 'saved') {\n onUnreadOnlyChanged(undefined);\n onSavedChanged(true);\n } else {\n // All\n onUnreadOnlyChanged(undefined);\n onSavedChanged(undefined);\n }\n };\n\n const handleOnSortByChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const idx = (event.target.value as string) || 'newest';\n const option = SortByOptions[idx];\n onSortingChanged({ ...option.sortBy });\n };\n\n let viewValue = 'all';\n if (saved) {\n viewValue = 'saved';\n } else if (unreadOnly) {\n viewValue = 'unread';\n } else if (unreadOnly === false) {\n viewValue = 'read';\n }\n\n const handleOnSeverityChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const value: NotificationSeverity =\n (event.target.value as NotificationSeverity) || 'normal';\n onSeverityChanged(value);\n };\n\n const handleOnTopicChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const value = event.target.value as string;\n onTopicChanged(value === ALL ? undefined : value);\n };\n\n const sortedAllTopics = (allTopics || []).sort((a, b) => a.localeCompare(b));\n\n return (\n <>\n <Grid container>\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-view\">View</InputLabel>\n <Select\n labelId=\"notifications-filter-view\"\n label=\"View\"\n value={viewValue}\n onChange={handleOnViewChanged}\n >\n <MenuItem value=\"unread\">Unread notifications</MenuItem>\n <MenuItem value=\"read\">Read notifications</MenuItem>\n <MenuItem value=\"saved\">Saved</MenuItem>\n <MenuItem value=\"all\">All</MenuItem>\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-created\">Sent out</InputLabel>\n\n <Select\n label=\"Sent out\"\n labelId=\"notifications-filter-created\"\n placeholder=\"Notifications since\"\n value={createdAfter}\n onChange={handleOnCreatedAfterChanged}\n >\n {Object.keys(CreatedAfterOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {CreatedAfterOptions[key].label}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-sort\">Sort by</InputLabel>\n\n <Select\n label=\"Sort by\"\n labelId=\"notifications-filter-sort\"\n placeholder=\"Field to sort by\"\n value={sortByText}\n onChange={handleOnSortByChanged}\n >\n {Object.keys(SortByOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {SortByOptions[key].label}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-severity\">\n Min severity\n </InputLabel>\n\n <Select\n label=\"Min severity\"\n labelId=\"notifications-filter-severity\"\n value={severity}\n onChange={handleOnSeverityChanged}\n >\n {Object.keys(AllSeverityOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {AllSeverityOptions[key as NotificationSeverity]}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-topic\">Topic</InputLabel>\n\n <Select\n label=\"Topic\"\n labelId=\"notifications-filter-topic\"\n value={topic ?? ALL}\n onChange={handleOnTopicChanged}\n >\n <MenuItem value={ALL} key={ALL}>\n Any topic\n </MenuItem>\n\n {sortedAllTopics.map((item: string) => (\n <MenuItem value={item} key={item}>\n {item}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;AA4CA,MAAM,GAAA,GAAM,WAAA;AAEL,MAAM,mBAAA,GAET;AAAA,EACF,OAAA,EAAS;AAAA,IACP,KAAA,EAAO,UAAA;AAAA,IACP,OAAA,EAAS,MAAM,IAAI,IAAA,CAAK,KAAK,GAAA,EAAI,GAAI,EAAA,GAAK,IAAA,GAAO,GAAI;AAAA,GACvD;AAAA,EACA,QAAA,EAAU;AAAA,IACR,KAAA,EAAO,WAAA;AAAA,IACP,OAAA,EAAS,MAAM,IAAI,IAAA,CAAK,IAAA,CAAK,KAAI,GAAI,CAAA,GAAI,EAAA,GAAK,IAAA,GAAO,GAAI;AAAA,GAC3D;AAAA,EACA,GAAA,EAAK;AAAA,IACH,KAAA,EAAO,UAAA;AAAA,IACP,OAAA,EAAS,sBAAM,IAAI,IAAA,CAAK,CAAC;AAAA;AAE7B;AAEO,MAAM,aAAA,GAKT;AAAA,EACF,MAAA,EAAQ;AAAA,IACN,KAAA,EAAO,eAAA;AAAA,IACP,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,SAAA;AAAA,MACN,SAAA,EAAW;AAAA;AACb,GACF;AAAA,EACA,MAAA,EAAQ;AAAA,IACN,KAAA,EAAO,eAAA;AAAA,IACP,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,SAAA;AAAA,MACN,SAAA,EAAW;AAAA;AACb,GACF;AAAA,EACA,KAAA,EAAO;AAAA,IACL,K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;AAAA;AACH,KAAA,EACF,CAAA,EACF,CAAA;AAAA,oBAEA,GAAA,CAAC,IAAA,EAAA,EAAK,IAAA,EAAI,IAAA,EAAC,EAAA,EAAI,EAAA,EACb,QAAA,kBAAA,IAAA,CAAC,WAAA,EAAA,EAAY,SAAA,EAAS,IAAA,EAAC,OAAA,EAAQ,UAAA,EAAW,MAAK,OAAA,EAC7C,QAAA,EAAA;AAAA,sBAAA,GAAA,CAAC,UAAA,EAAA,EAAW,EAAA,EAAG,4BAAA,EAA6B,QAAA,EAAA,OAAA,EAAK,CAAA;AAAA,sBAEjD,IAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAM,OAAA;AAAA,UACN,OAAA,EAAQ,4BAAA;AAAA,UACR,OAAO,KAAA,IAAS,GAAA;AAAA,UAChB,QAAA,EAAU,oBAAA;AAAA,UAEV,QAAA,EAAA;AAAA,4BAAA,GAAA,CAAC,QAAA,EAAA,EAAS,KAAA,EAAO,GAAA,EAAe,QAAA,EAAA,WAAA,EAAA,EAAL,GAE3B,CAAA;AAAA,YAEC,eAAA,CAAgB,GAAA,CAAI,CAAC,IAAA,qBACpB,GAAA,CAAC,YAAS,KAAA,EAAO,IAAA,EACd,QAAA,EAAA,IAAA,EAAA,EADyB,IAE5B,CACD;AAAA;AAAA;AAAA;AACH,KAAA,EACF,CAAA,EACF;AAAA,GAAA,EACF,CAAA,EACF,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"NotificationsFilters.esm.js","sources":["../../../src/components/NotificationsFilters/NotificationsFilters.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ChangeEvent } from 'react';\nimport FormControl from '@material-ui/core/FormControl';\nimport Divider from '@material-ui/core/Divider';\nimport Grid from '@material-ui/core/Grid';\nimport InputLabel from '@material-ui/core/InputLabel';\nimport MenuItem from '@material-ui/core/MenuItem';\nimport Select from '@material-ui/core/Select';\nimport Typography from '@material-ui/core/Typography';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { notificationsTranslationRef } from '../../translation';\nimport { GetNotificationsOptions } from '../../api';\nimport { NotificationSeverity } from '@backstage/plugin-notifications-common';\n\nexport type SortBy = Required<\n Pick<GetNotificationsOptions, 'sort' | 'sortOrder'>\n>;\n\nexport type NotificationsFiltersProps = {\n unreadOnly?: boolean;\n onUnreadOnlyChanged: (checked: boolean | undefined) => void;\n createdAfter?: string;\n onCreatedAfterChanged: (value: string) => void;\n sorting: SortBy;\n onSortingChanged: (sortBy: SortBy) => void;\n saved?: boolean;\n onSavedChanged: (checked: boolean | undefined) => void;\n severity: NotificationSeverity;\n onSeverityChanged: (severity: NotificationSeverity) => void;\n topic?: string;\n onTopicChanged: (value: string | undefined) => void;\n allTopics?: string[];\n};\n\nconst ALL = '___all___';\n\ntype TranslationKey = keyof (typeof notificationsTranslationRef)['T'];\n\nexport const CreatedAfterOptions = {\n last24h: {\n labelKey: 'filters.createdAfter.last24h' satisfies TranslationKey,\n getDate: () => new Date(Date.now() - 24 * 3600 * 1000),\n },\n lastWeek: {\n labelKey: 'filters.createdAfter.lastWeek' satisfies TranslationKey,\n getDate: () => new Date(Date.now() - 7 * 24 * 3600 * 1000),\n },\n all: {\n labelKey: 'filters.createdAfter.anyTime' satisfies TranslationKey,\n getDate: () => new Date(0),\n },\n} as const;\n\nexport const SortByOptions = {\n newest: {\n labelKey: 'filters.sortBy.newest' satisfies TranslationKey,\n sortBy: {\n sort: 'created' as const,\n sortOrder: 'desc' as const,\n },\n },\n oldest: {\n labelKey: 'filters.sortBy.oldest' satisfies TranslationKey,\n sortBy: {\n sort: 'created' as const,\n sortOrder: 'asc' as const,\n },\n },\n topic: {\n labelKey: 'filters.sortBy.topic' satisfies TranslationKey,\n sortBy: {\n sort: 'topic' as const,\n sortOrder: 'asc' as const,\n },\n },\n origin: {\n labelKey: 'filters.sortBy.origin' satisfies TranslationKey,\n sortBy: {\n sort: 'origin' as const,\n sortOrder: 'asc' as const,\n },\n },\n} as const;\n\nconst getSortByText = (sortBy?: SortBy): string => {\n if (sortBy?.sort === 'created' && sortBy?.sortOrder === 'asc') {\n return 'oldest';\n }\n if (sortBy?.sort === 'topic') {\n return 'topic';\n }\n if (sortBy?.sort === 'origin') {\n return 'origin';\n }\n\n return 'newest';\n};\n\nexport const NotificationsFilters = ({\n sorting,\n onSortingChanged,\n unreadOnly,\n onUnreadOnlyChanged,\n createdAfter,\n onCreatedAfterChanged,\n saved,\n onSavedChanged,\n severity,\n onSeverityChanged,\n topic,\n onTopicChanged,\n allTopics,\n}: NotificationsFiltersProps) => {\n const { t } = useTranslationRef(notificationsTranslationRef);\n const sortByText = getSortByText(sorting);\n\n const handleOnCreatedAfterChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n onCreatedAfterChanged(event.target.value as string);\n };\n\n const handleOnViewChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n if (event.target.value === 'unread') {\n onUnreadOnlyChanged(true);\n onSavedChanged(undefined);\n } else if (event.target.value === 'read') {\n onUnreadOnlyChanged(false);\n onSavedChanged(undefined);\n } else if (event.target.value === 'saved') {\n onUnreadOnlyChanged(undefined);\n onSavedChanged(true);\n } else {\n // All\n onUnreadOnlyChanged(undefined);\n onSavedChanged(undefined);\n }\n };\n\n const handleOnSortByChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const idx = ((event.target.value as string) ||\n 'newest') as keyof typeof SortByOptions;\n const option = SortByOptions[idx];\n onSortingChanged({ ...option.sortBy });\n };\n\n let viewValue = 'all';\n if (saved) {\n viewValue = 'saved';\n } else if (unreadOnly) {\n viewValue = 'unread';\n } else if (unreadOnly === false) {\n viewValue = 'read';\n }\n\n const handleOnSeverityChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const value: NotificationSeverity =\n (event.target.value as NotificationSeverity) || 'normal';\n onSeverityChanged(value);\n };\n\n const handleOnTopicChanged = (\n event: ChangeEvent<{ name?: string; value: unknown }>,\n ) => {\n const value = event.target.value as string;\n onTopicChanged(value === ALL ? undefined : value);\n };\n\n const sortedAllTopics = (allTopics || []).sort((a, b) => a.localeCompare(b));\n\n return (\n <>\n <Grid container>\n <Grid item xs={12}>\n <Typography variant=\"h6\">{t('filters.title')}</Typography>\n <Divider variant=\"fullWidth\" />\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-view\">\n {t('filters.view.label')}\n </InputLabel>\n <Select\n labelId=\"notifications-filter-view\"\n label={t('filters.view.label')}\n value={viewValue}\n onChange={handleOnViewChanged}\n >\n <MenuItem value=\"unread\">{t('filters.view.unread')}</MenuItem>\n <MenuItem value=\"read\">{t('filters.view.read')}</MenuItem>\n <MenuItem value=\"saved\">{t('filters.view.saved')}</MenuItem>\n <MenuItem value=\"all\">{t('filters.view.all')}</MenuItem>\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-created\">\n {t('filters.createdAfter.label')}\n </InputLabel>\n\n <Select\n label={t('filters.createdAfter.label')}\n labelId=\"notifications-filter-created\"\n placeholder={t('filters.createdAfter.placeholder')}\n value={createdAfter}\n onChange={handleOnCreatedAfterChanged}\n >\n {Object.keys(CreatedAfterOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {t(\n CreatedAfterOptions[key as keyof typeof CreatedAfterOptions]\n .labelKey,\n )}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-sort\">\n {t('filters.sortBy.label')}\n </InputLabel>\n\n <Select\n label={t('filters.sortBy.label')}\n labelId=\"notifications-filter-sort\"\n placeholder={t('filters.sortBy.placeholder')}\n value={sortByText}\n onChange={handleOnSortByChanged}\n >\n {Object.keys(SortByOptions).map((key: string) => (\n <MenuItem value={key} key={key}>\n {t(SortByOptions[key as keyof typeof SortByOptions].labelKey)}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-severity\">\n {t('filters.severity.label')}\n </InputLabel>\n\n <Select\n label={t('filters.severity.label')}\n labelId=\"notifications-filter-severity\"\n value={severity}\n onChange={handleOnSeverityChanged}\n >\n {(\n ['critical', 'high', 'normal', 'low'] as NotificationSeverity[]\n ).map(key => (\n <MenuItem value={key} key={key}>\n {t(`filters.severity.${key}`)}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n\n <Grid item xs={12}>\n <FormControl fullWidth variant=\"outlined\" size=\"small\">\n <InputLabel id=\"notifications-filter-topic\">\n {t('filters.topic.label')}\n </InputLabel>\n\n <Select\n label={t('filters.topic.label')}\n labelId=\"notifications-filter-topic\"\n value={topic ?? ALL}\n onChange={handleOnTopicChanged}\n >\n <MenuItem value={ALL} key={ALL}>\n {t('filters.topic.anyTopic')}\n </MenuItem>\n\n {sortedAllTopics.map((item: string) => (\n <MenuItem value={item} key={item}>\n {item}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAgDA,MAAM,GAAA,GAAM,WAAA;AAIL,MAAM,mBAAA,GAAsB;AAAA,EACjC,OAAA,EAAS;AAAA,IACP,QAAA,EAAU,8BAAA;AAAA,IACV,OAAA,EAAS,MA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E3B,CACD;AAAA;AAAA;AACH,KAAA,EACF,CAAA,EACF,CAAA;AAAA,oBAEA,GAAA,CAAC,IAAA,EAAA,EAAK,IAAA,EAAI,IAAA,EAAC,EAAA,EAAI,EAAA,EACb,QAAA,kBAAA,IAAA,CAAC,WAAA,EAAA,EAAY,SAAA,EAAS,IAAA,EAAC,OAAA,EAAQ,UAAA,EAAW,MAAK,OAAA,EAC7C,QAAA,EAAA;AAAA,sBAAA,GAAA,CAAC,UAAA,EAAA,EAAW,EAAA,EAAG,4BAAA,EACZ,QAAA,EAAA,CAAA,CAAE,qBAAqB,CAAA,EAC1B,CAAA;AAAA,sBAEA,IAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAO,EAAE,qBAAqB,CAAA;AAAA,UAC9B,OAAA,EAAQ,4BAAA;AAAA,UACR,OAAO,KAAA,IAAS,GAAA;AAAA,UAChB,QAAA,EAAU,oBAAA;AAAA,UAEV,QAAA,EAAA;AAAA,4BAAA,GAAA,CAAC,YAAS,KAAA,EAAO,GAAA,EACd,QAAA,EAAA,CAAA,CAAE,wBAAwB,KADF,GAE3B,CAAA;AAAA,YAEC,eAAA,CAAgB,GAAA,CAAI,CAAC,IAAA,qBACpB,GAAA,CAAC,YAAS,KAAA,EAAO,IAAA,EACd,QAAA,EAAA,IAAA,EAAA,EADyB,IAE5B,CACD;AAAA;AAAA;AAAA;AACH,KAAA,EACF,CAAA,EACF;AAAA,GAAA,EACF,CAAA,EACF,CAAA;AAEJ;;;;"}
|
|
@@ -5,6 +5,8 @@ import { ResponseErrorPanel, PageWithHeader, Content } from '@backstage/core-com
|
|
|
5
5
|
import Grid from '@material-ui/core/Grid';
|
|
6
6
|
import { ConfirmProvider } from 'material-ui-confirm';
|
|
7
7
|
import { useSignal } from '@backstage/plugin-signals-react';
|
|
8
|
+
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
9
|
+
import { notificationsTranslationRef } from '../../translation.esm.js';
|
|
8
10
|
import { NotificationsTable } from '../NotificationsTable/NotificationsTable.esm.js';
|
|
9
11
|
import { useNotificationsApi } from '../../hooks/useNotificationsApi.esm.js';
|
|
10
12
|
import '@backstage/core-plugin-api';
|
|
@@ -14,10 +16,17 @@ import '../../routes.esm.js';
|
|
|
14
16
|
import '../../hooks/useTitleCounter.esm.js';
|
|
15
17
|
import { SortByOptions, NotificationsFilters, CreatedAfterOptions } from '../NotificationsFilters/NotificationsFilters.esm.js';
|
|
16
18
|
|
|
19
|
+
const TableTitleKeys = {
|
|
20
|
+
all: "notificationsPage.tableTitle.all",
|
|
21
|
+
saved: "notificationsPage.tableTitle.saved",
|
|
22
|
+
unread: "notificationsPage.tableTitle.unread",
|
|
23
|
+
read: "notificationsPage.tableTitle.read"
|
|
24
|
+
};
|
|
17
25
|
const ThrottleDelayMs = 2e3;
|
|
18
26
|
const NotificationsPage = (props) => {
|
|
27
|
+
const { t } = useTranslationRef(notificationsTranslationRef);
|
|
19
28
|
const {
|
|
20
|
-
title = "
|
|
29
|
+
title = t("notificationsPage.title"),
|
|
21
30
|
themeId = "tool",
|
|
22
31
|
subtitle,
|
|
23
32
|
tooltip,
|
|
@@ -101,16 +110,21 @@ const NotificationsPage = (props) => {
|
|
|
101
110
|
const totalCount = value?.[0]?.totalCount;
|
|
102
111
|
const isUnread = !!value?.[1]?.unread;
|
|
103
112
|
const allTopics = value?.[2]?.topics;
|
|
104
|
-
let tableTitle =
|
|
113
|
+
let tableTitle = t(TableTitleKeys.all, {
|
|
114
|
+
count: totalCount ?? 0
|
|
115
|
+
});
|
|
105
116
|
if (saved) {
|
|
106
|
-
tableTitle =
|
|
117
|
+
tableTitle = t(TableTitleKeys.saved, {
|
|
118
|
+
count: totalCount ?? 0
|
|
119
|
+
});
|
|
107
120
|
} else if (unreadOnly === true) {
|
|
108
|
-
tableTitle =
|
|
121
|
+
tableTitle = t(TableTitleKeys.unread, {
|
|
122
|
+
count: totalCount ?? 0
|
|
123
|
+
});
|
|
109
124
|
} else if (unreadOnly === false) {
|
|
110
|
-
tableTitle =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
tableTitle += ` (${totalCount})`;
|
|
125
|
+
tableTitle = t(TableTitleKeys.read, {
|
|
126
|
+
count: totalCount ?? 0
|
|
127
|
+
});
|
|
114
128
|
}
|
|
115
129
|
return /* @__PURE__ */ jsx(
|
|
116
130
|
PageWithHeader,
|
|
@@ -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 { useEffect, useMemo, useState } 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 {\n GetNotificationsOptions,\n GetNotificationsResponse,\n GetTopicsResponse,\n} 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] = useState(false);\n const { lastSignal } = useSignal('notifications');\n const [unreadOnly, setUnreadOnly] = useState<boolean | undefined>(true);\n const [saved, setSaved] = useState<boolean | undefined>(undefined);\n const [pageNumber, setPageNumber] = useState(0);\n const [pageSize, setPageSize] = useState(5);\n const [containsText, setContainsText] = useState<string>();\n const [createdAfter, setCreatedAfter] = useState<string>('all');\n const [sorting, setSorting] = useState<SortBy>(SortByOptions.newest.sortBy);\n const [severity, setSeverity] = useState<NotificationSeverity>('low');\n const [topic, setTopic] = useState<string>();\n\n const { error, value, retry, loading } = useNotificationsApi<\n [GetNotificationsResponse, NotificationStatus, GetTopicsResponse]\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 if (topic !== undefined) {\n options.topic = topic;\n }\n\n const createdAfterDate = CreatedAfterOptions[createdAfter].getDate();\n if (createdAfterDate.valueOf() > 0) {\n options.createdAfter = createdAfterDate;\n }\n\n return Promise.all([\n api.getNotifications(options),\n api.getStatus(),\n api.getTopics(options),\n ]);\n },\n [\n containsText,\n unreadOnly,\n createdAfter,\n pageNumber,\n pageSize,\n sorting,\n saved,\n severity,\n topic,\n ],\n );\n\n const throttledSetRefresh = 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 const allTopics = value?.[2]?.topics;\n\n let tableTitle = `All notifications `;\n if (saved) {\n tableTitle = `Saved notifications`;\n } else if (unreadOnly === true) {\n tableTitle = `Unread notifications`;\n } else if (unreadOnly === false) {\n tableTitle = `Read notifications`;\n }\n\n if (totalCount) {\n tableTitle += ` (${totalCount})`;\n }\n\n return (\n <PageWithHeader\n title={title}\n themeId={themeId}\n tooltip={tooltip}\n subtitle={subtitle}\n type={type}\n typeLink={typeLink}\n >\n <Content>\n <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 topic={topic}\n onTopicChanged={setTopic}\n allTopics={allTopics}\n />\n </Grid>\n <Grid item xs={10}>\n <NotificationsTable\n title={tableTitle}\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":";;;;;;;;;;;;;;;;AA6CA,MAAM,eAAA,GAAkB,GAAA;AAcjB,MAAM,iBAAA,GAAoB,CAAC,KAAA,KAAmC;AACnE,EAAA,MAAM;AAAA,IACJ,KAAA,GAAQ,eAAA;AAAA,IACR,OAAA,GAAU,MA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AA,CAAC,mBACC,QAAA,kBAAA,IAAA,CAAC,IAAA,EAAA,EAAK,WAAS,IAAA,EACb,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,IAAA,EAAA,EAAK,IAAA,EAAI,IAAA,EAAC,EAAA,EAAI,CAAA,EACb,QAAA,kBAAA,GAAA;AAAA,UAAC,oBAAA;AAAA,UAAA;AAAA,YACC,UAAA;AAAA,YACA,mBAAA,EAAqB,aAAA;AAAA,YACrB,YAAA;AAAA,YACA,qBAAA,EAAuB,eAAA;AAAA,YACvB,gBAAA,EAAkB,UAAA;AAAA,YAClB,OAAA;AAAA,YACA,KAAA;AAAA,YACA,cAAA,EAAgB,QAAA;AAAA,YAChB,QAAA;AAAA,YACA,iBAAA,EAAmB,WAAA;AAAA,YACnB,KAAA;AAAA,YACA,cAAA,EAAgB,QAAA;AAAA,YAChB;AAAA;AAAA,SACF,EACF,CAAA;AAAA,wBACA,GAAA,CAAC,IAAA,EAAA,EAAK,IAAA,EAAI,IAAA,EAAC,IAAI,EAAA,EACb,QAAA,kBAAA,GAAA;AAAA,UAAC,kBAAA;AAAA,UAAA;AAAA,YACC,KAAA,EAAO,UAAA;AAAA,YACP,SAAA,EAAW,OAAA;AAAA,YACX,QAAA;AAAA,YACA,oBAAA;AAAA,YACA,aAAA;AAAA,YACA,QAAA;AAAA,YACA,eAAA;AAAA,YACA,YAAA,EAAc,aAAA;AAAA,YACd,mBAAA,EAAqB,WAAA;AAAA,YACrB,IAAA,EAAM,UAAA;AAAA,YACN,QAAA;AAAA,YACA;AAAA;AAAA,SACF,EACF;AAAA,OAAA,EACF,GACF,CAAA,EACF;AAAA;AAAA,GACF;AAEJ;;;;"}
|
|
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 { useEffect, useMemo, useState } 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';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { notificationsTranslationRef } from '../../translation';\n\nconst TableTitleKeys = {\n all: 'notificationsPage.tableTitle.all',\n saved: 'notificationsPage.tableTitle.saved',\n unread: 'notificationsPage.tableTitle.unread',\n read: 'notificationsPage.tableTitle.read',\n} as const;\n\nimport { NotificationsTable } from '../NotificationsTable';\nimport { useNotificationsApi } from '../../hooks';\nimport {\n CreatedAfterOptions,\n NotificationsFilters,\n SortBy,\n SortByOptions,\n} from '../NotificationsFilters';\nimport {\n GetNotificationsOptions,\n GetNotificationsResponse,\n GetTopicsResponse,\n} 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 { t } = useTranslationRef(notificationsTranslationRef);\n const {\n title = t('notificationsPage.title'),\n themeId = 'tool',\n subtitle,\n tooltip,\n type,\n typeLink,\n markAsReadOnLinkOpen,\n } = props ?? {};\n\n const [refresh, setRefresh] = useState(false);\n const { lastSignal } = useSignal('notifications');\n const [unreadOnly, setUnreadOnly] = useState<boolean | undefined>(true);\n const [saved, setSaved] = useState<boolean | undefined>(undefined);\n const [pageNumber, setPageNumber] = useState(0);\n const [pageSize, setPageSize] = useState(5);\n const [containsText, setContainsText] = useState<string>();\n const [createdAfter, setCreatedAfter] = useState<string>('all');\n const [sorting, setSorting] = useState<SortBy>(SortByOptions.newest.sortBy);\n const [severity, setSeverity] = useState<NotificationSeverity>('low');\n const [topic, setTopic] = useState<string>();\n\n const { error, value, retry, loading } = useNotificationsApi<\n [GetNotificationsResponse, NotificationStatus, GetTopicsResponse]\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 if (topic !== undefined) {\n options.topic = topic;\n }\n\n const createdAfterDate =\n CreatedAfterOptions[\n createdAfter as keyof typeof CreatedAfterOptions\n ].getDate();\n if (createdAfterDate.valueOf() > 0) {\n options.createdAfter = createdAfterDate;\n }\n\n return Promise.all([\n api.getNotifications(options),\n api.getStatus(),\n api.getTopics(options),\n ]);\n },\n [\n containsText,\n unreadOnly,\n createdAfter,\n pageNumber,\n pageSize,\n sorting,\n saved,\n severity,\n topic,\n ],\n );\n\n const throttledSetRefresh = 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 const allTopics = value?.[2]?.topics;\n\n let tableTitle: string = t(TableTitleKeys.all, {\n count: totalCount ?? 0,\n });\n if (saved) {\n tableTitle = t(TableTitleKeys.saved, {\n count: totalCount ?? 0,\n });\n } else if (unreadOnly === true) {\n tableTitle = t(TableTitleKeys.unread, {\n count: totalCount ?? 0,\n });\n } else if (unreadOnly === false) {\n tableTitle = t(TableTitleKeys.read, {\n count: totalCount ?? 0,\n });\n }\n\n return (\n <PageWithHeader\n title={title}\n themeId={themeId}\n tooltip={tooltip}\n subtitle={subtitle}\n type={type}\n typeLink={typeLink}\n >\n <Content>\n <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 topic={topic}\n onTopicChanged={setTopic}\n allTopics={allTopics}\n />\n </Grid>\n <Grid item xs={10}>\n <NotificationsTable\n title={tableTitle}\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":";;;;;;;;;;;;;;;;;;AA6BA,MAAM,cAAA,GAAiB;AAAA,EACrB,GAAA,EAAK,kCAAA;AAAA,EACL,KAAA,EAAO,oCAAA;AAAA,EACP,MAAA,EAAQ,qCAAA;AAAA,EACR,IAAA,EAAM;AACR,CAAA;AAoBA,MAAM,eAAA,GAAkB,GAAA;AAcjB,MAAM,iBAAA,GAAoB,CAAC,KAAA,KAAmC;AACnE,EAAA,MAAM,EAAE,CAAA,EA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A;AAAA,SACF,EACF;AAAA,OAAA,EACF,GACF,CAAA,EACF;AAAA;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -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 * as React from 'react';\nimport { useCallback, useEffect, useMemo, useState } 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 NotificationSeverity,\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 Chip from '@material-ui/core/Chip';\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/**\n * @public\n */\nexport type NotificationSnackbarProperties = {\n enabled?: boolean;\n autoHideDuration?: number | null;\n anchorOrigin?: {\n vertical: 'top' | 'bottom';\n horizontal: 'left' | 'center' | 'right';\n };\n dense?: boolean;\n maxSnack?: number;\n snackStyle?: React.CSSProperties;\n iconVariant?: Partial<Record<NotificationSeverity, React.ReactNode>>;\n Components?: {\n [key in NotificationSeverity]: React.JSXElementConstructor<any>;\n };\n};\n\n/**\n * @public\n */\nexport type NotificationsSideBarItemProps = {\n webNotificationsEnabled?: boolean;\n titleCounterEnabled?: boolean;\n /**\n * @deprecated Use `snackbarProps` instead.\n */\n snackbarEnabled?: boolean;\n /**\n * @deprecated Use `snackbarProps` instead.\n */\n snackbarAutoHideDuration?: number | null;\n snackbarProps?: NotificationSnackbarProperties;\n className?: string;\n icon?: IconComponent;\n text?: string;\n disableHighlight?: boolean;\n noTrack?: boolean;\n};\n\n/** @public */\nexport const NotificationsSidebarItem = (\n props?: NotificationsSideBarItemProps,\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 snackbarProps: {\n enabled: true,\n autoHideDuration: 10000,\n },\n };\n\n const snackbarProps = useMemo(\n () =>\n props?.snackbarProps ?? {\n enabled: snackbarEnabled,\n autoHideDuration: snackbarAutoHideDuration,\n },\n [props?.snackbarProps, snackbarAutoHideDuration, snackbarEnabled],\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] = 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] = 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 && !snackbarProps.enabled) ||\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 (snackbarProps.enabled) {\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 style: snackbarProps.snackStyle,\n variant: notification.payload.severity,\n anchorOrigin: snackbarProps.anchorOrigin ?? {\n vertical: 'bottom',\n horizontal: 'right',\n },\n action,\n autoHideDuration: snackbarProps.autoHideDuration,\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 notificationsApi,\n alertApi,\n getSnackbarProperties,\n snackbarProps,\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 const count = !error && !!unreadCount ? unreadCount : undefined;\n\n return (\n <>\n {snackbarEnabled && (\n <SnackbarProvider\n iconVariant={{\n normal: snackbarProps?.iconVariant?.normal ?? (\n <SeverityIcon severity=\"normal\" />\n ),\n critical: snackbarProps?.iconVariant?.critical ?? (\n <SeverityIcon severity=\"critical\" />\n ),\n high: snackbarProps?.iconVariant?.high ?? (\n <SeverityIcon severity=\"high\" />\n ),\n low: snackbarProps?.iconVariant?.low ?? (\n <SeverityIcon severity=\"low\" />\n ),\n }}\n dense={snackbarProps?.dense}\n maxSnack={snackbarProps?.maxSnack}\n Components={{\n normal:\n snackbarProps?.Components?.normal ?? StyledMaterialDesignContent,\n critical:\n snackbarProps?.Components?.critical ??\n StyledMaterialDesignContent,\n high:\n snackbarProps?.Components?.high ?? StyledMaterialDesignContent,\n low: snackbarProps?.Components?.low ?? StyledMaterialDesignContent,\n }}\n />\n )}\n <SidebarItem\n to={notificationsRoute}\n onClick={() => {\n requestUserPermission();\n }}\n text={text}\n icon={icon}\n {...restProps}\n >\n {count && <Chip size=\"small\" label={count > 99 ? '99+' : count} />}\n </SidebarItem>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAoDA,MAAM,2BAAA,GAA8B,OAAO,qBAAqB,CAAA;AAAA,EAC9D,CAAC,EAAE,KAAA,EAAM,MAAO;AAAA,IACd,4BAAA,EAA8B;AAAA,MAC5B,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,UAAA,CAAW,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA,KAC5B;AAAA,IACA,+BAAA,EAAiC;AAAA,MAC/B,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,UAAA,CAAW,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA,KAC5B;AAAA,IACA,6BAAA,EAA+B;AAAA,MAC7B,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,UAAA,CAAW,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA,KAC5B;AAAA,IACA,iCAAA,EAAmC;AAAA,MACjC,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,UAAA,CAAW,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA;AAC5B,GACF;AACF,CAAA;AAsDO,MAAM,wBAAA,GAA2B,CACtC,KAAA,KACG;AACH,EAAA,MAAM;AAAA,IACJ,uBAAA,GAA0B,K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;AACzC;AAAA,KACF;AAAA,oBAEF,GAAA;AAAA,MAAC,WAAA;AAAA,MAAA;AAAA,QACC,EAAA,EAAI,kBAAA;AAAA,QACJ,SAAS,MAAM;AACb,UAAA,qBAAA,EAAsB;AAAA,QACxB,CAAA;AAAA,QACA,IAAA;AAAA,QACA,IAAA;AAAA,QACC,GAAG,SAAA;AAAA,QAEH,QAAA,EAAA,KAAA,wBAAU,IAAA,EAAA,EAAK,IAAA,EAAK,SAAQ,KAAA,EAAO,KAAA,GAAQ,EAAA,GAAK,KAAA,GAAQ,KAAA,EAAO;AAAA;AAAA;AAClE,GAAA,EACF,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 { useCallback, useEffect, useMemo, useState } 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 NotificationSeverity,\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 Chip from '@material-ui/core/Chip';\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/**\n * @public\n */\nexport type NotificationSnackbarProperties = {\n enabled?: boolean;\n autoHideDuration?: number | null;\n anchorOrigin?: {\n vertical: 'top' | 'bottom';\n horizontal: 'left' | 'center' | 'right';\n };\n dense?: boolean;\n maxSnack?: number;\n snackStyle?: React.CSSProperties;\n iconVariant?: Partial<Record<NotificationSeverity, React.ReactNode>>;\n Components?: {\n [key in NotificationSeverity]: React.JSXElementConstructor<any>;\n };\n};\n\n/**\n * @public\n */\nexport type NotificationsSideBarItemProps = {\n webNotificationsEnabled?: boolean;\n titleCounterEnabled?: boolean;\n /**\n * @deprecated Use `snackbarProps` instead.\n */\n snackbarEnabled?: boolean;\n /**\n * @deprecated Use `snackbarProps` instead.\n */\n snackbarAutoHideDuration?: number | null;\n snackbarProps?: NotificationSnackbarProperties;\n className?: string;\n icon?: IconComponent;\n text?: string;\n disableHighlight?: boolean;\n noTrack?: boolean;\n};\n\n/** @public */\nexport const NotificationsSidebarItem = (\n props?: NotificationsSideBarItemProps,\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 snackbarProps: {\n enabled: true,\n autoHideDuration: 10000,\n },\n };\n\n const snackbarProps = useMemo(\n () =>\n props?.snackbarProps ?? {\n enabled: snackbarEnabled,\n autoHideDuration: snackbarAutoHideDuration,\n },\n [props?.snackbarProps, snackbarAutoHideDuration, snackbarEnabled],\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] = 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] = 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 && !snackbarProps.enabled) ||\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 (snackbarProps.enabled) {\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 style: snackbarProps.snackStyle,\n variant: notification.payload.severity,\n anchorOrigin: snackbarProps.anchorOrigin ?? {\n vertical: 'bottom',\n horizontal: 'right',\n },\n action,\n autoHideDuration: snackbarProps.autoHideDuration,\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 notificationsApi,\n alertApi,\n getSnackbarProperties,\n snackbarProps,\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 const count = !error && !!unreadCount ? unreadCount : undefined;\n\n return (\n <>\n {snackbarEnabled && (\n <SnackbarProvider\n iconVariant={{\n normal: snackbarProps?.iconVariant?.normal ?? (\n <SeverityIcon severity=\"normal\" />\n ),\n critical: snackbarProps?.iconVariant?.critical ?? (\n <SeverityIcon severity=\"critical\" />\n ),\n high: snackbarProps?.iconVariant?.high ?? (\n <SeverityIcon severity=\"high\" />\n ),\n low: snackbarProps?.iconVariant?.low ?? (\n <SeverityIcon severity=\"low\" />\n ),\n }}\n dense={snackbarProps?.dense}\n maxSnack={snackbarProps?.maxSnack}\n Components={{\n normal:\n snackbarProps?.Components?.normal ?? StyledMaterialDesignContent,\n critical:\n snackbarProps?.Components?.critical ??\n StyledMaterialDesignContent,\n high:\n snackbarProps?.Components?.high ?? StyledMaterialDesignContent,\n low: snackbarProps?.Components?.low ?? StyledMaterialDesignContent,\n }}\n />\n )}\n <SidebarItem\n to={notificationsRoute}\n onClick={() => {\n requestUserPermission();\n }}\n text={text}\n icon={icon}\n {...restProps}\n >\n {count && <Chip size=\"small\" label={count > 99 ? '99+' : count} />}\n </SidebarItem>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,2BAAA,GAA8B,OAAO,qBAAqB,CAAA;AAAA,EAC9D,CAAC,EAAE,KAAA,EAAM,MAAO;AAAA,IACd,4BAAA,EAA8B;AAAA,MAC5B,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,UAAA,CAAW,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA,KAC5B;AAAA,IACA,+BAAA,EAAiC;AAAA,MAC/B,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,UAAA,CAAW,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA,KAC5B;AAAA,IACA,6BAAA,EAA+B;AAAA,MAC7B,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,UAAA,CAAW,OAAA;AAAA,MAC1C,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAA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A;AAAA,QACzB,UAAA,EAAY;AAAA,UACV,MAAA,EACE,aAAA,EAAe,UAAA,EAAY,MAAA,IAAU,2BAAA;AAAA,UACvC,QAAA,EACE,aAAA,EAAe,UAAA,EAAY,QAAA,IAC3B,2BAAA;AAAA,UACF,IAAA,EACE,aAAA,EAAe,UAAA,EAAY,IAAA,IAAQ,2BAAA;AAAA,UACrC,GAAA,EAAK,aAAA,EAAe,UAAA,EAAY,GAAA,IAAO;AAAA;AACzC;AAAA,KACF;AAAA,oBAEF,GAAA;AAAA,MAAC,WAAA;AAAA,MAAA;AAAA,QACC,EAAA,EAAI,kBAAA;AAAA,QACJ,SAAS,MAAM;AACb,UAAA,qBAAA,EAAsB;AAAA,QACxB,CAAA;AAAA,QACA,IAAA;AAAA,QACA,IAAA;AAAA,QACC,GAAG,SAAA;AAAA,QAEH,QAAA,EAAA,KAAA,wBAAU,IAAA,EAAA,EAAK,IAAA,EAAK,SAAQ,KAAA,EAAO,KAAA,GAAQ,EAAA,GAAK,KAAA,GAAQ,KAAA,EAAO;AAAA;AAAA;AAClE,GAAA,EACF,CAAA;AAEJ;;;;"}
|
|
@@ -7,6 +7,8 @@ import MarkAsReadIcon from '@material-ui/icons/CheckCircle';
|
|
|
7
7
|
import MarkAsUnsavedIcon from '@material-ui/icons/LabelOff';
|
|
8
8
|
import MarkAsSavedIcon from '@material-ui/icons/Label';
|
|
9
9
|
import MarkAllReadIcon from '@material-ui/icons/DoneAll';
|
|
10
|
+
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
11
|
+
import { notificationsTranslationRef } from '../../translation.esm.js';
|
|
10
12
|
|
|
11
13
|
const BulkActions = ({
|
|
12
14
|
selectedNotifications,
|
|
@@ -16,6 +18,7 @@ const BulkActions = ({
|
|
|
16
18
|
onSwitchSavedStatus,
|
|
17
19
|
onMarkAllRead
|
|
18
20
|
}) => {
|
|
21
|
+
const { t } = useTranslationRef(notificationsTranslationRef);
|
|
19
22
|
const isDisabled = selectedNotifications.size === 0;
|
|
20
23
|
const bulkNotifications = notifications.filter(
|
|
21
24
|
(notification) => selectedNotifications.has(notification.id)
|
|
@@ -26,12 +29,13 @@ const BulkActions = ({
|
|
|
26
29
|
const isOneSaved = !!bulkNotifications.find(
|
|
27
30
|
(notification) => !!notification.saved
|
|
28
31
|
);
|
|
29
|
-
const markAsReadText = isOneRead ? "
|
|
32
|
+
const markAsReadText = isOneRead ? t("table.bulkActions.returnSelectedAmongUnread") : t("table.bulkActions.markSelectedAsRead");
|
|
30
33
|
const IconComponent = isOneRead ? MarkAsUnreadIcon : MarkAsReadIcon;
|
|
31
|
-
const markAsSavedText = isOneSaved ? "
|
|
34
|
+
const markAsSavedText = isOneSaved ? t("table.bulkActions.undoSaveForSelected") : t("table.bulkActions.saveSelectedForLater");
|
|
32
35
|
const SavedIconComponent = isOneSaved ? MarkAsUnsavedIcon : MarkAsSavedIcon;
|
|
36
|
+
const markAllReadText = t("table.bulkActions.markAllRead");
|
|
33
37
|
return /* @__PURE__ */ jsxs(Grid, { container: true, wrap: "nowrap", children: [
|
|
34
|
-
/* @__PURE__ */ jsx(Grid, { item: true, xs: 3, children: onMarkAllRead ? /* @__PURE__ */ jsx(Tooltip, { title:
|
|
38
|
+
/* @__PURE__ */ jsx(Grid, { item: true, xs: 3, children: onMarkAllRead ? /* @__PURE__ */ jsx(Tooltip, { title: markAllReadText, children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(IconButton, { disabled: !isUnread, onClick: onMarkAllRead, children: /* @__PURE__ */ jsx(MarkAllReadIcon, { "aria-label": markAllReadText }) }) }) }) : /* @__PURE__ */ jsx("div", {}) }),
|
|
35
39
|
/* @__PURE__ */ jsx(Grid, { item: true, xs: 3, children: /* @__PURE__ */ jsx(Tooltip, { title: markAsSavedText, children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
36
40
|
IconButton,
|
|
37
41
|
{
|
|
@@ -1 +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 { 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 ? '
|
|
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 { 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';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { notificationsTranslationRef } from '../../translation';\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 { t } = useTranslationRef(notificationsTranslationRef);\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 ? t('table.bulkActions.returnSelectedAmongUnread')\n : t('table.bulkActions.markSelectedAsRead');\n const IconComponent = isOneRead ? MarkAsUnreadIcon : MarkAsReadIcon;\n\n const markAsSavedText = isOneSaved\n ? t('table.bulkActions.undoSaveForSelected')\n : t('table.bulkActions.saveSelectedForLater');\n const SavedIconComponent = isOneSaved ? MarkAsUnsavedIcon : MarkAsSavedIcon;\n const markAllReadText = t('table.bulkActions.markAllRead');\n\n return (\n <Grid container wrap=\"nowrap\">\n <Grid item xs={3}>\n {onMarkAllRead ? (\n <Tooltip title={markAllReadText}>\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={markAllReadText} />\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":";;;;;;;;;;;;AA2BO,MAAM,cAAc,CAAC;AAAA,EAC1B,qBAAA;AAAA,EACA,aAAA;AAAA,EACA,QAAA;AAAA,EACA,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAA,KAOM;AACJ,EAAA,MAAM,EAAE,C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GAAA,EACF,CAAA;AAEJ;;;;"}
|
|
@@ -11,6 +11,8 @@ import { useConfirm } from 'material-ui-confirm';
|
|
|
11
11
|
import BroadcastIcon from '@material-ui/icons/RssFeed';
|
|
12
12
|
import { useApi, alertApiRef } from '@backstage/core-plugin-api';
|
|
13
13
|
import { Link, Table } from '@backstage/core-components';
|
|
14
|
+
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
15
|
+
import { notificationsTranslationRef } from '../../translation.esm.js';
|
|
14
16
|
import { notificationsApiRef } from '../../api/NotificationsApi.esm.js';
|
|
15
17
|
import '@backstage/errors';
|
|
16
18
|
import { SelectAll } from './SelectAll.esm.js';
|
|
@@ -48,6 +50,7 @@ const NotificationsTable = ({
|
|
|
48
50
|
pageSize,
|
|
49
51
|
totalCount
|
|
50
52
|
}) => {
|
|
53
|
+
const { t } = useTranslationRef(notificationsTranslationRef);
|
|
51
54
|
const classes = useStyles();
|
|
52
55
|
const notificationsApi = useApi(notificationsApiRef);
|
|
53
56
|
const alertApi = useApi(alertApiRef);
|
|
@@ -269,7 +272,20 @@ const NotificationsTable = ({
|
|
|
269
272
|
totalCount,
|
|
270
273
|
onSearchChange: throttledContainsTextHandler,
|
|
271
274
|
data: notifications,
|
|
272
|
-
columns: compactColumns
|
|
275
|
+
columns: compactColumns,
|
|
276
|
+
localization: {
|
|
277
|
+
body: {
|
|
278
|
+
emptyDataSourceMessage: t("table.emptyMessage")
|
|
279
|
+
},
|
|
280
|
+
pagination: {
|
|
281
|
+
firstTooltip: t("table.pagination.firstTooltip"),
|
|
282
|
+
labelDisplayedRows: t("table.pagination.labelDisplayedRows"),
|
|
283
|
+
labelRowsSelect: t("table.pagination.labelRowsSelect"),
|
|
284
|
+
lastTooltip: t("table.pagination.lastTooltip"),
|
|
285
|
+
nextTooltip: t("table.pagination.nextTooltip"),
|
|
286
|
+
previousTooltip: t("table.pagination.previousTooltip")
|
|
287
|
+
}
|
|
288
|
+
}
|
|
273
289
|
}
|
|
274
290
|
);
|
|
275
291
|
};
|
|
@@ -1 +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 { useCallback, useEffect, useMemo, useState } 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 BroadcastIcon from '@material-ui/icons/RssFeed';\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';\nimport { SelectAll } from './SelectAll';\nimport { BulkActions } from './BulkActions';\nimport { NotificationIcon } from './NotificationIcon';\nimport { NotificationDescription } from './NotificationDescription';\n\nconst ThrottleDelayMs = 1000;\n\nconst useStyles = makeStyles(theme => ({\n severityItem: {\n alignContent: 'center',\n },\n broadcastIcon: {\n fontSize: '1rem',\n verticalAlign: 'text-bottom',\n },\n notificationInfoRow: {\n marginRight: theme.spacing(0.5),\n '&:not(:first-child)': {\n marginLeft: theme.spacing(0.5),\n },\n },\n}));\n\n/** @public */\nexport type NotificationsTableProps = Pick<\n TableProps,\n 'onPageChange' | 'onRowsPerPageChange' | 'page' | 'totalCount' | 'title'\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 title,\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] = useState(\n new Set<Notification['id']>(),\n );\n\n const onNotificationsSelectChange = 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 = 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 = 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 = 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 = useMemo(\n () => throttle(setContainsText, ThrottleDelayMs),\n [setContainsText],\n );\n\n 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 = useMemo((): TableColumn<Notification>[] => {\n const showToolbar = notifications.length > 0;\n return [\n {\n /* selection column */\n width: '1rem',\n title: showToolbar ? (\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 ) : undefined,\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 <NotificationIcon notification={notification} />\n </Grid>\n <Grid item xs={11}>\n <Box>\n <Typography variant=\"subtitle1\">\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 <NotificationDescription\n description={notification.payload.description}\n />\n ) : null}\n\n <Typography variant=\"caption\">\n {!notification.user && (\n <>\n <BroadcastIcon className={classes.broadcastIcon} />\n </>\n )}\n {notification.origin && (\n <>\n <Typography\n variant=\"inherit\"\n className={classes.notificationInfoRow}\n >\n {notification.origin}\n </Typography>\n •\n </>\n )}\n {notification.payload.topic && (\n <>\n <Typography\n variant=\"inherit\"\n className={classes.notificationInfoRow}\n >\n {notification.payload.topic}\n </Typography>\n •\n </>\n )}\n {notification.created && (\n <RelativeTime\n value={notification.created}\n className={classes.notificationInfoRow}\n />\n )}\n </Typography>\n </Box>\n </Grid>\n </Grid>\n );\n },\n },\n {\n /* actions column */\n width: '1rem',\n title: showToolbar ? (\n <BulkActions\n notifications={notifications}\n selectedNotifications={selectedNotifications}\n isUnread={isUnread}\n onSwitchReadStatus={onSwitchReadStatus}\n onSwitchSavedStatus={onSwitchSavedStatus}\n onMarkAllRead={onMarkAllRead}\n />\n ) : undefined,\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 notifications,\n selectedNotifications,\n isUnread,\n onSwitchReadStatus,\n onSwitchSavedStatus,\n onMarkAllRead,\n onNotificationsSelectChange,\n classes.severityItem,\n classes.broadcastIcon,\n classes.notificationInfoRow,\n markAsReadOnLinkOpen,\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 title={title}\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":";;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,eAAA,GAAkB,GAAA;AAExB,MAAM,SAAA,GAAY,WAAW,CAAA,KAAA,MAAU;AAAA,EACrC,YAAA,EAAc;AAAA,IACZ,YAAA,EAAc;AAAA,GAChB;AAAA,EACA,aAAA,EAAe;AAAA,IACb,QAAA,EAAU,MA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,IAAA;AAAA,QACR,QAAA;AAAA,QACA,MAAA,EAAQ,IAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACX;AAAA,MACA,KAAA;AAAA,MACA,YAAA;AAAA,MACA,mBAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAA;AAAA,MACA,cAAA,EAAgB,4BAAA;AAAA,MAChB,IAAA,EAAM,aAAA;AAAA,MACN,OAAA,EAAS;AAAA;AAAA,GACX;AAEJ;;;;"}
|
|
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 { useCallback, useEffect, useMemo, useState } 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 BroadcastIcon from '@material-ui/icons/RssFeed';\nimport { alertApiRef, useApi } from '@backstage/core-plugin-api';\nimport {\n Link,\n Table,\n TableColumn,\n TableProps,\n} from '@backstage/core-components';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { notificationsTranslationRef } from '../../translation';\n\nimport { notificationsApiRef } from '../../api';\nimport { SelectAll } from './SelectAll';\nimport { BulkActions } from './BulkActions';\nimport { NotificationIcon } from './NotificationIcon';\nimport { NotificationDescription } from './NotificationDescription';\n\nconst ThrottleDelayMs = 1000;\n\nconst useStyles = makeStyles(theme => ({\n severityItem: {\n alignContent: 'center',\n },\n broadcastIcon: {\n fontSize: '1rem',\n verticalAlign: 'text-bottom',\n },\n notificationInfoRow: {\n marginRight: theme.spacing(0.5),\n '&:not(:first-child)': {\n marginLeft: theme.spacing(0.5),\n },\n },\n}));\n\n/** @public */\nexport type NotificationsTableProps = Pick<\n TableProps,\n 'onPageChange' | 'onRowsPerPageChange' | 'page' | 'totalCount' | 'title'\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 title,\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 { t } = useTranslationRef(notificationsTranslationRef);\n const classes = useStyles();\n const notificationsApi = useApi(notificationsApiRef);\n const alertApi = useApi(alertApiRef);\n const confirm = useConfirm();\n\n const [selectedNotifications, setSelectedNotifications] = useState(\n new Set<Notification['id']>(),\n );\n\n const onNotificationsSelectChange = 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 = 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 = 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 = 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 = useMemo(\n () => throttle(setContainsText, ThrottleDelayMs),\n [setContainsText],\n );\n\n 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 = useMemo((): TableColumn<Notification>[] => {\n const showToolbar = notifications.length > 0;\n return [\n {\n /* selection column */\n width: '1rem',\n title: showToolbar ? (\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 ) : undefined,\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 <NotificationIcon notification={notification} />\n </Grid>\n <Grid item xs={11}>\n <Box>\n <Typography variant=\"subtitle1\">\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 <NotificationDescription\n description={notification.payload.description}\n />\n ) : null}\n\n <Typography variant=\"caption\">\n {!notification.user && (\n <>\n <BroadcastIcon className={classes.broadcastIcon} />\n </>\n )}\n {notification.origin && (\n <>\n <Typography\n variant=\"inherit\"\n className={classes.notificationInfoRow}\n >\n {notification.origin}\n </Typography>\n •\n </>\n )}\n {notification.payload.topic && (\n <>\n <Typography\n variant=\"inherit\"\n className={classes.notificationInfoRow}\n >\n {notification.payload.topic}\n </Typography>\n •\n </>\n )}\n {notification.created && (\n <RelativeTime\n value={notification.created}\n className={classes.notificationInfoRow}\n />\n )}\n </Typography>\n </Box>\n </Grid>\n </Grid>\n );\n },\n },\n {\n /* actions column */\n width: '1rem',\n title: showToolbar ? (\n <BulkActions\n notifications={notifications}\n selectedNotifications={selectedNotifications}\n isUnread={isUnread}\n onSwitchReadStatus={onSwitchReadStatus}\n onSwitchSavedStatus={onSwitchSavedStatus}\n onMarkAllRead={onMarkAllRead}\n />\n ) : undefined,\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 notifications,\n selectedNotifications,\n isUnread,\n onSwitchReadStatus,\n onSwitchSavedStatus,\n onMarkAllRead,\n onNotificationsSelectChange,\n classes.severityItem,\n classes.broadcastIcon,\n classes.notificationInfoRow,\n markAsReadOnLinkOpen,\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 title={title}\n onPageChange={onPageChange}\n onRowsPerPageChange={onRowsPerPageChange}\n page={page}\n totalCount={totalCount}\n onSearchChange={throttledContainsTextHandler}\n data={notifications}\n columns={compactColumns}\n localization={{\n body: {\n emptyDataSourceMessage: t('table.emptyMessage'),\n },\n pagination: {\n firstTooltip: t('table.pagination.firstTooltip'),\n labelDisplayedRows: t('table.pagination.labelDisplayedRows'),\n labelRowsSelect: t('table.pagination.labelRowsSelect'),\n lastTooltip: t('table.pagination.lastTooltip'),\n nextTooltip: t('table.pagination.nextTooltip'),\n previousTooltip: t('table.pagination.previousTooltip'),\n },\n }}\n />\n );\n};\n"],"names":["CheckBox"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,eAAA,GAAkB,GAAA;AAExB,MAAM,SAAA,GAAY,WAAW,CAAA,KAAA,MAAU;AAAA,EACrC,YAAA,EAAc;AAAA,IACZ,YAAA,EAAc;AAAA,GAChB;AAAA,EACA,aAAA,EAAe;AAAA,IACb,QAAA,EAAU,MAAA;AAAA,IACV,aAAA,EAAe;AAAA,GACjB;AAAA,EACA,mBAAA,EAAqB;AAAA,IACnB,WAAA,EAAa,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AAAA,IAC9B,qBAAA,EAAuB;AAAA,MACrB,UAAA,EAAY,KAAA,CAAM,OAAA,CAAQ,GAAG;AAAA;AAC/B;AAEJ,CAAA,CAAE,CAAA;AAiBK,MAAM,qBAAqB,CAAC;AAAA,EACjC,KAAA;AAAA,EACA,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;AACF,CAAA,KAA+B;AAC7B,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,2BAA2B,CAAA;AAC3D,EAAA,MAAM,UAAU,SAAA,EAAU;AAC1B,EAAA,MA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8BAA8B,CAAA;AAAA,UAC7C,WAAA,EAAa,EAAE,8BAA8B,CAAA;AAAA,UAC7C,eAAA,EAAiB,EAAE,kCAAkC;AAAA;AACvD;AACF;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -7,6 +7,8 @@ import { notificationsApiRef } from '../../api/NotificationsApi.esm.js';
|
|
|
7
7
|
import '@backstage/errors';
|
|
8
8
|
import '../../routes.esm.js';
|
|
9
9
|
import '../../hooks/useTitleCounter.esm.js';
|
|
10
|
+
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
11
|
+
import { notificationsTranslationRef } from '../../translation.esm.js';
|
|
10
12
|
import { UserNotificationSettingsPanel } from './UserNotificationSettingsPanel.esm.js';
|
|
11
13
|
import { capitalize } from 'lodash';
|
|
12
14
|
|
|
@@ -14,11 +16,9 @@ const NotificationFormatContext = createContext(
|
|
|
14
16
|
void 0
|
|
15
17
|
);
|
|
16
18
|
const useNotificationFormat = () => {
|
|
19
|
+
const { t } = useTranslationRef(notificationsTranslationRef);
|
|
17
20
|
const context = useContext(NotificationFormatContext);
|
|
18
|
-
if (!context)
|
|
19
|
-
throw new Error(
|
|
20
|
-
"useNotificationFormat must be used within a NotificationFormatProvider"
|
|
21
|
-
);
|
|
21
|
+
if (!context) throw new Error(t("settings.errors.useNotificationFormat"));
|
|
22
22
|
return context;
|
|
23
23
|
};
|
|
24
24
|
const NotificationFormatProvider = ({
|
|
@@ -47,6 +47,7 @@ const NotificationFormatProvider = ({
|
|
|
47
47
|
);
|
|
48
48
|
};
|
|
49
49
|
const UserNotificationSettingsCard = (props) => {
|
|
50
|
+
const { t } = useTranslationRef(notificationsTranslationRef);
|
|
50
51
|
const [settings, setNotificationSettings] = useState(void 0);
|
|
51
52
|
const client = useApi(notificationsApiRef);
|
|
52
53
|
const { error, value, loading } = useNotificationsApi((api) => {
|
|
@@ -60,9 +61,9 @@ const UserNotificationSettingsCard = (props) => {
|
|
|
60
61
|
const onUpdate = (newSettings) => {
|
|
61
62
|
client.updateNotificationSettings(newSettings).then((updatedSettings) => setNotificationSettings(updatedSettings));
|
|
62
63
|
};
|
|
63
|
-
return /* @__PURE__ */ jsxs(InfoCard, { title: "
|
|
64
|
+
return /* @__PURE__ */ jsxs(InfoCard, { title: t("settings.title"), variant: "gridItem", children: [
|
|
64
65
|
loading && /* @__PURE__ */ jsx(Progress, {}),
|
|
65
|
-
error && /* @__PURE__ */ jsx(ErrorPanel, { title: "
|
|
66
|
+
error && /* @__PURE__ */ jsx(ErrorPanel, { title: t("settings.errorTitle"), error }),
|
|
66
67
|
settings && /* @__PURE__ */ jsx(
|
|
67
68
|
NotificationFormatProvider,
|
|
68
69
|
{
|
package/dist/components/UserNotificationSettingsCard/UserNotificationSettingsCard.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserNotificationSettingsCard.esm.js","sources":["../../../src/components/UserNotificationSettingsCard/UserNotificationSettingsCard.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 */\n\nimport { createContext, useState, useContext, useEffect } from 'react';\nimport { ErrorPanel, InfoCard, Progress } from '@backstage/core-components';\nimport { useNotificationsApi } from '../../hooks';\nimport { NotificationSettings } from '@backstage/plugin-notifications-common';\nimport { notificationsApiRef } from '../../api';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { UserNotificationSettingsPanel } from './UserNotificationSettingsPanel';\nimport { capitalize } from 'lodash';\n\ntype FormatContextType = {\n formatOriginName: (id: string) => string;\n formatTopicName: (id: string) => string;\n};\n\nconst NotificationFormatContext = createContext<FormatContextType | undefined>(\n undefined,\n);\n\nexport const useNotificationFormat = () => {\n const context = useContext(NotificationFormatContext);\n if (!context)
|
|
1
|
+
{"version":3,"file":"UserNotificationSettingsCard.esm.js","sources":["../../../src/components/UserNotificationSettingsCard/UserNotificationSettingsCard.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 */\n\nimport { createContext, useState, useContext, useEffect } from 'react';\nimport { ErrorPanel, InfoCard, Progress } from '@backstage/core-components';\nimport { useNotificationsApi } from '../../hooks';\nimport { NotificationSettings } from '@backstage/plugin-notifications-common';\nimport { notificationsApiRef } from '../../api';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { notificationsTranslationRef } from '../../translation';\nimport { UserNotificationSettingsPanel } from './UserNotificationSettingsPanel';\nimport { capitalize } from 'lodash';\n\ntype FormatContextType = {\n formatOriginName: (id: string) => string;\n formatTopicName: (id: string) => string;\n};\n\nconst NotificationFormatContext = createContext<FormatContextType | undefined>(\n undefined,\n);\n\nexport const useNotificationFormat = () => {\n const { t } = useTranslationRef(notificationsTranslationRef);\n const context = useContext(NotificationFormatContext);\n if (!context) throw new Error(t('settings.errors.useNotificationFormat'));\n return context;\n};\n\ntype Props = {\n children: React.ReactNode;\n originMap: Record<string, string> | undefined;\n topicMap: Record<string, string> | undefined;\n};\n\nexport const NotificationFormatProvider = ({\n children,\n originMap,\n topicMap,\n}: Props) => {\n const formatName = (\n id: string,\n nameMap: Record<string, string> | undefined,\n ) => {\n if (nameMap && id in nameMap) {\n return nameMap[id];\n }\n return capitalize(id.replaceAll(/[-_:]/g, ' '));\n };\n\n const formatOriginName = (originId: string) => {\n return formatName(originId, originMap);\n };\n\n const formatTopicName = (topicId: string) => {\n return formatName(topicId, topicMap);\n };\n return (\n <NotificationFormatContext.Provider\n value={{ formatOriginName, formatTopicName }}\n >\n {children}\n </NotificationFormatContext.Provider>\n );\n};\n\n/** @public */\nexport const UserNotificationSettingsCard = (props: {\n originNames?: Record<string, string>;\n topicNames?: Record<string, string>;\n}) => {\n const { t } = useTranslationRef(notificationsTranslationRef);\n const [settings, setNotificationSettings] = useState<\n NotificationSettings | undefined\n >(undefined);\n\n const client = useApi(notificationsApiRef);\n const { error, value, loading } = useNotificationsApi(api => {\n return api.getNotificationSettings();\n });\n\n useEffect(() => {\n if (!loading && !error) {\n setNotificationSettings(value);\n }\n }, [loading, value, error]);\n\n const onUpdate = (newSettings: NotificationSettings) => {\n client\n .updateNotificationSettings(newSettings)\n .then(updatedSettings => setNotificationSettings(updatedSettings));\n };\n\n return (\n <InfoCard title={t('settings.title')} variant=\"gridItem\">\n {loading && <Progress />}\n {error && <ErrorPanel title={t('settings.errorTitle')} error={error} />}\n {settings && (\n <NotificationFormatProvider\n originMap={props.originNames}\n topicMap={props.topicNames}\n >\n <UserNotificationSettingsPanel\n settings={settings}\n onChange={onUpdate}\n />\n </NotificationFormatProvider>\n )}\n </InfoCard>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAgCA,MAAM,yBAAA,GAA4B,aAAA;AAAA,EAChC;AACF,CAAA;AAEO,MAAM,wBAAwB,MAAM;AACzC,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,2BAA2B,CAAA;AAC3D,EAAA,MAAM,OAAA,GAAU,WAAW,yBAAyB,CAAA;AACpD,EAAA,IAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,CAAA,CAAE,uCAAuC,CAAC,CAAA;AACxE,EAAA,OAAO,OAAA;AACT;AAQO,MAAM,6BAA6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AwB,KAAK,CAAA;AAAA,IAC/B;AAAA,EACF,CAAA,EAAG,CAAC,OAAA,EAAS,KAAA,EAAO,KAAK,CAAC,CAAA;AAE1B,EAAA,MAAM,QAAA,GAAW,CAAC,WAAA,KAAsC;AACtD,IAAA,MAAA,CACG,2BAA2B,WAAW,CAAA,CACtC,KAAK,CAAA,eAAA,KAAmB,uBAAA,CAAwB,eAAe,CAAC,CAAA;AAAA,EACrE,CAAA;AAEA,EAAA,4BACG,QAAA,EAAA,EAAS,KAAA,EAAO,EAAE,gBAAgB,CAAA,EAAG,SAAQ,UAAA,EAC3C,QAAA,EAAA;AAAA,IAAA,OAAA,wBAAY,QAAA,EAAA,EAAS,CAAA;AAAA,IACrB,yBAAS,GAAA,CAAC,UAAA,EAAA,EAAW,OAAO,CAAA,CAAE,qBAAqB,GAAG,KAAA,EAAc,CAAA;AAAA,IACpE,QAAA,oBACC,GAAA;AAAA,MAAC,0BAAA;AAAA,MAAA;AAAA,QACC,WAAW,KAAA,CAAM,WAAA;AAAA,QACjB,UAAU,KAAA,CAAM,UAAA;AAAA,QAEhB,QAAA,kBAAA,GAAA;AAAA,UAAC,6BAAA;AAAA,UAAA;AAAA,YACC,QAAA;AAAA,YACA,QAAA,EAAU;AAAA;AAAA;AACZ;AAAA;AACF,GAAA,EAEJ,CAAA;AAEJ;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
2
|
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
4
3
|
import { IconComponent, DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';
|
|
5
4
|
import { NotificationSeverity, Notification, NotificationStatus, NotificationSettings } from '@backstage/plugin-notifications-common';
|
package/dist/package.json.esm.js
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createTranslationRef } from '@backstage/frontend-plugin-api';
|
|
2
|
+
|
|
3
|
+
const notificationsTranslationRef = createTranslationRef({
|
|
4
|
+
id: "plugin.notifications",
|
|
5
|
+
messages: {
|
|
6
|
+
notificationsPage: {
|
|
7
|
+
title: "Notifications",
|
|
8
|
+
tableTitle: {
|
|
9
|
+
all_one: "All notifications ({{count}})",
|
|
10
|
+
all_other: "All notifications ({{count}})",
|
|
11
|
+
saved_one: "Saved notifications ({{count}})",
|
|
12
|
+
saved_other: "Saved notifications ({{count}})",
|
|
13
|
+
unread_one: "Unread notifications ({{count}})",
|
|
14
|
+
unread_other: "Unread notifications ({{count}})",
|
|
15
|
+
read_one: "Read notifications ({{count}})",
|
|
16
|
+
read_other: "Read notifications ({{count}})"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
filters: {
|
|
20
|
+
title: "Filters",
|
|
21
|
+
view: {
|
|
22
|
+
label: "View",
|
|
23
|
+
unread: "Unread notifications",
|
|
24
|
+
read: "Read notifications",
|
|
25
|
+
saved: "Saved",
|
|
26
|
+
all: "All"
|
|
27
|
+
},
|
|
28
|
+
createdAfter: {
|
|
29
|
+
label: "Sent out",
|
|
30
|
+
placeholder: "Notifications since",
|
|
31
|
+
last24h: "Last 24h",
|
|
32
|
+
lastWeek: "Last week",
|
|
33
|
+
anyTime: "Any time"
|
|
34
|
+
},
|
|
35
|
+
sortBy: {
|
|
36
|
+
label: "Sort by",
|
|
37
|
+
placeholder: "Field to sort by",
|
|
38
|
+
newest: "Newest on top",
|
|
39
|
+
oldest: "Oldest on top",
|
|
40
|
+
topic: "Topic",
|
|
41
|
+
origin: "Origin"
|
|
42
|
+
},
|
|
43
|
+
severity: {
|
|
44
|
+
label: "Min severity",
|
|
45
|
+
critical: "Critical",
|
|
46
|
+
high: "High",
|
|
47
|
+
normal: "Normal",
|
|
48
|
+
low: "Low"
|
|
49
|
+
},
|
|
50
|
+
topic: {
|
|
51
|
+
label: "Topic",
|
|
52
|
+
anyTopic: "Any topic"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
table: {
|
|
56
|
+
emptyMessage: "No records to display",
|
|
57
|
+
pagination: {
|
|
58
|
+
firstTooltip: "First Page",
|
|
59
|
+
labelDisplayedRows: "{from}-{to} of {count}",
|
|
60
|
+
labelRowsSelect: "rows",
|
|
61
|
+
lastTooltip: "Last Page",
|
|
62
|
+
nextTooltip: "Next Page",
|
|
63
|
+
previousTooltip: "Previous Page"
|
|
64
|
+
},
|
|
65
|
+
bulkActions: {
|
|
66
|
+
markAllRead: "Mark all read",
|
|
67
|
+
markSelectedAsRead: "Mark selected as read",
|
|
68
|
+
returnSelectedAmongUnread: "Return selected among unread",
|
|
69
|
+
saveSelectedForLater: "Save selected for later",
|
|
70
|
+
undoSaveForSelected: "Undo save for selected"
|
|
71
|
+
},
|
|
72
|
+
confirmDialog: {
|
|
73
|
+
title: "Are you sure?",
|
|
74
|
+
markAllReadDescription: "Mark <b>all</b> notifications as <b>read</b>.",
|
|
75
|
+
markAllReadConfirmation: "Mark All"
|
|
76
|
+
},
|
|
77
|
+
errors: {
|
|
78
|
+
markAllReadFailed: "Failed to mark all notifications as read"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
sidebar: {
|
|
82
|
+
title: "Notifications",
|
|
83
|
+
errors: {
|
|
84
|
+
markAsReadFailed: "Failed to mark notification as read",
|
|
85
|
+
fetchNotificationFailed: "Failed to fetch notification"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
settings: {
|
|
89
|
+
title: "Notification settings",
|
|
90
|
+
errorTitle: "Failed to load settings",
|
|
91
|
+
noSettingsAvailable: "No notification settings available, check back later",
|
|
92
|
+
table: {
|
|
93
|
+
origin: "Origin",
|
|
94
|
+
topic: "Topic"
|
|
95
|
+
},
|
|
96
|
+
errors: {
|
|
97
|
+
useNotificationFormat: "useNotificationFormat must be used within a NotificationFormatProvider"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export { notificationsTranslationRef };
|
|
104
|
+
//# sourceMappingURL=translation.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation.esm.js","sources":["../src/translation.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { createTranslationRef } from '@backstage/frontend-plugin-api';\n\n/** @alpha */\nexport const notificationsTranslationRef = createTranslationRef({\n id: 'plugin.notifications',\n messages: {\n notificationsPage: {\n title: 'Notifications',\n tableTitle: {\n all_one: 'All notifications ({{count}})',\n all_other: 'All notifications ({{count}})',\n saved_one: 'Saved notifications ({{count}})',\n saved_other: 'Saved notifications ({{count}})',\n unread_one: 'Unread notifications ({{count}})',\n unread_other: 'Unread notifications ({{count}})',\n read_one: 'Read notifications ({{count}})',\n read_other: 'Read notifications ({{count}})',\n },\n },\n filters: {\n title: 'Filters',\n view: {\n label: 'View',\n unread: 'Unread notifications',\n read: 'Read notifications',\n saved: 'Saved',\n all: 'All',\n },\n createdAfter: {\n label: 'Sent out',\n placeholder: 'Notifications since',\n last24h: 'Last 24h',\n lastWeek: 'Last week',\n anyTime: 'Any time',\n },\n sortBy: {\n label: 'Sort by',\n placeholder: 'Field to sort by',\n newest: 'Newest on top',\n oldest: 'Oldest on top',\n topic: 'Topic',\n origin: 'Origin',\n },\n severity: {\n label: 'Min severity',\n critical: 'Critical',\n high: 'High',\n normal: 'Normal',\n low: 'Low',\n },\n topic: {\n label: 'Topic',\n anyTopic: 'Any topic',\n },\n },\n table: {\n emptyMessage: 'No records to display',\n pagination: {\n firstTooltip: 'First Page',\n labelDisplayedRows: '{from}-{to} of {count}',\n labelRowsSelect: 'rows',\n lastTooltip: 'Last Page',\n nextTooltip: 'Next Page',\n previousTooltip: 'Previous Page',\n },\n bulkActions: {\n markAllRead: 'Mark all read',\n markSelectedAsRead: 'Mark selected as read',\n returnSelectedAmongUnread: 'Return selected among unread',\n saveSelectedForLater: 'Save selected for later',\n undoSaveForSelected: 'Undo save for selected',\n },\n confirmDialog: {\n title: 'Are you sure?',\n markAllReadDescription: 'Mark <b>all</b> notifications as <b>read</b>.',\n markAllReadConfirmation: 'Mark All',\n },\n errors: {\n markAllReadFailed: 'Failed to mark all notifications as read',\n },\n },\n sidebar: {\n title: 'Notifications',\n errors: {\n markAsReadFailed: 'Failed to mark notification as read',\n fetchNotificationFailed: 'Failed to fetch notification',\n },\n },\n settings: {\n title: 'Notification settings',\n errorTitle: 'Failed to load settings',\n noSettingsAvailable:\n 'No notification settings available, check back later',\n table: {\n origin: 'Origin',\n topic: 'Topic',\n },\n errors: {\n useNotificationFormat:\n 'useNotificationFormat must be used within a NotificationFormatProvider',\n },\n },\n },\n});\n"],"names":[],"mappings":";;AAmBO,MAAM,8BAA8B,oBAAA,CAAqB;AAAA,EAC9D,EAAA,EAAI,sBAAA;AAAA,EACJ,QAAA,EAAU;AAAA,IACR,iBAAA,EAAmB;AAAA,MACjB,KAAA,EAAO,eAAA;AAAA,MACP,UAAA,EAAY;AAAA,QACV,OAAA,EAAS,+BAAA;AAAA,QACT,SAAA,EAAW,+BAAA;AAAA,QACX,SAAA,EAAW,iCAAA;AAAA,QACX,WAAA,EAAa,iCAAA;AAAA,QACb,UAAA,EAAY,kCAAA;AAAA,QACZ,YAAA,EAAc,kCAAA;AAAA,QACd,QAAA,EAAU,gCAAA;AAAA,QACV,UAAA,EAAY;AAAA;AACd,KACF;AAAA,IACA,OAAA,EAAS;AAAA,MACP,KAAA,EAAO,SAAA;AAAA,MACP,IAAA,EAAM;AAAA,QACJ,KAAA,EAAO,MAAA;AAAA,QACP,MAAA,EAAQ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ACb,KAAA,EAAO,eAAA;AAAA,QACP,sBAAA,EAAwB,+CAAA;AAAA,QACxB,uBAAA,EAAyB;AAAA,OAC3B;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,iBAAA,EAAmB;AAAA;AACrB,KACF;AAAA,IACA,OAAA,EAAS;AAAA,MACP,KAAA,EAAO,eAAA;AAAA,MACP,MAAA,EAAQ;AAAA,QACN,gBAAA,EAAkB,qCAAA;AAAA,QAClB,uBAAA,EAAyB;AAAA;AAC3B,KACF;AAAA,IACA,QAAA,EAAU;AAAA,MACR,KAAA,EAAO,uBAAA;AAAA,MACP,UAAA,EAAY,yBAAA;AAAA,MACZ,mBAAA,EACE,sDAAA;AAAA,MACF,KAAA,EAAO;AAAA,QACL,MAAA,EAAQ,QAAA;AAAA,QACR,KAAA,EAAO;AAAA,OACT;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,qBAAA,EACE;AAAA;AACJ;AACF;AAEJ,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-notifications",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "frontend-plugin",
|
|
6
6
|
"pluginId": "notifications",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"test": "backstage-cli package test"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@backstage/core-components": "^0.18.
|
|
66
|
+
"@backstage/core-components": "^0.18.5",
|
|
67
67
|
"@backstage/core-plugin-api": "^1.12.1",
|
|
68
68
|
"@backstage/errors": "^1.2.7",
|
|
69
|
-
"@backstage/frontend-plugin-api": "^0.13.
|
|
69
|
+
"@backstage/frontend-plugin-api": "^0.13.3",
|
|
70
70
|
"@backstage/plugin-notifications-common": "^0.2.0",
|
|
71
71
|
"@backstage/plugin-signals-react": "^0.0.18",
|
|
72
72
|
"@backstage/theme": "^0.7.1",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"react-use": "^17.2.4"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@backstage/cli": "^0.35.
|
|
83
|
-
"@backstage/dev-utils": "^1.1.
|
|
84
|
-
"@backstage/plugin-signals": "^0.0.
|
|
82
|
+
"@backstage/cli": "^0.35.2",
|
|
83
|
+
"@backstage/dev-utils": "^1.1.19",
|
|
84
|
+
"@backstage/plugin-signals": "^0.0.27",
|
|
85
85
|
"@backstage/test-utils": "^1.7.14",
|
|
86
86
|
"@testing-library/jest-dom": "^6.0.0",
|
|
87
87
|
"@testing-library/react": "^16.0.0",
|