@shopgate/pwa-common 7.30.0-alpha.7 → 7.30.0-alpha.9
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 +214 -7
- 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 +21 -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 +228 -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 -4
- 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
package/selectors/menu.js
CHANGED
|
@@ -1,21 +1,49 @@
|
|
|
1
|
-
import{createSelector}from'reselect'
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Selects the menu state from the store.
|
|
3
5
|
* @param {Object} state The global state.
|
|
4
6
|
* @return {Object}
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export const getMenuState = state => state.menu;
|
|
9
|
+
|
|
10
|
+
/**
|
|
6
11
|
* @param {Object} state The global state.
|
|
7
12
|
* @return {Object|null}
|
|
8
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
export const getMenus = createSelector(getMenuState, menuState => {
|
|
15
|
+
if (!menuState || !menuState.menusById) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return menuState.menusById;
|
|
19
|
+
});
|
|
20
|
+
const defaultValue = [];
|
|
21
|
+
|
|
22
|
+
/**
|
|
9
23
|
* Selects a menu by id.
|
|
10
24
|
* @param {Object} state The global state.
|
|
11
25
|
* @param {Object} props The menu props.
|
|
12
26
|
* @return {Array}
|
|
13
|
-
*/
|
|
27
|
+
*/
|
|
28
|
+
export const getMenuById = createSelector(getMenus, (state, {
|
|
29
|
+
id
|
|
30
|
+
}) => id, (menus, id) => {
|
|
31
|
+
if (!menus || !menus[id] || !menus[id].entries) {
|
|
32
|
+
return defaultValue;
|
|
33
|
+
}
|
|
34
|
+
return menus[id].entries;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
14
38
|
* Creates a selector that retrieves a list of entries for a specified menu id.
|
|
15
39
|
* @param {string} menuId The menu id.
|
|
16
40
|
* @returns {Function}
|
|
17
|
-
*/
|
|
41
|
+
*/
|
|
42
|
+
export const makeGetMenu = menuId => createSelector(getMenus, menus => menus?.[menuId]?.entries || null);
|
|
43
|
+
|
|
44
|
+
/**
|
|
18
45
|
* Creates a selector that determines if a menu is fetching.
|
|
19
46
|
* @param {string} menuId The menu id.
|
|
20
47
|
* @returns {Function}
|
|
21
|
-
*/
|
|
48
|
+
*/
|
|
49
|
+
export const makeGetIsFetchingMenu = menuId => createSelector(getMenus, menus => menus?.[menuId]?.isFetching || false);
|
package/selectors/modal.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import{createSelector}from'reselect'
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Returns modal state (state.modal)
|
|
3
5
|
* @param {Object} state The application state.
|
|
4
6
|
* @returns {Object}
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export const getModalState = state => state.modal || [];
|
|
9
|
+
|
|
10
|
+
/**
|
|
6
11
|
* Returns the first modal of the current modal stack.
|
|
7
12
|
* @return {Object|undefined}
|
|
8
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
export const getFirstModal = createSelector(getModalState, modals => modals[0]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
9
17
|
* Searches for a modal with a specific id in the current modal stack.
|
|
10
18
|
* @return {Object|undefined}
|
|
11
|
-
*/
|
|
19
|
+
*/
|
|
20
|
+
export const getModalById = createSelector(getModalState, (state, modalId) => modalId, (modals, modalId) => modals.find(({
|
|
21
|
+
id
|
|
22
|
+
}) => id === modalId));
|
package/selectors/page.js
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
import{createSelector}from'reselect'
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* @param {Object} state The current application state.
|
|
3
5
|
* @return {Object}
|
|
4
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
export const getPageState = state => state.page;
|
|
8
|
+
|
|
9
|
+
/**
|
|
5
10
|
* @param {Object} state The current application state.
|
|
6
11
|
* @param {Object} props The current component props.
|
|
7
12
|
* @return {Array|null}
|
|
8
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
export const getPageConfigById = createSelector(getPageState, (state, props) => props.pageId, (pageState, pageId) => {
|
|
15
|
+
if (!pageState || !pageState[pageId]) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return pageState[pageId];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
9
22
|
* Creates a selector that retrieves a page configuration by its ID.
|
|
10
23
|
* @param {Object} params The selector parameters.
|
|
11
24
|
* @param {string} params.pageId The ID of the page.
|
|
12
25
|
* @returns {Function} A selector function that retrieves the page configuration.
|
|
13
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
export const makeGetPageConfigById = ({
|
|
28
|
+
pageId
|
|
29
|
+
}) => createSelector(getPageState, pageState => {
|
|
30
|
+
if (!pageState || !pageState[pageId]) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return pageState[pageId];
|
|
34
|
+
});
|
package/selectors/router.js
CHANGED
|
@@ -1,65 +1,189 @@
|
|
|
1
|
-
import{createSelector}from'reselect';
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import { isObject } from "../helpers/validation";
|
|
3
|
+
import authRoutes from "../collections/AuthRoutes";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* @param {Object} state The application state.
|
|
3
7
|
* @return {Object}
|
|
4
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
export const getRouterState = state => state.router;
|
|
10
|
+
|
|
11
|
+
/**
|
|
5
12
|
* @param {Object} state The application state.
|
|
6
13
|
* @return {Array}
|
|
7
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
export const getRouterStack = createSelector(getRouterState, state => state && state.stack ? state.stack : []);
|
|
16
|
+
|
|
17
|
+
/**
|
|
8
18
|
* @param {Object} state The application state.
|
|
9
19
|
* @returns {Object|null}
|
|
10
|
-
*/
|
|
20
|
+
*/
|
|
21
|
+
export const getCurrentRoute = createSelector(getRouterState, getRouterStack, (state, props = {}) => props.routeId, (router, stack, routeId) => {
|
|
22
|
+
if (!router || !router.currentRoute) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (!routeId) {
|
|
26
|
+
return router.currentRoute;
|
|
27
|
+
}
|
|
28
|
+
return stack.find(entry => entry.id === routeId);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
11
32
|
* @param {Object} state The application state.
|
|
12
33
|
* @returns {Object|null}
|
|
13
|
-
*/
|
|
34
|
+
*/
|
|
35
|
+
export const getCurrentParams = createSelector(getCurrentRoute, route => {
|
|
36
|
+
if (!route || !route.params) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return route.params;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
14
43
|
* @param {Object} state The application state.
|
|
15
44
|
* @returns {string|null} The current history pathname.
|
|
16
|
-
*/
|
|
45
|
+
*/
|
|
46
|
+
export const getCurrentPathname = createSelector(getCurrentRoute, route => {
|
|
47
|
+
if (!route || !route.pathname) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return route.pathname;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
17
54
|
* @param {Object} state The application state.
|
|
18
55
|
* @returns {Object|null} The current history query.
|
|
19
|
-
*/
|
|
56
|
+
*/
|
|
57
|
+
export const getCurrentQuery = createSelector(getCurrentRoute, route => {
|
|
58
|
+
if (!route || !route.query) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return route.query;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
20
65
|
* @param {Object} state The application state.
|
|
21
66
|
* @returns {string|null} The current history search query.
|
|
22
|
-
*/
|
|
67
|
+
*/
|
|
68
|
+
export const getCurrentSearchQuery = createSelector(getCurrentQuery, query => {
|
|
69
|
+
if (!query || !query.s) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return query.s;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
23
76
|
* @param {Object} state The application state.
|
|
24
77
|
* @returns {string|null} The current history entry state.
|
|
25
|
-
*/
|
|
78
|
+
*/
|
|
79
|
+
export const getCurrentState = createSelector(getCurrentRoute, route => {
|
|
80
|
+
if (!route || !route.state) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return route.state;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
26
87
|
* Determines, if a router state entry is the last entry in the stack.
|
|
27
88
|
* @param {string} id The id of the entry.
|
|
28
89
|
* @returns {Function}
|
|
29
|
-
*/
|
|
90
|
+
*/
|
|
91
|
+
export function makeIsLastStackEntry() {
|
|
92
|
+
return createSelector((state, props = {}) => props.routeId, getRouterStack, (routeId, stack) => {
|
|
93
|
+
const index = stack.findIndex(entry => entry.id === routeId);
|
|
94
|
+
return index >= 0 && index === stack.length - 1;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
30
99
|
* Get the previous route from stack.
|
|
31
100
|
* @returns {Function}
|
|
32
|
-
*/
|
|
101
|
+
*/
|
|
102
|
+
export function makeGetPrevRoute() {
|
|
103
|
+
return createSelector((state, props = {}) => props.routeId, getRouterStack, (routeId, stack) => {
|
|
104
|
+
const routeIndex = stack.findIndex(entry => entry.id === routeId);
|
|
105
|
+
if (routeIndex <= 0) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return stack[routeIndex - 1];
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
33
113
|
* Creates a selector that retrieves the pattern of the route.
|
|
34
114
|
* @returns {Function}
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
115
|
+
*/
|
|
116
|
+
export const makeGetRoutePattern = () =>
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves the route pattern.
|
|
119
|
+
* @param {Object} state The application state.
|
|
120
|
+
* @param {Object} props The component props.
|
|
121
|
+
* @returns {string|null} The pattern.
|
|
122
|
+
*/
|
|
123
|
+
createSelector(getCurrentRoute, route => {
|
|
124
|
+
if (!route || !route.pattern) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return route.pattern;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/**
|
|
41
131
|
* Creates a selector that retrieves the value of a specific parameter from the route.
|
|
42
132
|
* @param {string} name The name of the desired parameter.
|
|
43
133
|
* @returns {Function}
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
134
|
+
*/
|
|
135
|
+
export const makeGetRouteParam = (name = '') =>
|
|
136
|
+
/**
|
|
137
|
+
* Retrieves a parameter from the route.
|
|
138
|
+
* @param {Object} state The application state.
|
|
139
|
+
* @param {Object} props The component props.
|
|
140
|
+
* @returns {string|null} The parameter value.
|
|
141
|
+
*/
|
|
142
|
+
createSelector(getCurrentParams, params => {
|
|
143
|
+
if (!isObject(params)) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return params[name] || null;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
50
150
|
* Creates a selector that retrieves the index of the current or a specific route when passed
|
|
51
151
|
* within the props.
|
|
52
152
|
* @returns {number|null}
|
|
53
|
-
*/
|
|
153
|
+
*/
|
|
154
|
+
export const getRouterStackIndex = createSelector(getRouterStack, getCurrentRoute, (routerStack, currentRoute) => {
|
|
155
|
+
if (!currentRoute) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const {
|
|
159
|
+
id: currentId
|
|
160
|
+
} = currentRoute;
|
|
161
|
+
const index = routerStack.findIndex(({
|
|
162
|
+
id
|
|
163
|
+
}) => currentId === id);
|
|
164
|
+
return index >= 0 ? index : null;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
/**
|
|
54
168
|
* Creates a selector that retrieves the index of the most next previous route with
|
|
55
169
|
* the desired pattern within the stack
|
|
56
170
|
* @param {string} pattern The desired route pattern
|
|
57
171
|
* @returns {Function}
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
172
|
+
*/
|
|
173
|
+
export const makeGetPrevRouteIndexByPattern = pattern =>
|
|
174
|
+
/**
|
|
175
|
+
* @param {Object} state The application state.
|
|
176
|
+
* @param {Object} props The component props.
|
|
177
|
+
* @returns {Object} The route.
|
|
178
|
+
*/
|
|
179
|
+
createSelector(getRouterStack, getRouterStackIndex, (routerStack, routerStackIndex) => {
|
|
180
|
+
const sliced = routerStack.slice(0, routerStackIndex);
|
|
181
|
+
const reversedIndex = sliced.reverse().findIndex(route => route.pattern === pattern);
|
|
182
|
+
return reversedIndex === -1 ? reversedIndex : sliced.length - 1 - reversedIndex;
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
/**
|
|
63
186
|
* Creates a selector to determine if the current active route is "protected" (needs login).
|
|
64
187
|
* @returns {Function}
|
|
65
|
-
*/
|
|
188
|
+
*/
|
|
189
|
+
export const makeGetIsCurrentRouteProtected = () => createSelector(getCurrentPathname, pattern => !!authRoutes.getProtector(pattern));
|
package/selectors/url.js
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
import{createSelector}from'reselect'
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Returns url state (state.url)
|
|
3
5
|
* @param {Object} state The application state.
|
|
4
6
|
* @returns {Object}
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export const getUrlState = state => state.url;
|
|
9
|
+
|
|
10
|
+
/**
|
|
6
11
|
* Returns the complete state entry for state.url[type]
|
|
7
12
|
* @param {string} type The url type.
|
|
8
13
|
* @param {Object} state The application state.
|
|
9
14
|
* @returns {Object|undefined}
|
|
10
|
-
*/
|
|
15
|
+
*/
|
|
16
|
+
export const getEntryByType = createSelector(getUrlState, (state, {
|
|
17
|
+
type
|
|
18
|
+
}) => type, (urlState, type) => {
|
|
19
|
+
if (!urlState || !urlState[type]) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return urlState[type];
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
11
26
|
* Returns the url for the given url type.
|
|
12
27
|
* @param {string} type The url type.
|
|
13
28
|
* @param {Object} state The application state.
|
|
14
29
|
* @returns {string|null}
|
|
15
|
-
*/
|
|
30
|
+
*/
|
|
31
|
+
export const getUrl = createSelector(getEntryByType, entry => {
|
|
32
|
+
if (!entry) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return entry.url;
|
|
36
|
+
});
|
package/selectors/user.js
CHANGED
|
@@ -1,45 +1,122 @@
|
|
|
1
|
-
import{createSelector}from'reselect';
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import { getUrl } from "./url";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* @param {Object} state The current application state.
|
|
3
6
|
* @return {Object}
|
|
4
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export const getUserState = state => state.user;
|
|
9
|
+
|
|
10
|
+
/**
|
|
5
11
|
* Gets user.login from the redux store.
|
|
6
12
|
* @param {Object} state The application state.
|
|
7
13
|
* @return {Object|null}
|
|
8
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
export const getLoginData = createSelector(getUserState, user => {
|
|
16
|
+
if (!user || !user.login) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return user.login;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
9
23
|
* @param {Object} state The current application state.
|
|
10
24
|
* @return {Object|null}
|
|
11
25
|
* @deprecated
|
|
12
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
export const getUserLogin = getLoginData;
|
|
28
|
+
|
|
29
|
+
/**
|
|
13
30
|
* @param {Object} state The current application state.
|
|
14
31
|
* @return {Object}
|
|
15
|
-
*/
|
|
32
|
+
*/
|
|
33
|
+
export const getUserData = createSelector(getUserState, user => {
|
|
34
|
+
if (!user.data) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return user.data;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/**
|
|
16
41
|
* Selects the isLoggedIn state from the user.
|
|
17
42
|
* @param {Object} state The global state.
|
|
18
43
|
* @return {boolean}
|
|
19
|
-
*/
|
|
44
|
+
*/
|
|
45
|
+
export const isUserLoggedIn = createSelector(getLoginData, login => {
|
|
46
|
+
if (!login) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return login.isLoggedIn;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
20
53
|
* @param {Object} state The global state.
|
|
21
54
|
* @returns {string}
|
|
22
|
-
*/
|
|
55
|
+
*/
|
|
56
|
+
export const getUserDisplayName = createSelector(getUserData, data => {
|
|
57
|
+
if (!data) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return [data.firstName, data.lastName].join(' ').trim();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/**
|
|
23
64
|
* @param {Object} state The global state.
|
|
24
65
|
* @returns {string}
|
|
25
|
-
*/
|
|
66
|
+
*/
|
|
67
|
+
export const getUserFirstName = createSelector(getUserData, data => {
|
|
68
|
+
if (!data) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return data.firstName;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
26
75
|
* @param {Object} state The global state.
|
|
27
76
|
* @returns {string}
|
|
28
|
-
*/
|
|
77
|
+
*/
|
|
78
|
+
export const getUserEmail = createSelector(getUserData, data => {
|
|
79
|
+
if (!data) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return data.mail || null;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
29
86
|
* Selects the disabled state of the login action from the redux store.
|
|
30
87
|
* @param {Object} state The application state.
|
|
31
88
|
* @return {Object|null}
|
|
32
|
-
*/
|
|
89
|
+
*/
|
|
90
|
+
export const isUserLoginDisabled = createSelector(getLoginData, login => {
|
|
91
|
+
if (!login) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return login.disabled;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
33
98
|
* Gets the register url.
|
|
34
99
|
* @param {Object} state The application state.
|
|
35
100
|
* @return {string|null}
|
|
36
|
-
*/
|
|
101
|
+
*/
|
|
102
|
+
export const getRegisterUrl = state => getUrl(state, {
|
|
103
|
+
type: 'register'
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/**
|
|
37
107
|
* Retrieves the expiry timestamp from the user login storage
|
|
38
|
-
*/
|
|
108
|
+
*/
|
|
109
|
+
export const getSessionExpiry = createSelector(getLoginData, loginData => loginData.expires);
|
|
110
|
+
|
|
111
|
+
/**
|
|
39
112
|
* Checks if the current session is expired.
|
|
40
113
|
*
|
|
41
114
|
* !!! CAUTION Not implemented with createSelector since selector caching conflicts with processing
|
|
42
115
|
* the current timestamp
|
|
43
116
|
* @param {Object} state The application state.
|
|
44
117
|
* @returns {boolean}
|
|
45
|
-
*/
|
|
118
|
+
*/
|
|
119
|
+
export const getIsSessionExpired = state => {
|
|
120
|
+
const expiry = getSessionExpiry(state);
|
|
121
|
+
return typeof expiry === 'number' && new Date().getTime() >= expiry;
|
|
122
|
+
};
|
package/store/index.js
CHANGED
|
@@ -1,18 +1,72 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "core-js/modules/es.string.replace.js";
|
|
2
|
+
import { createStore, applyMiddleware } from 'redux';
|
|
3
|
+
import thunk from 'redux-thunk';
|
|
4
|
+
import { composeWithDevTools } from '@redux-devtools/extension';
|
|
5
|
+
import { persistState } from '@virtuous/redux-persister';
|
|
6
|
+
import benchmarkMiddleware from '@shopgate/pwa-benchmark/profilers/redux';
|
|
7
|
+
import benchmarkController from '@shopgate/pwa-benchmark';
|
|
8
|
+
import persistedReducers from "../collections/PersistedReducers";
|
|
9
|
+
import initSubscribers from "../subscriptions";
|
|
10
|
+
import appConfig, { themeName, shopNumber } from "../helpers/config";
|
|
11
|
+
import makeRootReducer from "../reducers";
|
|
12
|
+
import streams from "./middelwares/streams";
|
|
13
|
+
import logger from "./middelwares/logger";
|
|
14
|
+
|
|
15
|
+
/**
|
|
2
16
|
* The current version of the state created by this reducer.
|
|
3
17
|
* @type {string}
|
|
4
|
-
*/
|
|
18
|
+
*/
|
|
19
|
+
const STATE_VERSION = 'v3';
|
|
20
|
+
const storeKey = `shopgate-connect_${shopNumber}-${themeName}_${STATE_VERSION}`;
|
|
21
|
+
|
|
22
|
+
/**
|
|
5
23
|
* Returns a normalized initialState from the local storage.
|
|
6
24
|
* @returns {Object}
|
|
7
|
-
*/
|
|
25
|
+
*/
|
|
26
|
+
function getInitialState() {
|
|
27
|
+
if (!window.localStorage) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const storedState = window.localStorage.getItem(storeKey);
|
|
31
|
+
if (!storedState) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const normalizedState = storedState.replace(new RegExp('"isFetching":true', 'g'), '"isFetching":false');
|
|
35
|
+
return JSON.parse(normalizedState);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
8
39
|
* Configures the redux store with all it's middleware and enhancers.
|
|
9
40
|
* @param {Function} reducers The reducers from the theme.
|
|
10
41
|
* @param {Array} subscribers The subscribers to the streams middleware.
|
|
11
42
|
* @return {Object} The redux store.
|
|
12
|
-
*/
|
|
13
|
-
|
|
43
|
+
*/
|
|
44
|
+
export function configureStore(reducers, subscribers) {
|
|
45
|
+
// Starts benchmark controller BEFORE adding the middleware.
|
|
46
|
+
if (appConfig.benchmark) {
|
|
47
|
+
benchmarkController.startup();
|
|
48
|
+
}
|
|
49
|
+
const store = createStore(makeRootReducer(reducers), getInitialState(), composeWithDevTools(applyMiddleware(...[thunk, ...(appConfig.benchmark ? [benchmarkMiddleware] : []), streams, logger]), persistState({
|
|
50
|
+
key: storeKey,
|
|
51
|
+
paths: persistedReducers.getAll()
|
|
52
|
+
})));
|
|
53
|
+
initSubscribers(subscribers);
|
|
54
|
+
if (window.Cypress) {
|
|
55
|
+
window.store = store;
|
|
56
|
+
}
|
|
57
|
+
return store;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
14
61
|
* Configures a mocked store for tests.
|
|
15
62
|
* @param {Function} reducers The reducers to use in the mock store.
|
|
16
63
|
* @param {Array} subscribers Streams subscribers to initialize.
|
|
17
64
|
* @returns {Store}
|
|
18
|
-
*/
|
|
65
|
+
*/
|
|
66
|
+
export function createMockStore(reducers = () => {}, subscribers = []) {
|
|
67
|
+
const store = createStore(reducers, undefined, applyMiddleware(thunk, streams));
|
|
68
|
+
if (subscribers.length !== 0) {
|
|
69
|
+
initSubscribers([].concat(subscribers));
|
|
70
|
+
}
|
|
71
|
+
return store;
|
|
72
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{createLogger}from'redux-logger';
|
|
1
|
+
import { createLogger } from 'redux-logger';
|
|
2
|
+
import { logger } from '@shopgate/pwa-core';
|
|
3
|
+
export default createLogger({
|
|
4
|
+
logger,
|
|
5
|
+
collapsed: true,
|
|
6
|
+
duration: true
|
|
7
|
+
});
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import{Subject}from'rxjs/Subject';
|
|
1
|
+
import { Subject } from 'rxjs/Subject';
|
|
2
|
+
import { UIEvents } from '@shopgate/pwa-core';
|
|
3
|
+
export const mainSubject = new Subject();
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Connects the redux store with RxJS and Observable streams.
|
|
3
7
|
* @param {Object} store The redux store.
|
|
4
8
|
* @return {Function}
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const observableMiddleware = store => next => action => {
|
|
11
|
+
const prevState = store.getState();
|
|
12
|
+
const result = next(action);
|
|
13
|
+
mainSubject.next({
|
|
14
|
+
action,
|
|
15
|
+
dispatch: store.dispatch,
|
|
16
|
+
events: UIEvents,
|
|
17
|
+
getState: store.getState,
|
|
18
|
+
prevState
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
export default observableMiddleware;
|