@shopgate/pwa-common 7.30.0-alpha.7 → 7.30.0-alpha.8
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/App.js +48 -6
- package/action-creators/app/index.js +75 -12
- package/action-creators/app/spec.js +96 -1
- package/action-creators/client/index.js +27 -5
- package/action-creators/client/spec.js +44 -1
- package/action-creators/error/index.js +15 -3
- package/action-creators/index.js +9 -1
- package/action-creators/menu/index.js +23 -4
- package/action-creators/menu/spec.js +37 -1
- package/action-creators/modal/index.js +15 -3
- package/action-creators/modal/spec.js +26 -1
- package/action-creators/page/index.js +24 -4
- package/action-creators/page/spec.js +38 -1
- package/action-creators/router/index.js +48 -7
- package/action-creators/url/index.js +24 -4
- package/action-creators/url/spec.js +45 -1
- package/action-creators/user/index.js +90 -13
- package/action-creators/user/spec.js +186 -2
- package/actions/app/handleDeepLink.js +11 -2
- package/actions/app/handleLink.js +62 -6
- package/actions/app/handlePushNotification.js +32 -4
- package/actions/app/handleUniversalLink.js +11 -2
- package/actions/app/registerLinkEvents.js +24 -3
- package/actions/client/fetchClientInformation.js +26 -2
- package/actions/menu/fetchMenu.js +23 -2
- package/actions/modal/closeModal.js +18 -2
- package/actions/modal/promiseMap.js +3 -1
- package/actions/modal/showModal.js +54 -8
- package/actions/page/fetchPageConfig.js +69 -2
- package/actions/page/getPageConfig.js +6 -2
- package/actions/page/index.js +1 -1
- package/actions/router/historyPop.js +12 -2
- package/actions/router/historyPopToRoute.js +27 -2
- package/actions/router/historyPush.js +12 -2
- package/actions/router/historyRedirect.js +21 -2
- package/actions/router/historyReplace.js +20 -3
- package/actions/router/historyReset.js +11 -2
- package/actions/router/historyResetTo.js +12 -2
- package/actions/router/index.js +17 -1
- package/actions/router/routeDidPop.js +11 -2
- package/actions/router/routeDidPush.js +13 -2
- package/actions/router/routeDidReplace.js +11 -2
- package/actions/router/routeDidReset.js +11 -2
- package/actions/router/routeDidUpdate.js +10 -2
- package/actions/router/routeWillPop.js +11 -2
- package/actions/router/routeWillPush.js +13 -2
- package/actions/router/routeWillReplace.js +11 -2
- package/actions/router/routeWillReset.js +11 -2
- package/actions/router/windowOpenOverride.js +10 -2
- package/actions/user/fetchRegisterUrl.js +36 -2
- package/actions/user/fetchUser.js +29 -3
- package/actions/user/getUser.js +6 -2
- package/actions/user/index.js +1 -1
- package/actions/user/login.js +76 -9
- package/actions/user/logout.js +30 -2
- package/collections/AuthRoutes.js +73 -14
- package/collections/Configuration.js +54 -7
- package/collections/EmbeddedMedia.js +84 -11
- package/collections/PersistedReducers.js +41 -6
- package/collections/Redirects.js +103 -17
- package/collections/index.js +5 -1
- package/collections/media-providers/MediaProvider.js +151 -26
- package/collections/media-providers/Vimeo.js +113 -19
- package/collections/media-providers/YouTube.js +74 -14
- package/collections/media-providers/index.js +3 -1
- package/collections/media-providers/style.js +52 -2
- package/components/Backdrop/index.js +95 -6
- package/components/Backdrop/spec.js +23 -1
- package/components/Backdrop/style.js +11 -2
- package/components/Button/index.js +47 -5
- package/components/Button/spec.js +36 -1
- package/components/Button/style.js +6 -1
- package/components/Checkbox/index.js +126 -32
- package/components/Checkbox/spec.js +94 -3
- package/components/Consume/helpers/buildParams.js +13 -2
- package/components/Consume/index.js +14 -2
- package/components/CountdownTimer/index.js +115 -17
- package/components/CountdownTimer/spec.js +126 -12
- package/components/Drawer/index.js +131 -16
- package/components/Drawer/spec.js +76 -1
- package/components/Drawer/style.js +37 -1
- package/components/Dropdown/index.js +65 -6
- package/components/Dropdown/style.js +4 -1
- package/components/Dropdown/transitions.js +34 -1
- package/components/Ellipsis/index.js +16 -2
- package/components/Ellipsis/spec.js +13 -1
- package/components/EmbeddedMedia/index.js +56 -6
- package/components/EmbeddedMedia/spec.js +52 -3
- package/components/ErrorBoundary/connector.js +9 -2
- package/components/ErrorBoundary/index.js +43 -7
- package/components/Grid/components/Item/index.js +40 -4
- package/components/Grid/components/Item/spec.js +23 -1
- package/components/Grid/components/Item/style.js +17 -3
- package/components/Grid/index.js +36 -4
- package/components/Grid/spec.js +23 -1
- package/components/Grid/style.js +11 -2
- package/components/HtmlSanitizer/connector.js +24 -3
- package/components/HtmlSanitizer/index.js +104 -12
- package/components/HtmlSanitizer/spec.js +207 -6
- package/components/I18n/components/FormatDate/index.js +26 -2
- package/components/I18n/components/FormatDate/spec.js +46 -1
- package/components/I18n/components/FormatNumber/index.js +34 -2
- package/components/I18n/components/FormatNumber/spec.js +41 -2
- package/components/I18n/components/FormatPrice/index.js +32 -2
- package/components/I18n/components/FormatPrice/spec.js +46 -1
- package/components/I18n/components/FormatTime/index.js +26 -2
- package/components/I18n/components/FormatTime/spec.js +43 -2
- package/components/I18n/components/I18nProvider/index.js +52 -9
- package/components/I18n/components/I18nProvider/spec.js +39 -1
- package/components/I18n/components/Placeholder/index.js +8 -2
- package/components/I18n/components/Placeholder/spec.js +30 -1
- package/components/I18n/components/Translate/index.js +68 -7
- package/components/I18n/components/Translate/spec.js +30 -1
- package/components/I18n/index.js +16 -1
- package/components/Icon/index.js +25 -2
- package/components/Icon/style.js +6 -1
- package/components/Image/Image.js +176 -19
- package/components/Image/ImageInner.js +48 -2
- package/components/Image/index.js +1 -1
- package/components/Image/style.js +29 -2
- package/components/InfiniteContainer/index.js +381 -49
- package/components/InfiniteContainer/spec.js +199 -10
- package/components/Input/components/DateInput.js +262 -6
- package/components/Input/components/MultiLineInput.js +98 -12
- package/components/Input/components/SimpleInput.js +207 -31
- package/components/Input/index.js +32 -3
- package/components/Input/spec.js +122 -1
- package/components/KeyboardConsumer/index.js +48 -7
- package/components/Link/connector.js +7 -1
- package/components/Link/index.js +96 -11
- package/components/Link/spec.js +56 -1
- package/components/Link/style.js +10 -1
- package/components/List/components/Item/index.js +35 -3
- package/components/List/components/Item/style.js +16 -1
- package/components/List/index.js +20 -2
- package/components/List/spec.js +31 -1
- package/components/Loading/index.js +6 -2
- package/components/Modal/index.js +38 -3
- package/components/Modal/style.js +36 -1
- package/components/ModalContainer/connector.js +17 -3
- package/components/ModalContainer/index.js +36 -3
- package/components/ModalContainer/spec.js +105 -5
- package/components/Picker/components/Button/index.js +34 -2
- package/components/Picker/components/Button/style.js +19 -1
- package/components/Picker/components/List/index.js +33 -2
- package/components/Picker/components/List/style.js +17 -1
- package/components/Picker/components/Modal/index.js +60 -7
- package/components/Picker/components/Modal/style.js +78 -1
- package/components/Picker/index.js +167 -21
- package/components/Picker/spec.js +83 -2
- package/components/Portal/index.js +130 -19
- package/components/ProductCharacteristics/connector.js +33 -4
- package/components/ProductCharacteristics/context.js +2 -1
- package/components/ProductCharacteristics/helpers/index.js +135 -21
- package/components/ProductCharacteristics/index.js +266 -31
- package/components/RangeSlider/components/Handle/index.js +25 -2
- package/components/RangeSlider/components/Handle/style.js +14 -1
- package/components/RangeSlider/helper.js +43 -8
- package/components/RangeSlider/index.js +228 -38
- package/components/RangeSlider/style.js +14 -1
- package/components/Route/RouteNotFound.js +46 -3
- package/components/Route/index.js +78 -10
- package/components/Router/connector.js +9 -2
- package/components/Router/index.js +237 -31
- package/components/ScannerContainer/connector.js +9 -2
- package/components/ScannerContainer/index.js +42 -6
- package/components/Select/components/Item/index.js +20 -4
- package/components/Select/components/Item/style.js +4 -1
- package/components/Select/index.js +149 -28
- package/components/Select/spec.js +86 -2
- package/components/Select/style.js +17 -1
- package/components/SelectBox/components/Item/index.js +47 -5
- package/components/SelectBox/components/Item/style.js +7 -1
- package/components/SelectBox/index.js +173 -17
- package/components/SelectBox/spec.js +59 -3
- package/components/SelectBox/style.js +18 -1
- package/components/Slider/index.js +6 -2
- package/components/SurroundPortals/index.js +26 -2
- package/components/Swiper/components/SwiperItem/index.js +28 -4
- package/components/Swiper/components/SwiperItem/spec.js +17 -1
- package/components/Swiper/components/SwiperItem/styles.js +5 -1
- package/components/Swiper/index.js +210 -18
- package/components/Swiper/styles.js +75 -7
- package/components/Toaster/index.js +10 -2
- package/components/Transition/index.js +89 -13
- package/components/Widgets/components/Widget/index.js +52 -4
- package/components/Widgets/components/Widget/spec.js +68 -3
- package/components/Widgets/components/Widget/style.js +21 -3
- package/components/Widgets/components/WidgetGrid/index.js +52 -7
- package/components/Widgets/components/WidgetGrid/spec.js +46 -2
- package/components/Widgets/components/WidgetGrid/style.js +8 -1
- package/components/Widgets/helpers/shouldShowWidget.js +44 -7
- package/components/Widgets/index.js +127 -15
- package/components/Widgets/spec.js +213 -6
- package/components/index.js +9 -1
- package/constants/ActionTypes.js +97 -19
- package/constants/Configuration.js +12 -2
- package/constants/Device.js +29 -2
- package/constants/DisplayOptions.js +8 -1
- package/constants/MenuIDs.js +2 -1
- package/constants/ModalTypes.js +1 -1
- package/constants/PageIDs.js +1 -1
- package/constants/Pipelines.js +7 -1
- package/constants/Portals.js +136 -3
- package/constants/Registration.js +3 -1
- package/constants/RoutePaths.js +13 -2
- package/constants/Tracking.js +3 -1
- package/constants/client.js +6 -1
- package/constants/ui.js +2 -1
- package/constants/user.js +6 -2
- package/context/index.js +33 -3
- package/helpers/config/index.js +139 -21
- package/helpers/config/mock.js +200 -8
- package/helpers/config/theme.js +50 -4
- package/helpers/data/index.js +204 -29
- package/helpers/data/spec.js +187 -7
- package/helpers/date/index.js +58 -6
- package/helpers/date/spec.js +92 -1
- package/helpers/dom/index.js +48 -11
- package/helpers/environment/index.js +14 -2
- package/helpers/html/decodeHTML.js +7 -1
- package/helpers/html/handleDOM.js +172 -21
- package/helpers/html/parseHTML.js +67 -12
- package/helpers/i18n/getDateFormatter.js +23 -4
- package/helpers/i18n/getNumberFormatter.js +32 -4
- package/helpers/i18n/getPriceFormatter.js +38 -4
- package/helpers/i18n/getTimeFormatter.js +23 -4
- package/helpers/i18n/getTranslator.js +62 -8
- package/helpers/i18n/index.js +5 -1
- package/helpers/i18n/mergeTranslations.js +36 -9
- package/helpers/i18n/messageCache.js +3 -1
- package/helpers/legacy/index.js +47 -9
- package/helpers/modal/withShowModal.js +13 -2
- package/helpers/portals/portalCollection.js +28 -6
- package/helpers/portals/routePortals.js +12 -1
- package/helpers/redux/compareObjects.js +7 -2
- package/helpers/redux/generateResultHash.js +36 -3
- package/helpers/redux/generateSortedHash.js +7 -2
- package/helpers/redux/hasExpired.js +10 -2
- package/helpers/redux/index.js +7 -1
- package/helpers/redux/mutable.js +143 -24
- package/helpers/redux/shouldFetchData.js +46 -10
- package/helpers/redux/shouldFetchFilters.js +17 -4
- package/helpers/router/index.js +49 -5
- package/helpers/style/index.js +43 -4
- package/helpers/style/spec.js +108 -2
- package/helpers/tracking/index.js +52 -9
- package/helpers/validation/index.js +39 -12
- package/helpers/validation/spec.js +10 -1
- package/package.json +3 -3
- package/providers/index.js +4 -1
- package/providers/loading/context.js +2 -1
- package/providers/loading/index.js +137 -22
- package/providers/toast/context.js +2 -1
- package/providers/toast/index.js +105 -11
- package/reducers/client/connectivity.js +22 -2
- package/reducers/client/index.js +7 -1
- package/reducers/client/info.js +27 -2
- package/reducers/index.js +23 -4
- package/reducers/menu/index.js +5 -1
- package/reducers/menu/menusById.js +41 -2
- package/reducers/modal/index.js +14 -2
- package/reducers/page/index.js +68 -5
- package/reducers/router/index.js +48 -2
- package/reducers/url/index.js +42 -3
- package/reducers/user/data.js +27 -2
- package/reducers/user/index.js +7 -1
- package/reducers/user/login.js +65 -2
- package/selectors/client.js +138 -21
- package/selectors/history.js +49 -11
- package/selectors/menu.js +34 -6
- package/selectors/modal.js +15 -4
- package/selectors/page.js +25 -4
- package/selectors/router.js +154 -30
- package/selectors/url.js +25 -4
- package/selectors/user.js +90 -13
- package/store/index.js +60 -6
- package/store/middelwares/logger.js +7 -1
- package/store/middelwares/streams.js +19 -2
- package/streams/app.js +60 -8
- package/streams/client.js +8 -2
- package/streams/error.js +14 -3
- package/streams/index.js +6 -1
- package/streams/interval.js +6 -2
- package/streams/main.js +27 -2
- package/streams/router.js +45 -8
- package/streams/user.js +89 -15
- package/streams/view.js +97 -25
- package/styles/reset/form.js +57 -5
- package/styles/reset/index.js +6 -1
- package/styles/reset/media.js +22 -1
- package/styles/reset/root.js +33 -1
- package/styles/reset/table.js +10 -1
- package/styles/reset/typography.js +26 -1
- package/subscriptions/app.js +148 -17
- package/subscriptions/error.js +292 -13
- package/subscriptions/helpers/buildRegisterUrl.js +25 -6
- package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
- package/subscriptions/helpers/handleLinks.js +267 -25
- package/subscriptions/helpers/pipeline.js +12 -1
- package/subscriptions/history.js +34 -6
- package/subscriptions/index.js +25 -4
- package/subscriptions/menu.js +22 -5
- package/subscriptions/mock.js +39 -7
- package/subscriptions/router.js +336 -23
- package/subscriptions/user.js +93 -3
|
@@ -1,39 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* Tests if the prop is an array-object.
|
|
3
3
|
* @param {*} prop The property to test.
|
|
4
4
|
* @return {boolean}
|
|
5
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
export const isArray = prop => typeof prop === 'object' && prop !== null && prop.constructor === Array;
|
|
7
|
+
|
|
8
|
+
/**
|
|
6
9
|
* Tests if the prop is an object.
|
|
7
10
|
* @param {*} prop The property to test.
|
|
8
11
|
* @return {boolean}
|
|
9
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
export const isObject = prop => typeof prop === 'object' && prop !== null && prop.constructor === Object;
|
|
14
|
+
|
|
15
|
+
/**
|
|
10
16
|
* Checks if a passed value is numeric.
|
|
11
17
|
* @param {*} prop The property to test.
|
|
12
18
|
* @return {boolean}
|
|
13
|
-
*/
|
|
14
|
-
|
|
19
|
+
*/
|
|
20
|
+
export const isNumeric = prop =>
|
|
21
|
+
// eslint-disable-next-line no-restricted-globals
|
|
22
|
+
!Number.isNaN(parseFloat(prop)) && isFinite(prop);
|
|
23
|
+
|
|
24
|
+
/**
|
|
15
25
|
* Tests if the prop is a number.
|
|
16
26
|
* @param {*} prop The property to test.
|
|
17
27
|
* @return {boolean}
|
|
18
|
-
*/
|
|
19
|
-
|
|
28
|
+
*/
|
|
29
|
+
export const isNumber = prop =>
|
|
30
|
+
// eslint-disable-next-line no-restricted-globals
|
|
31
|
+
typeof prop === 'number' && isFinite(prop);
|
|
32
|
+
|
|
33
|
+
/**
|
|
20
34
|
* Tests if the prop is an integer.
|
|
21
35
|
* @param {*} prop The property to test.
|
|
22
36
|
* @return {boolean}
|
|
23
|
-
*/
|
|
37
|
+
*/
|
|
38
|
+
export const isInteger = prop => isNumber(prop) && prop % 1 === 0;
|
|
39
|
+
|
|
40
|
+
/**
|
|
24
41
|
* Tests if the prop is boolean.
|
|
25
42
|
* @param {*} prop The property to test.
|
|
26
43
|
* @return {boolean}
|
|
27
|
-
*/
|
|
44
|
+
*/
|
|
45
|
+
export const isBoolean = prop => typeof prop === 'boolean';
|
|
46
|
+
|
|
47
|
+
/**
|
|
28
48
|
* Tests if the prop is function.
|
|
29
49
|
* @param {*} prop The property to test.
|
|
30
50
|
* @return {boolean}
|
|
31
|
-
*/
|
|
51
|
+
*/
|
|
52
|
+
export const isFunction = prop => typeof prop === 'function';
|
|
53
|
+
|
|
54
|
+
/**
|
|
32
55
|
* Tests if the prop is undefined.
|
|
33
56
|
* @param {*} prop The property to test.
|
|
34
57
|
* @return {boolean}
|
|
35
|
-
*/
|
|
58
|
+
*/
|
|
59
|
+
export const isUndefined = prop => typeof prop === 'undefined';
|
|
60
|
+
|
|
61
|
+
/**
|
|
36
62
|
* Tests if the prop is a promise.
|
|
37
63
|
* @param {*} prop The property to test.
|
|
38
64
|
* @return {boolean}
|
|
39
|
-
*/
|
|
65
|
+
*/
|
|
66
|
+
export const isPromise = prop => prop !== null && (typeof prop === 'object' || typeof prop === 'function') && typeof prop.then === 'function';
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
import{isNumeric}from"./index";
|
|
1
|
+
import { isNumeric } from "./index";
|
|
2
|
+
describe('helpers/validation', () => {
|
|
3
|
+
describe('isNumeric', () => {
|
|
4
|
+
describe('Non-regression, "123" is not numeric', () => {
|
|
5
|
+
it('should treat numeric number as numeric', () => {
|
|
6
|
+
expect(isNumeric('123')).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-common",
|
|
3
|
-
"version": "7.30.0-alpha.
|
|
3
|
+
"version": "7.30.0-alpha.8",
|
|
4
4
|
"description": "Common library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@redux-devtools/extension": "^3.3.0",
|
|
19
19
|
"@sentry/browser": "6.0.1",
|
|
20
|
-
"@shopgate/pwa-benchmark": "7.30.0-alpha.
|
|
20
|
+
"@shopgate/pwa-benchmark": "7.30.0-alpha.8",
|
|
21
21
|
"@virtuous/conductor": "~2.5.0",
|
|
22
22
|
"@virtuous/react-conductor": "~2.5.0",
|
|
23
23
|
"@virtuous/redux-persister": "1.1.0-beta.7",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"url-search-params": "^0.10.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@shopgate/pwa-core": "7.30.0-alpha.
|
|
45
|
+
"@shopgate/pwa-core": "7.30.0-alpha.8",
|
|
46
46
|
"@types/react-portal": "^3.0.9",
|
|
47
47
|
"lodash": "^4.17.21",
|
|
48
48
|
"prop-types": "~15.8.1",
|
package/providers/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export{default as LoadingProvider
|
|
1
|
+
export { default as LoadingProvider } from "./loading";
|
|
2
|
+
export { default as LoadingContext } from "./loading/context";
|
|
3
|
+
export { default as ToastProvider } from "./toast";
|
|
4
|
+
export { default as ToastContext } from "./toast/context";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default /*#__PURE__*/React.createContext();
|
|
@@ -1,31 +1,146 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { UIEvents } from '@shopgate/pwa-core';
|
|
4
|
+
import LoadingContext from "./context";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* The LoadingProvider component.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
*/
|
|
9
|
+
class LoadingProvider extends Component {
|
|
10
|
+
/**
|
|
6
11
|
* Adds or increases the loading counter for a path.
|
|
7
12
|
* @param {string} path The path which loads.
|
|
8
|
-
*/
|
|
9
|
-
|
|
13
|
+
*/
|
|
14
|
+
static setLoading(path) {
|
|
15
|
+
UIEvents.emit(LoadingProvider.SET, path);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
10
19
|
* Resets the loading counter for a path.
|
|
11
20
|
* @param {string} path The path which loads.
|
|
12
|
-
*/
|
|
13
|
-
|
|
21
|
+
*/
|
|
22
|
+
static resetLoading(path) {
|
|
23
|
+
UIEvents.emit(LoadingProvider.RESET, path);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
14
27
|
* Decreases the loading counter for a path.
|
|
15
28
|
* @param {string} path The path which loads.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
*/
|
|
30
|
+
static unsetLoading(path) {
|
|
31
|
+
UIEvents.emit(LoadingProvider.UNSET, path);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {Object} props The component props.
|
|
36
|
+
*/
|
|
37
|
+
constructor(props) {
|
|
38
|
+
super(props);
|
|
39
|
+
/**
|
|
40
|
+
* Adds or increases the loading counter for a path.
|
|
41
|
+
* @param {string} path The path which loads.
|
|
42
|
+
*/
|
|
43
|
+
this.setLoading = path => {
|
|
44
|
+
const {
|
|
45
|
+
loading
|
|
46
|
+
} = this;
|
|
47
|
+
const newLoading = {
|
|
48
|
+
...loading,
|
|
49
|
+
[path]: loading[path] ? loading[path] + 1 : 1
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Immediately updates state due to multiple sets before actual rerender.
|
|
53
|
+
this.loading = newLoading;
|
|
54
|
+
this.setState({
|
|
55
|
+
loading: newLoading
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Resets the loading counter for a path.
|
|
60
|
+
* @param {string} path The path which loads.
|
|
61
|
+
*/
|
|
62
|
+
this.resetLoading = path => {
|
|
63
|
+
const {
|
|
64
|
+
[path]: removedPath,
|
|
65
|
+
...remaining
|
|
66
|
+
} = this.loading;
|
|
67
|
+
|
|
68
|
+
// Immediately updates state due to multiple sets before actual rerender.
|
|
69
|
+
this.loading = remaining;
|
|
70
|
+
this.setState({
|
|
71
|
+
loading: remaining
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Decreases the loading counter for a path.
|
|
76
|
+
* @param {string} path The path which loads.
|
|
77
|
+
*/
|
|
78
|
+
this.unsetLoading = path => {
|
|
79
|
+
const {
|
|
80
|
+
loading
|
|
81
|
+
} = this;
|
|
82
|
+
if (typeof loading[path] === 'undefined') {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (loading[path] <= 1) {
|
|
86
|
+
this.resetLoading(path);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const newLoading = {
|
|
90
|
+
...loading,
|
|
91
|
+
[path]: loading[path] - 1
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Immediately updates state due to multiple sets before actual rerender.
|
|
95
|
+
this.loading = newLoading;
|
|
96
|
+
this.setState({
|
|
97
|
+
loading: newLoading
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Checks if a path is loading.
|
|
102
|
+
* @param {string} path The path it inspect.
|
|
103
|
+
* @return {boolean}
|
|
104
|
+
*/
|
|
105
|
+
this.isLoading = path => {
|
|
106
|
+
const {
|
|
107
|
+
loading
|
|
108
|
+
} = this.state;
|
|
109
|
+
return !!loading[path];
|
|
110
|
+
};
|
|
111
|
+
this.loading = {};
|
|
112
|
+
this.state = {
|
|
113
|
+
loading: {}
|
|
114
|
+
};
|
|
115
|
+
UIEvents.addListener(this.constructor.SET, this.setLoading);
|
|
116
|
+
UIEvents.addListener(this.constructor.RESET, this.resetLoading);
|
|
117
|
+
UIEvents.addListener(this.constructor.UNSET, this.unsetLoading);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
22
121
|
* Removes the event listeners when the component unmounts.
|
|
23
|
-
*/
|
|
122
|
+
*/
|
|
123
|
+
componentWillUnmount() {
|
|
124
|
+
UIEvents.removeListener(this.constructor.SET, this.setLoading);
|
|
125
|
+
UIEvents.removeListener(this.constructor.RESET, this.resetLoading);
|
|
126
|
+
UIEvents.removeListener(this.constructor.UNSET, this.unsetLoading);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
24
129
|
* @return {JSX}
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
130
|
+
*/
|
|
131
|
+
render() {
|
|
132
|
+
const value = {
|
|
133
|
+
loading: this.state.loading,
|
|
134
|
+
setLoading: this.setLoading,
|
|
135
|
+
unsetLoading: this.unsetLoading,
|
|
136
|
+
isLoading: this.isLoading
|
|
137
|
+
};
|
|
138
|
+
return /*#__PURE__*/React.createElement(LoadingContext.Provider, {
|
|
139
|
+
value: value
|
|
140
|
+
}, this.props.children);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
LoadingProvider.SET = 'loading_set';
|
|
144
|
+
LoadingProvider.RESET = 'loading_reset';
|
|
145
|
+
LoadingProvider.UNSET = 'loading_unset';
|
|
146
|
+
export default LoadingProvider;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default /*#__PURE__*/React.createContext();
|
package/providers/toast/index.js
CHANGED
|
@@ -1,15 +1,109 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { UIEvents } from '@shopgate/pwa-core';
|
|
4
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
5
|
+
import ToastContext from "./context";
|
|
6
|
+
const {
|
|
7
|
+
variables: {
|
|
8
|
+
toast: {
|
|
9
|
+
duration = 5000
|
|
10
|
+
} = {}
|
|
11
|
+
} = {}
|
|
12
|
+
} = themeConfig;
|
|
13
|
+
|
|
14
|
+
/**
|
|
2
15
|
* The ToastProvider component
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
*/
|
|
17
|
+
class ToastProvider extends Component {
|
|
18
|
+
/**
|
|
19
|
+
* @param {Object} props The component props.
|
|
20
|
+
*/
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super(props);
|
|
23
|
+
/**
|
|
24
|
+
* Adds a new, unique, toast to the list.
|
|
25
|
+
* @param {Object} toast The toast object to add.
|
|
26
|
+
*/
|
|
27
|
+
this.addToast = toast => {
|
|
28
|
+
if (!toast.message) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const {
|
|
32
|
+
toasts
|
|
33
|
+
} = this.state;
|
|
34
|
+
|
|
35
|
+
// Check if the toast id already is present.
|
|
36
|
+
const found = toasts.find(({
|
|
37
|
+
id
|
|
38
|
+
}) => toast.id === id);
|
|
39
|
+
|
|
40
|
+
// If found, update the toast with the new data.
|
|
41
|
+
if (found) {
|
|
42
|
+
found.action = toast.action;
|
|
43
|
+
found.actionLabel = toast.actionLabel;
|
|
44
|
+
found.message = toast.message;
|
|
45
|
+
found.messageParams = toast.messageParams;
|
|
46
|
+
found.duration = toast.duration || duration;
|
|
47
|
+
} else {
|
|
48
|
+
toasts.push({
|
|
49
|
+
id: toast.id,
|
|
50
|
+
action: toast.action,
|
|
51
|
+
actionLabel: toast.actionLabel,
|
|
52
|
+
message: toast.message,
|
|
53
|
+
messageParams: toast.messageParams,
|
|
54
|
+
duration: toast.duration || duration
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.setState({
|
|
58
|
+
toasts
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Removes the first toast from the list.
|
|
63
|
+
*/
|
|
64
|
+
this.removeToast = () => {
|
|
65
|
+
const {
|
|
66
|
+
toasts
|
|
67
|
+
} = this.state;
|
|
68
|
+
toasts.shift();
|
|
69
|
+
this.setState({
|
|
70
|
+
toasts
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
this.flushToasts = () => {
|
|
74
|
+
if (this.state.toasts.length) {
|
|
75
|
+
this.setState({
|
|
76
|
+
toasts: []
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
this.state = {
|
|
81
|
+
toasts: []
|
|
82
|
+
};
|
|
83
|
+
UIEvents.addListener(this.constructor.ADD, this.addToast);
|
|
84
|
+
UIEvents.addListener(this.constructor.FLUSH, this.flushToasts);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
11
88
|
* Returns the context value to be passed to consumers.
|
|
12
89
|
* @returns {Object}
|
|
13
|
-
*/
|
|
90
|
+
*/
|
|
91
|
+
get provided() {
|
|
92
|
+
return {
|
|
93
|
+
addToast: this.addToast,
|
|
94
|
+
removeToast: this.removeToast,
|
|
95
|
+
toasts: this.state.toasts
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
14
99
|
* @returns {JSX}
|
|
15
|
-
*/
|
|
100
|
+
*/
|
|
101
|
+
render() {
|
|
102
|
+
return /*#__PURE__*/React.createElement(ToastContext.Provider, {
|
|
103
|
+
value: this.provided
|
|
104
|
+
}, this.props.children);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
ToastProvider.ADD = 'toast_add';
|
|
108
|
+
ToastProvider.FLUSH = 'toast_flush';
|
|
109
|
+
export default ToastProvider;
|
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { RECEIVE_CLIENT_CONNECTIVITY } from "../../constants/ActionTypes";
|
|
2
|
+
import { CONNECTIVITY_NETWORK_UNKNOWN, CONNECTIVITY_TYPE_UNKNOWN } from "../../constants/client";
|
|
3
|
+
const defaultState = {
|
|
4
|
+
connected: true,
|
|
5
|
+
network: CONNECTIVITY_NETWORK_UNKNOWN,
|
|
6
|
+
type: CONNECTIVITY_TYPE_UNKNOWN
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* Stores the client connectivity data.
|
|
3
11
|
* @param {Object} [state] The current state.
|
|
4
12
|
* @param {Object} action The action object.
|
|
5
13
|
* @return {Object} The new state.
|
|
6
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
export default function clientConnectivityReducer(state = defaultState, action) {
|
|
16
|
+
switch (action.type) {
|
|
17
|
+
case RECEIVE_CLIENT_CONNECTIVITY:
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
...defaultState,
|
|
21
|
+
...action.data
|
|
22
|
+
};
|
|
23
|
+
default:
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
}
|
package/reducers/client/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{combineReducers}from'redux';
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import info from "./info";
|
|
3
|
+
import connectivity from "./connectivity";
|
|
4
|
+
export default combineReducers({
|
|
5
|
+
info,
|
|
6
|
+
connectivity
|
|
7
|
+
});
|
package/reducers/client/info.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { REQUEST_CLIENT_INFORMATION, RECEIVE_CLIENT_INFORMATION, ERROR_CLIENT_INFORMATION } from "../../constants/ActionTypes";
|
|
2
|
+
const defaultState = {};
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Stores all the client information.
|
|
3
6
|
* @param {Object} [state] The current state.
|
|
4
7
|
* @param {Object} action The action object.
|
|
5
8
|
* @return {Object} The new state.
|
|
6
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
export default function clientInformationReducer(state = defaultState, action) {
|
|
11
|
+
switch (action.type) {
|
|
12
|
+
case REQUEST_CLIENT_INFORMATION:
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
isFetching: true
|
|
16
|
+
};
|
|
17
|
+
case RECEIVE_CLIENT_INFORMATION:
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
...action.data,
|
|
21
|
+
isFetching: false
|
|
22
|
+
};
|
|
23
|
+
case ERROR_CLIENT_INFORMATION:
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
isFetching: false
|
|
27
|
+
};
|
|
28
|
+
default:
|
|
29
|
+
return state;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/reducers/index.js
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
import configuration from"../collections/Configuration";
|
|
1
|
+
import configuration from "../collections/Configuration";
|
|
2
|
+
import { RESET_APP_REDUCERS } from "../constants/Configuration";
|
|
3
|
+
import { RESET_APP } from "../constants/ActionTypes";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* The root reducer.
|
|
3
7
|
* @param {Function} appReducers The app reducers from combineReducers.
|
|
4
8
|
* @returns {Function}
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
*/
|
|
10
|
+
const makeRootReducer = appReducers => (state, action) => {
|
|
11
|
+
if (action.type === RESET_APP) {
|
|
12
|
+
const resetReducers = action.reducers || configuration.get(RESET_APP_REDUCERS);
|
|
13
|
+
if (Array.isArray(resetReducers)) {
|
|
14
|
+
resetReducers.forEach(reducer => {
|
|
15
|
+
if (typeof state[reducer] === 'undefined') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// Set reset reducer to undefined
|
|
19
|
+
// eslint-disable-next-line no-param-reassign
|
|
20
|
+
state[reducer] = undefined;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return appReducers(state, action);
|
|
25
|
+
};
|
|
26
|
+
export default makeRootReducer;
|
package/reducers/menu/index.js
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
import { REQUEST_MENU, RECEIVE_MENU, ERROR_MENU } from "../../constants/ActionTypes";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Stores the entries of the service menu.
|
|
3
5
|
* @param {Object} [state] The current state.
|
|
4
6
|
* @param {Object} action The action object.
|
|
5
7
|
* @return {Object} The new state.
|
|
6
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
export default function menusByIdReducer(state = {}, action) {
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case REQUEST_MENU:
|
|
12
|
+
{
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
[action.id]: {
|
|
16
|
+
...state[action.id],
|
|
17
|
+
isFetching: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
case RECEIVE_MENU:
|
|
22
|
+
{
|
|
23
|
+
return {
|
|
24
|
+
...state,
|
|
25
|
+
[action.id]: {
|
|
26
|
+
...state[action.id],
|
|
27
|
+
entries: action.entries,
|
|
28
|
+
isFetching: false
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
case ERROR_MENU:
|
|
33
|
+
{
|
|
34
|
+
return {
|
|
35
|
+
...state,
|
|
36
|
+
[action.id]: {
|
|
37
|
+
...state[action.id],
|
|
38
|
+
isFetching: false
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
return state;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/reducers/modal/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import{CREATE_MODAL,REMOVE_MODAL}from"../../constants/ActionTypes"
|
|
1
|
+
import { CREATE_MODAL, REMOVE_MODAL } from "../../constants/ActionTypes";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Stores all the view information.
|
|
3
5
|
* @param {Object} state The current state.
|
|
4
6
|
* @param {Object} action The action object.
|
|
5
7
|
* @return {Object} The new state.
|
|
6
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
export default function modalReducer(state = [], action) {
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case CREATE_MODAL:
|
|
12
|
+
return [...state, action.options];
|
|
13
|
+
case REMOVE_MODAL:
|
|
14
|
+
return state.filter(modal => modal.id !== action.id);
|
|
15
|
+
default:
|
|
16
|
+
return state;
|
|
17
|
+
}
|
|
18
|
+
}
|