@zengenti/contensis-react-base 2.5.1-beta.3 → 3.0.0-beta.2
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/README.md +8 -2
- package/cjs/{App-fbd91490.js → App-581b6653.js} +20 -19
- package/cjs/App-581b6653.js.map +1 -0
- package/cjs/{RouteLoader-f99cd734.js → RouteLoader-282c03ab.js} +5 -5
- package/cjs/RouteLoader-282c03ab.js.map +1 -0
- package/cjs/ToJs-87edc45d.js +230 -0
- package/cjs/ToJs-87edc45d.js.map +1 -0
- package/cjs/{actions-e9f69947.js → actions-12871aca.js} +9 -13
- package/cjs/actions-12871aca.js.map +1 -0
- package/cjs/client.js +48 -65
- package/cjs/client.js.map +1 -1
- package/cjs/contensis-react-base.js +63 -68
- package/cjs/contensis-react-base.js.map +1 -1
- package/cjs/forms.js +1 -1
- package/cjs/fromJSLeaveImmer-9b550c8e.js +40 -0
- package/cjs/fromJSLeaveImmer-9b550c8e.js.map +1 -0
- package/cjs/{login-4f274c6a.js → login-81d7f9ef.js} +11 -10
- package/cjs/login-81d7f9ef.js.map +1 -0
- package/cjs/{reducers-cb531715.js → reducers-fde41d6b.js} +76 -31
- package/cjs/reducers-fde41d6b.js.map +1 -0
- package/cjs/redux.js +11 -8
- package/cjs/redux.js.map +1 -1
- package/cjs/routing.js +5 -5
- package/cjs/search.js +409 -233
- package/cjs/search.js.map +1 -1
- package/cjs/selectors-ed26ed97.js +141 -0
- package/cjs/selectors-ed26ed97.js.map +1 -0
- package/cjs/user.js +14 -14
- package/cjs/user.js.map +1 -1
- package/cjs/util.js +24 -10
- package/cjs/util.js.map +1 -1
- package/cjs/version-0c190929.js +20 -0
- package/cjs/version-0c190929.js.map +1 -0
- package/cjs/{version-3a808c12.js → version-f061e409.js} +154 -76
- package/cjs/version-f061e409.js.map +1 -0
- package/esm/{App-fbef99b3.js → App-122f28a3.js} +20 -19
- package/esm/App-122f28a3.js.map +1 -0
- package/esm/{RouteLoader-281d47e1.js → RouteLoader-c2faac87.js} +5 -5
- package/esm/RouteLoader-c2faac87.js.map +1 -0
- package/esm/ToJs-52fee252.js +199 -0
- package/esm/ToJs-52fee252.js.map +1 -0
- package/esm/{actions-ddd9c623.js → actions-3cc39599.js} +4 -7
- package/esm/actions-3cc39599.js.map +1 -0
- package/esm/client.js +49 -66
- package/esm/client.js.map +1 -1
- package/esm/contensis-react-base.js +62 -65
- package/esm/contensis-react-base.js.map +1 -1
- package/esm/forms.js +1 -1
- package/esm/fromJSLeaveImmer-e44d1a91.js +38 -0
- package/esm/fromJSLeaveImmer-e44d1a91.js.map +1 -0
- package/esm/{login-1f9ad133.js → login-92db44d1.js} +11 -10
- package/esm/login-92db44d1.js.map +1 -0
- package/esm/{reducers-feab84fc.js → reducers-d6c0edb1.js} +77 -31
- package/esm/reducers-d6c0edb1.js.map +1 -0
- package/esm/redux.js +9 -8
- package/esm/redux.js.map +1 -1
- package/esm/routing.js +5 -5
- package/esm/search.js +409 -235
- package/esm/search.js.map +1 -1
- package/esm/selectors-82e71d8e.js +116 -0
- package/esm/selectors-82e71d8e.js.map +1 -0
- package/esm/user.js +10 -10
- package/esm/user.js.map +1 -1
- package/esm/util.js +24 -10
- package/esm/util.js.map +1 -1
- package/esm/version-59c8f9be.js +15 -0
- package/esm/version-59c8f9be.js.map +1 -0
- package/esm/{version-64906b26.js → version-cb9cd09d.js} +133 -76
- package/esm/version-cb9cd09d.js.map +1 -0
- package/models/app/pages/VersionInfo/components/VersionInfo.d.ts +1 -1
- package/models/config.d.ts +2 -0
- package/models/redux/appstate.d.ts +85 -0
- package/models/redux/index.d.ts +1 -0
- package/models/redux/reducers/navigation.d.ts +6 -2
- package/models/redux/reducers/version.d.ts +5 -2
- package/models/redux/store/store.d.ts +4 -1
- package/models/redux/util.d.ts +2 -0
- package/models/routing/components/RouteLoader.d.ts +20 -2
- package/models/routing/redux/reducers.d.ts +21 -3
- package/models/routing/redux/selectors.d.ts +29 -25
- package/models/routing/routes.d.ts +10 -2
- package/models/search/hooks/useMinilist.hook.d.ts +5 -5
- package/models/search/models/Search.d.ts +8 -1
- package/models/search/models/SearchActions.d.ts +3 -4
- package/models/search/models/SearchState.d.ts +25 -9
- package/models/search/models/WithSearch.d.ts +61 -0
- package/models/search/redux/getIn.d.ts +3 -0
- package/models/search/redux/reducers.d.ts +346 -2
- package/models/search/redux/sagas.d.ts +2 -2
- package/models/search/redux/schema.d.ts +56 -8
- package/models/search/redux/selectors.d.ts +75 -66
- package/models/search/redux/util.d.ts +1 -1
- package/models/search/search/util.d.ts +2 -3
- package/models/user/components/Login.d.ts +10 -1
- package/models/user/containers/ChangePassword.container.d.ts +4 -1
- package/models/user/containers/ForgotPassword.container.d.ts +4 -1
- package/models/user/containers/Login.container.d.ts +4 -1
- package/models/user/containers/Registration.container.d.ts +4 -1
- package/models/user/hocs/withLogin.d.ts +9 -1
- package/models/user/hocs/withRegistration.d.ts +9 -1
- package/models/user/hooks/useChangePassword.d.ts +5 -5
- package/models/user/hooks/useForgotPassword.d.ts +6 -6
- package/models/user/hooks/useLogin.d.ts +45 -7
- package/models/user/hooks/useRegistration.d.ts +4 -4
- package/models/user/redux/reducers.d.ts +54 -3
- package/models/user/redux/selectors.d.ts +72 -27
- package/models/util/ToJs.d.ts +4 -1
- package/package-lock.json +1126 -533
- package/package.json +8 -9
- package/cjs/App-fbd91490.js.map +0 -1
- package/cjs/RouteLoader-f99cd734.js.map +0 -1
- package/cjs/ToJs-d72e5b10.js +0 -167
- package/cjs/ToJs-d72e5b10.js.map +0 -1
- package/cjs/actions-e9f69947.js.map +0 -1
- package/cjs/login-4f274c6a.js.map +0 -1
- package/cjs/reducers-cb531715.js.map +0 -1
- package/cjs/selectors-1295124a.js +0 -139
- package/cjs/selectors-1295124a.js.map +0 -1
- package/cjs/version-2193b4a2.js +0 -24
- package/cjs/version-2193b4a2.js.map +0 -1
- package/cjs/version-3a808c12.js.map +0 -1
- package/esm/App-fbef99b3.js.map +0 -1
- package/esm/RouteLoader-281d47e1.js.map +0 -1
- package/esm/ToJs-6e7b247c.js +0 -136
- package/esm/ToJs-6e7b247c.js.map +0 -1
- package/esm/actions-ddd9c623.js.map +0 -1
- package/esm/login-1f9ad133.js.map +0 -1
- package/esm/reducers-feab84fc.js.map +0 -1
- package/esm/selectors-68799788.js +0 -117
- package/esm/selectors-68799788.js.map +0 -1
- package/esm/version-64906b26.js.map +0 -1
- package/esm/version-7fdbd2d5.js +0 -19
- package/esm/version-7fdbd2d5.js.map +0 -1
package/cjs/search.js
CHANGED
|
@@ -5,20 +5,25 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var reactRedux = require('react-redux');
|
|
7
7
|
var mapJson = require('jsonpath-mapper');
|
|
8
|
-
var
|
|
8
|
+
var immer = require('immer');
|
|
9
9
|
var effects = require('@redux-saga/core/effects');
|
|
10
10
|
var contensisDeliveryApi = require('contensis-delivery-api');
|
|
11
11
|
var queryString = require('query-string');
|
|
12
12
|
var log = require('loglevel');
|
|
13
|
+
var reselect = require('reselect');
|
|
13
14
|
var contensisCoreApi = require('contensis-core-api');
|
|
15
|
+
var merge = require('deepmerge');
|
|
16
|
+
var equals = require('deep-equal');
|
|
14
17
|
|
|
15
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
19
|
|
|
17
20
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
21
|
var mapJson__default = /*#__PURE__*/_interopDefaultLegacy(mapJson);
|
|
19
22
|
var queryString__default = /*#__PURE__*/_interopDefaultLegacy(queryString);
|
|
23
|
+
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
|
|
24
|
+
var equals__default = /*#__PURE__*/_interopDefaultLegacy(equals);
|
|
20
25
|
|
|
21
|
-
/* eslint-disable
|
|
26
|
+
/* eslint-disable import/default */
|
|
22
27
|
const toJS = WrappedComponent => wrappedComponentProps => {
|
|
23
28
|
const KEY = 0;
|
|
24
29
|
const VALUE = 1;
|
|
@@ -195,132 +200,167 @@ let Context; // export type Context = 'facets' | 'listings' | 'minilist';
|
|
|
195
200
|
Context["minilist"] = "minilist";
|
|
196
201
|
})(Context || (Context = {}));
|
|
197
202
|
|
|
198
|
-
|
|
203
|
+
// or replace with a stub function for non-immutable gets
|
|
204
|
+
|
|
205
|
+
const makeFromJS = (returnType = globalThis.STATE_TYPE || 'immutable') => {
|
|
206
|
+
var _immutable, _immutable2;
|
|
207
|
+
|
|
208
|
+
return returnType === 'immutable' ? ((_immutable = globalThis.immutable) === null || _immutable === void 0 ? void 0 : _immutable.fromJSOrdered) || ((_immutable2 = globalThis.immutable) === null || _immutable2 === void 0 ? void 0 : _immutable2.fromJS) || (v => v) : v => v;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const getImmutableOrJS = (state, stateKey, fallbackValue, returnType = globalThis.STATE_TYPE || 'immutable') => {
|
|
212
|
+
// Find a fromJS function from global that is dynamically loaded in createStore
|
|
213
|
+
// or replace with a stub function for non-immutable gets
|
|
214
|
+
const fromJS = makeFromJS(returnType);
|
|
215
|
+
|
|
216
|
+
if (state && 'get' in state && typeof state.get === 'function' && 'getIn' in state && typeof state.getIn === 'function' && 'toJS' in state && typeof state.toJS === 'function') {
|
|
217
|
+
if (Array.isArray(stateKey)) return fromJS(state.getIn(stateKey, fallbackValue));
|
|
218
|
+
return fromJS(state.get(stateKey, fallbackValue));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (Array.isArray(stateKey) && state && typeof state === 'object') {
|
|
222
|
+
const result = mapJson.jpath(stateKey.join('.'), state);
|
|
223
|
+
if (typeof result === 'undefined') return fallbackValue;
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const result = state && typeof state === 'object' ? state[stateKey] : undefined;
|
|
228
|
+
if (typeof result === 'undefined') return fallbackValue;
|
|
229
|
+
return result;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const getSearchContext = state => getImmutableOrJS(state, ['search', 'context'], Context.facets);
|
|
199
233
|
const getCurrent = (state, context = Context.facets) => context === Context.facets ? getCurrentFacet(state) : getCurrentListing(state);
|
|
200
|
-
const getCurrentFacet = state => state
|
|
201
|
-
const getCurrentListing = state => state
|
|
202
|
-
const getCurrentTab = state => state
|
|
203
|
-
const getFacets = state => state
|
|
204
|
-
const getTabFacets = state => getFacets(state).filter((
|
|
205
|
-
const getFacetTitles = state => getFacets(state).map((facet =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
234
|
+
const getCurrentFacet = state => getImmutableOrJS(state, ['search', 'currentFacet']);
|
|
235
|
+
const getCurrentListing = state => getImmutableOrJS(state, ['search', 'currentListing']);
|
|
236
|
+
const getCurrentTab = state => getImmutableOrJS(state, ['search', Context.facets, getCurrentFacet(state), 'tabId'], 0);
|
|
237
|
+
const getFacets = (state, returnType) => getImmutableOrJS(state, ['search', Context.facets], {}, returnType);
|
|
238
|
+
const getTabFacets = state => Object.fromEntries(Object.entries(getFacets(state, 'js')).filter(([key]) => getImmutableOrJS(getFacets(state), [key, 'tabId'], 0) === getCurrentTab(state)));
|
|
239
|
+
const getFacetTitles = state => Object.entries(getFacets(state, 'js')).map(([key, facet = {}]) => {
|
|
240
|
+
var _facet$pagingInfo;
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
key,
|
|
244
|
+
title: facet.title,
|
|
245
|
+
totalCount: (_facet$pagingInfo = facet.pagingInfo) === null || _facet$pagingInfo === void 0 ? void 0 : _facet$pagingInfo.totalCount
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
const getFacet = (state, facetName = '', context = Context.facets, returnType) => {
|
|
211
249
|
const currentFacet = facetName || getCurrentFacet(state);
|
|
212
|
-
return state
|
|
250
|
+
return getImmutableOrJS(state, ['search', context, currentFacet], {}, returnType);
|
|
213
251
|
};
|
|
214
252
|
const getListing = (state, listing = '') => {
|
|
215
253
|
const currentListing = listing || getCurrentListing(state);
|
|
216
|
-
return state
|
|
254
|
+
return getImmutableOrJS(state, ['search', Context.listings, currentListing], {});
|
|
217
255
|
};
|
|
218
|
-
const getFilters = (state, facet, context = Context.facets) => {
|
|
219
|
-
return state
|
|
256
|
+
const getFilters = (state, facet, context = Context.facets, returnType) => {
|
|
257
|
+
return getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'filters'], {}, returnType);
|
|
220
258
|
};
|
|
221
|
-
const getRenderableFilters = (state, facet = '', context = Context.facets) => getFilters(state, facet, context).filter((f =
|
|
222
|
-
const getFiltersToLoad = (state, facet, context = Context.facets) => {
|
|
223
|
-
const filters = getFilters(state, facet, context);
|
|
224
|
-
const loadedFilters = filters.map((f =
|
|
225
|
-
const title = i === null || i === void 0 ? void 0 : i.
|
|
259
|
+
const getRenderableFilters = (state, facet = '', context = Context.facets) => Object.fromEntries(Object.entries(getFilters(state, facet, context, 'js')).filter(([, f = {}]) => typeof f.renderable !== 'boolean' ? true : f.renderable));
|
|
260
|
+
const getFiltersToLoad = (state, facet, context = Context.facets, returnType) => {
|
|
261
|
+
const filters = getFilters(state, facet, context, returnType);
|
|
262
|
+
const loadedFilters = Object.entries(filters).map(([key, f = {}]) => [key, (f.items || []).filter(i => {
|
|
263
|
+
const title = i === null || i === void 0 ? void 0 : i.title;
|
|
226
264
|
return typeof title !== 'undefined' && !!title;
|
|
227
|
-
}).
|
|
228
|
-
return loadedFilters.map((
|
|
265
|
+
}).length > 0 && (f.isError || false) === false]);
|
|
266
|
+
return loadedFilters.map(([filterKey, isLoaded]) => !isLoaded ? filterKey : null).filter(f => !!f);
|
|
229
267
|
}; // We lowercase the filter key unless it's an ISO date string where the T must be uppercase
|
|
230
268
|
|
|
231
|
-
const getSelectedFilters = (state, facet = '', context = Context.facets) => {
|
|
232
|
-
const filters = getFilters(state, facet, context);
|
|
269
|
+
const getSelectedFilters = (state, facet = '', context = Context.facets, returnType) => {
|
|
270
|
+
const filters = getFilters(state, facet, context, 'js');
|
|
233
271
|
const isoDateRegex = RegExp(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d/);
|
|
234
|
-
const selectedFilters = filters.map((filter =
|
|
235
|
-
const key = item === null || item === void 0 ? void 0 : item.
|
|
272
|
+
const selectedFilters = Object.fromEntries(Object.entries(filters).map(([key, filter = {}]) => [key, (filter.items || []).filter(item => !!(item.isSelected || false)).map(item => {
|
|
273
|
+
const key = (item === null || item === void 0 ? void 0 : item.key) || '';
|
|
236
274
|
const isIsoDate = isoDateRegex.test(key);
|
|
237
275
|
return isIsoDate ? key : key.toLowerCase();
|
|
238
|
-
}));
|
|
239
|
-
|
|
276
|
+
})]));
|
|
277
|
+
const fromJS = makeFromJS(returnType);
|
|
278
|
+
return fromJS(selectedFilters);
|
|
240
279
|
};
|
|
241
|
-
const getResults = (state, current = '', context = Context.facets) => {
|
|
242
|
-
return state
|
|
280
|
+
const getResults = (state, current = '', context = Context.facets, returnType) => {
|
|
281
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'results'], [], returnType);
|
|
243
282
|
};
|
|
244
283
|
const getIsInternalPaging = (state, current, context = Context.facets) => {
|
|
245
|
-
return state
|
|
284
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'queryParams', 'internalPaging'], false);
|
|
246
285
|
};
|
|
247
286
|
const getIsLoaded = (state, context = Context.facets, facet) => {
|
|
248
|
-
return !!state
|
|
287
|
+
return !!getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'queryDuration'], 0);
|
|
249
288
|
};
|
|
250
289
|
const getIsLoading = (state, context = Context.facets, facet) => {
|
|
251
|
-
return state
|
|
252
|
-
};
|
|
253
|
-
const getIsSsr = state => {
|
|
254
|
-
return state.getIn(['search', 'config', 'ssr'], false);
|
|
290
|
+
return getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'entries', 'isLoading']);
|
|
255
291
|
};
|
|
292
|
+
const getIsSsr = state => getImmutableOrJS(state, ['search', 'config', 'ssr'], false);
|
|
256
293
|
const getFeaturedResults = (state, current = '', context = Context.facets) => {
|
|
257
|
-
return state
|
|
294
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'featuredResults'], []);
|
|
258
295
|
};
|
|
259
|
-
const getPaging = (state, current = '', context = Context.facets) => {
|
|
260
|
-
return state
|
|
296
|
+
const getPaging = (state, current = '', context = Context.facets, returnType) => {
|
|
297
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo'], {}, returnType);
|
|
261
298
|
};
|
|
262
299
|
const getPageIndex = (state, current = '', context = Context.facets) => {
|
|
263
|
-
return state
|
|
300
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pageIndex']);
|
|
264
301
|
};
|
|
265
302
|
const getPrevPageIndex = (state, current = '', context = Context.facets) => {
|
|
266
|
-
return state
|
|
303
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'prevPageIndex']);
|
|
267
304
|
};
|
|
268
305
|
const getPageIsLoading = (state, current = '', context = Context.facets) => {
|
|
269
|
-
return state
|
|
306
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'isLoading']);
|
|
270
307
|
};
|
|
271
308
|
const getPagesLoaded = (state, current = '', context = Context.facets) => {
|
|
272
|
-
return state
|
|
309
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pagesLoaded'], [], 'js');
|
|
273
310
|
};
|
|
274
311
|
const getTotalCount = (state, current = '', context = Context.facets) => {
|
|
275
|
-
return state
|
|
276
|
-
};
|
|
277
|
-
const getFacetAuthentication = (state, facet) => state.getIn(['search', Context.facets, facet, 'authentication']);
|
|
278
|
-
const getFeaturedEntryIds = state => {
|
|
279
|
-
const currentFacet = getCurrentFacet(state);
|
|
280
|
-
const entryIds = state.getIn(['search', Context.facets, currentFacet, 'featuredEntries', 'items']).map(entry => entry.getIn(['sys', 'id']));
|
|
281
|
-
return entryIds;
|
|
312
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'totalCount']);
|
|
282
313
|
};
|
|
283
|
-
const getSearchTerm = state => state
|
|
284
|
-
const getSearchTabs = state => state
|
|
314
|
+
const getSearchTerm = state => getImmutableOrJS(state, ['search', 'term']);
|
|
315
|
+
const getSearchTabs = (state, returnType) => getImmutableOrJS(state, ['search', 'tabs'], [], returnType);
|
|
285
316
|
const getQueryParams = (state, current = '', context = Context.facets) => {
|
|
286
|
-
return state
|
|
317
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'queryParams'], {}, 'js');
|
|
287
318
|
};
|
|
288
319
|
const getQueryParameter = ({
|
|
289
320
|
state,
|
|
290
321
|
facet,
|
|
291
322
|
context = Context.facets
|
|
292
323
|
}, key, ifnull = null) => {
|
|
293
|
-
return getQueryParams(state, facet, context)
|
|
324
|
+
return getImmutableOrJS(getQueryParams(state, facet, context), key, ifnull, 'js');
|
|
294
325
|
};
|
|
295
|
-
const getCustomApi = (state, current, context = Context.facets) => {
|
|
296
|
-
return state
|
|
326
|
+
const getCustomApi = (state, current, context = Context.facets, returnType) => {
|
|
327
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'customApi'], null, returnType);
|
|
297
328
|
};
|
|
298
329
|
const getCustomEnv = (state, current, context = Context.facets) => {
|
|
299
|
-
return state
|
|
330
|
+
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'env']);
|
|
300
331
|
};
|
|
301
|
-
const getTabsAndFacets = state => {
|
|
302
|
-
const tabs = getSearchTabs(state);
|
|
303
|
-
const facets = getFacets(state);
|
|
304
|
-
|
|
305
|
-
const fieldsToCount = tab.
|
|
332
|
+
const getTabsAndFacets = (state, returnType) => {
|
|
333
|
+
const tabs = getSearchTabs(state, 'js');
|
|
334
|
+
const facets = getFacets(state, 'js');
|
|
335
|
+
const tabsAndFacets = (tabs || []).map((tab = {}) => {
|
|
336
|
+
const fieldsToCount = tab.totalCount;
|
|
306
337
|
let countFields;
|
|
307
|
-
if (typeof fieldsToCount === 'string') countFields =
|
|
308
|
-
const thisTabFacets = facets.filter((
|
|
309
|
-
const thisTabTotal = thisTabFacets.map((facet =
|
|
310
|
-
if (!countFields || countFields.find((f =
|
|
338
|
+
if (typeof fieldsToCount === 'string') countFields = [[fieldsToCount]];
|
|
339
|
+
const thisTabFacets = Object.entries(facets).filter(([key]) => getImmutableOrJS(facets, [key, 'tabId'], 0) === tab.id);
|
|
340
|
+
const thisTabTotal = thisTabFacets.map(([facetName, facet = {}]) => {
|
|
341
|
+
if (!countFields || countFields.find((f = []) => (f === null || f === void 0 ? void 0 : f[0]) === facetName)) return getImmutableOrJS(facet, ['pagingInfo', 'totalCount']);
|
|
311
342
|
return 0;
|
|
312
343
|
}).reduce((a, b) => a + b, 0);
|
|
313
|
-
return tab
|
|
344
|
+
return { ...tab,
|
|
345
|
+
[Context.facets]: Object.fromEntries(thisTabFacets),
|
|
346
|
+
totalCount: thisTabTotal
|
|
347
|
+
};
|
|
314
348
|
});
|
|
349
|
+
const fromJS = makeFromJS(returnType);
|
|
350
|
+
return fromJS(tabsAndFacets);
|
|
315
351
|
};
|
|
316
352
|
const getSearchTotalCount = state => {
|
|
317
|
-
const tabsAndFacets = getTabsAndFacets(state);
|
|
318
|
-
const wholeSearchTotal = tabsAndFacets.map((t =
|
|
353
|
+
const tabsAndFacets = getTabsAndFacets(state, 'js');
|
|
354
|
+
const wholeSearchTotal = tabsAndFacets.map((t = {}) => t.totalCount).reduce((a, b) => a + b, 0);
|
|
319
355
|
return wholeSearchTotal;
|
|
320
356
|
};
|
|
321
357
|
const getFacetsTotalCount = state => {
|
|
322
358
|
const facets = getFacets(state);
|
|
323
|
-
const wholeSearchTotal = facets.map((t =
|
|
359
|
+
const wholeSearchTotal = Object.entries(facets).map(([, t = {}]) => {
|
|
360
|
+
var _t$pagingInfo;
|
|
361
|
+
|
|
362
|
+
return ((_t$pagingInfo = t.pagingInfo) === null || _t$pagingInfo === void 0 ? void 0 : _t$pagingInfo.totalCount) || 0;
|
|
363
|
+
}).reduce((a, b) => a + b, 0);
|
|
324
364
|
return wholeSearchTotal;
|
|
325
365
|
}; // An exported copy of the relevant selectors scoped by default to a facets context
|
|
326
366
|
|
|
@@ -389,8 +429,8 @@ const selectListing = {
|
|
|
389
429
|
getTotalCount: (state, listing = '') => getTotalCount(state, listing, Context.listings),
|
|
390
430
|
getSelectedFilters: (state, listing = '') => getSelectedFilters(state, listing, Context.listings)
|
|
391
431
|
};
|
|
392
|
-
const selectCurrentPath = state => state
|
|
393
|
-
const selectVersionStatus = state => state
|
|
432
|
+
const selectCurrentPath = state => getImmutableOrJS(state, ['routing', 'currentPath']);
|
|
433
|
+
const selectVersionStatus = state => getImmutableOrJS(state, ['version', 'contensisVersionStatus']);
|
|
394
434
|
|
|
395
435
|
var selectors = /*#__PURE__*/Object.freeze({
|
|
396
436
|
__proto__: null,
|
|
@@ -420,8 +460,6 @@ var selectors = /*#__PURE__*/Object.freeze({
|
|
|
420
460
|
getPageIsLoading: getPageIsLoading,
|
|
421
461
|
getPagesLoaded: getPagesLoaded,
|
|
422
462
|
getTotalCount: getTotalCount,
|
|
423
|
-
getFacetAuthentication: getFacetAuthentication,
|
|
424
|
-
getFeaturedEntryIds: getFeaturedEntryIds,
|
|
425
463
|
getSearchTerm: getSearchTerm,
|
|
426
464
|
getSearchTabs: getSearchTabs,
|
|
427
465
|
getQueryParams: getQueryParams,
|
|
@@ -437,6 +475,8 @@ var selectors = /*#__PURE__*/Object.freeze({
|
|
|
437
475
|
selectVersionStatus: selectVersionStatus
|
|
438
476
|
});
|
|
439
477
|
|
|
478
|
+
// eslint-disable-next-line import/default
|
|
479
|
+
|
|
440
480
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
441
481
|
const withSearch = mappers => SearchComponent => {
|
|
442
482
|
const Wrapper = props => {
|
|
@@ -702,6 +742,7 @@ const now = () => {
|
|
|
702
742
|
return window.performance.now();
|
|
703
743
|
};
|
|
704
744
|
|
|
745
|
+
// eslint-disable-next-line import/default
|
|
705
746
|
function fixFreeTextForElastic(s) {
|
|
706
747
|
const illegalChars = ['>', '<', '=', '|', '!', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', '/'];
|
|
707
748
|
const illegalRegEx = new RegExp(illegalChars.map(c => '\\' + c).join('|'), 'g');
|
|
@@ -729,6 +770,7 @@ const getItemsFromResult = result => {
|
|
|
729
770
|
if (payload) {
|
|
730
771
|
if (Array.isArray(payload)) return payload;
|
|
731
772
|
if (Array.isArray(payload.items)) return payload.items;
|
|
773
|
+
return payload;
|
|
732
774
|
}
|
|
733
775
|
|
|
734
776
|
return [];
|
|
@@ -743,7 +785,7 @@ const buildUrl = (route, params) => {
|
|
|
743
785
|
return path;
|
|
744
786
|
};
|
|
745
787
|
const callCustomApi = async (customApi, filters) => {
|
|
746
|
-
const apiUri = customApi.
|
|
788
|
+
const apiUri = customApi.uri || '';
|
|
747
789
|
let uri = buildUrl(apiUri, filters);
|
|
748
790
|
if (!uri) throw new Error('uri is required to use customApi');
|
|
749
791
|
if (typeof window == 'undefined' && uri.startsWith('/')) uri = `http://localhost:3001${uri}`;
|
|
@@ -1127,19 +1169,21 @@ const searchUriTemplate = {
|
|
|
1127
1169
|
const searchContext = getSearchContext(state); // Lose stateFilters and currentSearch if a new
|
|
1128
1170
|
// term is passed via an argument
|
|
1129
1171
|
|
|
1130
|
-
const stateFilters = term ?
|
|
1131
|
-
const currentSearch = !term && state
|
|
1172
|
+
const stateFilters = term ? {} : Object.fromEntries(Object.entries(getSelectedFilters(state, facet, searchContext, 'js')).map(([key, f]) => [key, f === null || f === void 0 ? void 0 : f.join(',')]));
|
|
1173
|
+
const currentSearch = !term && getImmutableOrJS(state, ['routing', 'location', 'search']);
|
|
1132
1174
|
const currentQs = removeEmptyAttributes(queryString__default['default'].parse(currentSearch));
|
|
1133
1175
|
if (orderBy) currentQs.orderBy = orderBy;
|
|
1134
1176
|
const searchTerm = getSearchTerm(state); // Use Immutable's merge to merge the stateFilters with any current Qs
|
|
1135
1177
|
// to build the new Qs.
|
|
1136
1178
|
|
|
1137
|
-
const mergedSearch = removeEmptyAttributes(
|
|
1179
|
+
const mergedSearch = removeEmptyAttributes({ ...merge__default['default'](currentQs, stateFilters),
|
|
1180
|
+
term: searchTerm
|
|
1181
|
+
});
|
|
1138
1182
|
return queryString__default['default'].stringify(mergedSearch);
|
|
1139
1183
|
},
|
|
1140
1184
|
hash: {
|
|
1141
1185
|
$path: 'state',
|
|
1142
|
-
$formatting: state => state
|
|
1186
|
+
$formatting: state => getImmutableOrJS(state, ['routing', 'location', 'hash'], '').replace('#', '')
|
|
1143
1187
|
}
|
|
1144
1188
|
};
|
|
1145
1189
|
|
|
@@ -1196,9 +1240,13 @@ const facetTemplate = {
|
|
|
1196
1240
|
pageIndex,
|
|
1197
1241
|
pagesLoaded
|
|
1198
1242
|
}) => {
|
|
1199
|
-
const loaded =
|
|
1200
|
-
|
|
1201
|
-
|
|
1243
|
+
const loaded = [...(pagesLoaded || [])];
|
|
1244
|
+
|
|
1245
|
+
if (isNaN(loaded.find(l => l === pageIndex))) {
|
|
1246
|
+
loaded.push(pageIndex);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
return loaded.sort((a, b) => a - b);
|
|
1202
1250
|
}
|
|
1203
1251
|
},
|
|
1204
1252
|
prevPageIndex: 'action.queryParams.prevPageIndex'
|
|
@@ -1227,14 +1275,14 @@ const facetTemplate = {
|
|
|
1227
1275
|
_pagePosition: idx,
|
|
1228
1276
|
...r
|
|
1229
1277
|
}));
|
|
1230
|
-
const loadedPages =
|
|
1278
|
+
const loadedPages = pagesLoaded || []; // if pageIndex is found in loadedPages, we have already loaded this page
|
|
1231
1279
|
|
|
1232
1280
|
if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults; // Determine where we put the results depending on if we
|
|
1233
1281
|
// are paging forwards, backwards, or doing a new search
|
|
1234
1282
|
|
|
1235
1283
|
const firstResultSet = pageIndex > prevPageIndex ? prevResults || [] : nextResults;
|
|
1236
1284
|
const secondResultSet = pageIndex > prevPageIndex ? nextResults : prevResults || [];
|
|
1237
|
-
const onlyResultSet = loadedPages.
|
|
1285
|
+
const onlyResultSet = loadedPages.length === 0 ? nextResults : false;
|
|
1238
1286
|
return onlyResultSet || [...firstResultSet, ...secondResultSet];
|
|
1239
1287
|
}
|
|
1240
1288
|
},
|
|
@@ -1318,10 +1366,10 @@ const mapFiltersToFilterExpression = (filters, selectedFilters) => {
|
|
|
1318
1366
|
};
|
|
1319
1367
|
|
|
1320
1368
|
const queryParamsTemplate = {
|
|
1321
|
-
assetTypes: root => getQueryParameter(root, 'assetTypes',
|
|
1322
|
-
contentTypeIds: root => getQueryParameter(root, 'contentTypeIds',
|
|
1323
|
-
customWhere: root => getQueryParameter(root, 'customWhere',
|
|
1324
|
-
dynamicOrderBy: root => getQueryParameter(root, 'dynamicOrderBy',
|
|
1369
|
+
assetTypes: root => getQueryParameter(root, 'assetTypes', []),
|
|
1370
|
+
contentTypeIds: root => getQueryParameter(root, 'contentTypeIds', []),
|
|
1371
|
+
customWhere: root => getQueryParameter(root, 'customWhere', []),
|
|
1372
|
+
dynamicOrderBy: root => getQueryParameter(root, 'dynamicOrderBy', []),
|
|
1325
1373
|
env: ({
|
|
1326
1374
|
state,
|
|
1327
1375
|
facet,
|
|
@@ -1337,19 +1385,19 @@ const queryParamsTemplate = {
|
|
|
1337
1385
|
return null;
|
|
1338
1386
|
},
|
|
1339
1387
|
featuredResults: root => getQueryParameter(root, 'featuredResults', null),
|
|
1340
|
-
fields: root => getQueryParameter(root, 'fields',
|
|
1388
|
+
fields: root => getQueryParameter(root, 'fields', []),
|
|
1341
1389
|
filters: ({
|
|
1342
1390
|
state,
|
|
1343
1391
|
facet,
|
|
1344
1392
|
context
|
|
1345
1393
|
}) => {
|
|
1346
|
-
const stateFilters = getFilters(state, facet, context)
|
|
1347
|
-
const selectedFilters = getSelectedFilters(state, facet, context)
|
|
1394
|
+
const stateFilters = getFilters(state, facet, context, 'js');
|
|
1395
|
+
const selectedFilters = getSelectedFilters(state, facet, context, 'js'); // Use another mapping function to map the filter parameters for the query
|
|
1348
1396
|
|
|
1349
1397
|
const filterParams = mapFiltersToFilterExpression(stateFilters, selectedFilters);
|
|
1350
1398
|
return filterParams;
|
|
1351
1399
|
},
|
|
1352
|
-
includeInSearchFields: root => getQueryParameter(root, 'includeInSearch',
|
|
1400
|
+
includeInSearchFields: root => getQueryParameter(root, 'includeInSearch', []),
|
|
1353
1401
|
internalPageIndex: ({
|
|
1354
1402
|
action,
|
|
1355
1403
|
state
|
|
@@ -1360,7 +1408,7 @@ const queryParamsTemplate = {
|
|
|
1360
1408
|
}) => action.defaultLang ? [action.defaultLang] : [],
|
|
1361
1409
|
linkDepth: root => getQueryParameter(root, 'linkDepth', 0),
|
|
1362
1410
|
loadMorePaging: root => getQueryParameter(root, 'loadMorePaging', false),
|
|
1363
|
-
orderBy: root => getQueryParameter(root, 'orderBy',
|
|
1411
|
+
orderBy: root => getQueryParameter(root, 'orderBy', []),
|
|
1364
1412
|
pageIndex: root => {
|
|
1365
1413
|
const {
|
|
1366
1414
|
action,
|
|
@@ -1385,31 +1433,35 @@ const queryParamsTemplate = {
|
|
|
1385
1433
|
state,
|
|
1386
1434
|
facet,
|
|
1387
1435
|
context
|
|
1388
|
-
}) =>
|
|
1436
|
+
}) => {
|
|
1437
|
+
var _getFacet;
|
|
1438
|
+
|
|
1439
|
+
return (_getFacet = getFacet(state, facet, context)) === null || _getFacet === void 0 ? void 0 : _getFacet.projectId;
|
|
1440
|
+
},
|
|
1389
1441
|
searchTerm: root => root.context !== Context.minilist || getQueryParameter(root, 'useSearchTerm', false) ? getSearchTerm(root.state) : '',
|
|
1390
1442
|
selectedFilters: ({
|
|
1391
1443
|
state,
|
|
1392
1444
|
facet,
|
|
1393
1445
|
context
|
|
1394
|
-
}) => getSelectedFilters(state, facet, context).map(f => f === null || f === void 0 ? void 0 : f.join(',')),
|
|
1446
|
+
}) => Object.fromEntries(Object.entries(getSelectedFilters(state, facet, context, 'js')).map(([key, f]) => [key, f === null || f === void 0 ? void 0 : f.join(',')])),
|
|
1395
1447
|
versionStatus: ({
|
|
1396
1448
|
state
|
|
1397
1449
|
}) => selectVersionStatus(state),
|
|
1398
1450
|
weightedSearchFields: root => {
|
|
1399
|
-
const wsf = getQueryParameter(root, 'weightedSearchFields',
|
|
1400
|
-
const deduped = wsf.
|
|
1451
|
+
const wsf = getQueryParameter(root, 'weightedSearchFields', []);
|
|
1452
|
+
const deduped = wsf.filter((v, i, a) => a.findIndex(t => t.fieldId === v.fieldId) === i);
|
|
1401
1453
|
return deduped; // return wsf;
|
|
1402
1454
|
},
|
|
1403
|
-
webpageTemplates: root => getQueryParameter(root, 'webpageTemplates',
|
|
1455
|
+
webpageTemplates: root => getQueryParameter(root, 'webpageTemplates', [])
|
|
1404
1456
|
};
|
|
1405
1457
|
|
|
1406
|
-
const mapStateToQueryParams = sourceJson =>
|
|
1458
|
+
const mapStateToQueryParams = sourceJson => mapJson__default['default'](sourceJson, queryParamsTemplate);
|
|
1407
1459
|
|
|
1408
1460
|
/**
|
|
1409
1461
|
* 1, Generates all the parameters required to run the search query.
|
|
1410
1462
|
* 2, Tells us if we should run the search.
|
|
1411
1463
|
* @param {object} action
|
|
1412
|
-
* @param {
|
|
1464
|
+
* @param {AppState} state
|
|
1413
1465
|
* @returns [queryParams, runSearch]
|
|
1414
1466
|
*/
|
|
1415
1467
|
const generateQueryParams = (action, state) => {
|
|
@@ -1444,7 +1496,8 @@ const runSearch = (action, state, queryParams) => {
|
|
|
1444
1496
|
} = action;
|
|
1445
1497
|
let willRun = false;
|
|
1446
1498
|
const facetIsLoaded = defaultLang ? false : getIsLoaded(state, context, facet);
|
|
1447
|
-
const stateParams = getQueryParams(ogState, facet, context)
|
|
1499
|
+
const stateParams = { ...getQueryParams(ogState, facet, context)
|
|
1500
|
+
};
|
|
1448
1501
|
stateParams.pageIndex = getPageIndex(ogState, facet, context);
|
|
1449
1502
|
stateParams.searchTerm = getSearchTerm(ogState);
|
|
1450
1503
|
|
|
@@ -1485,7 +1538,7 @@ const filterParamsChanged = (action, state) => {
|
|
|
1485
1538
|
params,
|
|
1486
1539
|
ogState = state
|
|
1487
1540
|
} = action;
|
|
1488
|
-
const selectedFilters = getSelectedFilters(ogState, facet, context)
|
|
1541
|
+
const selectedFilters = getSelectedFilters(ogState, facet, context);
|
|
1489
1542
|
const paramsChanged = Object.entries(selectedFilters).map(([filterKey, selectedValues]) => {
|
|
1490
1543
|
const inboundValues = params && params[filterKey] && params[filterKey].split(',') || [];
|
|
1491
1544
|
if (!areArraysEqualSets(selectedValues, inboundValues)) return true;
|
|
@@ -1497,11 +1550,11 @@ const filterParamsChanged = (action, state) => {
|
|
|
1497
1550
|
const debugExecuteSearch = (action, state) => {
|
|
1498
1551
|
const [queryParams, runSearch] = generateQueryParams(action, state);
|
|
1499
1552
|
console.log('runSearch', runSearch, 'action', action, 'filterParamsChanged', filterParamsChanged(action, state), 'getIsLoaded(state, context, facet)', getIsLoaded(state, action.context, action.facet));
|
|
1500
|
-
const stateParams = getQueryParams(action.ogState || state, action.facet, action.context)
|
|
1553
|
+
const stateParams = getQueryParams(action.ogState || state, action.facet, action.context);
|
|
1501
1554
|
stateParams.pageIndex = getPageIndex(action.ogState || state, action.facet, action.context);
|
|
1502
1555
|
stateParams.searchTerm = getSearchTerm(action.ogState || state);
|
|
1503
1556
|
console.log(stateParams, queryParams);
|
|
1504
|
-
console.log('getSelectedFilters', getSelectedFilters(action.ogState || state, action.facet, action.context)
|
|
1557
|
+
console.log('getSelectedFilters', getSelectedFilters(action.ogState || state, action.facet, action.context), 'params', action.params);
|
|
1505
1558
|
};
|
|
1506
1559
|
|
|
1507
1560
|
// Base mapping, fields that are the same across all mappings
|
|
@@ -1530,6 +1583,9 @@ const mapEntriesToFilterItems = entries => {
|
|
|
1530
1583
|
};
|
|
1531
1584
|
|
|
1532
1585
|
const searchSagas = [effects.takeEvery(CLEAR_FILTERS, clearFilters$1), effects.takeEvery(DO_SEARCH, doSearch), effects.takeEvery(SET_ROUTE_FILTERS, loadFilters), effects.takeEvery(SET_SEARCH_ENTRIES, preloadOtherFacets), effects.takeEvery(UPDATE_CURRENT_FACET, updateCurrentFacet$1), effects.takeEvery(UPDATE_CURRENT_TAB, updateCurrentTab$1), effects.takeEvery(UPDATE_PAGE_INDEX, updatePageIndex$1), effects.takeEvery(UPDATE_SEARCH_TERM, updateSearchTerm$1), effects.takeEvery(UPDATE_SORT_ORDER, updateSortOrder$1), effects.takeEvery(UPDATE_SELECTED_FILTERS, applySearchFilter)];
|
|
1586
|
+
|
|
1587
|
+
const toJS$1 = obj => obj && 'toJS' in obj && typeof obj.toJS === 'function' ? obj.toJS() : obj;
|
|
1588
|
+
|
|
1533
1589
|
function* setRouteFilters(action) {
|
|
1534
1590
|
const {
|
|
1535
1591
|
mappers,
|
|
@@ -1539,14 +1595,16 @@ function* setRouteFilters(action) {
|
|
|
1539
1595
|
debug
|
|
1540
1596
|
} = action;
|
|
1541
1597
|
const context = listingType ? Context.listings : Context.facets;
|
|
1542
|
-
const state = yield effects.select();
|
|
1598
|
+
const state = toJS$1(yield effects.select());
|
|
1543
1599
|
const ssr = getIsSsr(state); // Get current facet from params or state
|
|
1544
1600
|
|
|
1545
1601
|
let currentFacet = params && params.facet || listingType; // Pick the default facet from initialState
|
|
1546
1602
|
|
|
1547
1603
|
if (!currentFacet) {
|
|
1548
|
-
|
|
1549
|
-
|
|
1604
|
+
var _Object$keys;
|
|
1605
|
+
|
|
1606
|
+
const tabs = getSearchTabs(state, 'js');
|
|
1607
|
+
currentFacet = (tabs === null || tabs === void 0 ? void 0 : tabs[0].defaultFacet) || ((_Object$keys = Object.keys(getFacets(state, 'js'))) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0]) || '';
|
|
1550
1608
|
}
|
|
1551
1609
|
|
|
1552
1610
|
const nextAction = {
|
|
@@ -1567,7 +1625,7 @@ function* setRouteFilters(action) {
|
|
|
1567
1625
|
});
|
|
1568
1626
|
}
|
|
1569
1627
|
function* doSearch(action) {
|
|
1570
|
-
const state = yield effects.select();
|
|
1628
|
+
const state = toJS$1(yield effects.select());
|
|
1571
1629
|
|
|
1572
1630
|
if (action.config) {
|
|
1573
1631
|
// If the action contains a config object, we can add this to the
|
|
@@ -1593,30 +1651,30 @@ function* loadFilters(action) {
|
|
|
1593
1651
|
context,
|
|
1594
1652
|
mappers = {}
|
|
1595
1653
|
} = action;
|
|
1596
|
-
const filtersToLoad = yield effects.select(getFiltersToLoad, facetKey, context);
|
|
1654
|
+
const filtersToLoad = yield effects.select(getFiltersToLoad, facetKey, context, 'js');
|
|
1597
1655
|
|
|
1598
|
-
if (filtersToLoad.
|
|
1656
|
+
if (filtersToLoad.length > 0) {
|
|
1599
1657
|
yield effects.put({
|
|
1600
1658
|
type: LOAD_FILTERS,
|
|
1601
1659
|
filtersToLoad,
|
|
1602
1660
|
facetKey,
|
|
1603
1661
|
context
|
|
1604
1662
|
});
|
|
1605
|
-
const selectedKeys = yield effects.select(getSelectedFilters, facetKey, context);
|
|
1606
|
-
const facet = yield effects.select(getFacet, facetKey, context);
|
|
1607
|
-
const filters = facet.
|
|
1608
|
-
const projectId = facet.
|
|
1663
|
+
const selectedKeys = yield effects.select(getSelectedFilters, facetKey, context, 'js');
|
|
1664
|
+
const facet = yield effects.select(getFacet, facetKey, context, 'js');
|
|
1665
|
+
const filters = facet.filters || {};
|
|
1666
|
+
const projectId = facet.projectId;
|
|
1609
1667
|
const filtersToLoadSagas = filters && filtersToLoad.map((filterKey = '') => {
|
|
1610
1668
|
return effects.call(loadFilter, {
|
|
1611
1669
|
facetKey,
|
|
1612
1670
|
filterKey,
|
|
1613
|
-
filter: filters
|
|
1671
|
+
filter: filters[filterKey],
|
|
1614
1672
|
projectId,
|
|
1615
|
-
selectedKeys: selectedKeys
|
|
1673
|
+
selectedKeys: selectedKeys[filterKey],
|
|
1616
1674
|
context,
|
|
1617
1675
|
mapper: 'filterItems' in mappers && mappers.filterItems || mapEntriesToFilterItems
|
|
1618
1676
|
});
|
|
1619
|
-
})
|
|
1677
|
+
});
|
|
1620
1678
|
if (filtersToLoadSagas) yield effects.all(filtersToLoadSagas);
|
|
1621
1679
|
}
|
|
1622
1680
|
}
|
|
@@ -1635,7 +1693,7 @@ function* loadFilter(action) {
|
|
|
1635
1693
|
contentTypeId,
|
|
1636
1694
|
customWhere,
|
|
1637
1695
|
path
|
|
1638
|
-
} =
|
|
1696
|
+
} = filter;
|
|
1639
1697
|
const createStateFrom = {
|
|
1640
1698
|
type: LOAD_FILTERS_COMPLETE,
|
|
1641
1699
|
context,
|
|
@@ -1701,6 +1759,7 @@ function* ensureSearch(action) {
|
|
|
1701
1759
|
});
|
|
1702
1760
|
}
|
|
1703
1761
|
} catch (error) {
|
|
1762
|
+
// eslint-disable-next-line import/namespace
|
|
1704
1763
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1705
1764
|
}
|
|
1706
1765
|
}
|
|
@@ -1718,7 +1777,7 @@ function* executeSearch(action) {
|
|
|
1718
1777
|
let result = {};
|
|
1719
1778
|
let featuredResult;
|
|
1720
1779
|
let featuredQuery;
|
|
1721
|
-
const customApi = getCustomApi(state, facet, context);
|
|
1780
|
+
const customApi = getCustomApi(state, facet, context, 'js');
|
|
1722
1781
|
|
|
1723
1782
|
if (customApi) {
|
|
1724
1783
|
const apiParams = typeof mappers === 'object' && typeof mappers.customApi === 'function' && mappers.customApi(queryParams) || {};
|
|
@@ -1744,13 +1803,14 @@ function* executeSearch(action) {
|
|
|
1744
1803
|
action,
|
|
1745
1804
|
featuredResult,
|
|
1746
1805
|
pageIndex: queryParams.internalPaging && queryParams.internalPageIndex || queryParams.pageIndex,
|
|
1747
|
-
prevResults: getResults(state, facet, action.context),
|
|
1806
|
+
prevResults: getResults(state, facet, action.context, 'js'),
|
|
1748
1807
|
result,
|
|
1749
1808
|
state
|
|
1750
1809
|
};
|
|
1751
1810
|
const nextAction = mapJson__default['default'](createStateFrom, facetTemplate);
|
|
1752
1811
|
yield effects.put(nextAction);
|
|
1753
1812
|
} catch (error) {
|
|
1813
|
+
// eslint-disable-next-line import/namespace
|
|
1754
1814
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1755
1815
|
}
|
|
1756
1816
|
}
|
|
@@ -1766,7 +1826,7 @@ function* preloadOtherFacets(action) {
|
|
|
1766
1826
|
const currentFacet = getCurrentFacet(state);
|
|
1767
1827
|
|
|
1768
1828
|
if (!preload && facet === currentFacet && context !== Context.listings) {
|
|
1769
|
-
const allFacets = getFacets(state)
|
|
1829
|
+
const allFacets = getFacets(state, 'js');
|
|
1770
1830
|
const otherFacets = Object.keys(allFacets).filter(f => f !== currentFacet);
|
|
1771
1831
|
yield effects.all(otherFacets.map((preloadFacet = '') => {
|
|
1772
1832
|
const preloadAction = { ...action,
|
|
@@ -1791,19 +1851,19 @@ function* updateCurrentTab$1(action) {
|
|
|
1791
1851
|
mappers
|
|
1792
1852
|
} = action;
|
|
1793
1853
|
const state = yield effects.select();
|
|
1794
|
-
const facets = getFacets(state);
|
|
1795
|
-
const tabs = getSearchTabs(state);
|
|
1796
|
-
let nextFacet = tabs
|
|
1854
|
+
const facets = getFacets(state, 'js');
|
|
1855
|
+
const tabs = getSearchTabs(state, 'js');
|
|
1856
|
+
let nextFacet = tabs === null || tabs === void 0 ? void 0 : tabs[id].currentFacet;
|
|
1797
1857
|
|
|
1798
1858
|
if (!nextFacet) {
|
|
1799
|
-
facets.map((
|
|
1800
|
-
if (facet.
|
|
1859
|
+
Object.entries(facets).map(([facetName, facet]) => {
|
|
1860
|
+
if (facet.tabId === id && (tabs === null || tabs === void 0 ? void 0 : tabs[id].defaultFacet) === facetName) nextFacet = facetName;
|
|
1801
1861
|
});
|
|
1802
1862
|
} // If the next Tab does not have a defaultFacet,
|
|
1803
1863
|
// take the first facet for that tab
|
|
1804
1864
|
|
|
1805
1865
|
|
|
1806
|
-
if (!nextFacet) nextFacet = facets.filter((f
|
|
1866
|
+
if (!nextFacet) nextFacet = Object.entries(facets).filter(([, f]) => f.tabId === id)[0][0];
|
|
1807
1867
|
yield effects.put(withMappers(updateCurrentFacet(nextFacet), mappers));
|
|
1808
1868
|
}
|
|
1809
1869
|
|
|
@@ -1890,6 +1950,15 @@ function* buildUri({
|
|
|
1890
1950
|
return `${uri.path}${uri.search && `?${uri.search}` || ''}${uri.hash && `#${uri.hash}` || ''}`;
|
|
1891
1951
|
}
|
|
1892
1952
|
|
|
1953
|
+
const makeSelectMinilistProps = () => reselect.createSelector(state => state, (_, id) => id, (state, id) => ({
|
|
1954
|
+
facet: getFacet(state, id, Context.minilist, 'js'),
|
|
1955
|
+
filters: getFilters(state, id, Context.minilist, 'js'),
|
|
1956
|
+
isLoading: getIsLoading(state, Context.minilist, id),
|
|
1957
|
+
pagingInfo: getPaging(state, id, Context.minilist, 'js'),
|
|
1958
|
+
results: getResults(state, id, Context.minilist, 'js'),
|
|
1959
|
+
searchTerm: getSearchTerm(state)
|
|
1960
|
+
}));
|
|
1961
|
+
|
|
1893
1962
|
const useMinilist = ({
|
|
1894
1963
|
id,
|
|
1895
1964
|
config,
|
|
@@ -1903,6 +1972,7 @@ const useMinilist = ({
|
|
|
1903
1972
|
id: ''
|
|
1904
1973
|
}) => {
|
|
1905
1974
|
const dispatch = reactRedux.useDispatch();
|
|
1975
|
+
const selectMinilistProps = React.useMemo(makeSelectMinilistProps, [id]);
|
|
1906
1976
|
const {
|
|
1907
1977
|
facet,
|
|
1908
1978
|
filters,
|
|
@@ -1910,14 +1980,15 @@ const useMinilist = ({
|
|
|
1910
1980
|
pagingInfo,
|
|
1911
1981
|
results,
|
|
1912
1982
|
searchTerm
|
|
1913
|
-
} = reactRedux.useSelector(state => ({
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
}));
|
|
1983
|
+
} = reactRedux.useSelector(state => selectMinilistProps(state, id)); // useSelector((state: AppState) => ({
|
|
1984
|
+
// facet: getFacet(state, id, Context.minilist).toJS(),
|
|
1985
|
+
// filters: getFilters(state, id, Context.minilist).toJS(),
|
|
1986
|
+
// isLoading: getIsLoading(state, Context.minilist, id),
|
|
1987
|
+
// pagingInfo: getPaging(state, id, Context.minilist).toJS(),
|
|
1988
|
+
// results: getResults(state, id, Context.minilist).toJS(),
|
|
1989
|
+
// searchTerm: getSearchTerm(state),
|
|
1990
|
+
// }));
|
|
1991
|
+
|
|
1921
1992
|
React.useEffect(() => {
|
|
1922
1993
|
if (id && (mapper || mappers && mappers.results)) {
|
|
1923
1994
|
dispatch(triggerSearch({
|
|
@@ -1943,68 +2014,72 @@ const useMinilist = ({
|
|
|
1943
2014
|
};
|
|
1944
2015
|
};
|
|
1945
2016
|
|
|
1946
|
-
const entries =
|
|
2017
|
+
const entries = {
|
|
1947
2018
|
isLoading: false,
|
|
1948
2019
|
isError: false,
|
|
1949
|
-
items:
|
|
1950
|
-
}
|
|
1951
|
-
const pagingInfo =
|
|
2020
|
+
items: []
|
|
2021
|
+
};
|
|
2022
|
+
const pagingInfo = {
|
|
1952
2023
|
isLoading: false,
|
|
1953
2024
|
pageCount: 0,
|
|
1954
2025
|
pageIndex: 0,
|
|
1955
2026
|
pageSize: 0,
|
|
1956
|
-
pagesLoaded:
|
|
2027
|
+
pagesLoaded: [],
|
|
1957
2028
|
prevPageIndex: 0,
|
|
1958
2029
|
totalCount: 0
|
|
1959
|
-
}
|
|
1960
|
-
const searchFacet =
|
|
2030
|
+
};
|
|
2031
|
+
const searchFacet = {
|
|
1961
2032
|
title: null,
|
|
1962
2033
|
featuredEntries: entries,
|
|
1963
|
-
featuredResults:
|
|
2034
|
+
featuredResults: [],
|
|
1964
2035
|
entries,
|
|
1965
|
-
results:
|
|
1966
|
-
queryParams:
|
|
1967
|
-
filters:
|
|
2036
|
+
results: [],
|
|
2037
|
+
queryParams: {},
|
|
2038
|
+
filters: {},
|
|
1968
2039
|
queryDuration: 0,
|
|
1969
2040
|
pagingInfo,
|
|
1970
2041
|
projectId: ''
|
|
1971
|
-
}
|
|
1972
|
-
const searchTab =
|
|
2042
|
+
};
|
|
2043
|
+
const searchTab = {
|
|
1973
2044
|
currentFacet: undefined,
|
|
1974
|
-
facets:
|
|
2045
|
+
facets: {},
|
|
1975
2046
|
id: 0,
|
|
1976
2047
|
label: undefined,
|
|
1977
2048
|
totalCount: ''
|
|
1978
|
-
}
|
|
1979
|
-
const filtering =
|
|
2049
|
+
};
|
|
2050
|
+
const filtering = {
|
|
1980
2051
|
isLoading: false,
|
|
1981
2052
|
isError: false,
|
|
1982
2053
|
isGrouped: false,
|
|
1983
2054
|
title: undefined,
|
|
1984
2055
|
contentTypeId: undefined,
|
|
1985
|
-
customWhere:
|
|
2056
|
+
customWhere: [],
|
|
1986
2057
|
fieldId: undefined,
|
|
1987
|
-
items:
|
|
1988
|
-
}
|
|
1989
|
-
const filterItem =
|
|
2058
|
+
items: []
|
|
2059
|
+
};
|
|
2060
|
+
const filterItem = {
|
|
1990
2061
|
key: '',
|
|
1991
2062
|
type: undefined,
|
|
1992
2063
|
title: undefined,
|
|
1993
2064
|
path: undefined,
|
|
1994
2065
|
isSelected: false
|
|
1995
|
-
}
|
|
1996
|
-
const config =
|
|
2066
|
+
};
|
|
2067
|
+
const config = {
|
|
1997
2068
|
isLoaded: false,
|
|
1998
2069
|
isError: false
|
|
1999
|
-
}
|
|
2070
|
+
};
|
|
2000
2071
|
const searchState = {
|
|
2072
|
+
context: 'facets',
|
|
2001
2073
|
currentFacet: '',
|
|
2074
|
+
currentListing: '',
|
|
2075
|
+
facets: {},
|
|
2076
|
+
listings: {},
|
|
2077
|
+
minilist: {},
|
|
2002
2078
|
term: '',
|
|
2003
|
-
|
|
2004
|
-
tabs: immutable.List(),
|
|
2079
|
+
tabs: [],
|
|
2005
2080
|
config
|
|
2006
2081
|
};
|
|
2007
|
-
const initialState =
|
|
2082
|
+
const initialState = searchState;
|
|
2008
2083
|
|
|
2009
2084
|
var schema = /*#__PURE__*/Object.freeze({
|
|
2010
2085
|
__proto__: null,
|
|
@@ -2017,8 +2092,6 @@ var schema = /*#__PURE__*/Object.freeze({
|
|
|
2017
2092
|
initialState: initialState
|
|
2018
2093
|
});
|
|
2019
2094
|
|
|
2020
|
-
// eslint-disable no-console
|
|
2021
|
-
|
|
2022
2095
|
const addConfigToState = (state, action) => {
|
|
2023
2096
|
const {
|
|
2024
2097
|
context,
|
|
@@ -2027,26 +2100,27 @@ const addConfigToState = (state, action) => {
|
|
|
2027
2100
|
} = action; // Adding or changing the config of a single facet, listing or minilist
|
|
2028
2101
|
|
|
2029
2102
|
if (context && facet && config) {
|
|
2030
|
-
|
|
2103
|
+
state[context][facet] = { ...searchFacet,
|
|
2104
|
+
...config
|
|
2105
|
+
};
|
|
2031
2106
|
} else if (config) {
|
|
2032
2107
|
// Changing the entire search config
|
|
2033
|
-
|
|
2034
|
-
return newState;
|
|
2108
|
+
state = config;
|
|
2035
2109
|
}
|
|
2036
2110
|
|
|
2037
2111
|
return state;
|
|
2038
2112
|
};
|
|
2039
2113
|
|
|
2040
2114
|
const generateSearchFacets = (context, config) => {
|
|
2041
|
-
|
|
2115
|
+
const facets = {};
|
|
2042
2116
|
|
|
2043
2117
|
if (config) {
|
|
2044
2118
|
const thisConfig = config[context] || {};
|
|
2045
2119
|
|
|
2046
2120
|
if (Object.keys(thisConfig).length > 0) {
|
|
2047
2121
|
Object.entries(thisConfig).map(([facetName, facet]) => {
|
|
2048
|
-
const newFacet = searchFacet
|
|
2049
|
-
if (!('isDisabled' in facet) || facet.isDisabled !== true) facets =
|
|
2122
|
+
const newFacet = merge__default['default'](searchFacet, facet);
|
|
2123
|
+
if (!('isDisabled' in facet) || facet.isDisabled !== true) facets[facetName] = newFacet;
|
|
2050
2124
|
});
|
|
2051
2125
|
}
|
|
2052
2126
|
}
|
|
@@ -2061,15 +2135,27 @@ const generateFiltersState = ({
|
|
|
2061
2135
|
isCurrentFacet
|
|
2062
2136
|
}, state) => {
|
|
2063
2137
|
// Remove filters we know about from params
|
|
2064
|
-
const filterParams =
|
|
2138
|
+
const filterParams = { ...params,
|
|
2065
2139
|
facet: undefined,
|
|
2066
2140
|
orderBy: undefined,
|
|
2067
2141
|
pageIndex: undefined,
|
|
2068
2142
|
term: undefined
|
|
2069
|
-
}
|
|
2143
|
+
}; // Get any existing filters and normalise the items[]
|
|
2070
2144
|
// so we can start off with isSelected is false
|
|
2071
2145
|
|
|
2072
|
-
let filters =
|
|
2146
|
+
let filters = Object.entries(state[context][facet].filters || []).map(([key, filter]) => {
|
|
2147
|
+
if (isCurrentFacet || filter.isGrouped) {
|
|
2148
|
+
var _filter$items;
|
|
2149
|
+
|
|
2150
|
+
return [key, { ...filter,
|
|
2151
|
+
items: (_filter$items = filter.items) === null || _filter$items === void 0 ? void 0 : _filter$items.map(item => ({ ...item,
|
|
2152
|
+
isSelected: false
|
|
2153
|
+
}))
|
|
2154
|
+
}];
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
return [key, filter];
|
|
2158
|
+
});
|
|
2073
2159
|
|
|
2074
2160
|
const addFilterItem = (filters, paramKey, paramValue) => // Iterate through all filters within the facet,
|
|
2075
2161
|
// if the paramKey matches the filter key
|
|
@@ -2077,14 +2163,25 @@ const generateFiltersState = ({
|
|
|
2077
2163
|
// already exists, if so set isSelected to true,
|
|
2078
2164
|
// if not create a new filterItem, setting the key only
|
|
2079
2165
|
// so we can match this key later on when we load the filters
|
|
2080
|
-
filters.map((
|
|
2081
|
-
if (paramKey !== key || !isCurrentFacet && !filter.
|
|
2082
|
-
return filter;
|
|
2166
|
+
filters.map(([key, filter]) => {
|
|
2167
|
+
if (paramKey !== key || !isCurrentFacet && !filter.isGrouped) {
|
|
2168
|
+
return [key, filter];
|
|
2083
2169
|
} else {
|
|
2084
|
-
const items = filter.
|
|
2085
|
-
const itemIndex = items.findIndex(item => (item === null || item === void 0 ? void 0 : item.
|
|
2086
|
-
|
|
2087
|
-
|
|
2170
|
+
const items = filter.items || [];
|
|
2171
|
+
const itemIndex = items.findIndex(item => (item === null || item === void 0 ? void 0 : item.key) === paramValue);
|
|
2172
|
+
|
|
2173
|
+
if (items.length > 0 && itemIndex !== -1) {
|
|
2174
|
+
items[itemIndex].isSelected = true;
|
|
2175
|
+
} else {
|
|
2176
|
+
items.push({ ...filterItem,
|
|
2177
|
+
key: paramValue,
|
|
2178
|
+
isSelected: true
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
return [key, { ...filter,
|
|
2183
|
+
items
|
|
2184
|
+
}];
|
|
2088
2185
|
}
|
|
2089
2186
|
}); // For each value found in filterParams
|
|
2090
2187
|
// we are looking to split that value into multiple by any comma
|
|
@@ -2094,44 +2191,66 @@ const generateFiltersState = ({
|
|
|
2094
2191
|
// the search results during SSR without needing to fetch the filters first
|
|
2095
2192
|
|
|
2096
2193
|
|
|
2097
|
-
filterParams.map((
|
|
2098
|
-
return filters;
|
|
2194
|
+
Object.entries(filterParams).map(([paramName = '', paramValue]) => typeof paramValue === 'string' && paramValue.split(',').map(pVal => filters = addFilterItem(filters, paramName, pVal)));
|
|
2195
|
+
return Object.fromEntries(filters);
|
|
2099
2196
|
};
|
|
2100
2197
|
|
|
2101
|
-
const resetFacets = (state, context) =>
|
|
2198
|
+
const resetFacets = (state, context) => Object.fromEntries(Object.entries(state[context]).map(([k, v]) => [k, resetFacet(v)]));
|
|
2102
2199
|
|
|
2103
|
-
const resetFacet = facet =>
|
|
2200
|
+
const resetFacet = facet => {
|
|
2201
|
+
facet.pagingInfo.pagesLoaded = [];
|
|
2202
|
+
facet.pagingInfo.pageIndex = 0;
|
|
2203
|
+
facet.queryDuration = 0;
|
|
2204
|
+
return facet;
|
|
2205
|
+
};
|
|
2104
2206
|
|
|
2105
2207
|
var reducers = (config => {
|
|
2106
2208
|
// Add facets from SearchConfig to initialState
|
|
2107
|
-
const initState = initialState
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2209
|
+
const initState = { ...initialState,
|
|
2210
|
+
tabs: config.tabs,
|
|
2211
|
+
facets: generateSearchFacets(Context.facets, config),
|
|
2212
|
+
listings: generateSearchFacets(Context.listings, config),
|
|
2213
|
+
minilist: generateSearchFacets(Context.minilist, config)
|
|
2214
|
+
};
|
|
2215
|
+
return immer.produce((state = initState, action) => {
|
|
2216
|
+
const context = state.context;
|
|
2217
|
+
const current = context !== 'listings' ? state.currentFacet : state.currentListing;
|
|
2111
2218
|
|
|
2112
2219
|
switch (action.type) {
|
|
2113
2220
|
case APPLY_CONFIG:
|
|
2114
2221
|
{
|
|
2115
|
-
|
|
2222
|
+
state = addConfigToState(state, action);
|
|
2223
|
+
return;
|
|
2116
2224
|
}
|
|
2117
2225
|
|
|
2118
2226
|
case CLEAR_FILTERS:
|
|
2119
2227
|
{
|
|
2120
|
-
const currentFilters = state
|
|
2121
|
-
|
|
2122
|
-
const filterItems = filter
|
|
2123
|
-
|
|
2124
|
-
|
|
2228
|
+
const currentFilters = state[context][current].filters;
|
|
2229
|
+
state[context][current].filters = Object.fromEntries(Object.entries(currentFilters).map(([key, filter]) => {
|
|
2230
|
+
const filterItems = filter.items || [];
|
|
2231
|
+
filter.items = filterItems.map(item => ({ ...item,
|
|
2232
|
+
isSelected: false
|
|
2233
|
+
}));
|
|
2234
|
+
return [key, filter];
|
|
2235
|
+
}));
|
|
2236
|
+
state[context][current].queryDuration = 0;
|
|
2237
|
+
state[context][current].pagingInfo.pagesLoaded = [];
|
|
2238
|
+
return;
|
|
2125
2239
|
}
|
|
2126
2240
|
|
|
2127
2241
|
case EXECUTE_SEARCH:
|
|
2128
2242
|
{
|
|
2129
|
-
|
|
2243
|
+
state[action.context][action.facet].entries.isLoading = true;
|
|
2244
|
+
return;
|
|
2130
2245
|
}
|
|
2131
2246
|
|
|
2132
2247
|
case EXECUTE_SEARCH_ERROR:
|
|
2133
2248
|
{
|
|
2134
|
-
|
|
2249
|
+
state[action.context][action.facet].entries = { ...entries,
|
|
2250
|
+
isError: true,
|
|
2251
|
+
error: action.error
|
|
2252
|
+
};
|
|
2253
|
+
return;
|
|
2135
2254
|
}
|
|
2136
2255
|
|
|
2137
2256
|
case LOAD_FILTERS:
|
|
@@ -2140,8 +2259,20 @@ var reducers = (config => {
|
|
|
2140
2259
|
facetKey,
|
|
2141
2260
|
filtersToLoad
|
|
2142
2261
|
} = action;
|
|
2143
|
-
const filters = state
|
|
2144
|
-
|
|
2262
|
+
const filters = state[action.context][facetKey].filters;
|
|
2263
|
+
Object.entries(filters).map(([filterKey, filter]) => {
|
|
2264
|
+
if (filtersToLoad.find(f => f === filterKey)) return { ...filter,
|
|
2265
|
+
isLoading: true
|
|
2266
|
+
};
|
|
2267
|
+
return filter;
|
|
2268
|
+
});
|
|
2269
|
+
state[action.context][facetKey].filters = Object.fromEntries(Object.entries(filters).map(([filterKey, filter]) => {
|
|
2270
|
+
if (filtersToLoad.find(f => f === filterKey)) return [filterKey, { ...filter,
|
|
2271
|
+
isLoading: true
|
|
2272
|
+
}];
|
|
2273
|
+
return [filterKey, filter];
|
|
2274
|
+
}));
|
|
2275
|
+
return;
|
|
2145
2276
|
}
|
|
2146
2277
|
|
|
2147
2278
|
case LOAD_FILTERS_ERROR:
|
|
@@ -2152,10 +2283,21 @@ var reducers = (config => {
|
|
|
2152
2283
|
filterKey,
|
|
2153
2284
|
nextFilter
|
|
2154
2285
|
} = action;
|
|
2155
|
-
const filter = state
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2286
|
+
const filter = state[action.context][facetKey].filters[filterKey];
|
|
2287
|
+
|
|
2288
|
+
if (!(nextFilter.items && nextFilter.items.length > 0) && (filter.items || []).length >= nextFilter.items.length) {
|
|
2289
|
+
// Preserve items already in state
|
|
2290
|
+
state[action.context][facetKey].filters[filterKey] = { ...filter,
|
|
2291
|
+
isLoading: false,
|
|
2292
|
+
isError: nextFilter.isError
|
|
2293
|
+
};
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
state[action.context][facetKey].filters[filterKey] = merge__default['default'](filter, nextFilter, {
|
|
2298
|
+
arrayMerge: (source, inbound) => inbound
|
|
2299
|
+
});
|
|
2300
|
+
return;
|
|
2159
2301
|
}
|
|
2160
2302
|
|
|
2161
2303
|
case SET_ROUTE_FILTERS:
|
|
@@ -2170,8 +2312,8 @@ var reducers = (config => {
|
|
|
2170
2312
|
pageIndex,
|
|
2171
2313
|
orderBy
|
|
2172
2314
|
} = params;
|
|
2173
|
-
const stateTerm = state.
|
|
2174
|
-
const tabId = state
|
|
2315
|
+
const stateTerm = state.term;
|
|
2316
|
+
const tabId = state[context][facet].tabId || 0; // Reset the facet if the search term has changed, or if the any of
|
|
2175
2317
|
// the filters have changed
|
|
2176
2318
|
|
|
2177
2319
|
const resetAllFacets = stateTerm && term !== stateTerm;
|
|
@@ -2179,7 +2321,7 @@ var reducers = (config => {
|
|
|
2179
2321
|
// causing unfetched filter items to be generated with isSelected: true
|
|
2180
2322
|
// or existing filter items to be tagged with isSelected: true
|
|
2181
2323
|
|
|
2182
|
-
const nextFacets =
|
|
2324
|
+
const nextFacets = Object.fromEntries(Object.entries(state[context]).map(([facetName = '', stateFacet]) => {
|
|
2183
2325
|
const isCurrentFacet = facetName === facet;
|
|
2184
2326
|
const nextFilters = generateFiltersState({
|
|
2185
2327
|
facet: facetName,
|
|
@@ -2187,18 +2329,32 @@ var reducers = (config => {
|
|
|
2187
2329
|
context,
|
|
2188
2330
|
isCurrentFacet
|
|
2189
2331
|
}, state);
|
|
2190
|
-
resetCurrentFacet = state.
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2332
|
+
resetCurrentFacet = state.config.isLoaded === true && !equals__default['default'](nextFilters, stateFacet.filters);
|
|
2333
|
+
stateFacet = resetCurrentFacet ? resetFacet(stateFacet) : stateFacet;
|
|
2334
|
+
stateFacet.filters = nextFilters;
|
|
2335
|
+
stateFacet.queryParams.dynamicOrderBy = toArray(orderBy) || [];
|
|
2336
|
+
return [facetName, stateFacet];
|
|
2337
|
+
}));
|
|
2338
|
+
state.context = context;
|
|
2339
|
+
state[context] = nextFacets;
|
|
2340
|
+
state[action.context === Context.facets ? 'currentFacet' : 'currentListing'] = facet;
|
|
2341
|
+
state.term = term;
|
|
2342
|
+
state.tabs[tabId].currentFacet = facet;
|
|
2343
|
+
state[context][facet].pagingInfo.pageIndex = Number(pageIndex) - 1 || (state[context][facet].queryParams.loadMorePaging ? state[context][facet].pagingInfo.pageIndex || 0 : 0);
|
|
2344
|
+
state.config.isLoaded = true;
|
|
2345
|
+
state.config.ssr = typeof window === 'undefined';
|
|
2346
|
+
if (resetAllFacets) state[context] = resetFacets(state, context);
|
|
2347
|
+
return;
|
|
2195
2348
|
}
|
|
2196
2349
|
|
|
2197
2350
|
case SET_SEARCH_ENTRIES:
|
|
2198
2351
|
{
|
|
2199
2352
|
const thisContext = action.context || context;
|
|
2200
|
-
const currentFacet = state
|
|
2201
|
-
|
|
2353
|
+
const currentFacet = state[thisContext][action.facet];
|
|
2354
|
+
state[thisContext][action.facet] = merge__default['default'](currentFacet, action.nextFacet, {
|
|
2355
|
+
arrayMerge: (source, inbound) => inbound
|
|
2356
|
+
});
|
|
2357
|
+
return;
|
|
2202
2358
|
}
|
|
2203
2359
|
|
|
2204
2360
|
case SET_SEARCH_FILTERS:
|
|
@@ -2214,8 +2370,12 @@ var reducers = (config => {
|
|
|
2214
2370
|
isCurrentFacet: true
|
|
2215
2371
|
}, state);
|
|
2216
2372
|
const term = action === null || action === void 0 ? void 0 : (_action$params = action.params) === null || _action$params === void 0 ? void 0 : _action$params.term;
|
|
2217
|
-
const useSearchTerm = state
|
|
2218
|
-
|
|
2373
|
+
const useSearchTerm = state[action.context || Context.minilist][action.facet].queryParams.useSearchTerm || false;
|
|
2374
|
+
state[action.context || Context.minilist][action.facet].filters = filters;
|
|
2375
|
+
state[action.context || Context.minilist][action.facet].queryParams.excludeIds = action.excludeIds;
|
|
2376
|
+
state.term = useSearchTerm ? term : state.term;
|
|
2377
|
+
state.config.ssr = typeof window === 'undefined';
|
|
2378
|
+
return;
|
|
2219
2379
|
}
|
|
2220
2380
|
|
|
2221
2381
|
case UPDATE_PAGE_INDEX:
|
|
@@ -2223,16 +2383,21 @@ var reducers = (config => {
|
|
|
2223
2383
|
const {
|
|
2224
2384
|
pageIndex
|
|
2225
2385
|
} = action;
|
|
2226
|
-
const internalPaging = state
|
|
2227
|
-
const currentPageIndex = state
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2386
|
+
const internalPaging = state[context][current].queryParams.internalPaging || false;
|
|
2387
|
+
const currentPageIndex = state[context][current].pagingInfo.pageIndex || 0;
|
|
2388
|
+
state[context][current].pagingInfo.pageIndex = Number(pageIndex) || 0;
|
|
2389
|
+
state[context][current].pagingInfo.prevPageIndex = currentPageIndex;
|
|
2390
|
+
state[context][current].pagingInfo.isLoading = true;
|
|
2391
|
+
if (internalPaging) return;
|
|
2392
|
+
state[context][current].queryDuration = 0;
|
|
2393
|
+
return;
|
|
2231
2394
|
}
|
|
2232
2395
|
|
|
2233
2396
|
case UPDATE_SEARCH_TERM:
|
|
2234
2397
|
{
|
|
2235
|
-
|
|
2398
|
+
state.term = action.term;
|
|
2399
|
+
state[context] = resetFacets(state, context);
|
|
2400
|
+
return;
|
|
2236
2401
|
}
|
|
2237
2402
|
|
|
2238
2403
|
case UPDATE_SELECTED_FILTERS:
|
|
@@ -2241,16 +2406,24 @@ var reducers = (config => {
|
|
|
2241
2406
|
filter,
|
|
2242
2407
|
key
|
|
2243
2408
|
} = action;
|
|
2244
|
-
const isSingleSelect = state
|
|
2245
|
-
const isGrouped = state
|
|
2246
|
-
const currentItems = state
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2409
|
+
const isSingleSelect = state[context][current].filters[filter].isSingleSelect || false;
|
|
2410
|
+
const isGrouped = state[context][current].filters[filter].isGrouped || false;
|
|
2411
|
+
const currentItems = state[context][current].filters[filter].items;
|
|
2412
|
+
if (isGrouped) state[context] = resetFacets(state, context);
|
|
2413
|
+
state[context][current] = resetFacet(state[context][current]);
|
|
2414
|
+
state[context][current].filters[filter].items = currentItems === null || currentItems === void 0 ? void 0 : currentItems.map(item => {
|
|
2415
|
+
if (item.key === key) {
|
|
2416
|
+
return { ...item,
|
|
2417
|
+
isSelected: !item.isSelected
|
|
2418
|
+
};
|
|
2250
2419
|
}
|
|
2251
2420
|
|
|
2252
|
-
|
|
2253
|
-
|
|
2421
|
+
if (isSingleSelect) return { ...item,
|
|
2422
|
+
isSelected: false
|
|
2423
|
+
};
|
|
2424
|
+
return item;
|
|
2425
|
+
});
|
|
2426
|
+
return;
|
|
2254
2427
|
}
|
|
2255
2428
|
|
|
2256
2429
|
case UPDATE_SORT_ORDER:
|
|
@@ -2259,13 +2432,16 @@ var reducers = (config => {
|
|
|
2259
2432
|
orderBy,
|
|
2260
2433
|
facet
|
|
2261
2434
|
} = action;
|
|
2262
|
-
|
|
2435
|
+
state[context] = resetFacets(state, context);
|
|
2436
|
+
const currentFacet = facet || current;
|
|
2437
|
+
state[context][currentFacet].queryParams.dynamicOrderBy = orderBy ? toArray(orderBy) || [] : [];
|
|
2438
|
+
return;
|
|
2263
2439
|
}
|
|
2264
2440
|
|
|
2265
2441
|
default:
|
|
2266
|
-
return
|
|
2442
|
+
return;
|
|
2267
2443
|
}
|
|
2268
|
-
};
|
|
2444
|
+
}, initState);
|
|
2269
2445
|
});
|
|
2270
2446
|
|
|
2271
2447
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|