@commercetools-frontend/react-notifications 21.23.9 → 21.24.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/commercetools-frontend-react-notifications.cjs.dev.js +142 -170
- package/dist/commercetools-frontend-react-notifications.cjs.prod.js +131 -159
- package/dist/commercetools-frontend-react-notifications.esm.js +142 -170
- package/dist/declarations/src/components/map-notification-to-component/map-notification-to-component.d.ts +1 -1
- package/dist/declarations/src/components/notification/notification.d.ts +1 -1
- package/dist/declarations/src/components/notification-kinds/api-error/api-error.d.ts +1 -1
- package/dist/declarations/src/components/notification-kinds/generic/generic.d.ts +1 -1
- package/dist/declarations/src/components/notification-kinds/unexpected-error/unexpected-error.d.ts +1 -1
- package/package.json +14 -14
|
@@ -15,13 +15,13 @@ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/ob
|
|
|
15
15
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
16
16
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
17
17
|
var reactIntl = require('react-intl');
|
|
18
|
-
var
|
|
18
|
+
var constants = require('@commercetools-frontend/constants');
|
|
19
19
|
var designSystem = require('@commercetools-uikit/design-system');
|
|
20
|
+
var hooks = require('@commercetools-uikit/hooks');
|
|
20
21
|
var IconButton = require('@commercetools-uikit/icon-button');
|
|
22
|
+
var icons = require('@commercetools-uikit/icons');
|
|
21
23
|
var SecondaryIconButton = require('@commercetools-uikit/secondary-icon-button');
|
|
22
|
-
var constants = require('@commercetools-frontend/constants');
|
|
23
24
|
var utils = require('@commercetools-uikit/utils');
|
|
24
|
-
var hooks = require('@commercetools-uikit/hooks');
|
|
25
25
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
26
26
|
var omitBy = require('lodash/omitBy');
|
|
27
27
|
var _taggedTemplateLiteral = require('@babel/runtime-corejs3/helpers/taggedTemplateLiteral');
|
|
@@ -64,11 +64,9 @@ var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanc
|
|
|
64
64
|
var isNumber__default = /*#__PURE__*/_interopDefault(isNumber);
|
|
65
65
|
|
|
66
66
|
// NOTE: This string will be replaced on build time with the package version.
|
|
67
|
-
var version = "21.
|
|
67
|
+
var version = "21.24.0";
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
return null;
|
|
71
|
-
});
|
|
69
|
+
const Context = /*#__PURE__*/react.createContext(() => null);
|
|
72
70
|
|
|
73
71
|
function NotificationProviderForCustomComponent(props) {
|
|
74
72
|
return jsxRuntime.jsx(Context.Provider, {
|
|
@@ -79,14 +77,10 @@ function NotificationProviderForCustomComponent(props) {
|
|
|
79
77
|
|
|
80
78
|
NotificationProviderForCustomComponent.propTypes = {};
|
|
81
79
|
NotificationProviderForCustomComponent.displayName = 'NotificationProviderForCustomComponent';
|
|
82
|
-
|
|
83
|
-
return react.useContext(Context);
|
|
84
|
-
}; // Exports
|
|
80
|
+
const useCustomNotificationComponent = () => react.useContext(Context); // Exports
|
|
85
81
|
|
|
86
82
|
function filterDataAttributes(obj) {
|
|
87
|
-
return omitBy__default["default"](obj,
|
|
88
|
-
return !_startsWithInstanceProperty__default["default"](key).call(key, 'data-');
|
|
89
|
-
});
|
|
83
|
+
return omitBy__default["default"](obj, (_value, key) => !_startsWithInstanceProperty__default["default"](key).call(key, 'data-'));
|
|
90
84
|
}
|
|
91
85
|
|
|
92
86
|
var messages = reactIntl.defineMessages({
|
|
@@ -99,7 +93,7 @@ var messages = reactIntl.defineMessages({
|
|
|
99
93
|
|
|
100
94
|
var _templateObject, _templateObject2;
|
|
101
95
|
|
|
102
|
-
|
|
96
|
+
const getColorByType = value => {
|
|
103
97
|
switch (value) {
|
|
104
98
|
case constants.NOTIFICATION_KINDS_SIDE.success:
|
|
105
99
|
return designSystem.designTokens.colorPrimary;
|
|
@@ -118,7 +112,7 @@ var getColorByType = function getColorByType(value) {
|
|
|
118
112
|
}
|
|
119
113
|
};
|
|
120
114
|
|
|
121
|
-
|
|
115
|
+
const getBorderColor = notificationKind => {
|
|
122
116
|
switch (notificationKind) {
|
|
123
117
|
case constants.NOTIFICATION_KINDS_SIDE.success:
|
|
124
118
|
return designSystem.designTokens.colorPrimary85;
|
|
@@ -137,25 +131,21 @@ var getBorderColor = function getBorderColor(notificationKind) {
|
|
|
137
131
|
}
|
|
138
132
|
};
|
|
139
133
|
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
const showNotificationAnimation = react$1.keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n max-height: 0;\n padding-top: 0;\n padding-bottom: 0;\n overflow: hidden;\n }\n 100% {\n max-height: 200px;\n }\n"])));
|
|
135
|
+
const showNotificationSideAnimation = react$1.keyframes(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n 0% {\n transform: translateX(50px);\n }\n 100% {\n transform: translateX(0);\n }\n"])));
|
|
142
136
|
|
|
143
|
-
|
|
144
|
-
return /*#__PURE__*/react$1.css("display:flex;align-items:center;justify-content:center;position:absolute;left:0;top:0;width:48px;height:100%;color:", designSystem.designTokens.colorSurface, ";border-radius:3px 0 0 3px;background:", getColorByType(props.type), ";" + ("" ), "" );
|
|
145
|
-
};
|
|
137
|
+
const getStylesForNotificationIcon = props => /*#__PURE__*/react$1.css("display:flex;align-items:center;justify-content:center;position:absolute;left:0;top:0;width:48px;height:100%;color:", designSystem.designTokens.colorSurface, ";border-radius:3px 0 0 3px;background:", getColorByType(props.type), ";" + ("" ), "" );
|
|
146
138
|
|
|
147
|
-
|
|
148
|
-
return /*#__PURE__*/react$1.css("display:flex;justify-content:center;", props.isNewTheme ? '& svg { width: 16px; height: 16px; }' : '', " ", props.isNewTheme && props.domain !== constants.NOTIFICATION_DOMAINS.SIDE ? '& svg { fill: ' + designSystem.designTokens.colorSurface + '; }' : '', ";" + ("" ), "" );
|
|
149
|
-
};
|
|
139
|
+
const getStylesForCloseIcon = props => /*#__PURE__*/react$1.css("display:flex;justify-content:center;", props.isNewTheme ? '& svg { width: 16px; height: 16px; }' : '', " ", props.isNewTheme && props.domain !== constants.NOTIFICATION_DOMAINS.SIDE ? '& svg { fill: ' + designSystem.designTokens.colorSurface + '; }' : '', ";" + ("" ), "" );
|
|
150
140
|
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
const getStylesForContent = props => {
|
|
142
|
+
const fontColor = props.domain === constants.NOTIFICATION_DOMAINS.SIDE ? designSystem.designTokens.colorSolid : designSystem.designTokens.colorSurface;
|
|
153
143
|
return /*#__PURE__*/react$1.css("flex-basis:100%;flex-grow:1;padding:0 ", props.isNewTheme ? designSystem.designTokens.spacingM : designSystem.designTokens.spacingS, ";margin:0;font-size:", props.domain === constants.NOTIFICATION_DOMAINS.SIDE ? props.isNewTheme ? '1rem' : '0.929rem' : 'inherit', ";color:", fontColor, ";p{color:", fontColor, ";}ul{padding:0;margin:0;list-style:none;}" + ("" ), "" );
|
|
154
144
|
};
|
|
155
145
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
const getStylesForNotification = props => {
|
|
147
|
+
const baseStyles = /*#__PURE__*/react$1.css("position:relative;display:flex;align-items:center;padding:", designSystem.designTokens.spacingM, ";color:", designSystem.designTokens.colorSurface, ";" + ("" ), "" );
|
|
148
|
+
const pageStyles = /*#__PURE__*/react$1.css(baseStyles, ";animation:", showNotificationAnimation, " 0.3s forwards;text-align:center;background-color:", props.fixed ? 'transparent' : getColorByType(props.type), ";>*+*{margin-left:", designSystem.designTokens.spacingS, ";}" + ("" ), "" );
|
|
159
149
|
|
|
160
150
|
switch (props.domain) {
|
|
161
151
|
case constants.NOTIFICATION_DOMAINS.GLOBAL:
|
|
@@ -166,7 +156,7 @@ var getStylesForNotification = function getStylesForNotification(props) {
|
|
|
166
156
|
|
|
167
157
|
case constants.NOTIFICATION_DOMAINS.SIDE:
|
|
168
158
|
{
|
|
169
|
-
|
|
159
|
+
const sideStyles = /*#__PURE__*/react$1.css(baseStyles, ";animation:", showNotificationAnimation, " 0.3s forwards;padding:", designSystem.designTokens.spacingM, " ", designSystem.designTokens.spacingM, " ", designSystem.designTokens.spacingM, " 50px!important;text-align:left;background:", designSystem.designTokens.colorSurface, ";border:1px solid ", props.isNewTheme ? getBorderColor(props.type) : getColorByType(props.type), ";box-shadow:", props.isNewTheme ? '0px 2px 5px 0px rgba(0, 0, 0, 0.15)' : '0 1px 2px rgba(0, 0, 0, 0.24)', ";border-radius:", designSystem.designTokens.borderRadius6, ";word-break:break-word;hyphens:auto;" + ("" ), "" );
|
|
170
160
|
if (props.fixed) return sideStyles;
|
|
171
161
|
return /*#__PURE__*/react$1.css(sideStyles, ";animation:", showNotificationSideAnimation, " 0.3s forwards;position:relative;z-index:10000;margin-top:", designSystem.designTokens.spacingL, "!important;right:", designSystem.designTokens.spacingXl, ";float:right;clear:both;max-width:50%;" + ("" ), "" );
|
|
172
162
|
}
|
|
@@ -179,9 +169,9 @@ var getStylesForNotification = function getStylesForNotification(props) {
|
|
|
179
169
|
function ownKeys$4(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
180
170
|
|
|
181
171
|
function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$4(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$4(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
182
|
-
|
|
172
|
+
const sequentialId = utils.createSequentialId('notification-');
|
|
183
173
|
|
|
184
|
-
|
|
174
|
+
const NotificationIcon = props => {
|
|
185
175
|
if (props.type === constants.NOTIFICATION_KINDS_SIDE.error) {
|
|
186
176
|
return jsxRuntime.jsx(icons.ErrorIcon, {
|
|
187
177
|
color: props.color
|
|
@@ -209,35 +199,35 @@ var NotificationIcon = function NotificationIcon(props) {
|
|
|
209
199
|
|
|
210
200
|
NotificationIcon.propTypes = {};
|
|
211
201
|
NotificationIcon.displayName = 'NotificationIcon';
|
|
212
|
-
|
|
202
|
+
const defaultProps$1 = {
|
|
213
203
|
fixed: false
|
|
214
204
|
};
|
|
215
205
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
206
|
+
const Notification = props => {
|
|
207
|
+
const intl = reactIntl.useIntl();
|
|
208
|
+
const id = hooks.useFieldId(undefined, sequentialId);
|
|
219
209
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
210
|
+
const _useTheme = designSystem.useTheme(),
|
|
211
|
+
isNewTheme = _useTheme.isNewTheme,
|
|
212
|
+
themedValue = _useTheme.themedValue;
|
|
223
213
|
|
|
224
|
-
|
|
214
|
+
const Button = themedValue(IconButton__default["default"], SecondaryIconButton__default["default"]);
|
|
225
215
|
return jsxRuntime.jsxs("div", _objectSpread$4(_objectSpread$4({
|
|
226
216
|
role: "alertdialog",
|
|
227
217
|
"aria-describedby": id,
|
|
228
218
|
css: getStylesForNotification(_objectSpread$4(_objectSpread$4({}, props), {}, {
|
|
229
|
-
isNewTheme
|
|
219
|
+
isNewTheme
|
|
230
220
|
}))
|
|
231
221
|
}, filterDataAttributes(props)), {}, {
|
|
232
222
|
children: [jsxRuntime.jsx("div", {
|
|
233
223
|
id: id,
|
|
234
224
|
css: getStylesForContent(_objectSpread$4(_objectSpread$4({}, props), {}, {
|
|
235
|
-
isNewTheme
|
|
225
|
+
isNewTheme
|
|
236
226
|
})),
|
|
237
227
|
children: props.children
|
|
238
228
|
}), props.onCloseClick ? jsxRuntime.jsx("div", {
|
|
239
229
|
css: getStylesForCloseIcon(_objectSpread$4(_objectSpread$4({}, props), {}, {
|
|
240
|
-
isNewTheme
|
|
230
|
+
isNewTheme
|
|
241
231
|
})),
|
|
242
232
|
children: jsxRuntime.jsx(Button, {
|
|
243
233
|
label: intl.formatMessage(messages.hideNotification),
|
|
@@ -260,18 +250,6 @@ Notification.propTypes = {};
|
|
|
260
250
|
Notification.displayName = 'Notification';
|
|
261
251
|
Notification.defaultProps = defaultProps$1;
|
|
262
252
|
|
|
263
|
-
var GenericNotification = function GenericNotification(props) {
|
|
264
|
-
return jsxRuntime.jsx(Notification, {
|
|
265
|
-
domain: props.notification.domain,
|
|
266
|
-
type: props.notification.kind,
|
|
267
|
-
onCloseClick: props.dismiss,
|
|
268
|
-
children: props.notification.text
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
GenericNotification.propTypes = {};
|
|
273
|
-
GenericNotification.displayName = 'GenericNotification';
|
|
274
|
-
|
|
275
253
|
var apiErrorMessages = reactIntl.defineMessages({
|
|
276
254
|
General: {
|
|
277
255
|
id: 'ApiError.General',
|
|
@@ -416,13 +394,13 @@ var apiErrorMessages = reactIntl.defineMessages({
|
|
|
416
394
|
function ownKeys$3(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
417
395
|
|
|
418
396
|
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context6 = ownKeys$3(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context7 = ownKeys$3(Object(source))).call(_context7, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
419
|
-
|
|
397
|
+
const regexInvalidOperationRequiredAttribute = /Required attribute '(.*)' cannot be removed/;
|
|
420
398
|
|
|
421
399
|
// The values passed to the Intl message must be a map of scalar values.
|
|
422
400
|
// Some of the message values are already mapped in the `getSpecialFormattedMessageByErrorCode`
|
|
423
401
|
// function. Here we map other possible error properties that can be
|
|
424
402
|
// used in the message.
|
|
425
|
-
|
|
403
|
+
const mapErrorFieldsToMessageValues = error => {
|
|
426
404
|
if (error.field) return {
|
|
427
405
|
field: error.field
|
|
428
406
|
};
|
|
@@ -433,18 +411,16 @@ var mapErrorFieldsToMessageValues = function mapErrorFieldsToMessageValues(error
|
|
|
433
411
|
}; // Type-guard validation for error code to be included in the message object keys.
|
|
434
412
|
|
|
435
413
|
|
|
436
|
-
|
|
437
|
-
return errorCode in apiErrorMessages;
|
|
438
|
-
};
|
|
414
|
+
const hasErrorCodeAMatchingMessage = errorCode => errorCode in apiErrorMessages;
|
|
439
415
|
|
|
440
|
-
|
|
416
|
+
const FormattedErrorMessage = props => {
|
|
441
417
|
var _props$error$extensio, _props$error$extensio2, _context2;
|
|
442
418
|
|
|
443
|
-
|
|
419
|
+
const intl = reactIntl.useIntl(); // Attempt to map the error by code
|
|
444
420
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
react.useEffect(
|
|
421
|
+
const extensionErrorCode = (_props$error$extensio = (_props$error$extensio2 = props.error.extensions) === null || _props$error$extensio2 === void 0 ? void 0 : _props$error$extensio2.code) !== null && _props$error$extensio !== void 0 ? _props$error$extensio : props.error.code;
|
|
422
|
+
const messageCode = extensionErrorCode && hasErrorCodeAMatchingMessage(extensionErrorCode) ? apiErrorMessages[extensionErrorCode] : undefined;
|
|
423
|
+
react.useEffect(() => {
|
|
448
424
|
if (!messageCode) {
|
|
449
425
|
var _context;
|
|
450
426
|
|
|
@@ -476,10 +452,10 @@ FormattedErrorMessage.propTypes = {
|
|
|
476
452
|
};
|
|
477
453
|
FormattedErrorMessage.displayName = 'FormattedErrorMessage';
|
|
478
454
|
|
|
479
|
-
|
|
480
|
-
|
|
455
|
+
const ApiErrorMessage = props => {
|
|
456
|
+
const intl = reactIntl.useIntl(); // Attempt to map the error to a specific error message
|
|
481
457
|
|
|
482
|
-
|
|
458
|
+
const specialFormattedMessage = getSpecialFormattedMessageByErrorCode(props.error, intl);
|
|
483
459
|
|
|
484
460
|
if (specialFormattedMessage) {
|
|
485
461
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
@@ -496,10 +472,10 @@ ApiErrorMessage.displayName = 'ApiErrorMessage';
|
|
|
496
472
|
function getSpecialFormattedMessageByErrorCode(error, intl) {
|
|
497
473
|
var _error$extensions$cod, _error$extensions, _context3, _context4, _context5;
|
|
498
474
|
|
|
499
|
-
|
|
475
|
+
const extensionErrorCode = (_error$extensions$cod = (_error$extensions = error.extensions) === null || _error$extensions === void 0 ? void 0 : _error$extensions.code) !== null && _error$extensions$cod !== void 0 ? _error$extensions$cod : error.code;
|
|
500
476
|
|
|
501
477
|
if (error.errorByExtension) {
|
|
502
|
-
|
|
478
|
+
let extensionMessage;
|
|
503
479
|
|
|
504
480
|
if (error.localizedMessage) {
|
|
505
481
|
extensionMessage = error.localizedMessage[intl.locale];
|
|
@@ -528,7 +504,7 @@ function getSpecialFormattedMessageByErrorCode(error, intl) {
|
|
|
528
504
|
}
|
|
529
505
|
|
|
530
506
|
if (extensionErrorCode === 'InvalidOperation' && regexInvalidOperationRequiredAttribute.test(error.message)) {
|
|
531
|
-
|
|
507
|
+
const attrName = error.message.replace(regexInvalidOperationRequiredAttribute, '$1');
|
|
532
508
|
return intl.formatMessage(apiErrorMessages.RequiredField, {
|
|
533
509
|
field: attrName
|
|
534
510
|
});
|
|
@@ -554,7 +530,7 @@ function getSpecialFormattedMessageByErrorCode(error, intl) {
|
|
|
554
530
|
return;
|
|
555
531
|
}
|
|
556
532
|
|
|
557
|
-
|
|
533
|
+
const ApiErrorNotification = props => {
|
|
558
534
|
var _context;
|
|
559
535
|
|
|
560
536
|
return jsxRuntime.jsx(Notification, {
|
|
@@ -562,11 +538,11 @@ var ApiErrorNotification = function ApiErrorNotification(props) {
|
|
|
562
538
|
domain: props.notification.domain,
|
|
563
539
|
onCloseClick: props.dismiss,
|
|
564
540
|
children: jsxRuntime.jsx("ul", {
|
|
565
|
-
children: _valuesInstanceProperty__default["default"](props.notification) && _mapInstanceProperty__default["default"](_context = _valuesInstanceProperty__default["default"](props.notification).errors).call(_context,
|
|
541
|
+
children: _valuesInstanceProperty__default["default"](props.notification) && _mapInstanceProperty__default["default"](_context = _valuesInstanceProperty__default["default"](props.notification).errors).call(_context, (error, idx) => {
|
|
566
542
|
var _error$extensions$cod, _error$extensions;
|
|
567
543
|
|
|
568
|
-
|
|
569
|
-
|
|
544
|
+
const extensionErrorCode = (_error$extensions$cod = (_error$extensions = error.extensions) === null || _error$extensions === void 0 ? void 0 : _error$extensions.code) !== null && _error$extensions$cod !== void 0 ? _error$extensions$cod : error.code;
|
|
545
|
+
const shouldLogErrorToConsole = !extensionErrorCode && "production" === 'development';
|
|
570
546
|
|
|
571
547
|
if (shouldLogErrorToConsole) {
|
|
572
548
|
/**
|
|
@@ -592,54 +568,38 @@ var ApiErrorNotification = function ApiErrorNotification(props) {
|
|
|
592
568
|
ApiErrorNotification.propTypes = {};
|
|
593
569
|
ApiErrorNotification.displayName = 'ApiErrorNotification';
|
|
594
570
|
|
|
571
|
+
const GenericNotification = props => jsxRuntime.jsx(Notification, {
|
|
572
|
+
domain: props.notification.domain,
|
|
573
|
+
type: props.notification.kind,
|
|
574
|
+
onCloseClick: props.dismiss,
|
|
575
|
+
children: props.notification.text
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
GenericNotification.propTypes = {};
|
|
579
|
+
GenericNotification.displayName = 'GenericNotification';
|
|
580
|
+
|
|
595
581
|
function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
596
582
|
|
|
597
583
|
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
598
584
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
children: jsxRuntime.
|
|
605
|
-
children:
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
});
|
|
612
|
-
};
|
|
585
|
+
const UnexpectedErrorNotification = props => jsxRuntime.jsx(Notification, {
|
|
586
|
+
type: "error",
|
|
587
|
+
domain: props.notification.domain,
|
|
588
|
+
onCloseClick: props.dismiss,
|
|
589
|
+
children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
|
|
590
|
+
children: [jsxRuntime.jsx("div", {
|
|
591
|
+
children: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$2({}, apiErrorMessages.General))
|
|
592
|
+
}), _valuesInstanceProperty__default["default"](props.notification) && _valuesInstanceProperty__default["default"](props.notification).errorId && jsxRuntime.jsx("div", {
|
|
593
|
+
children: "ID (".concat(_valuesInstanceProperty__default["default"](props.notification).errorId, ")")
|
|
594
|
+
})]
|
|
595
|
+
})
|
|
596
|
+
});
|
|
613
597
|
|
|
614
598
|
UnexpectedErrorNotification.propTypes = {};
|
|
615
599
|
UnexpectedErrorNotification.displayName = 'UnexpectedErrorNotification';
|
|
616
600
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
var selectNotifications = function selectNotifications(state) {
|
|
620
|
-
return state.notifications;
|
|
621
|
-
};
|
|
622
|
-
var selectGlobalNotifications = reselect.createSelector(selectNotifications, function (notifications) {
|
|
623
|
-
var _context;
|
|
624
|
-
|
|
625
|
-
return _sliceInstanceProperty__default["default"](_context = _filterInstanceProperty__default["default"](notifications).call(notifications, function (notification) {
|
|
626
|
-
return notification.domain === constants.NOTIFICATION_DOMAINS.GLOBAL;
|
|
627
|
-
}) // Return only 1 at a time
|
|
628
|
-
).call(_context, 0, 1);
|
|
629
|
-
});
|
|
630
|
-
var selectPageNotifications = reselect.createSelector(selectNotifications, function (notifications) {
|
|
631
|
-
return _filterInstanceProperty__default["default"](notifications).call(notifications, function (notification) {
|
|
632
|
-
return notification.domain === constants.NOTIFICATION_DOMAINS.PAGE;
|
|
633
|
-
});
|
|
634
|
-
});
|
|
635
|
-
var selectSideNotifications = reselect.createSelector(selectNotifications, function (notifications) {
|
|
636
|
-
return _filterInstanceProperty__default["default"](notifications).call(notifications, function (notification) {
|
|
637
|
-
return notification.domain === constants.NOTIFICATION_DOMAINS.SIDE;
|
|
638
|
-
});
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
var getStyles = function getStyles(props) {
|
|
642
|
-
var baseStyles = /*#__PURE__*/react$1.css("color:", designSystem.customProperties.colorSurface, ";position:relative;width:100%;z-index:19999;" + ("" ), "" );
|
|
601
|
+
const getStyles = props => {
|
|
602
|
+
const baseStyles = /*#__PURE__*/react$1.css("color:", designSystem.customProperties.colorSurface, ";position:relative;width:100%;z-index:19999;" + ("" ), "" );
|
|
643
603
|
|
|
644
604
|
switch (props.domain) {
|
|
645
605
|
case constants.NOTIFICATION_DOMAINS.GLOBAL:
|
|
@@ -656,31 +616,43 @@ var getStyles = function getStyles(props) {
|
|
|
656
616
|
}
|
|
657
617
|
};
|
|
658
618
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
619
|
+
// These selectors are okay memoization-wise, but once a single notifications
|
|
620
|
+
// is added or removed the memoization for all domain selectors is reset
|
|
621
|
+
const selectNotifications = state => state.notifications;
|
|
622
|
+
const selectGlobalNotifications = reselect.createSelector(selectNotifications, notifications => {
|
|
623
|
+
var _context;
|
|
624
|
+
|
|
625
|
+
return _sliceInstanceProperty__default["default"](_context = _filterInstanceProperty__default["default"](notifications).call(notifications, notification => notification.domain === constants.NOTIFICATION_DOMAINS.GLOBAL) // Return only 1 at a time
|
|
626
|
+
).call(_context, 0, 1);
|
|
627
|
+
});
|
|
628
|
+
const selectPageNotifications = reselect.createSelector(selectNotifications, notifications => _filterInstanceProperty__default["default"](notifications).call(notifications, notification => notification.domain === constants.NOTIFICATION_DOMAINS.PAGE));
|
|
629
|
+
const selectSideNotifications = reselect.createSelector(selectNotifications, notifications => _filterInstanceProperty__default["default"](notifications).call(notifications, notification => notification.domain === constants.NOTIFICATION_DOMAINS.SIDE));
|
|
630
|
+
|
|
631
|
+
const _excluded = ["values"],
|
|
632
|
+
_excluded2 = ["text"],
|
|
633
|
+
_excluded3 = ["values"],
|
|
634
|
+
_excluded4 = ["text"],
|
|
635
|
+
_excluded5 = ["text"];
|
|
664
636
|
|
|
665
637
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
666
638
|
|
|
667
639
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
668
640
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
641
|
+
const NotificationsListGlobal = props => {
|
|
642
|
+
const dispatch = reactRedux.useDispatch();
|
|
643
|
+
const mapCustomNotificationToComponent = useCustomNotificationComponent();
|
|
644
|
+
const notifications$1 = reactRedux.useSelector(selectGlobalNotifications);
|
|
673
645
|
return jsxRuntime.jsx("div", {
|
|
674
646
|
id: "notifications-".concat(props.domain),
|
|
675
647
|
css: getStyles(props),
|
|
676
|
-
children: _mapInstanceProperty__default["default"](notifications$1).call(notifications$1,
|
|
648
|
+
children: _mapInstanceProperty__default["default"](notifications$1).call(notifications$1, notification => {
|
|
677
649
|
// 1. Check if there is a custom notification component first
|
|
678
|
-
|
|
650
|
+
const CustomNotificationComponent = mapCustomNotificationToComponent(notification);
|
|
679
651
|
|
|
680
652
|
if (CustomNotificationComponent) {
|
|
681
653
|
return jsxRuntime.jsx(CustomNotificationComponent, {
|
|
682
654
|
notification: notification,
|
|
683
|
-
dismiss:
|
|
655
|
+
dismiss: () => {
|
|
684
656
|
dispatch(notifications.removeNotification(notification.id));
|
|
685
657
|
}
|
|
686
658
|
}, notification.id);
|
|
@@ -693,11 +665,11 @@ var NotificationsListGlobal = function NotificationsListGlobal(props) {
|
|
|
693
665
|
case constants.NOTIFICATION_KINDS_GLOBAL.success:
|
|
694
666
|
{
|
|
695
667
|
_valuesInstanceProperty__default["default"](notification);
|
|
696
|
-
|
|
668
|
+
const genericNotification = _objectWithoutProperties(notification, _excluded);
|
|
697
669
|
|
|
698
670
|
return jsxRuntime.jsx(GenericNotification, {
|
|
699
671
|
notification: genericNotification,
|
|
700
|
-
dismiss:
|
|
672
|
+
dismiss: () => {
|
|
701
673
|
dispatch(notifications.removeNotification(notification.id));
|
|
702
674
|
}
|
|
703
675
|
}, notification.id);
|
|
@@ -706,11 +678,11 @@ var NotificationsListGlobal = function NotificationsListGlobal(props) {
|
|
|
706
678
|
case constants.NOTIFICATION_KINDS_GLOBAL['unexpected-error']:
|
|
707
679
|
{
|
|
708
680
|
notification.text;
|
|
709
|
-
|
|
681
|
+
const errorNotification = _objectWithoutProperties(notification, _excluded2);
|
|
710
682
|
|
|
711
683
|
return jsxRuntime.jsx(UnexpectedErrorNotification, {
|
|
712
684
|
notification: errorNotification,
|
|
713
|
-
dismiss:
|
|
685
|
+
dismiss: () => {
|
|
714
686
|
dispatch(notifications.removeNotification(notification.id));
|
|
715
687
|
}
|
|
716
688
|
}, notification.id);
|
|
@@ -726,21 +698,21 @@ var NotificationsListGlobal = function NotificationsListGlobal(props) {
|
|
|
726
698
|
});
|
|
727
699
|
};
|
|
728
700
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
701
|
+
const NotificationsListPage = props => {
|
|
702
|
+
const dispatch = reactRedux.useDispatch();
|
|
703
|
+
const mapCustomNotificationToComponent = useCustomNotificationComponent();
|
|
704
|
+
const notifications$1 = reactRedux.useSelector(selectPageNotifications);
|
|
733
705
|
return jsxRuntime.jsx("div", {
|
|
734
706
|
id: "notifications-".concat(props.domain),
|
|
735
707
|
css: getStyles(props),
|
|
736
|
-
children: _mapInstanceProperty__default["default"](notifications$1).call(notifications$1,
|
|
708
|
+
children: _mapInstanceProperty__default["default"](notifications$1).call(notifications$1, notification => {
|
|
737
709
|
// 1. Check if there is a custom notification component first
|
|
738
|
-
|
|
710
|
+
const CustomNotificationComponent = mapCustomNotificationToComponent(notification);
|
|
739
711
|
|
|
740
712
|
if (CustomNotificationComponent) {
|
|
741
713
|
return jsxRuntime.jsx(CustomNotificationComponent, {
|
|
742
714
|
notification: notification,
|
|
743
|
-
dismiss:
|
|
715
|
+
dismiss: () => {
|
|
744
716
|
dispatch(notifications.removeNotification(notification.id));
|
|
745
717
|
}
|
|
746
718
|
}, notification.id);
|
|
@@ -753,13 +725,13 @@ var NotificationsListPage = function NotificationsListPage(props) {
|
|
|
753
725
|
case constants.NOTIFICATION_KINDS_PAGE.success:
|
|
754
726
|
{
|
|
755
727
|
_valuesInstanceProperty__default["default"](notification);
|
|
756
|
-
|
|
728
|
+
const genericNotification = _objectWithoutProperties(notification, _excluded3);
|
|
757
729
|
|
|
758
730
|
return jsxRuntime.jsx(GenericNotification, {
|
|
759
731
|
notification: _objectSpread$1(_objectSpread$1({}, genericNotification), {}, {
|
|
760
732
|
kind: notification.kind
|
|
761
733
|
}),
|
|
762
|
-
dismiss:
|
|
734
|
+
dismiss: () => {
|
|
763
735
|
dispatch(notifications.removeNotification(notification.id));
|
|
764
736
|
}
|
|
765
737
|
}, notification.id);
|
|
@@ -768,11 +740,11 @@ var NotificationsListPage = function NotificationsListPage(props) {
|
|
|
768
740
|
case constants.NOTIFICATION_KINDS_PAGE['api-error']:
|
|
769
741
|
{
|
|
770
742
|
notification.text;
|
|
771
|
-
|
|
743
|
+
const errorNotification = _objectWithoutProperties(notification, _excluded4);
|
|
772
744
|
|
|
773
745
|
return jsxRuntime.jsx(ApiErrorNotification, {
|
|
774
746
|
notification: errorNotification,
|
|
775
|
-
dismiss:
|
|
747
|
+
dismiss: () => {
|
|
776
748
|
dispatch(notifications.removeNotification(notification.id));
|
|
777
749
|
}
|
|
778
750
|
}, notification.id);
|
|
@@ -781,13 +753,13 @@ var NotificationsListPage = function NotificationsListPage(props) {
|
|
|
781
753
|
case constants.NOTIFICATION_KINDS_PAGE['unexpected-error']:
|
|
782
754
|
{
|
|
783
755
|
notification.text;
|
|
784
|
-
|
|
756
|
+
const errorNotification = _objectWithoutProperties(notification, _excluded5);
|
|
785
757
|
|
|
786
758
|
return jsxRuntime.jsx(UnexpectedErrorNotification, {
|
|
787
|
-
notification: _objectSpread$1(_objectSpread$1({},
|
|
759
|
+
notification: _objectSpread$1(_objectSpread$1({}, errorNotification), {}, {
|
|
788
760
|
values: _valuesInstanceProperty__default["default"](notification)
|
|
789
761
|
}),
|
|
790
|
-
dismiss:
|
|
762
|
+
dismiss: () => {
|
|
791
763
|
dispatch(notifications.removeNotification(notification.id));
|
|
792
764
|
}
|
|
793
765
|
}, notification.id);
|
|
@@ -800,21 +772,21 @@ var NotificationsListPage = function NotificationsListPage(props) {
|
|
|
800
772
|
});
|
|
801
773
|
};
|
|
802
774
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
775
|
+
const NotificationsListSide = props => {
|
|
776
|
+
const dispatch = reactRedux.useDispatch();
|
|
777
|
+
const mapCustomNotificationToComponent = useCustomNotificationComponent();
|
|
778
|
+
const notifications$1 = reactRedux.useSelector(selectSideNotifications);
|
|
807
779
|
return jsxRuntime.jsx("div", {
|
|
808
780
|
id: "notifications-".concat(props.domain),
|
|
809
781
|
css: getStyles(props),
|
|
810
|
-
children: _mapInstanceProperty__default["default"](notifications$1).call(notifications$1,
|
|
782
|
+
children: _mapInstanceProperty__default["default"](notifications$1).call(notifications$1, notification => {
|
|
811
783
|
// 1. Check if there is a custom notification component first
|
|
812
|
-
|
|
784
|
+
const CustomNotificationComponent = mapCustomNotificationToComponent(notification);
|
|
813
785
|
|
|
814
786
|
if (CustomNotificationComponent) {
|
|
815
787
|
return jsxRuntime.jsx(CustomNotificationComponent, {
|
|
816
788
|
notification: notification,
|
|
817
|
-
dismiss:
|
|
789
|
+
dismiss: () => {
|
|
818
790
|
dispatch(notifications.removeNotification(notification.id));
|
|
819
791
|
}
|
|
820
792
|
}, notification.id);
|
|
@@ -827,7 +799,7 @@ var NotificationsListSide = function NotificationsListSide(props) {
|
|
|
827
799
|
case constants.NOTIFICATION_KINDS_SIDE.success:
|
|
828
800
|
return jsxRuntime.jsx(GenericNotification, {
|
|
829
801
|
notification: notification,
|
|
830
|
-
dismiss:
|
|
802
|
+
dismiss: () => {
|
|
831
803
|
dispatch(notifications.removeNotification(notification.id));
|
|
832
804
|
}
|
|
833
805
|
}, notification.id);
|
|
@@ -839,7 +811,7 @@ var NotificationsListSide = function NotificationsListSide(props) {
|
|
|
839
811
|
});
|
|
840
812
|
};
|
|
841
813
|
|
|
842
|
-
|
|
814
|
+
const NotificationsList = props => {
|
|
843
815
|
switch (props.domain) {
|
|
844
816
|
case constants.NOTIFICATION_DOMAINS.GLOBAL:
|
|
845
817
|
return jsxRuntime.jsx(NotificationsListGlobal, _objectSpread$1({}, props));
|
|
@@ -860,22 +832,22 @@ NotificationsList.displayName = 'NotificationsList';
|
|
|
860
832
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
861
833
|
|
|
862
834
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
863
|
-
|
|
835
|
+
const defaultProps = {
|
|
864
836
|
domain: constants.NOTIFICATION_DOMAINS.SIDE,
|
|
865
837
|
kind: constants.NOTIFICATION_KINDS_SIDE.success
|
|
866
838
|
};
|
|
867
839
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
react.useEffect(
|
|
871
|
-
|
|
840
|
+
const Notifier = props => {
|
|
841
|
+
const showNotification = actionsGlobal.useShowNotification();
|
|
842
|
+
react.useEffect(() => {
|
|
843
|
+
const notification = showNotification({
|
|
872
844
|
domain: props.domain,
|
|
873
845
|
kind: props.kind,
|
|
874
846
|
text: props.text
|
|
875
847
|
}, isNumber__default["default"](props.dismissAfter) ? _objectSpread(_objectSpread({}, props.meta), {}, {
|
|
876
848
|
dismissAfter: props.dismissAfter
|
|
877
849
|
}) : props.meta);
|
|
878
|
-
return
|
|
850
|
+
return () => {
|
|
879
851
|
// Remove notification when component "unmounts"
|
|
880
852
|
notification.dismiss && notification.dismiss();
|
|
881
853
|
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|