@servicetitan/notifications 28.5.0 → 29.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/intercept.test.d.ts +2 -0
- package/dist/__tests__/intercept.test.d.ts.map +1 -0
- package/dist/__tests__/intercept.test.js +13 -0
- package/dist/__tests__/intercept.test.js.map +1 -0
- package/dist/__tests__/notifications-service.test.d.ts +2 -0
- package/dist/__tests__/notifications-service.test.d.ts.map +1 -0
- package/dist/__tests__/notifications-service.test.js +42 -0
- package/dist/__tests__/notifications-service.test.js.map +1 -0
- package/dist/api/notifications.api.d.ts +2 -2
- package/dist/api/notifications.api.d.ts.map +1 -1
- package/dist/common.d.ts +4 -22
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +4 -11
- package/dist/common.js.map +1 -1
- package/dist/components/__tests__/notifications.test.d.ts +2 -0
- package/dist/components/__tests__/notifications.test.d.ts.map +1 -0
- package/dist/components/__tests__/notifications.test.js +93 -0
- package/dist/components/__tests__/notifications.test.js.map +1 -0
- package/dist/components/notifications.d.ts +8 -1
- package/dist/components/notifications.d.ts.map +1 -1
- package/dist/components/notifications.js +43 -23
- package/dist/components/notifications.js.map +1 -1
- package/dist/demo/action-button-preview.d.ts.map +1 -1
- package/dist/demo/action-button-preview.js +2 -2
- package/dist/demo/action-button-preview.js.map +1 -1
- package/dist/demo/basic-preview.d.ts.map +1 -1
- package/dist/demo/basic-preview.js +1 -1
- package/dist/demo/basic-preview.js.map +1 -1
- package/dist/demo/container.d.ts +1 -3
- package/dist/demo/container.d.ts.map +1 -1
- package/dist/demo/container.js.map +1 -1
- package/dist/demo/duration-preview.d.ts.map +1 -1
- package/dist/demo/duration-preview.js +2 -2
- package/dist/demo/duration-preview.js.map +1 -1
- package/dist/demo/multiline-message-preview.d.ts.map +1 -1
- package/dist/demo/multiline-message-preview.js +2 -2
- package/dist/demo/multiline-message-preview.js.map +1 -1
- package/dist/demo/prevent-duplicates-preview.d.ts.map +1 -1
- package/dist/demo/prevent-duplicates-preview.js +2 -2
- package/dist/demo/prevent-duplicates-preview.js.map +1 -1
- package/dist/demo/progress-preview.d.ts.map +1 -1
- package/dist/demo/progress-preview.js +2 -2
- package/dist/demo/progress-preview.js.map +1 -1
- package/dist/demo/server-custom-preview.d.ts +1 -1
- package/dist/demo/server-custom-preview.d.ts.map +1 -1
- package/dist/demo/server-custom-preview.js +21 -7
- package/dist/demo/server-custom-preview.js.map +1 -1
- package/dist/demo/server-custom.d.ts +0 -1
- package/dist/demo/server-custom.d.ts.map +1 -1
- package/dist/demo/server-custom.js +25 -21
- package/dist/demo/server-custom.js.map +1 -1
- package/dist/demo/server-default.d.ts.map +1 -1
- package/dist/demo/server-default.js +1 -1
- package/dist/demo/server-default.js.map +1 -1
- package/dist/demo/status-variations-preview.d.ts.map +1 -1
- package/dist/demo/status-variations-preview.js +2 -2
- package/dist/demo/status-variations-preview.js.map +1 -1
- package/dist/demo/status-variations.d.ts.map +1 -1
- package/dist/demo/status-variations.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/intercept.d.ts +4 -0
- package/dist/intercept.d.ts.map +1 -0
- package/dist/intercept.js +5 -0
- package/dist/intercept.js.map +1 -0
- package/dist/notifications-channel.d.ts +2 -6
- package/dist/notifications-channel.d.ts.map +1 -1
- package/dist/notifications-channel.js.map +1 -1
- package/dist/notifications-service.d.ts +10 -8
- package/dist/notifications-service.d.ts.map +1 -1
- package/dist/notifications-service.js.map +1 -1
- package/dist/notifications.stories.d.ts +14 -0
- package/dist/notifications.stories.d.ts.map +1 -0
- package/dist/notifications.stories.js +20 -0
- package/dist/notifications.stories.js.map +1 -0
- package/dist/stores/__mocks__/mock-notifications-channel.d.ts +11 -0
- package/dist/stores/__mocks__/mock-notifications-channel.d.ts.map +1 -0
- package/dist/stores/__mocks__/mock-notifications-channel.js +36 -0
- package/dist/stores/__mocks__/mock-notifications-channel.js.map +1 -0
- package/dist/stores/__tests__/notifications.store.test.d.ts +2 -0
- package/dist/stores/__tests__/notifications.store.test.d.ts.map +1 -0
- package/dist/stores/__tests__/notifications.store.test.js +360 -0
- package/dist/stores/__tests__/notifications.store.test.js.map +1 -0
- package/dist/stores/notifications.store.d.ts +20 -8
- package/dist/stores/notifications.store.d.ts.map +1 -1
- package/dist/stores/notifications.store.js +156 -45
- package/dist/stores/notifications.store.js.map +1 -1
- package/dist/utils/__tests__/date-from-string.test.d.ts +2 -0
- package/dist/utils/__tests__/date-from-string.test.d.ts.map +1 -0
- package/dist/utils/__tests__/date-from-string.test.js +39 -0
- package/dist/utils/__tests__/date-from-string.test.js.map +1 -0
- package/dist/utils/__tests__/use-compatible-navigate.test.d.ts +2 -0
- package/dist/utils/__tests__/use-compatible-navigate.test.d.ts.map +1 -0
- package/dist/utils/__tests__/use-compatible-navigate.test.js +27 -0
- package/dist/utils/__tests__/use-compatible-navigate.test.js.map +1 -0
- package/dist/utils/date-from-string.d.ts.map +1 -0
- package/dist/utils/date-from-string.js +19 -0
- package/dist/utils/date-from-string.js.map +1 -0
- package/package.json +6 -6
- package/src/__tests__/intercept.test.ts +18 -0
- package/src/__tests__/notifications-service.test.ts +62 -0
- package/src/api/notifications.api.ts +2 -2
- package/src/common.ts +12 -27
- package/src/components/__tests__/notifications.test.tsx +107 -0
- package/src/components/notifications.tsx +59 -36
- package/src/demo/action-button-preview.tsx +4 -6
- package/src/demo/basic-preview.tsx +2 -4
- package/src/demo/container.tsx +1 -4
- package/src/demo/duration-preview.tsx +4 -6
- package/src/demo/multiline-message-preview.tsx +3 -9
- package/src/demo/prevent-duplicates-preview.tsx +3 -9
- package/src/demo/progress-preview.tsx +3 -9
- package/src/demo/server-custom-preview.tsx +17 -14
- package/src/demo/server-custom.tsx +30 -29
- package/src/demo/server-default.tsx +1 -3
- package/src/demo/status-variations-preview.tsx +4 -6
- package/src/demo/status-variations.tsx +0 -1
- package/src/index.ts +13 -4
- package/src/intercept.ts +14 -0
- package/src/notifications-channel.ts +2 -6
- package/src/notifications-service.ts +14 -42
- package/src/stores/__mocks__/mock-notifications-channel.ts +31 -0
- package/src/stores/__tests__/notifications.store.test.ts +458 -0
- package/src/stores/notifications.store.ts +178 -53
- package/src/utils/__tests__/date-from-string.test.ts +53 -0
- package/src/utils/__tests__/use-compatible-navigate.test.ts +43 -0
- package/src/utils/date-from-string.ts +22 -0
- package/dist/components/__tests__/container.test.d.ts +0 -2
- package/dist/components/__tests__/container.test.d.ts.map +0 -1
- package/dist/components/__tests__/container.test.js +0 -59
- package/dist/components/__tests__/container.test.js.map +0 -1
- package/dist/components/container.d.ts +0 -3
- package/dist/components/container.d.ts.map +0 -1
- package/dist/components/container.js +0 -26
- package/dist/components/container.js.map +0 -1
- package/dist/components/default-notification.d.ts +0 -7
- package/dist/components/default-notification.d.ts.map +0 -1
- package/dist/components/default-notification.js +0 -26
- package/dist/components/default-notification.js.map +0 -1
- package/dist/components/default-notification.module.css +0 -3
- package/dist/components/no-ssr.d.ts +0 -5
- package/dist/components/no-ssr.d.ts.map +0 -1
- package/dist/components/no-ssr.js +0 -9
- package/dist/components/no-ssr.js.map +0 -1
- package/dist/components/notifications-unwrapped.d.ts +0 -3
- package/dist/components/notifications-unwrapped.d.ts.map +0 -1
- package/dist/components/notifications-unwrapped.js +0 -27
- package/dist/components/notifications-unwrapped.js.map +0 -1
- package/dist/components/shadow-dom.d.ts +0 -3
- package/dist/components/shadow-dom.d.ts.map +0 -1
- package/dist/components/shadow-dom.js +0 -41
- package/dist/components/shadow-dom.js.map +0 -1
- package/dist/components/use-style-sheets.d.ts +0 -2
- package/dist/components/use-style-sheets.d.ts.map +0 -1
- package/dist/components/use-style-sheets.js +0 -15
- package/dist/components/use-style-sheets.js.map +0 -1
- package/dist/create-element.d.ts +0 -2
- package/dist/create-element.d.ts.map +0 -1
- package/dist/create-element.js +0 -8
- package/dist/create-element.js.map +0 -1
- package/dist/date-from-string.d.ts.map +0 -1
- package/dist/date-from-string.js +0 -27
- package/dist/date-from-string.js.map +0 -1
- package/dist/register.d.ts +0 -3
- package/dist/register.d.ts.map +0 -1
- package/dist/register.js +0 -5
- package/dist/register.js.map +0 -1
- package/src/components/__tests__/container.test.tsx +0 -71
- package/src/components/container.tsx +0 -35
- package/src/components/default-notification.module.css +0 -3
- package/src/components/default-notification.module.css.d.ts +0 -4
- package/src/components/default-notification.tsx +0 -59
- package/src/components/no-ssr.tsx +0 -11
- package/src/components/notifications-unwrapped.tsx +0 -51
- package/src/components/shadow-dom.tsx +0 -53
- package/src/components/use-style-sheets.ts +0 -19
- package/src/create-element.ts +0 -12
- package/src/date-from-string.ts +0 -30
- package/src/register.ts +0 -6
- /package/dist/{date-from-string.d.ts → utils/date-from-string.d.ts} +0 -0
@@ -19,14 +19,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
19
19
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20
20
|
});
|
21
21
|
};
|
22
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
23
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
24
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
25
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
26
|
+
};
|
27
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
28
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
29
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
30
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
31
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
32
|
+
};
|
33
|
+
var _NotificationsStore_navigate;
|
22
34
|
var NotificationsStore_1;
|
35
|
+
import { toast } from '@servicetitan/anvil2';
|
23
36
|
import { injectable, inject, optional } from '@servicetitan/react-ioc';
|
24
|
-
import {
|
37
|
+
import { action, runInAction, comparer, makeObservable } from 'mobx';
|
38
|
+
import { NotificationsApi, NotificationProcessStatus as ServerNotificationStatus, } from '../api/notifications.api';
|
39
|
+
import { Status, isLinkAction, isNewer } from '../common';
|
25
40
|
import { NOTIFICATIONS_CHANNEL_TOKEN } from '../notifications-channel';
|
26
|
-
import {
|
27
|
-
import { isNewer, toClientNotification, DEFAULT_CLIENT_NOTIFICATION_TYPE, } from '../common';
|
28
|
-
import { dateFromString } from '../date-from-string';
|
41
|
+
import { dateFromString } from '../utils/date-from-string';
|
29
42
|
const EVENT_NAME = 'NotificationEvent';
|
43
|
+
const CLIENT_NOTIFICATION_TYPE = 'ClientNotification';
|
44
|
+
const CLIENT_NOTIFICATION_VERSION = 1;
|
30
45
|
const DAY_INTERVAL = 24 * 60 * 60 * 1000;
|
31
46
|
let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
32
47
|
constructor(notificationsApi, notificationsChannel) {
|
@@ -42,12 +57,6 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
42
57
|
writable: true,
|
43
58
|
value: notificationsChannel
|
44
59
|
});
|
45
|
-
Object.defineProperty(this, "innerNotifications", {
|
46
|
-
enumerable: true,
|
47
|
-
configurable: true,
|
48
|
-
writable: true,
|
49
|
-
value: new Map()
|
50
|
-
});
|
51
60
|
Object.defineProperty(this, "index", {
|
52
61
|
enumerable: true,
|
53
62
|
configurable: true,
|
@@ -66,12 +75,19 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
66
75
|
writable: true,
|
67
76
|
value: void 0
|
68
77
|
});
|
78
|
+
Object.defineProperty(this, "notifications", {
|
79
|
+
enumerable: true,
|
80
|
+
configurable: true,
|
81
|
+
writable: true,
|
82
|
+
value: new Map()
|
83
|
+
});
|
69
84
|
Object.defineProperty(this, "closedNotifications", {
|
70
85
|
enumerable: true,
|
71
86
|
configurable: true,
|
72
87
|
writable: true,
|
73
88
|
value: new Map()
|
74
89
|
});
|
90
|
+
_NotificationsStore_navigate.set(this, void 0);
|
75
91
|
Object.defineProperty(this, "initialize", {
|
76
92
|
enumerable: true,
|
77
93
|
configurable: true,
|
@@ -112,19 +128,23 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
112
128
|
const notification = {
|
113
129
|
id: this.index,
|
114
130
|
userId: this.userId,
|
115
|
-
type:
|
116
|
-
status:
|
131
|
+
type: CLIENT_NOTIFICATION_TYPE,
|
132
|
+
status: ServerNotificationStatus.Info,
|
117
133
|
isRead: false,
|
118
134
|
createdOn: new Date(),
|
119
135
|
modifiedOn: new Date(),
|
120
|
-
version:
|
121
|
-
payload: options,
|
136
|
+
version: CLIENT_NOTIFICATION_VERSION,
|
137
|
+
payload: Object.assign({}, options),
|
122
138
|
};
|
123
|
-
if (
|
124
|
-
|
125
|
-
|
126
|
-
|
139
|
+
if (preventDuplicates) {
|
140
|
+
if ([...this.notifications.values()].some(({ payload }) => comparer.structural(payload, notification.payload))) {
|
141
|
+
return;
|
142
|
+
}
|
143
|
+
this.notifications.set(notification.id, notification);
|
127
144
|
}
|
145
|
+
const method = this.getToastMethod(notification);
|
146
|
+
notification.toastId = toast[method](this.getToastProps(notification));
|
147
|
+
this.index -= 1;
|
128
148
|
}
|
129
149
|
});
|
130
150
|
Object.defineProperty(this, "read", {
|
@@ -133,7 +153,7 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
133
153
|
writable: true,
|
134
154
|
value: (notification) => {
|
135
155
|
if (notification.id > 0) {
|
136
|
-
if (notification.status ===
|
156
|
+
if (notification.status === ServerNotificationStatus.InProgress) {
|
137
157
|
this.closedNotifications.set(notification.id, {
|
138
158
|
status: notification.status,
|
139
159
|
timestamp: Date.now(),
|
@@ -143,7 +163,7 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
143
163
|
this.notificationsApi.changeIsReadProperty(notification.id, true, notification.version);
|
144
164
|
}
|
145
165
|
}
|
146
|
-
this.
|
166
|
+
this.notifications.delete(notification.id);
|
147
167
|
}
|
148
168
|
});
|
149
169
|
Object.defineProperty(this, "onPublisherEvent", {
|
@@ -154,19 +174,28 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
154
174
|
if (notification.userId !== this.userId) {
|
155
175
|
return;
|
156
176
|
}
|
157
|
-
// FIXME: FAR-385
|
158
177
|
this.updateIfNewer(Object.assign(Object.assign({}, notification), { createdOn: dateFromString(notification.createdOn), modifiedOn: dateFromString(notification.modifiedOn) }));
|
159
178
|
}
|
160
179
|
});
|
161
180
|
makeObservable(this);
|
162
181
|
}
|
163
|
-
|
164
|
-
|
182
|
+
static intercept(type, fn) {
|
183
|
+
if (fn) {
|
184
|
+
NotificationsStore_1.interceptors.set(type, fn);
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
NotificationsStore_1.interceptors.delete(type);
|
188
|
+
}
|
165
189
|
}
|
166
190
|
get publisher() {
|
167
|
-
|
168
|
-
|
169
|
-
|
191
|
+
var _a;
|
192
|
+
return (_a = this.notificationsChannel) === null || _a === void 0 ? void 0 : _a.call(this);
|
193
|
+
}
|
194
|
+
get navigate() {
|
195
|
+
return __classPrivateFieldGet(this, _NotificationsStore_navigate, "f");
|
196
|
+
}
|
197
|
+
set navigate(fn) {
|
198
|
+
__classPrivateFieldSet(this, _NotificationsStore_navigate, fn, "f");
|
170
199
|
}
|
171
200
|
cleanupClosedNotifications() {
|
172
201
|
for (const [id, { timestamp }] of Array.from(this.closedNotifications)) {
|
@@ -176,7 +205,6 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
176
205
|
}
|
177
206
|
}
|
178
207
|
updateIfNewer(notification) {
|
179
|
-
const existing = this.innerNotifications.get(notification.id);
|
180
208
|
const closed = this.closedNotifications.get(notification.id);
|
181
209
|
if (closed) {
|
182
210
|
if (closed.status === notification.status) {
|
@@ -184,32 +212,115 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
|
|
184
212
|
}
|
185
213
|
this.closedNotifications.delete(notification.id);
|
186
214
|
}
|
187
|
-
|
188
|
-
|
215
|
+
const clientNotification = this.toClientNotification(notification);
|
216
|
+
if (!clientNotification) {
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
const existing = this.notifications.get(notification.id);
|
220
|
+
if (existing) {
|
221
|
+
if (!isNewer(existing, notification)) {
|
222
|
+
return;
|
223
|
+
}
|
224
|
+
if (notification.status === existing.status ||
|
225
|
+
notification.status === ServerNotificationStatus.InProgress) {
|
226
|
+
toast.update(existing.toastId, this.getToastProps(clientNotification));
|
227
|
+
return;
|
228
|
+
}
|
229
|
+
toast.dismiss(existing.toastId);
|
230
|
+
}
|
231
|
+
const method = this.getToastMethod(clientNotification);
|
232
|
+
clientNotification.toastId = toast[method](this.getToastProps(clientNotification));
|
233
|
+
this.notifications.set(notification.id, clientNotification);
|
234
|
+
}
|
235
|
+
getToastMethod({ payload: { status } }) {
|
236
|
+
switch (status) {
|
237
|
+
case Status.Success:
|
238
|
+
return 'success';
|
239
|
+
case Status.Error:
|
240
|
+
return 'danger';
|
241
|
+
case Status.Warning:
|
242
|
+
return 'warning';
|
243
|
+
default:
|
244
|
+
return 'info';
|
245
|
+
}
|
246
|
+
}
|
247
|
+
getToastProps(notification) {
|
248
|
+
const { action, duration, message = '', progress, title } = notification.payload;
|
249
|
+
return {
|
250
|
+
actions: this.getToastActions(notification),
|
251
|
+
duration: action ? false : duration,
|
252
|
+
message,
|
253
|
+
onClose: () => this.handleClose(notification),
|
254
|
+
progress,
|
255
|
+
title,
|
256
|
+
};
|
257
|
+
}
|
258
|
+
getToastActions(notification) {
|
259
|
+
const { action } = notification.payload;
|
260
|
+
if (!action) {
|
261
|
+
return;
|
262
|
+
}
|
263
|
+
return {
|
264
|
+
primary: {
|
265
|
+
label: action.label,
|
266
|
+
onClick: () => this.handleClick(notification),
|
267
|
+
},
|
268
|
+
};
|
269
|
+
}
|
270
|
+
handleClick({ payload: { action }, toastId }) {
|
271
|
+
var _a;
|
272
|
+
if (action) {
|
273
|
+
if (isLinkAction(action)) {
|
274
|
+
if (action.external) {
|
275
|
+
window.open(action.link);
|
276
|
+
}
|
277
|
+
else {
|
278
|
+
(_a = this.navigate) === null || _a === void 0 ? void 0 : _a.call(this, action.link);
|
279
|
+
}
|
280
|
+
}
|
281
|
+
else {
|
282
|
+
action.onClick();
|
283
|
+
}
|
284
|
+
}
|
285
|
+
toast.dismiss(toastId);
|
286
|
+
}
|
287
|
+
handleClose(notification) {
|
288
|
+
this.read(notification);
|
289
|
+
}
|
290
|
+
toClientNotification(serverNotification) {
|
291
|
+
var _a;
|
292
|
+
const result = Object.assign(Object.assign({}, serverNotification), { payload: Object.assign(Object.assign({}, JSON.parse((_a = serverNotification.payload) !== null && _a !== void 0 ? _a : '{}')), { status: this.toClientStatus(serverNotification.status) }) });
|
293
|
+
const interceptor = NotificationsStore_1.interceptors.get(serverNotification.type);
|
294
|
+
if (!interceptor) {
|
295
|
+
return result;
|
296
|
+
}
|
297
|
+
const dismiss = () => {
|
298
|
+
var _a;
|
299
|
+
const toastId = (_a = this.notifications.get(result.id)) === null || _a === void 0 ? void 0 : _a.toastId;
|
300
|
+
if (toastId) {
|
301
|
+
toast.dismiss(toastId);
|
302
|
+
}
|
303
|
+
};
|
304
|
+
return interceptor(result, dismiss);
|
305
|
+
}
|
306
|
+
toClientStatus(status) {
|
307
|
+
switch (status) {
|
308
|
+
case ServerNotificationStatus.Success:
|
309
|
+
return Status.Success;
|
310
|
+
case ServerNotificationStatus.Failure:
|
311
|
+
return Status.Error;
|
312
|
+
default:
|
313
|
+
return Status.Info;
|
189
314
|
}
|
190
315
|
}
|
191
316
|
};
|
192
|
-
|
317
|
+
_NotificationsStore_navigate = new WeakMap();
|
318
|
+
Object.defineProperty(NotificationsStore, "interceptors", {
|
193
319
|
enumerable: true,
|
194
320
|
configurable: true,
|
195
321
|
writable: true,
|
196
322
|
value: new Map()
|
197
323
|
});
|
198
|
-
Object.defineProperty(NotificationsStore, "register", {
|
199
|
-
enumerable: true,
|
200
|
-
configurable: true,
|
201
|
-
writable: true,
|
202
|
-
value: (type, mapper) => NotificationsStore_1.types.set(type, mapper)
|
203
|
-
});
|
204
|
-
__decorate([
|
205
|
-
observable,
|
206
|
-
__metadata("design:type", Object)
|
207
|
-
], NotificationsStore.prototype, "innerNotifications", void 0);
|
208
|
-
__decorate([
|
209
|
-
computed,
|
210
|
-
__metadata("design:type", Object),
|
211
|
-
__metadata("design:paramtypes", [])
|
212
|
-
], NotificationsStore.prototype, "notifications", null);
|
213
324
|
__decorate([
|
214
325
|
action,
|
215
326
|
__metadata("design:type", Object)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"notifications.store.js","sourceRoot":"","sources":["../../src/stores/notifications.store.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"notifications.store.js","sourceRoot":"","sources":["../../src/stores/notifications.store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAErE,OAAO,EAEH,gBAAgB,EAEhB,yBAAyB,IAAI,wBAAwB,GACxD,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAA4C,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpG,OAAO,EAAwB,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,UAAU,GAAG,mBAAmB,CAAC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tests__/date-from-string.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { dateFromString } from '../date-from-string';
|
2
|
+
describe(dateFromString.name, () => {
|
3
|
+
let value;
|
4
|
+
const subject = () => dateFromString(value);
|
5
|
+
describe('with Date value', () => {
|
6
|
+
beforeEach(() => (value = new Date()));
|
7
|
+
test('returns value', () => {
|
8
|
+
expect(subject()).toBe(value);
|
9
|
+
});
|
10
|
+
});
|
11
|
+
describe('with a ISO date string', () => {
|
12
|
+
const date = new Date(2025, 1, 3, 14, 15, 9, 265);
|
13
|
+
beforeEach(() => (value = date.toISOString()));
|
14
|
+
test('converts string to date', () => {
|
15
|
+
expect(subject()).toEqual(date);
|
16
|
+
});
|
17
|
+
});
|
18
|
+
describe('with a .NET date string', () => {
|
19
|
+
const now = Date.now();
|
20
|
+
beforeEach(() => (value = `/Date(${now})/`));
|
21
|
+
function itConvertsStringToDate() {
|
22
|
+
test('converts string to date', () => {
|
23
|
+
expect(subject()).toEqual(new Date(now));
|
24
|
+
});
|
25
|
+
}
|
26
|
+
itConvertsStringToDate();
|
27
|
+
describe('when date has optional local offset', () => {
|
28
|
+
beforeEach(() => (value = `/Date(${now}-0500)/`));
|
29
|
+
itConvertsStringToDate();
|
30
|
+
});
|
31
|
+
});
|
32
|
+
describe('with unrecognized value', () => {
|
33
|
+
beforeEach(() => (value = 'foo'));
|
34
|
+
test('throws error', () => {
|
35
|
+
expect(subject).toThrow('Incorrect date format');
|
36
|
+
});
|
37
|
+
});
|
38
|
+
});
|
39
|
+
//# sourceMappingURL=date-from-string.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"date-from-string.test.js","sourceRoot":"","sources":["../../../src/utils/__tests__/date-from-string.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE;IAC/B,IAAI,KAAoB,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AAC;QAEzB,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;YACjD,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC;YAElD,sBAAsB,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACrC,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;QAElC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;YACtB,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-compatible-navigate.test.d.ts","sourceRoot":"","sources":["../../../src/utils/__tests__/use-compatible-navigate.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { renderHook } from '@testing-library/react';
|
2
|
+
import * as ReactRouterDOM from 'react-router-dom';
|
3
|
+
import { useCompatibleNavigate } from '../use-compatible-navigate';
|
4
|
+
jest.mock('react-router-dom', () => ({
|
5
|
+
useHistory: jest.fn(),
|
6
|
+
useNavigate: jest.fn(),
|
7
|
+
}));
|
8
|
+
describe(useCompatibleNavigate.name, () => {
|
9
|
+
const subject = () => renderHook(() => useCompatibleNavigate());
|
10
|
+
describe('when useNavigate exists', () => {
|
11
|
+
const navigate = jest.fn();
|
12
|
+
beforeEach(() => jest.mocked(ReactRouterDOM.useNavigate).mockReturnValue(navigate));
|
13
|
+
test('returns useNavigate result', () => {
|
14
|
+
const { result: { current: value }, } = subject();
|
15
|
+
expect(value).toBe(navigate);
|
16
|
+
});
|
17
|
+
describe('when useHistory exists', () => {
|
18
|
+
const history = { push: jest.fn() };
|
19
|
+
beforeEach(() => jest.mocked(ReactRouterDOM.useHistory).mockReturnValue(history));
|
20
|
+
test('returns history.push', () => {
|
21
|
+
const { result: { current: value }, } = subject();
|
22
|
+
expect(value).toBe(history.push);
|
23
|
+
});
|
24
|
+
});
|
25
|
+
});
|
26
|
+
});
|
27
|
+
//# sourceMappingURL=use-compatible-navigate.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-compatible-navigate.test.js","sourceRoot":"","sources":["../../../src/utils/__tests__/use-compatible-navigate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,CAAC;IACjC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;IACrB,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE;CACzB,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAqB,CAAC,IAAI,EAAE,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAEhE,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QAE3B,UAAU,CAAC,GAAG,EAAE,CACZ,IAAI,CAAC,MAAM,CAAE,cAAsB,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAC7E,CAAC;QAEF,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACpC,MAAM,EACF,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GAC7B,GAAG,OAAO,EAAE,CAAC;YAEd,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;YACpC,MAAM,OAAO,GAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC;YAEzC,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;YAElF,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE;gBAC9B,MAAM,EACF,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GAC7B,GAAG,OAAO,EAAE,CAAC;gBAEd,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"date-from-string.d.ts","sourceRoot":"","sources":["../../src/utils/date-from-string.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,QAkBjD"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const dateISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:[.,]\d+)?Z?$/i;
|
2
|
+
const dateNet = /\/Date\((-?\d+)(?:[+-]\d+)?\)\//i;
|
3
|
+
export function dateFromString(date) {
|
4
|
+
if (typeof date === 'object') {
|
5
|
+
return date;
|
6
|
+
}
|
7
|
+
if (dateISO.test(date)) {
|
8
|
+
const d = date.split(/\D+/).map(s => +s);
|
9
|
+
return new Date(Date.UTC(d[0], --d[1], d[2], d[3], d[4], d[5], d[6]));
|
10
|
+
}
|
11
|
+
if (dateNet.test(date)) {
|
12
|
+
const parsedDate = dateNet.exec(date);
|
13
|
+
if (parsedDate !== null) {
|
14
|
+
return new Date(parseInt(parsedDate[1], 10));
|
15
|
+
}
|
16
|
+
}
|
17
|
+
throw new Error('Incorrect date format');
|
18
|
+
}
|
19
|
+
//# sourceMappingURL=date-from-string.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"date-from-string.js","sourceRoot":"","sources":["../../src/utils/date-from-string.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,sDAAsD,CAAC;AACvE,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAEnD,MAAM,UAAU,cAAc,CAAC,IAAmB;IAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC7C,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@servicetitan/notifications",
|
3
|
-
"version": "
|
3
|
+
"version": "29.0.0",
|
4
4
|
"description": "",
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/notifications-center",
|
6
6
|
"repository": {
|
@@ -10,9 +10,7 @@
|
|
10
10
|
},
|
11
11
|
"main": "./dist/index.js",
|
12
12
|
"typings": "./dist/index.d.ts",
|
13
|
-
"sideEffects":
|
14
|
-
"./dist/demo/**/*"
|
15
|
-
],
|
13
|
+
"sideEffects": false,
|
16
14
|
"files": [
|
17
15
|
"dist",
|
18
16
|
"src"
|
@@ -21,9 +19,11 @@
|
|
21
19
|
"react-shadow-dom-retarget-events": "~1.1.0"
|
22
20
|
},
|
23
21
|
"devDependencies": {
|
22
|
+
"@servicetitan/anvil2": "^1.20.3",
|
24
23
|
"@servicetitan/design-system": "~14.5.1",
|
25
24
|
"@servicetitan/log-service": "^24.0.3",
|
26
25
|
"@servicetitan/react-ioc": "^24.0.3",
|
26
|
+
"@servicetitan/testing-library": "^3.0.0",
|
27
27
|
"@servicetitan/web-components": "^24.0.3",
|
28
28
|
"@testing-library/jest-dom": "^6.4.2",
|
29
29
|
"@testing-library/react": "^14.2.1",
|
@@ -39,7 +39,7 @@
|
|
39
39
|
"react-router-dom": "~5.3.0"
|
40
40
|
},
|
41
41
|
"peerDependencies": {
|
42
|
-
"@servicetitan/
|
42
|
+
"@servicetitan/anvil2": ">=1.13.1",
|
43
43
|
"@servicetitan/log-service": ">21.0.0",
|
44
44
|
"@servicetitan/react-ioc": ">21.0.0",
|
45
45
|
"@servicetitan/web-components": ">21.0.0",
|
@@ -56,5 +56,5 @@
|
|
56
56
|
"cli": {
|
57
57
|
"webpack": false
|
58
58
|
},
|
59
|
-
"gitHead": "
|
59
|
+
"gitHead": "a7bd8d2fe17dbd2ee6499c8623cc777a6abd4dcc"
|
60
60
|
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { NotificationsStore } from '../stores/notifications.store';
|
2
|
+
|
3
|
+
import { intercept } from '../intercept';
|
4
|
+
|
5
|
+
describe(intercept.name, () => {
|
6
|
+
const fn = jest.fn();
|
7
|
+
const type = 'NotificationType';
|
8
|
+
|
9
|
+
const subject = () => intercept(type, fn);
|
10
|
+
|
11
|
+
test('registers interceptor', () => {
|
12
|
+
const interceptSpy = jest.spyOn(NotificationsStore, 'intercept');
|
13
|
+
|
14
|
+
subject();
|
15
|
+
|
16
|
+
expect(interceptSpy).toHaveBeenCalledWith(type, fn);
|
17
|
+
});
|
18
|
+
});
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { DefaultNotificationOptions, Status } from '../common';
|
2
|
+
import { NotificationsStore } from '../stores/notifications.store';
|
3
|
+
|
4
|
+
import { NotificationsService } from '../notifications-service';
|
5
|
+
|
6
|
+
describe(NotificationsService.name, () => {
|
7
|
+
const store: Partial<NotificationsStore> = { add: jest.fn(), initialize: jest.fn() };
|
8
|
+
let options: DefaultNotificationOptions;
|
9
|
+
|
10
|
+
beforeEach(() => {
|
11
|
+
jest.clearAllMocks();
|
12
|
+
options = { title: 'Foo', message: 'Bar!' };
|
13
|
+
});
|
14
|
+
|
15
|
+
const subject = new NotificationsService(store as any);
|
16
|
+
|
17
|
+
describe('initialize', () => {
|
18
|
+
test('initializes store', () => {
|
19
|
+
const userId = 123;
|
20
|
+
|
21
|
+
subject.initialize(userId);
|
22
|
+
|
23
|
+
expect(store.initialize).toHaveBeenCalledWith(userId);
|
24
|
+
});
|
25
|
+
});
|
26
|
+
|
27
|
+
interface TestCase {
|
28
|
+
method: 'info' | 'success' | 'warning' | 'error';
|
29
|
+
status: Status;
|
30
|
+
}
|
31
|
+
|
32
|
+
const testCases: TestCase[] = [
|
33
|
+
{ method: 'info', status: Status.Info },
|
34
|
+
{ method: 'success', status: Status.Success },
|
35
|
+
{ method: 'warning', status: Status.Warning },
|
36
|
+
{ method: 'error', status: Status.Error },
|
37
|
+
];
|
38
|
+
|
39
|
+
describe.each(testCases)('$method', ({ method, status }) => {
|
40
|
+
test(`adds "${status}" notification`, () => {
|
41
|
+
subject[method](options);
|
42
|
+
|
43
|
+
expect(store.add).toHaveBeenCalledWith({ ...options, status }, undefined);
|
44
|
+
});
|
45
|
+
|
46
|
+
test(`passes through preventDuplicates`, () => {
|
47
|
+
const preventDuplicates = true;
|
48
|
+
|
49
|
+
subject[method](options, preventDuplicates);
|
50
|
+
|
51
|
+
expect(store.add).toHaveBeenCalledWith(expect.anything(), preventDuplicates);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
55
|
+
describe('show', () => {
|
56
|
+
test('adds notification', () => {
|
57
|
+
subject.show(options);
|
58
|
+
|
59
|
+
expect(store.add).toHaveBeenCalledWith(options, undefined);
|
60
|
+
});
|
61
|
+
});
|
62
|
+
});
|
@@ -25,7 +25,7 @@ export interface Notification {
|
|
25
25
|
createdOn: Date;
|
26
26
|
modifiedOn: Date;
|
27
27
|
version: number;
|
28
|
-
payload?: string
|
28
|
+
payload?: string;
|
29
29
|
}
|
30
30
|
|
31
31
|
export enum NotificationProcessStatus {
|
@@ -38,7 +38,7 @@ export enum NotificationProcessStatus {
|
|
38
38
|
export interface DefaultServerNotificationPayload {
|
39
39
|
title: string;
|
40
40
|
message?: string;
|
41
|
-
duration
|
41
|
+
duration?: number;
|
42
42
|
progress?: number;
|
43
43
|
action?: {
|
44
44
|
label: string;
|
package/src/common.ts
CHANGED
@@ -1,32 +1,10 @@
|
|
1
|
-
import { ComponentType } from 'react';
|
2
1
|
import { Notification as ServerNotification } from './api/notifications.api';
|
3
2
|
|
4
|
-
export interface Notification extends
|
5
|
-
|
3
|
+
export interface Notification<T extends Record<keyof any, any> = Record<keyof any, any>>
|
4
|
+
extends Omit<ServerNotification, 'payload'> {
|
5
|
+
payload: T;
|
6
6
|
}
|
7
7
|
|
8
|
-
export type NotificationMapper = ComponentType<{
|
9
|
-
notification: Notification;
|
10
|
-
onClose(): void;
|
11
|
-
}>;
|
12
|
-
|
13
|
-
export function isNewer(
|
14
|
-
prev: Notification | ServerNotification,
|
15
|
-
next: Notification | ServerNotification
|
16
|
-
) {
|
17
|
-
return (
|
18
|
-
(!prev.modifiedOn && next.modifiedOn) ||
|
19
|
-
(prev.modifiedOn && next.modifiedOn && prev.modifiedOn < next.modifiedOn)
|
20
|
-
);
|
21
|
-
}
|
22
|
-
|
23
|
-
export function toClientNotification(serverNotification: ServerNotification) {
|
24
|
-
return { ...serverNotification, payload: JSON.parse(serverNotification.payload ?? '{}') };
|
25
|
-
}
|
26
|
-
|
27
|
-
export const DEFAULT_CLIENT_NOTIFICATION_TYPE = 'DefaultClientNotification';
|
28
|
-
export const DEFAULT_SERVER_NOTIFICATION_TYPE = 'DefaultServerNotification';
|
29
|
-
|
30
8
|
export interface DefaultNotificationOptions {
|
31
9
|
status?: Status;
|
32
10
|
title: string;
|
@@ -51,9 +29,16 @@ export interface LinkAction {
|
|
51
29
|
|
52
30
|
export interface FunctionAction {
|
53
31
|
label: string;
|
54
|
-
onClick()
|
32
|
+
onClick: () => void;
|
55
33
|
}
|
56
34
|
|
57
35
|
export function isLinkAction(action: LinkAction | FunctionAction): action is LinkAction {
|
58
|
-
return Object.
|
36
|
+
return Object.hasOwn(action, 'link');
|
37
|
+
}
|
38
|
+
|
39
|
+
export function isNewer(
|
40
|
+
prev: Pick<Notification, 'modifiedOn'>,
|
41
|
+
next: Pick<Notification, 'modifiedOn'>
|
42
|
+
) {
|
43
|
+
return next.modifiedOn && (!prev.modifiedOn || prev.modifiedOn < next.modifiedOn);
|
59
44
|
}
|