@zengenti/contensis-react-base 3.1.0 → 4.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/cjs/{App-7ff737fa.js → App-b56aca04.js} +139 -94
- package/cjs/{App-7ff737fa.js.map → App-b56aca04.js.map} +1 -1
- package/cjs/{ChangePassword.container-a617190b.js → ChangePassword.container-ae35785e.js} +120 -62
- package/{esm/ChangePassword.container-ae0f9ce4.js.map → cjs/ChangePassword.container-ae35785e.js.map} +1 -1
- package/cjs/{ContensisDeliveryApi-9e32960d.js → ContensisDeliveryApi-4fcf049d.js} +71 -17
- package/{esm/ContensisDeliveryApi-c66b0cc3.js.map → cjs/ContensisDeliveryApi-4fcf049d.js.map} +1 -1
- package/cjs/CookieConstants-000427db.js.map +1 -1
- package/cjs/RouteLoader-c06dccd5.js +321 -0
- package/cjs/RouteLoader-c06dccd5.js.map +1 -0
- package/cjs/{ToJs-149fc5e1.js → ToJs-a8d8f3f0.js} +14 -6
- package/cjs/{ToJs-149fc5e1.js.map → ToJs-a8d8f3f0.js.map} +1 -1
- package/cjs/client.js +52 -22
- package/cjs/client.js.map +1 -1
- package/cjs/contensis-react-base.js +277 -140
- package/cjs/contensis-react-base.js.map +1 -1
- package/cjs/forms.js +717 -228
- package/cjs/forms.js.map +1 -1
- package/cjs/{fromJSLeaveImmer-7c363211.js → fromJSLeaveImmer-e74c673c.js} +4 -1
- package/cjs/{fromJSLeaveImmer-7c363211.js.map → fromJSLeaveImmer-e74c673c.js.map} +1 -1
- package/cjs/{reducers-9afb5f89.js → reducers-73a03ef4.js} +31 -10
- package/cjs/{reducers-9afb5f89.js.map → reducers-73a03ef4.js.map} +1 -1
- package/cjs/redux.js +4 -5
- package/cjs/redux.js.map +1 -1
- package/cjs/routing.js +6 -5
- package/cjs/routing.js.map +1 -1
- package/cjs/{sagas-e04b94c1.js → sagas-570f23ba.js} +286 -187
- package/cjs/{sagas-e04b94c1.js.map → sagas-570f23ba.js.map} +1 -1
- package/cjs/search.js +82 -56
- package/cjs/search.js.map +1 -1
- package/cjs/{selectors-46b689d0.js → selectors-14caa813.js} +6 -1
- package/cjs/selectors-14caa813.js.map +1 -0
- package/cjs/urls-6fcaf4c6.js.map +1 -1
- package/cjs/user.js +9 -4
- package/cjs/user.js.map +1 -1
- package/cjs/util.js +55 -35
- package/cjs/util.js.map +1 -1
- package/cjs/{version-79a027cb.js → version-34d91f68.js} +60 -26
- package/cjs/version-34d91f68.js.map +1 -0
- package/cjs/{version-afd4f77e.js → version-a410c88e.js} +6 -3
- package/cjs/{version-afd4f77e.js.map → version-a410c88e.js.map} +1 -1
- package/esm/{App-ff944c78.js → App-83107d7e.js} +137 -92
- package/esm/{App-ff944c78.js.map → App-83107d7e.js.map} +1 -1
- package/esm/{ChangePassword.container-ae0f9ce4.js → ChangePassword.container-76fd5e9b.js} +120 -62
- package/{cjs/ChangePassword.container-a617190b.js.map → esm/ChangePassword.container-76fd5e9b.js.map} +1 -1
- package/esm/{ContensisDeliveryApi-c66b0cc3.js → ContensisDeliveryApi-fe57a037.js} +71 -17
- package/{cjs/ContensisDeliveryApi-9e32960d.js.map → esm/ContensisDeliveryApi-fe57a037.js.map} +1 -1
- package/esm/CookieConstants-3d3b6531.js.map +1 -1
- package/esm/RouteLoader-29fd689a.js +310 -0
- package/esm/RouteLoader-29fd689a.js.map +1 -0
- package/esm/{ToJs-ae860aad.js → ToJs-df57f31d.js} +14 -6
- package/esm/{ToJs-ae860aad.js.map → ToJs-df57f31d.js.map} +1 -1
- package/esm/client.js +52 -23
- package/esm/client.js.map +1 -1
- package/esm/contensis-react-base.js +272 -137
- package/esm/contensis-react-base.js.map +1 -1
- package/esm/forms.js +717 -228
- package/esm/forms.js.map +1 -1
- package/esm/{fromJSLeaveImmer-e2dacd63.js → fromJSLeaveImmer-0114ffcf.js} +4 -1
- package/esm/{fromJSLeaveImmer-e2dacd63.js.map → fromJSLeaveImmer-0114ffcf.js.map} +1 -1
- package/esm/{reducers-3d5c37d1.js → reducers-aa8cef1e.js} +31 -10
- package/esm/{reducers-3d5c37d1.js.map → reducers-aa8cef1e.js.map} +1 -1
- package/esm/redux.js +7 -8
- package/esm/redux.js.map +1 -1
- package/esm/routing.js +3 -5
- package/esm/routing.js.map +1 -1
- package/esm/{sagas-933a8fc8.js → sagas-07e82e18.js} +239 -139
- package/esm/{sagas-933a8fc8.js.map → sagas-07e82e18.js.map} +1 -1
- package/esm/search.js +83 -57
- package/esm/search.js.map +1 -1
- package/esm/{selectors-01074974.js → selectors-691caf02.js} +6 -1
- package/esm/selectors-691caf02.js.map +1 -0
- package/esm/urls-eac9a747.js.map +1 -1
- package/esm/user.js +11 -6
- package/esm/user.js.map +1 -1
- package/esm/util.js +55 -35
- package/esm/util.js.map +1 -1
- package/esm/{version-346a9787.js → version-3d9911e2.js} +60 -26
- package/esm/version-3d9911e2.js.map +1 -0
- package/esm/{version-0fbd1b82.js → version-9f29becb.js} +6 -3
- package/esm/{version-0fbd1b82.js.map → version-9f29becb.js.map} +1 -1
- package/models/app/App.d.ts +3 -3
- package/models/app/pages/VersionInfo/components/VersionInfo.d.ts +5 -3
- package/models/redux/appstate.d.ts +2 -3
- package/models/redux/store/history.d.ts +2 -2
- package/models/routing/components/Loading.d.ts +2 -2
- package/models/routing/components/NotFound.d.ts +2 -2
- package/models/routing/components/Redirect.d.ts +5 -0
- package/models/routing/components/StaticRouteLoader.d.ts +6 -0
- package/models/routing/components/Status.d.ts +1 -1
- package/models/routing/httpContext.d.ts +7 -0
- package/models/routing/index.d.ts +3 -0
- package/models/routing/redux/actions.d.ts +2 -3
- package/models/routing/routes.d.ts +11 -5
- package/models/user/components/Login.d.ts +2 -1
- package/models/user/components/LoginForm.d.ts +2 -1
- package/models/user/components/LogoutForm.d.ts +2 -1
- package/models/user/containers/ChangePassword.container.d.ts +1 -1
- package/models/user/containers/ForgotPassword.container.d.ts +1 -1
- package/models/user/containers/Login.container.d.ts +1 -1
- package/models/user/containers/Registration.container.d.ts +1 -1
- package/models/user/hocs/withLogin.d.ts +2 -1
- package/models/user/hocs/withRegistration.d.ts +1 -1
- package/models/util/ContensisDeliveryApi.d.ts +0 -1
- package/models/util/ToJs.d.ts +1 -1
- package/models/util/mergeStaticRoutes.d.ts +1 -0
- package/package.json +7 -10
- package/cjs/RouteLoader-049e81e5.js +0 -203
- package/cjs/RouteLoader-049e81e5.js.map +0 -1
- package/cjs/selectors-46b689d0.js.map +0 -1
- package/cjs/version-79a027cb.js.map +0 -1
- package/esm/RouteLoader-02eef6d9.js +0 -197
- package/esm/RouteLoader-02eef6d9.js.map +0 -1
- package/esm/selectors-01074974.js.map +0 -1
- package/esm/version-346a9787.js.map +0 -1
|
@@ -55,8 +55,7 @@ var types = /*#__PURE__*/Object.freeze({
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
const withMappers = (action, mappers) => {
|
|
58
|
-
return {
|
|
59
|
-
...action,
|
|
58
|
+
return { ...action,
|
|
60
59
|
mappers
|
|
61
60
|
};
|
|
62
61
|
};
|
|
@@ -176,33 +175,38 @@ var actions = /*#__PURE__*/Object.freeze({
|
|
|
176
175
|
updateSortOrder: updateSortOrder$1
|
|
177
176
|
});
|
|
178
177
|
|
|
179
|
-
let Context
|
|
178
|
+
let Context; // export type Context = 'facets' | 'listings' | 'minilist';
|
|
179
|
+
|
|
180
|
+
(function (Context) {
|
|
180
181
|
Context["facets"] = "facets";
|
|
181
182
|
Context["listings"] = "listings";
|
|
182
183
|
Context["minilist"] = "minilist";
|
|
183
|
-
|
|
184
|
-
}({});
|
|
185
|
-
// export type Context = 'facets' | 'listings' | 'minilist';
|
|
184
|
+
})(Context || (Context = {}));
|
|
186
185
|
|
|
187
|
-
// Find a fromJS function from global that is dynamically loaded in createStore
|
|
188
186
|
// or replace with a stub function for non-immutable gets
|
|
187
|
+
|
|
189
188
|
const makeFromJS = (returnType = globalThis.STATE_TYPE || 'immutable') => {
|
|
190
189
|
var _immutable, _immutable2;
|
|
190
|
+
|
|
191
191
|
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;
|
|
192
192
|
};
|
|
193
|
+
|
|
193
194
|
const getImmutableOrJS = (state, stateKey, fallbackValue, returnType = globalThis.STATE_TYPE || 'immutable') => {
|
|
194
195
|
// Find a fromJS function from global that is dynamically loaded in createStore
|
|
195
196
|
// or replace with a stub function for non-immutable gets
|
|
196
197
|
const fromJS = makeFromJS(returnType);
|
|
198
|
+
|
|
197
199
|
if (state && 'get' in state && typeof state.get === 'function' && 'getIn' in state && typeof state.getIn === 'function' && 'toJS' in state && typeof state.toJS === 'function') {
|
|
198
200
|
if (Array.isArray(stateKey)) return fromJS(state.getIn(stateKey, fallbackValue));
|
|
199
201
|
return fromJS(state.get(stateKey, fallbackValue));
|
|
200
202
|
}
|
|
203
|
+
|
|
201
204
|
if (Array.isArray(stateKey) && state && typeof state === 'object') {
|
|
202
205
|
const result = jpath(stateKey.join('.'), state);
|
|
203
206
|
if (typeof result === 'undefined') return fallbackValue;
|
|
204
207
|
return result;
|
|
205
208
|
}
|
|
209
|
+
|
|
206
210
|
const result = state && typeof state === 'object' ? state[stateKey] : undefined;
|
|
207
211
|
if (typeof result === 'undefined') return fallbackValue;
|
|
208
212
|
return result;
|
|
@@ -217,6 +221,7 @@ const getFacets = (state, returnType) => getImmutableOrJS(state, ['search', Cont
|
|
|
217
221
|
const getTabFacets = state => Object.fromEntries(Object.entries(getFacets(state, 'js')).filter(([key]) => getImmutableOrJS(getFacets(state), [key, 'tabId'], 0) === getCurrentTab(state)));
|
|
218
222
|
const getFacetTitles = state => Object.entries(getFacets(state, 'js')).map(([key, facet = {}]) => {
|
|
219
223
|
var _facet$pagingInfo;
|
|
224
|
+
|
|
220
225
|
return {
|
|
221
226
|
isSelected: getCurrentFacet(state) === key,
|
|
222
227
|
key,
|
|
@@ -243,9 +248,8 @@ const getFiltersToLoad = (state, facet, context = Context.facets, returnType) =>
|
|
|
243
248
|
return typeof title !== 'undefined' && !!title;
|
|
244
249
|
}).length > 0 && (f.isError || false) === false]);
|
|
245
250
|
return loadedFilters.map(([filterKey, isLoaded]) => !isLoaded ? filterKey : null).filter(f => !!f);
|
|
246
|
-
};
|
|
251
|
+
}; // We lowercase the filter key unless it's an ISO date string where the T must be uppercase
|
|
247
252
|
|
|
248
|
-
// We lowercase the filter key unless it's an ISO date string where the T must be uppercase
|
|
249
253
|
const getSelectedFilters = (state, facet = '', context = Context.facets, returnType) => {
|
|
250
254
|
const filters = getFilters(state, facet, context, 'js');
|
|
251
255
|
const isoDateRegex = RegExp(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d/);
|
|
@@ -283,7 +287,6 @@ const getPageSize = (state, current = '', context = Context.facets) => {
|
|
|
283
287
|
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pageSize'], 0 // Defaults to 0 because we want it to fall back to a query param if not defined
|
|
284
288
|
);
|
|
285
289
|
};
|
|
286
|
-
|
|
287
290
|
const getPrevPageIndex = (state, current = '', context = Context.facets) => {
|
|
288
291
|
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'prevPageIndex']);
|
|
289
292
|
};
|
|
@@ -326,8 +329,7 @@ const getTabsAndFacets = (state, returnType) => {
|
|
|
326
329
|
if (!countFields || countFields.find((f = []) => (f === null || f === void 0 ? void 0 : f[0]) === facetName)) return getImmutableOrJS(facet, ['pagingInfo', 'totalCount']);
|
|
327
330
|
return 0;
|
|
328
331
|
}).reduce((a, b) => a + b, 0);
|
|
329
|
-
return {
|
|
330
|
-
...tab,
|
|
332
|
+
return { ...tab,
|
|
331
333
|
[Context.facets]: Object.fromEntries(thisTabFacets),
|
|
332
334
|
totalCount: thisTabTotal
|
|
333
335
|
};
|
|
@@ -344,12 +346,12 @@ const getFacetsTotalCount = state => {
|
|
|
344
346
|
const facets = getFacets(state);
|
|
345
347
|
const wholeSearchTotal = Object.entries(facets).map(([, t = {}]) => {
|
|
346
348
|
var _t$pagingInfo;
|
|
349
|
+
|
|
347
350
|
return ((_t$pagingInfo = t.pagingInfo) === null || _t$pagingInfo === void 0 ? void 0 : _t$pagingInfo.totalCount) || 0;
|
|
348
351
|
}).reduce((a, b) => a + b, 0);
|
|
349
352
|
return wholeSearchTotal;
|
|
350
|
-
};
|
|
353
|
+
}; // An exported copy of the relevant selectors scoped by default to a facets context
|
|
351
354
|
|
|
352
|
-
// An exported copy of the relevant selectors scoped by default to a facets context
|
|
353
355
|
const selectFacets = {
|
|
354
356
|
getCurrent: getCurrentFacet,
|
|
355
357
|
getCurrentTab,
|
|
@@ -386,9 +388,8 @@ const selectFacets = {
|
|
|
386
388
|
getSearchTerm,
|
|
387
389
|
getSearchTotalCount,
|
|
388
390
|
getSelectedFilters
|
|
389
|
-
};
|
|
391
|
+
}; // An exported copy of the relevant selectors pre-scoped to a listing context
|
|
390
392
|
|
|
391
|
-
// An exported copy of the relevant selectors pre-scoped to a listing context
|
|
392
393
|
const selectListing = {
|
|
393
394
|
getCurrent: getCurrentListing,
|
|
394
395
|
getFeaturedResults: (state, listing = '') => getFeaturedResults(state, listing, Context.listings, 'js'),
|
|
@@ -469,23 +470,31 @@ const now = () => {
|
|
|
469
470
|
if (typeof window == 'undefined') {
|
|
470
471
|
return Date.now();
|
|
471
472
|
}
|
|
473
|
+
|
|
472
474
|
return window.performance.now();
|
|
473
475
|
};
|
|
474
476
|
|
|
475
477
|
const getClientConfig = (project, env) => {
|
|
476
|
-
let config = DELIVERY_API_CONFIG;
|
|
478
|
+
let config = DELIVERY_API_CONFIG;
|
|
479
|
+
/* global DELIVERY_API_CONFIG */
|
|
480
|
+
|
|
477
481
|
if (project) {
|
|
478
482
|
config.projectId = project;
|
|
479
483
|
}
|
|
480
|
-
|
|
484
|
+
|
|
485
|
+
if (typeof window != 'undefined' && PROXY_DELIVERY_API
|
|
486
|
+
/* global PROXY_DELIVERY_API */
|
|
487
|
+
) {
|
|
481
488
|
// ensure a relative url is used to bypass the need for CORS (separate OPTIONS calls)
|
|
482
489
|
config.rootUrl = env || '';
|
|
483
490
|
config.responseHandler = {
|
|
484
491
|
404: () => null
|
|
485
492
|
};
|
|
486
493
|
}
|
|
494
|
+
|
|
487
495
|
return config;
|
|
488
496
|
};
|
|
497
|
+
|
|
489
498
|
class CacheNode {
|
|
490
499
|
constructor(key, value) {
|
|
491
500
|
this.key = key;
|
|
@@ -493,7 +502,9 @@ class CacheNode {
|
|
|
493
502
|
this.next = null;
|
|
494
503
|
this.prev = null;
|
|
495
504
|
}
|
|
505
|
+
|
|
496
506
|
}
|
|
507
|
+
|
|
497
508
|
class LruCache {
|
|
498
509
|
constructor(limit = 100) {
|
|
499
510
|
this.map = {};
|
|
@@ -502,6 +513,7 @@ class LruCache {
|
|
|
502
513
|
this.limit = limit || 100;
|
|
503
514
|
this.size = 0;
|
|
504
515
|
}
|
|
516
|
+
|
|
505
517
|
get(key) {
|
|
506
518
|
if (this.map[key]) {
|
|
507
519
|
let value = this.map[key].value;
|
|
@@ -511,8 +523,10 @@ class LruCache {
|
|
|
511
523
|
return value;
|
|
512
524
|
}
|
|
513
525
|
}
|
|
526
|
+
|
|
514
527
|
set(key, value) {
|
|
515
528
|
let node = new CacheNode(key, value);
|
|
529
|
+
|
|
516
530
|
if (this.map[key]) {
|
|
517
531
|
this.remove(key);
|
|
518
532
|
} else {
|
|
@@ -523,46 +537,60 @@ class LruCache {
|
|
|
523
537
|
this.tail.next = null;
|
|
524
538
|
}
|
|
525
539
|
}
|
|
540
|
+
|
|
526
541
|
this.setHead(node);
|
|
527
542
|
}
|
|
543
|
+
|
|
528
544
|
setHead(node) {
|
|
529
545
|
node.next = this.head;
|
|
530
546
|
node.prev = null;
|
|
547
|
+
|
|
531
548
|
if (this.head) {
|
|
532
549
|
this.head.prev = node;
|
|
533
550
|
}
|
|
551
|
+
|
|
534
552
|
this.head = node;
|
|
553
|
+
|
|
535
554
|
if (!this.tail) {
|
|
536
555
|
this.tail = node;
|
|
537
556
|
}
|
|
557
|
+
|
|
538
558
|
this.size++;
|
|
539
559
|
this.map[node.key] = node;
|
|
540
560
|
}
|
|
561
|
+
|
|
541
562
|
remove(key) {
|
|
542
563
|
let node = this.map[key];
|
|
564
|
+
|
|
543
565
|
if (node.prev) {
|
|
544
566
|
node.prev.next = node.next;
|
|
545
567
|
} else {
|
|
546
568
|
this.head = node.next;
|
|
547
569
|
}
|
|
570
|
+
|
|
548
571
|
if (node.next) {
|
|
549
572
|
node.next.prev = node.prev;
|
|
550
573
|
} else {
|
|
551
574
|
this.tail = node.prev;
|
|
552
575
|
}
|
|
576
|
+
|
|
553
577
|
delete this.map[key];
|
|
554
578
|
this.size--;
|
|
555
579
|
}
|
|
580
|
+
|
|
556
581
|
}
|
|
582
|
+
|
|
557
583
|
class CachedSearch {
|
|
558
584
|
constructor() {
|
|
559
585
|
this.cache = new LruCache();
|
|
560
586
|
this.taxonomyLookup = {};
|
|
561
587
|
}
|
|
588
|
+
|
|
562
589
|
search(query, linkDepth, project, env) {
|
|
563
590
|
const client = Client.create(getClientConfig(project, env));
|
|
564
591
|
return this.request(project + JSON.stringify(query) + linkDepth.toString(), () => client.entries.search(query, linkDepth));
|
|
565
592
|
}
|
|
593
|
+
|
|
566
594
|
getTaxonomyNodeByPath(path, project, env) {
|
|
567
595
|
const client = Client.create(getClientConfig(project, env));
|
|
568
596
|
return this.request(`[TAXONOMY NODE] ${path}`, () => client.taxonomy.getNodeByPath({
|
|
@@ -571,6 +599,7 @@ class CachedSearch {
|
|
|
571
599
|
childDepth: 2
|
|
572
600
|
}).then(node => this.extendTaxonomyNode(node)));
|
|
573
601
|
}
|
|
602
|
+
|
|
574
603
|
request(key, execute) {
|
|
575
604
|
if (!this.cache.get(key) || typeof window == 'undefined') {
|
|
576
605
|
let promise = execute();
|
|
@@ -579,36 +608,41 @@ class CachedSearch {
|
|
|
579
608
|
this.cache.remove(key);
|
|
580
609
|
});
|
|
581
610
|
}
|
|
611
|
+
|
|
582
612
|
return this.cache.get(key);
|
|
583
613
|
}
|
|
614
|
+
|
|
584
615
|
extendTaxonomyNode(node) {
|
|
585
616
|
let id = this.getTaxonomyId(node);
|
|
586
617
|
this.taxonomyLookup[id] = node.key;
|
|
587
|
-
return {
|
|
588
|
-
...node,
|
|
618
|
+
return { ...node,
|
|
589
619
|
id,
|
|
590
620
|
children: node.children ? node.children.map(n => this.extendTaxonomyNode(n)) : null
|
|
591
621
|
};
|
|
592
622
|
}
|
|
623
|
+
|
|
593
624
|
getTaxonomyId(node) {
|
|
594
625
|
if (node.key) {
|
|
595
626
|
let parts = node.key.split('/');
|
|
596
627
|
return parts[parts.length - 1];
|
|
597
628
|
}
|
|
629
|
+
|
|
598
630
|
return '';
|
|
599
631
|
}
|
|
632
|
+
|
|
600
633
|
fetch(uri, opts = {}) {
|
|
601
634
|
return this.request(`[FETCH] ${uri} ${JSON.stringify(opts)}`, () => fetch(uri, opts));
|
|
602
635
|
}
|
|
636
|
+
|
|
603
637
|
}
|
|
638
|
+
|
|
604
639
|
const cachedSearch = new CachedSearch();
|
|
605
640
|
|
|
606
641
|
// eslint-disable-next-line import/default
|
|
607
642
|
function fixFreeTextForElastic(s) {
|
|
608
643
|
const illegalChars = ['>', '<', '=', '|', '!', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', '/'];
|
|
609
644
|
const illegalRegEx = new RegExp(illegalChars.map(c => '\\' + c).join('|'), 'g');
|
|
610
|
-
s = s.replace(illegalRegEx, '');
|
|
611
|
-
// s = s.replace(encodedRegEx, ''); // (m) => '\\\\' + m);
|
|
645
|
+
s = s.replace(illegalRegEx, ''); // s = s.replace(encodedRegEx, ''); // (m) => '\\\\' + m);
|
|
612
646
|
|
|
613
647
|
return s;
|
|
614
648
|
}
|
|
@@ -628,11 +662,13 @@ const getItemsFromResult = result => {
|
|
|
628
662
|
const {
|
|
629
663
|
payload
|
|
630
664
|
} = result || {};
|
|
665
|
+
|
|
631
666
|
if (payload) {
|
|
632
667
|
if (Array.isArray(payload)) return payload;
|
|
633
668
|
if (Array.isArray(payload.items)) return payload.items;
|
|
634
669
|
return payload;
|
|
635
670
|
}
|
|
671
|
+
|
|
636
672
|
return [];
|
|
637
673
|
};
|
|
638
674
|
const extractQuotedPhrases = searchTerm => {
|
|
@@ -644,7 +680,6 @@ const buildUrl = (route, params) => {
|
|
|
644
680
|
const path = qs ? `${route}${route.includes('?') ? '&' : '?'}${qs}` : route;
|
|
645
681
|
return path;
|
|
646
682
|
};
|
|
647
|
-
|
|
648
683
|
/**
|
|
649
684
|
* Returns all params from the current route query string or static route
|
|
650
685
|
* Supply static route argument if reading parameters from the route path
|
|
@@ -653,14 +688,15 @@ const buildUrl = (route, params) => {
|
|
|
653
688
|
* @param location location object containing at least pathname and search
|
|
654
689
|
* @returns Keyed params object
|
|
655
690
|
*/
|
|
691
|
+
|
|
656
692
|
const routeParams = (staticRoute, location) => {
|
|
657
693
|
var _staticRoute$match;
|
|
694
|
+
|
|
658
695
|
// match.params is react-router-config/react-router@5 style
|
|
659
696
|
// params is supplied with RouteObject in react-router@6
|
|
660
697
|
const pathParams = (staticRoute === null || staticRoute === void 0 ? void 0 : (_staticRoute$match = staticRoute.match) === null || _staticRoute$match === void 0 ? void 0 : _staticRoute$match.params) || (staticRoute === null || staticRoute === void 0 ? void 0 : staticRoute.params) || {};
|
|
661
698
|
const queryParams = parse(typeof window !== 'undefined' ? window.location.search : (location === null || location === void 0 ? void 0 : location.search) || '');
|
|
662
|
-
return {
|
|
663
|
-
...pathParams,
|
|
699
|
+
return { ...pathParams,
|
|
664
700
|
...queryParams
|
|
665
701
|
};
|
|
666
702
|
};
|
|
@@ -668,11 +704,13 @@ const callCustomApi = async (customApi, filters) => {
|
|
|
668
704
|
const apiUri = customApi.uri || '';
|
|
669
705
|
let uri = buildUrl(apiUri, filters);
|
|
670
706
|
if (!uri) throw new Error('uri is required to use customApi');
|
|
707
|
+
|
|
671
708
|
if (typeof window == 'undefined') {
|
|
672
709
|
if (!uri.startsWith('http')) uri = `http://localhost:3001${uri}`;
|
|
673
710
|
const response = await fetch(uri);
|
|
674
711
|
return await response.json();
|
|
675
712
|
}
|
|
713
|
+
|
|
676
714
|
const response = await cachedSearch.fetch(uri);
|
|
677
715
|
return await response.clone().json();
|
|
678
716
|
};
|
|
@@ -680,27 +718,32 @@ const removeEmptyAttributes = obj => {
|
|
|
680
718
|
Object.entries(obj).forEach(([key, val]) => val && typeof val === 'object' && removeEmptyAttributes(val) || (typeof val === 'undefined' || val === null || val === '') && delete obj[key]);
|
|
681
719
|
return obj;
|
|
682
720
|
};
|
|
683
|
-
const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator);
|
|
721
|
+
const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator); // assumes array elements are primitive types
|
|
684
722
|
|
|
685
|
-
// assumes array elements are primitive types
|
|
686
723
|
const areArraysEqualSets = (a1, a2) => {
|
|
687
724
|
const superSet = {};
|
|
725
|
+
|
|
688
726
|
for (const ai of a1) {
|
|
689
727
|
const e = ai + typeof ai;
|
|
690
728
|
superSet[e] = 1;
|
|
691
729
|
}
|
|
730
|
+
|
|
692
731
|
for (const ai of a2) {
|
|
693
732
|
const e = ai + typeof ai;
|
|
733
|
+
|
|
694
734
|
if (!superSet[e]) {
|
|
695
735
|
return false;
|
|
696
736
|
}
|
|
737
|
+
|
|
697
738
|
superSet[e] = 2;
|
|
698
739
|
}
|
|
740
|
+
|
|
699
741
|
for (const e in superSet) {
|
|
700
742
|
if (superSet[e] === 1) {
|
|
701
743
|
return false;
|
|
702
744
|
}
|
|
703
745
|
}
|
|
746
|
+
|
|
704
747
|
return true;
|
|
705
748
|
};
|
|
706
749
|
|
|
@@ -711,12 +754,12 @@ const searchUriTemplate = {
|
|
|
711
754
|
}) => {
|
|
712
755
|
const context = getSearchContext(state);
|
|
713
756
|
const currentPath = selectCurrentPath(state) || '/search';
|
|
757
|
+
|
|
714
758
|
if (context !== 'listings') {
|
|
715
759
|
const currentFacet = facet || getCurrentFacet(state);
|
|
716
760
|
const filters = getSelectedFilters(state, facet, context);
|
|
717
|
-
const currentFilter = filters.contentTypeId;
|
|
761
|
+
const currentFilter = filters.contentTypeId; // Check if we have a filter first
|
|
718
762
|
|
|
719
|
-
// Check if we have a filter first
|
|
720
763
|
const newPath = (currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.length) > 0 && currentFacet ? `${currentPath}/${currentFacet}/${currentFilter}` : currentFacet ? `${currentPath}/${currentFacet}` : currentPath;
|
|
721
764
|
return newPath;
|
|
722
765
|
} else {
|
|
@@ -731,29 +774,29 @@ const searchUriTemplate = {
|
|
|
731
774
|
pageIndex,
|
|
732
775
|
pageSize
|
|
733
776
|
}) => {
|
|
734
|
-
const searchContext = getSearchContext(state);
|
|
735
|
-
// Lose stateFilters and currentSearch if a new
|
|
777
|
+
const searchContext = getSearchContext(state); // Lose stateFilters and currentSearch if a new
|
|
736
778
|
// term is passed via an argument
|
|
779
|
+
|
|
737
780
|
const stateFilters = term ? {} : Object.fromEntries(Object.entries(getSelectedFilters(state, facet, searchContext, 'js')).map(([k, f]) => [k, f === null || f === void 0 ? void 0 : f.join(',')]));
|
|
738
781
|
const currentSearch = !term && getImmutableOrJS(state, ['routing', 'location', 'search']);
|
|
739
782
|
const currentQs = removeEmptyAttributes(parse(currentSearch));
|
|
740
783
|
if (orderBy) currentQs.orderBy = orderBy;
|
|
741
|
-
const searchTerm = getSearchTerm(state);
|
|
742
|
-
// Use Immutable's merge to merge the stateFilters with any current Qs
|
|
784
|
+
const searchTerm = getSearchTerm(state); // Use Immutable's merge to merge the stateFilters with any current Qs
|
|
743
785
|
// to build the new Qs.
|
|
786
|
+
|
|
744
787
|
const mergedSearch = removeEmptyAttributes(merge(currentQs, stateFilters));
|
|
745
788
|
if (searchTerm) mergedSearch.term = searchTerm;
|
|
746
789
|
if (pageIndex) mergedSearch.pageIndex = pageIndex + 1;
|
|
747
790
|
if (pageIndex === 0) mergedSearch.pageIndex = undefined;
|
|
748
|
-
if (pageSize) mergedSearch.pageSize = pageSize;
|
|
791
|
+
if (pageSize) mergedSearch.pageSize = pageSize; // We don't want these as search params in the url, we just need the search package to see them
|
|
749
792
|
|
|
750
|
-
// We don't want these as search params in the url, we just need the search package to see them
|
|
751
793
|
return stringify(mergedSearch);
|
|
752
794
|
},
|
|
753
795
|
hash: ({
|
|
754
796
|
state
|
|
755
797
|
}) => getImmutableOrJS(state, ['routing', 'location', 'hash'], '').replace('#', '')
|
|
756
798
|
};
|
|
799
|
+
|
|
757
800
|
const mapStateToSearchUri = state => mapJson(state, searchUriTemplate);
|
|
758
801
|
|
|
759
802
|
const DataFormats = {
|
|
@@ -788,8 +831,7 @@ const Fields = {
|
|
|
788
831
|
|
|
789
832
|
const fieldExpression = (field, value, operator = 'equalTo', weight, fuzzySearch = false) => {
|
|
790
833
|
if (!field || !value || Array.isArray(value) && value.length === 0) return [];
|
|
791
|
-
if (Array.isArray(field))
|
|
792
|
-
// If an array of fieldIds have been provided, call self for each fieldId
|
|
834
|
+
if (Array.isArray(field)) // If an array of fieldIds have been provided, call self for each fieldId
|
|
793
835
|
// to generate expressions that are combined with an 'or' operator
|
|
794
836
|
return [Op.or(...field.map(fieldId => fieldExpression(fieldId, value, operator, weight, fuzzySearch)).flat())];
|
|
795
837
|
if (operator === 'between') return between(field, value);
|
|
@@ -798,15 +840,19 @@ const fieldExpression = (field, value, operator = 'equalTo', weight, fuzzySearch
|
|
|
798
840
|
const contentTypeIdExpression = (contentTypeIds, webpageTemplates, assetTypes) => {
|
|
799
841
|
const expressions = [];
|
|
800
842
|
if (!contentTypeIds && !webpageTemplates && !assetTypes) return expressions;
|
|
843
|
+
|
|
801
844
|
if (contentTypeIds && contentTypeIds.length > 0) {
|
|
802
845
|
expressions.push(...dataFormatExpression(contentTypeIds, DataFormats.entry));
|
|
803
846
|
}
|
|
847
|
+
|
|
804
848
|
if (webpageTemplates && webpageTemplates.length > 0) {
|
|
805
849
|
expressions.push(...dataFormatExpression(webpageTemplates, DataFormats.webpage));
|
|
806
850
|
}
|
|
851
|
+
|
|
807
852
|
if (assetTypes && assetTypes.length > 0) {
|
|
808
853
|
expressions.push(...dataFormatExpression(assetTypes, DataFormats.asset));
|
|
809
854
|
}
|
|
855
|
+
|
|
810
856
|
if (expressions.length > 1) return [Op.or(...expressions)];
|
|
811
857
|
return expressions;
|
|
812
858
|
};
|
|
@@ -814,16 +860,14 @@ const filterExpressions = (filters, isOptional = false) => {
|
|
|
814
860
|
if (!filters) return [];
|
|
815
861
|
const expressions = [];
|
|
816
862
|
filters.map(selectedFilter => {
|
|
817
|
-
if (selectedFilter.logicOperator === 'and')
|
|
818
|
-
// using 'and' logic operator we loop through each filter
|
|
863
|
+
if (selectedFilter.logicOperator === 'and') // using 'and' logic operator we loop through each filter
|
|
819
864
|
// and loop through all values to add an expression for each filter value
|
|
820
865
|
selectedFilter.values.forEach(value => expressions.push(...fieldExpression(selectedFilter.key, value, selectedFilter.fieldOperator || 'equalTo')));else if (selectedFilter.logicOperator === 'not') {
|
|
821
866
|
const fieldExpressions = fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in');
|
|
822
867
|
fieldExpressions.forEach(expr => {
|
|
823
868
|
expressions.push(Op.not(expr));
|
|
824
869
|
});
|
|
825
|
-
}
|
|
826
|
-
// using 'or' logic operator we loop over each filter
|
|
870
|
+
} // using 'or' logic operator we loop over each filter
|
|
827
871
|
// and simply add the array of values to an expression with an 'in' operator
|
|
828
872
|
else expressions.push(...fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in'));
|
|
829
873
|
if (isOptional) expressions.push(Op.not(fieldExpression(selectedFilter.key, true, 'exists')[0]));
|
|
@@ -847,6 +891,7 @@ const dataFormatExpression = (contentTypeIds, dataFormat = DataFormats.entry) =>
|
|
|
847
891
|
if (notContentTypeIds.length > 0 && notExpr) andExpr.add(notExpr);
|
|
848
892
|
return [andExpr];
|
|
849
893
|
}
|
|
894
|
+
|
|
850
895
|
return [];
|
|
851
896
|
};
|
|
852
897
|
const featuredResultsExpression = ({
|
|
@@ -855,22 +900,24 @@ const featuredResultsExpression = ({
|
|
|
855
900
|
fieldValue = true
|
|
856
901
|
} = {}) => {
|
|
857
902
|
const expressions = [];
|
|
903
|
+
|
|
858
904
|
if (contentTypeId) {
|
|
859
905
|
expressions.push(...contentTypeIdExpression(Array.isArray(contentTypeId) ? contentTypeId : [contentTypeId]));
|
|
860
906
|
}
|
|
907
|
+
|
|
861
908
|
if (fieldId && fieldValue) {
|
|
862
909
|
expressions.push(...fieldExpression(fieldId, fieldValue));
|
|
863
910
|
}
|
|
911
|
+
|
|
864
912
|
return expressions;
|
|
865
913
|
};
|
|
866
914
|
const languagesExpression = languages => fieldExpression(Fields.sys.language, languages);
|
|
867
915
|
const includeInSearchExpressions = (webpageTemplates, includeInSearchFields) => {
|
|
868
|
-
const expressions = [];
|
|
869
|
-
// Or include this expression if we have explicity specified non-default includeInSearch fields
|
|
870
|
-
if (Array.isArray(includeInSearchFields)) expressions.push(...includeInSearchFields.map(includeInSearchField => Op.or(Op.and(Op.exists(includeInSearchField, true), Op.equalTo(includeInSearchField, true)), Op.exists(includeInSearchField, false))));
|
|
916
|
+
const expressions = []; // Or include this expression if we have explicity specified non-default includeInSearch fields
|
|
871
917
|
|
|
872
|
-
// If webpageTemplates have been specified, include this expression
|
|
918
|
+
if (Array.isArray(includeInSearchFields)) expressions.push(...includeInSearchFields.map(includeInSearchField => Op.or(Op.and(Op.exists(includeInSearchField, true), Op.equalTo(includeInSearchField, true)), Op.exists(includeInSearchField, false)))); // If webpageTemplates have been specified, include this expression
|
|
873
919
|
// with the default includeInSearch field from classic Contensis.
|
|
920
|
+
|
|
874
921
|
if (Array.isArray(webpageTemplates) && webpageTemplates.length > 0) expressions.push(Op.or(Op.and(Op.exists(Fields.sys.includeInSearch, true), Op.equalTo(Fields.sys.includeInSearch, true)), Op.exists(Fields.sys.includeInSearch, false)));
|
|
875
922
|
return expressions;
|
|
876
923
|
};
|
|
@@ -890,52 +937,69 @@ const excludeIdsExpression = excludeIds => {
|
|
|
890
937
|
};
|
|
891
938
|
const orderByExpression = orderBy => {
|
|
892
939
|
let expression;
|
|
940
|
+
|
|
893
941
|
if (orderBy && orderBy.length > 0) {
|
|
894
942
|
expression = OrderBy;
|
|
943
|
+
|
|
895
944
|
for (const ob of orderBy) {
|
|
896
945
|
var _expression, _expression2;
|
|
946
|
+
|
|
897
947
|
expression = ob.startsWith('-') ? (_expression = expression) === null || _expression === void 0 ? void 0 : _expression.desc(ob.substring(1)) : (_expression2 = expression) === null || _expression2 === void 0 ? void 0 : _expression2.asc(ob);
|
|
898
948
|
}
|
|
899
949
|
}
|
|
950
|
+
|
|
900
951
|
return expression;
|
|
901
952
|
};
|
|
953
|
+
|
|
902
954
|
const equalToOrIn = (field, value, operator = 'equalTo', fuzzySearch = false) => {
|
|
903
955
|
if (value.length === 0) return [];
|
|
956
|
+
|
|
904
957
|
if (Array.isArray(value)) {
|
|
905
958
|
if (operator === 'equalTo' || operator === 'in') return [Op.in(field, ...value)];
|
|
906
959
|
const expressions = value.map(innerValue => {
|
|
907
960
|
var _between, _distanceWithin;
|
|
961
|
+
|
|
908
962
|
switch (operator) {
|
|
909
963
|
case 'between':
|
|
910
964
|
return (_between = between(field, innerValue)) === null || _between === void 0 ? void 0 : _between[0];
|
|
965
|
+
|
|
911
966
|
case 'distanceWithin':
|
|
912
967
|
return (_distanceWithin = distanceWithin(field, innerValue)) === null || _distanceWithin === void 0 ? void 0 : _distanceWithin[0];
|
|
968
|
+
|
|
913
969
|
case 'exists':
|
|
914
970
|
return Op.exists(field, innerValue);
|
|
971
|
+
|
|
915
972
|
case 'freeText':
|
|
916
973
|
// TODO: Potentially needs further implementation of new options
|
|
917
974
|
return Op[operator](field, innerValue, fuzzySearch, undefined);
|
|
975
|
+
|
|
918
976
|
default:
|
|
919
977
|
return Op[operator](field, innerValue);
|
|
920
978
|
}
|
|
921
979
|
});
|
|
922
980
|
return (expressions === null || expressions === void 0 ? void 0 : expressions.length) > 1 ? [Op.or(...expressions)] : expressions || [];
|
|
923
981
|
}
|
|
982
|
+
|
|
924
983
|
switch (operator) {
|
|
925
984
|
case 'between':
|
|
926
985
|
return between(field, value);
|
|
986
|
+
|
|
927
987
|
case 'distanceWithin':
|
|
928
988
|
return distanceWithin(field, value);
|
|
989
|
+
|
|
929
990
|
case 'freeText':
|
|
930
991
|
// TODO: Potentially needs further implementation of new options
|
|
931
992
|
return [Op.freeText(field, value, fuzzySearch, undefined)];
|
|
993
|
+
|
|
932
994
|
default:
|
|
933
995
|
return [Op[operator](field, value)];
|
|
934
996
|
}
|
|
935
997
|
};
|
|
998
|
+
|
|
936
999
|
const between = (field, value) => {
|
|
937
1000
|
const handle = betweenValue => {
|
|
938
1001
|
const valArr = betweenValue.split('--');
|
|
1002
|
+
|
|
939
1003
|
if (valArr.length > 1) {
|
|
940
1004
|
const [minimum, maximum] = valArr;
|
|
941
1005
|
return Op.between(field, minimum, maximum);
|
|
@@ -945,14 +1009,17 @@ const between = (field, value) => {
|
|
|
945
1009
|
return false;
|
|
946
1010
|
}
|
|
947
1011
|
};
|
|
1012
|
+
|
|
948
1013
|
if (value.length === 0) return [];
|
|
949
1014
|
if (Array.isArray(value)) return [Op.or(...value.map(handle).filter(bc => bc !== false))];
|
|
950
1015
|
const op = handle(value);
|
|
951
1016
|
return op ? [op] : [];
|
|
952
1017
|
};
|
|
1018
|
+
|
|
953
1019
|
const distanceWithin = (field, value) => {
|
|
954
1020
|
const handle = distanceValue => {
|
|
955
1021
|
const valArr = distanceValue.split(' ');
|
|
1022
|
+
|
|
956
1023
|
if (valArr.length > 1) {
|
|
957
1024
|
const [lat, lon] = valArr;
|
|
958
1025
|
return Op.distanceWithin(field, Number(lat), Number(lon), (valArr === null || valArr === void 0 ? void 0 : valArr[2]) || '10mi');
|
|
@@ -962,27 +1029,28 @@ const distanceWithin = (field, value) => {
|
|
|
962
1029
|
return false;
|
|
963
1030
|
}
|
|
964
1031
|
};
|
|
1032
|
+
|
|
965
1033
|
if (value.length === 0) return [];
|
|
966
1034
|
if (Array.isArray(value)) return [Op.or(...value.map(handle).filter(bc => bc !== false))];
|
|
967
1035
|
const op = handle(value);
|
|
968
1036
|
return op ? [op] : [];
|
|
969
1037
|
};
|
|
970
|
-
|
|
971
1038
|
/**
|
|
972
1039
|
* Accept HTTP style objects and map them to
|
|
973
1040
|
* their equivalent JS client "Op" expressions
|
|
974
1041
|
* @param {array} where the where array as you'd provide it to the HTTP API
|
|
975
1042
|
* @returns {array} array of constructed Delivery API Operators
|
|
976
1043
|
*/
|
|
1044
|
+
|
|
1045
|
+
|
|
977
1046
|
const customWhereExpressions = where => {
|
|
978
|
-
if (!where || !Array.isArray(where)) return [];
|
|
1047
|
+
if (!where || !Array.isArray(where)) return []; // Map each clause inside the where array
|
|
979
1048
|
|
|
980
|
-
// Map each clause inside the where array
|
|
981
1049
|
return where.map(clause => {
|
|
982
|
-
let expression;
|
|
983
|
-
// Map through each property in the clause so we can
|
|
1050
|
+
let expression; // Map through each property in the clause so we can
|
|
984
1051
|
// capture the values required and reconstruct them as
|
|
985
1052
|
// a Delivery API expression
|
|
1053
|
+
|
|
986
1054
|
let operator;
|
|
987
1055
|
Object.keys(clause).map((key, idx) => {
|
|
988
1056
|
// The clause may contain only one key
|
|
@@ -990,6 +1058,7 @@ const customWhereExpressions = where => {
|
|
|
990
1058
|
const field = clause.field;
|
|
991
1059
|
const value = clause[Object.keys(clause).find(k => !['field', 'weight'].includes(k)) || ''];
|
|
992
1060
|
const weight = clause.weight;
|
|
1061
|
+
|
|
993
1062
|
if (idx === 0) {
|
|
994
1063
|
if (operator === 'and' || operator === 'or') {
|
|
995
1064
|
// These are array expressions so we can call ourself recursively
|
|
@@ -997,21 +1066,24 @@ const customWhereExpressions = where => {
|
|
|
997
1066
|
const recurseExpr = customWhereExpressions(clause[operator]);
|
|
998
1067
|
expression = Op[operator](...recurseExpr);
|
|
999
1068
|
}
|
|
1069
|
+
|
|
1000
1070
|
if (['not'].includes(operator)) {
|
|
1001
1071
|
// A 'not' expression is an object with only one inner field and inner operator
|
|
1002
1072
|
Object.keys(value).map((notKey, notIdx) => {
|
|
1003
1073
|
const innerOperator = notKey;
|
|
1004
1074
|
const innerValue = value[notKey];
|
|
1005
|
-
const innerField = value.field;
|
|
1006
|
-
// Map the expression when we've looped and scoped to
|
|
1075
|
+
const innerField = value.field; // Map the expression when we've looped and scoped to
|
|
1007
1076
|
// the second property inside the clause
|
|
1077
|
+
|
|
1008
1078
|
if (notIdx === 1) expression = Op.not(makeJsExpression(innerOperator, innerField, innerValue));
|
|
1009
1079
|
});
|
|
1010
1080
|
}
|
|
1011
|
-
}
|
|
1012
|
-
// Map the expression when we've looped and scoped to
|
|
1081
|
+
} // Map the expression when we've looped and scoped to
|
|
1013
1082
|
// the second property inside the clause
|
|
1083
|
+
|
|
1084
|
+
|
|
1014
1085
|
operator = Object.keys(clause).find(clauseKey => !['field', 'weight'].includes(clauseKey));
|
|
1086
|
+
|
|
1015
1087
|
if (idx === 1) {
|
|
1016
1088
|
expression = makeJsExpression(operator, field, value);
|
|
1017
1089
|
if (typeof weight === 'number') expression = expression.weight(weight);
|
|
@@ -1020,29 +1092,28 @@ const customWhereExpressions = where => {
|
|
|
1020
1092
|
return expression;
|
|
1021
1093
|
});
|
|
1022
1094
|
};
|
|
1095
|
+
|
|
1023
1096
|
const makeJsExpression = (operator, field, value) => operator === 'freeText' || operator === 'contains' ? Op[operator](field, value) : operator === 'in' ? Op[operator](field, ...value) : operator === 'exists' ? Op[operator](field, value) : operator === 'between' ? Op[operator](field, value[0], value[1]) : operator === 'distanceWithin' ? Op[operator](field, value === null || value === void 0 ? void 0 : value.lat, value === null || value === void 0 ? void 0 : value.lon, value === null || value === void 0 ? void 0 : value.distance) : Op[operator](field, value);
|
|
1097
|
+
|
|
1024
1098
|
const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch, omitSearchFields = []) => {
|
|
1025
1099
|
if (searchTerm && weightedSearchFields && weightedSearchFields.length > 0) {
|
|
1026
1100
|
// Extract any phrases in quotes to array
|
|
1027
|
-
const quotedPhrases = extractQuotedPhrases(searchTerm);
|
|
1101
|
+
const quotedPhrases = extractQuotedPhrases(searchTerm); // Modify the search term to remove any quoted phrases to leave any remaining terms
|
|
1028
1102
|
|
|
1029
|
-
// Modify the search term to remove any quoted phrases to leave any remaining terms
|
|
1030
1103
|
let modifiedSearchTerm = searchTerm;
|
|
1031
|
-
quotedPhrases.forEach(qp => modifiedSearchTerm = modifiedSearchTerm.replace(qp, '').replace('""', '').trim());
|
|
1104
|
+
quotedPhrases.forEach(qp => modifiedSearchTerm = modifiedSearchTerm.replace(qp, '').replace('""', '').trim()); // Push to the operators array to include in the query
|
|
1032
1105
|
|
|
1033
|
-
|
|
1034
|
-
const operators = [];
|
|
1106
|
+
const operators = []; // Helper functions to generate Op expressions
|
|
1035
1107
|
|
|
1036
|
-
// Helper functions to generate Op expressions
|
|
1037
1108
|
const containsOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'contains', f.weight);
|
|
1038
|
-
const freeTextOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'freeText', f.weight, fuzzySearch);
|
|
1039
1109
|
|
|
1040
|
-
// For each weighted search field
|
|
1110
|
+
const freeTextOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'freeText', f.weight, fuzzySearch); // For each weighted search field
|
|
1111
|
+
|
|
1112
|
+
|
|
1041
1113
|
weightedSearchFields.forEach(wsf => {
|
|
1042
1114
|
// Push to field operators
|
|
1043
|
-
const fieldOperators = [];
|
|
1115
|
+
const fieldOperators = []; // Add operator expressions for modified search term
|
|
1044
1116
|
|
|
1045
|
-
// Add operator expressions for modified search term
|
|
1046
1117
|
if (modifiedSearchTerm) {
|
|
1047
1118
|
if ([Fields.keywords, Fields.sys.filename, Fields.sys.uri].includes(wsf.fieldId)) {
|
|
1048
1119
|
fieldOperators.push(...containsOp(wsf, modifiedSearchTerm));
|
|
@@ -1053,35 +1124,33 @@ const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch, omitSear
|
|
|
1053
1124
|
fieldOperators.push(...freeTextOp(wsf, modifiedSearchTerm));
|
|
1054
1125
|
}
|
|
1055
1126
|
}
|
|
1056
|
-
}
|
|
1127
|
+
} // Add operator expressions for any quoted phrases
|
|
1057
1128
|
|
|
1058
|
-
// Add operator expressions for any quoted phrases
|
|
1059
|
-
quotedPhrases.forEach(qp => fieldOperators.push(...containsOp(wsf, qp)));
|
|
1060
1129
|
|
|
1061
|
-
// If we are using multiple operators for a field we will
|
|
1130
|
+
quotedPhrases.forEach(qp => fieldOperators.push(...containsOp(wsf, qp))); // If we are using multiple operators for a field we will
|
|
1062
1131
|
// wrap each field inside an And operator so we will match
|
|
1063
1132
|
// all terms/phrases rather than any terms/phrases
|
|
1133
|
+
|
|
1064
1134
|
if (fieldOperators.length > 1) {
|
|
1065
1135
|
operators.push(Op.and(...fieldOperators));
|
|
1066
1136
|
} else {
|
|
1067
1137
|
operators.push(...fieldOperators);
|
|
1068
1138
|
}
|
|
1069
|
-
});
|
|
1139
|
+
}); // Wrap operators in an Or operator
|
|
1070
1140
|
|
|
1071
|
-
// Wrap operators in an Or operator
|
|
1072
1141
|
const expressions = Op.or().addRange(operators);
|
|
1073
|
-
if (!omitSearchFields.find(sf => sf === Fields.searchContent))
|
|
1074
|
-
// include "searchContent" field by default unless omitted
|
|
1142
|
+
if (!omitSearchFields.find(sf => sf === Fields.searchContent)) // include "searchContent" field by default unless omitted
|
|
1075
1143
|
return [expressions.add(Op.freeText(Fields.searchContent, searchTerm, fuzzySearch))];else return [expressions];
|
|
1076
1144
|
} else if (searchTerm) {
|
|
1077
1145
|
// Searching without weightedSearchFields defined will fall back
|
|
1078
1146
|
// to a default set of search fields with arbritary weights set.
|
|
1079
|
-
|
|
1080
1147
|
const exp = [];
|
|
1148
|
+
|
|
1081
1149
|
if (!omitSearchFields.find(sf => sf === Fields.entryTitle)) {
|
|
1082
1150
|
exp.push(Op.equalTo(Fields.entryTitle, searchTerm).weight(10));
|
|
1083
1151
|
exp.push(Op.freeText(Fields.entryTitle, searchTerm, fuzzySearch).weight(2));
|
|
1084
1152
|
}
|
|
1153
|
+
|
|
1085
1154
|
if (!omitSearchFields.find(sf => sf === Fields.entryDescription)) exp.push(Op.freeText(Fields.entryDescription, searchTerm, fuzzySearch).weight(2));
|
|
1086
1155
|
if (!omitSearchFields.find(sf => sf === Fields.keywords)) exp.push(Op.contains(Fields.keywords, searchTerm).weight(2));
|
|
1087
1156
|
if (!omitSearchFields.find(sf => sf === Fields.sys.uri)) exp.push(Op.contains(Fields.sys.uri, searchTerm).weight(2));
|
|
@@ -1143,9 +1212,11 @@ const searchQuery = ({
|
|
|
1143
1212
|
const query = new Query(...expressions);
|
|
1144
1213
|
if (!searchTerm) query.orderBy = orderByExpression(orderBy);
|
|
1145
1214
|
if (dynamicOrderBy && dynamicOrderBy.length) query.orderBy = orderByExpression(dynamicOrderBy);
|
|
1215
|
+
|
|
1146
1216
|
if (fields && fields.length > 0 && !isFeatured) {
|
|
1147
1217
|
query.fields = fields;
|
|
1148
1218
|
}
|
|
1219
|
+
|
|
1149
1220
|
query.pageIndex = isFeatured ? 0 : pageIndex;
|
|
1150
1221
|
query.pageSize = isFeatured && typeof featuredResults.count === 'number' ? featuredResults.count : pageSize;
|
|
1151
1222
|
return query;
|
|
@@ -1166,6 +1237,7 @@ const mapEntriesToSearchResults = ({
|
|
|
1166
1237
|
const mapperFunc = mapper || mappers && mappers.results;
|
|
1167
1238
|
return items && typeof mapperFunc === 'function' ? mapperFunc(items, facet, context, state) : [];
|
|
1168
1239
|
};
|
|
1240
|
+
|
|
1169
1241
|
const facetTemplate = {
|
|
1170
1242
|
type: () => SET_SEARCH_ENTRIES,
|
|
1171
1243
|
context: 'action.context',
|
|
@@ -1208,9 +1280,11 @@ const facetTemplate = {
|
|
|
1208
1280
|
pagesLoaded
|
|
1209
1281
|
}) => {
|
|
1210
1282
|
const loaded = [...(pagesLoaded || [])];
|
|
1283
|
+
|
|
1211
1284
|
if (isNaN(loaded.find(l => l === pageIndex))) {
|
|
1212
1285
|
loaded.push(pageIndex);
|
|
1213
1286
|
}
|
|
1287
|
+
|
|
1214
1288
|
return loaded.sort((a, b) => a - b);
|
|
1215
1289
|
}
|
|
1216
1290
|
},
|
|
@@ -1233,21 +1307,18 @@ const facetTemplate = {
|
|
|
1233
1307
|
prevPageIndex
|
|
1234
1308
|
} = action.queryParams;
|
|
1235
1309
|
const results = mapEntriesToSearchResults(action, getItemsFromResult(result), state);
|
|
1236
|
-
if (!loadMorePaging) return results;
|
|
1310
|
+
if (!loadMorePaging) return results; // add a _pageIndex property to the returned results to help us later
|
|
1237
1311
|
|
|
1238
|
-
// add a _pageIndex property to the returned results to help us later
|
|
1239
1312
|
const nextResults = results.map((r, idx) => ({
|
|
1240
1313
|
_pageIndex: pageIndex,
|
|
1241
1314
|
_pagePosition: idx,
|
|
1242
1315
|
...r
|
|
1243
1316
|
}));
|
|
1244
|
-
const loadedPages = pagesLoaded || [];
|
|
1245
|
-
|
|
1246
|
-
// if pageIndex is found in loadedPages, we have already loaded this page
|
|
1247
|
-
if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults;
|
|
1317
|
+
const loadedPages = pagesLoaded || []; // if pageIndex is found in loadedPages, we have already loaded this page
|
|
1248
1318
|
|
|
1249
|
-
// Determine where we put the results depending on if we
|
|
1319
|
+
if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults; // Determine where we put the results depending on if we
|
|
1250
1320
|
// are paging forwards, backwards, or doing a new search
|
|
1321
|
+
|
|
1251
1322
|
const firstResultSet = pageIndex > prevPageIndex ? prevResults || [] : nextResults;
|
|
1252
1323
|
const secondResultSet = pageIndex > prevPageIndex ? nextResults : prevResults || [];
|
|
1253
1324
|
const onlyResultSet = loadedPages.length === 0 ? nextResults : false;
|
|
@@ -1278,11 +1349,13 @@ const filterTemplate = {
|
|
|
1278
1349
|
if (payload && (payload.items || payload.children)) {
|
|
1279
1350
|
const items = (payload.items || payload.children).map(item => {
|
|
1280
1351
|
var _item$sys;
|
|
1352
|
+
|
|
1281
1353
|
item.isSelected = selectedKeys === null || selectedKeys === void 0 ? void 0 : selectedKeys.includes((item === null || item === void 0 ? void 0 : (_item$sys = item.sys) === null || _item$sys === void 0 ? void 0 : _item$sys.id) || item.key);
|
|
1282
1354
|
return item;
|
|
1283
1355
|
});
|
|
1284
1356
|
return mapper(items);
|
|
1285
1357
|
}
|
|
1358
|
+
|
|
1286
1359
|
return [];
|
|
1287
1360
|
}
|
|
1288
1361
|
},
|
|
@@ -1305,22 +1378,22 @@ const filterExpressionMapper = {
|
|
|
1305
1378
|
fieldOperator: 'fieldOperator',
|
|
1306
1379
|
logicOperator: 'logicOperator'
|
|
1307
1380
|
};
|
|
1381
|
+
|
|
1308
1382
|
const mapFilterToFilterExpression = filter => mapJson(filter, filterExpressionMapper);
|
|
1309
1383
|
|
|
1310
1384
|
const mapFiltersToFilterExpression = (filters, selectedFilters) => {
|
|
1311
1385
|
if (!selectedFilters || Object.keys(selectedFilters).length === 0) return [];
|
|
1312
|
-
const filterExpressions = [];
|
|
1313
|
-
|
|
1314
|
-
// Iterate through the keys in selectedFilters and locate
|
|
1386
|
+
const filterExpressions = []; // Iterate through the keys in selectedFilters and locate
|
|
1315
1387
|
// the items that are selected and queryable
|
|
1388
|
+
|
|
1316
1389
|
Object.entries(selectedFilters).map(([fkey, selectedValues]) => {
|
|
1317
1390
|
const filter = filters[fkey];
|
|
1391
|
+
|
|
1318
1392
|
if (selectedValues && filter) {
|
|
1319
1393
|
// Where we have a value for a selectedFilter
|
|
1320
1394
|
// and a filter is found for the current key
|
|
1321
1395
|
// map the filter to a filterExpression object
|
|
1322
|
-
const expr = mapFilterToFilterExpression({
|
|
1323
|
-
...filter,
|
|
1396
|
+
const expr = mapFilterToFilterExpression({ ...filter,
|
|
1324
1397
|
selectedValues
|
|
1325
1398
|
});
|
|
1326
1399
|
filterExpressions.push(expr);
|
|
@@ -1356,8 +1429,8 @@ const queryParamsTemplate = {
|
|
|
1356
1429
|
context
|
|
1357
1430
|
}) => {
|
|
1358
1431
|
const stateFilters = getFilters(state, facet, context, 'js');
|
|
1359
|
-
const selectedFilters = getSelectedFilters(state, facet, context, 'js');
|
|
1360
|
-
|
|
1432
|
+
const selectedFilters = getSelectedFilters(state, facet, context, 'js'); // Use another mapping function to map the filter parameters for the query
|
|
1433
|
+
|
|
1361
1434
|
const filterParams = mapFiltersToFilterExpression(stateFilters, selectedFilters);
|
|
1362
1435
|
return filterParams;
|
|
1363
1436
|
},
|
|
@@ -1407,6 +1480,7 @@ const queryParamsTemplate = {
|
|
|
1407
1480
|
context
|
|
1408
1481
|
}) => {
|
|
1409
1482
|
var _getFacet;
|
|
1483
|
+
|
|
1410
1484
|
return ((_getFacet = getFacet(state, facet, context, 'js')) === null || _getFacet === void 0 ? void 0 : _getFacet.projectId) || selectCurrentProject(state);
|
|
1411
1485
|
},
|
|
1412
1486
|
searchTerm: root => root.context !== Context.minilist || getQueryParameter(root, 'useSearchTerm', false) ? getSearchTerm(root.state) : '',
|
|
@@ -1421,12 +1495,11 @@ const queryParamsTemplate = {
|
|
|
1421
1495
|
weightedSearchFields: root => {
|
|
1422
1496
|
const wsf = getQueryParameter(root, 'weightedSearchFields', []);
|
|
1423
1497
|
const deduped = wsf.filter((v, i, a) => a.findIndex(t => t.fieldId === v.fieldId) === i);
|
|
1424
|
-
return deduped;
|
|
1425
|
-
// return wsf;
|
|
1498
|
+
return deduped; // return wsf;
|
|
1426
1499
|
},
|
|
1427
|
-
|
|
1428
1500
|
webpageTemplates: root => getQueryParameter(root, 'webpageTemplates', [])
|
|
1429
1501
|
};
|
|
1502
|
+
|
|
1430
1503
|
const mapStateToQueryParams = sourceJson => mapJson(sourceJson, queryParamsTemplate);
|
|
1431
1504
|
|
|
1432
1505
|
/**
|
|
@@ -1440,9 +1513,9 @@ const generateQueryParams = (action, state) => {
|
|
|
1440
1513
|
const {
|
|
1441
1514
|
context,
|
|
1442
1515
|
facet
|
|
1443
|
-
} = action;
|
|
1444
|
-
// Map parameters using state and some additional
|
|
1516
|
+
} = action; // Map parameters using state and some additional
|
|
1445
1517
|
// inputs from the action
|
|
1518
|
+
|
|
1446
1519
|
const queryParams = mapStateToQueryParams({
|
|
1447
1520
|
context,
|
|
1448
1521
|
facet,
|
|
@@ -1451,12 +1524,12 @@ const generateQueryParams = (action, state) => {
|
|
|
1451
1524
|
});
|
|
1452
1525
|
return [queryParams, runSearch(action, state, queryParams)];
|
|
1453
1526
|
};
|
|
1454
|
-
|
|
1455
1527
|
/**
|
|
1456
1528
|
* Checks if we have already loaded everything we're asking for and tells us to run the search or not
|
|
1457
1529
|
* @param action
|
|
1458
1530
|
* @param state
|
|
1459
1531
|
*/
|
|
1532
|
+
|
|
1460
1533
|
const runSearch = (action, state, queryParams) => {
|
|
1461
1534
|
const {
|
|
1462
1535
|
context,
|
|
@@ -1468,14 +1541,13 @@ const runSearch = (action, state, queryParams) => {
|
|
|
1468
1541
|
} = action;
|
|
1469
1542
|
let willRun = false;
|
|
1470
1543
|
const facetIsLoaded = defaultLang ? false : getIsLoaded(state, context, facet);
|
|
1471
|
-
const stateParams = {
|
|
1472
|
-
...getQueryParams(ogState, facet, context)
|
|
1544
|
+
const stateParams = { ...getQueryParams(ogState, facet, context)
|
|
1473
1545
|
};
|
|
1474
1546
|
stateParams.pageIndex = getPageIndex(ogState, facet, context);
|
|
1475
1547
|
stateParams.searchTerm = getSearchTerm(ogState);
|
|
1476
1548
|
stateParams.pageSize = getPageSize(ogState, facet, context);
|
|
1477
|
-
|
|
1478
|
-
// context === Context.minilist ||
|
|
1549
|
+
|
|
1550
|
+
if (context === Context.facets && ssr || // context === Context.minilist ||
|
|
1479
1551
|
preload || !facetIsLoaded || filterParamsChanged(action) || defaultLang) {
|
|
1480
1552
|
willRun = true;
|
|
1481
1553
|
} else {
|
|
@@ -1483,24 +1555,28 @@ const runSearch = (action, state, queryParams) => {
|
|
|
1483
1555
|
// are the same as what we already have in state
|
|
1484
1556
|
Object.entries(stateParams).forEach(([param, value]) => {
|
|
1485
1557
|
const queryParam = queryParams[param];
|
|
1558
|
+
|
|
1486
1559
|
if (JSON.stringify(value) !== JSON.stringify(queryParam)) {
|
|
1487
1560
|
willRun = true;
|
|
1488
1561
|
}
|
|
1489
1562
|
});
|
|
1490
1563
|
}
|
|
1564
|
+
|
|
1491
1565
|
const internalPaging = getIsInternalPaging(ogState, facet, context);
|
|
1566
|
+
|
|
1492
1567
|
if (internalPaging && facetIsLoaded) {
|
|
1493
1568
|
willRun = false;
|
|
1494
1569
|
}
|
|
1570
|
+
|
|
1495
1571
|
return willRun;
|
|
1496
1572
|
};
|
|
1497
|
-
|
|
1498
1573
|
/**
|
|
1499
1574
|
* This will tell us if filter parameters have been
|
|
1500
1575
|
* changed by some external event such as a route change
|
|
1501
1576
|
* @param action
|
|
1502
1577
|
* @returns true or false
|
|
1503
1578
|
*/
|
|
1579
|
+
|
|
1504
1580
|
const filterParamsChanged = (action, state) => {
|
|
1505
1581
|
const {
|
|
1506
1582
|
context,
|
|
@@ -1515,13 +1591,12 @@ const filterParamsChanged = (action, state) => {
|
|
|
1515
1591
|
});
|
|
1516
1592
|
return paramsChanged.filter(f => f === true).length > 0;
|
|
1517
1593
|
};
|
|
1518
|
-
|
|
1519
1594
|
/* eslint-disable no-console */
|
|
1595
|
+
|
|
1520
1596
|
const debugExecuteSearch = (action, state) => {
|
|
1521
1597
|
const [queryParams, runSearch] = generateQueryParams(action, state);
|
|
1522
1598
|
console.log('runSearch', runSearch, 'action', action, 'filterParamsChanged', filterParamsChanged(action, state), 'getIsLoaded(state, context, facet)', getIsLoaded(state, action.context, action.facet));
|
|
1523
|
-
const stateParams = {
|
|
1524
|
-
...getQueryParams(action.ogState || state, action.facet, action.context),
|
|
1599
|
+
const stateParams = { ...getQueryParams(action.ogState || state, action.facet, action.context),
|
|
1525
1600
|
pageIndex: getPageIndex(action.ogState || state, action.facet, action.context),
|
|
1526
1601
|
searchTerm: getSearchTerm(action.ogState || state)
|
|
1527
1602
|
};
|
|
@@ -1530,8 +1605,7 @@ const debugExecuteSearch = (action, state) => {
|
|
|
1530
1605
|
};
|
|
1531
1606
|
const scrollTo = scrollToElement => {
|
|
1532
1607
|
if (typeof window !== 'undefined') {
|
|
1533
|
-
if (typeof scrollToElement === 'number')
|
|
1534
|
-
// Used to be Y coordinate, deprecated, because it's not accessible
|
|
1608
|
+
if (typeof scrollToElement === 'number') // Used to be Y coordinate, deprecated, because it's not accessible
|
|
1535
1609
|
console.warn('updatePageIndex arg2 needs string');else if (typeof scrollToElement === 'string') {
|
|
1536
1610
|
/* Effectively simulates an anchor link. Needed for accessibility, as window.scrollTo
|
|
1537
1611
|
does not change focus, only scrolls the screen */
|
|
@@ -1540,11 +1614,10 @@ const scrollTo = scrollToElement => {
|
|
|
1540
1614
|
}
|
|
1541
1615
|
};
|
|
1542
1616
|
|
|
1543
|
-
// *** FILTER ITEM MAPPING ***
|
|
1544
|
-
|
|
1545
1617
|
// Base mapping, fields that are the same across all mappings
|
|
1546
1618
|
// to save repeating these elements in every mapper, spread this
|
|
1547
1619
|
// into your discrete mappings
|
|
1620
|
+
|
|
1548
1621
|
const base = {
|
|
1549
1622
|
contentTypeId: Fields.sys.contentTypeId,
|
|
1550
1623
|
title: 'entryTitle',
|
|
@@ -1552,13 +1625,16 @@ const base = {
|
|
|
1552
1625
|
path: 'sys.slug',
|
|
1553
1626
|
isSelected: 'isSelected'
|
|
1554
1627
|
};
|
|
1628
|
+
|
|
1555
1629
|
const mapEntriesToFilterItems = entries => {
|
|
1556
1630
|
if (!entries) return [];
|
|
1557
1631
|
return entries.map(entry => {
|
|
1558
1632
|
const template = base;
|
|
1633
|
+
|
|
1559
1634
|
if (template) {
|
|
1560
1635
|
return mapJson(entry, template);
|
|
1561
1636
|
}
|
|
1637
|
+
|
|
1562
1638
|
return entry;
|
|
1563
1639
|
});
|
|
1564
1640
|
};
|
|
@@ -1588,7 +1664,9 @@ const mapQueryParamsToCustomApi = queryParams => {
|
|
|
1588
1664
|
};
|
|
1589
1665
|
|
|
1590
1666
|
const searchSagas = [takeEvery(CLEAR_FILTERS, clearFilters), takeEvery(DO_SEARCH, doSearch), takeEvery(SET_ROUTE_FILTERS, loadFilters), takeEvery(SET_SEARCH_ENTRIES, preloadOtherFacets), takeEvery(UPDATE_CURRENT_FACET, updateCurrentFacet), takeEvery(UPDATE_CURRENT_TAB, updateCurrentTab), takeEvery(UPDATE_PAGE_INDEX, updatePageIndex), takeEvery(UPDATE_PAGE_SIZE, updatePageSize), takeEvery(UPDATE_SEARCH_TERM, updateSearchTerm), takeEvery(UPDATE_SORT_ORDER, updateSortOrder), takeEvery(UPDATE_SELECTED_FILTERS, applySearchFilter)];
|
|
1667
|
+
|
|
1591
1668
|
const toJS = obj => obj && 'toJS' in obj && typeof obj.toJS === 'function' ? obj.toJS() : obj;
|
|
1669
|
+
|
|
1592
1670
|
function* setRouteFilters(action) {
|
|
1593
1671
|
const {
|
|
1594
1672
|
mappers,
|
|
@@ -1599,17 +1677,17 @@ function* setRouteFilters(action) {
|
|
|
1599
1677
|
} = action;
|
|
1600
1678
|
const context = listingType ? Context.listings : Context.facets;
|
|
1601
1679
|
const state = toJS(yield select());
|
|
1602
|
-
const ssr = getIsSsr(state);
|
|
1680
|
+
const ssr = getIsSsr(state); // Get current facet from params or state
|
|
1603
1681
|
|
|
1604
|
-
//
|
|
1605
|
-
let currentFacet = params && params.facet || listingType;
|
|
1682
|
+
let currentFacet = params && params.facet || listingType; // Pick the default facet from initialState
|
|
1606
1683
|
|
|
1607
|
-
// Pick the default facet from initialState
|
|
1608
1684
|
if (!currentFacet) {
|
|
1609
1685
|
var _Object$keys;
|
|
1686
|
+
|
|
1610
1687
|
const tabs = getSearchTabs(state, 'js');
|
|
1611
1688
|
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]) || '';
|
|
1612
1689
|
}
|
|
1690
|
+
|
|
1613
1691
|
const nextAction = {
|
|
1614
1692
|
type: SET_ROUTE_FILTERS,
|
|
1615
1693
|
context,
|
|
@@ -1620,50 +1698,48 @@ function* setRouteFilters(action) {
|
|
|
1620
1698
|
ssr,
|
|
1621
1699
|
debug
|
|
1622
1700
|
};
|
|
1623
|
-
yield put(nextAction);
|
|
1701
|
+
yield put(nextAction); // keep track of this state ref for comparing changes to params later
|
|
1624
1702
|
|
|
1625
|
-
// keep track of this state ref for comparing changes to params later
|
|
1626
1703
|
const ogState = {
|
|
1627
1704
|
search: state.search
|
|
1628
|
-
};
|
|
1629
|
-
|
|
1630
|
-
// Using call instead of triggering from the put
|
|
1705
|
+
}; // Using call instead of triggering from the put
|
|
1631
1706
|
// to allow this exported saga to continue during SSR
|
|
1632
|
-
|
|
1633
|
-
|
|
1707
|
+
|
|
1708
|
+
yield call(ensureSearch, { ...nextAction,
|
|
1634
1709
|
ogState
|
|
1635
1710
|
});
|
|
1636
1711
|
}
|
|
1637
1712
|
function* doSearch(action) {
|
|
1638
1713
|
var _action$params;
|
|
1714
|
+
|
|
1639
1715
|
const state = toJS(yield select());
|
|
1716
|
+
|
|
1640
1717
|
if (action.config) {
|
|
1641
1718
|
// If the action contains a config object, we can add this to the
|
|
1642
1719
|
// state at runtime
|
|
1643
|
-
yield put({
|
|
1644
|
-
...action,
|
|
1720
|
+
yield put({ ...action,
|
|
1645
1721
|
type: APPLY_CONFIG
|
|
1646
1722
|
});
|
|
1647
1723
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1724
|
+
|
|
1725
|
+
const nextAction = { ...action,
|
|
1650
1726
|
type: SET_SEARCH_FILTERS,
|
|
1651
1727
|
ssr: getIsSsr(state),
|
|
1652
1728
|
facet: action.facet || ((_action$params = action.params) === null || _action$params === void 0 ? void 0 : _action$params.facet)
|
|
1653
1729
|
};
|
|
1730
|
+
|
|
1654
1731
|
if (nextAction.facet && (action.config || Object.keys(getFacet(state, nextAction.facet, action.context, 'js')).length > 0)) {
|
|
1655
|
-
yield put(nextAction);
|
|
1732
|
+
yield put(nextAction); // keep track of this state ref for comparing changes to params later
|
|
1656
1733
|
|
|
1657
|
-
// keep track of this state ref for comparing changes to params later
|
|
1658
1734
|
const ogState = {
|
|
1659
1735
|
search: state.search
|
|
1660
1736
|
};
|
|
1661
|
-
yield call(ensureSearch, {
|
|
1662
|
-
...nextAction,
|
|
1737
|
+
yield call(ensureSearch, { ...nextAction,
|
|
1663
1738
|
ogState
|
|
1664
1739
|
});
|
|
1665
1740
|
}
|
|
1666
1741
|
}
|
|
1742
|
+
|
|
1667
1743
|
function* loadFilters(action) {
|
|
1668
1744
|
const {
|
|
1669
1745
|
facet: facetKey,
|
|
@@ -1671,6 +1747,7 @@ function* loadFilters(action) {
|
|
|
1671
1747
|
mappers = {}
|
|
1672
1748
|
} = action;
|
|
1673
1749
|
const filtersToLoad = yield select(getFiltersToLoad, facetKey, context, 'js');
|
|
1750
|
+
|
|
1674
1751
|
if (filtersToLoad.length > 0) {
|
|
1675
1752
|
yield put({
|
|
1676
1753
|
type: LOAD_FILTERS,
|
|
@@ -1696,6 +1773,7 @@ function* loadFilters(action) {
|
|
|
1696
1773
|
if (filtersToLoadSagas) yield all(filtersToLoadSagas);
|
|
1697
1774
|
}
|
|
1698
1775
|
}
|
|
1776
|
+
|
|
1699
1777
|
function* loadFilter(action) {
|
|
1700
1778
|
const {
|
|
1701
1779
|
facetKey,
|
|
@@ -1721,6 +1799,7 @@ function* loadFilter(action) {
|
|
|
1721
1799
|
selectedKeys,
|
|
1722
1800
|
mapper
|
|
1723
1801
|
};
|
|
1802
|
+
|
|
1724
1803
|
try {
|
|
1725
1804
|
if (contentTypeId) {
|
|
1726
1805
|
const versionStatus = yield select(selectVersionStatus);
|
|
@@ -1730,6 +1809,7 @@ function* loadFilter(action) {
|
|
|
1730
1809
|
if (payload.type === 'error') throw payload;
|
|
1731
1810
|
createStateFrom.payload = payload;
|
|
1732
1811
|
}
|
|
1812
|
+
|
|
1733
1813
|
if (path) {
|
|
1734
1814
|
const payload = yield cachedSearch.getTaxonomyNodeByPath(path, projectId);
|
|
1735
1815
|
if (!payload) throw new Error(`No payload returned for taxonomy path: '${path}'`);
|
|
@@ -1740,33 +1820,35 @@ function* loadFilter(action) {
|
|
|
1740
1820
|
createStateFrom.type = LOAD_FILTERS_ERROR;
|
|
1741
1821
|
createStateFrom.error = error;
|
|
1742
1822
|
}
|
|
1823
|
+
|
|
1743
1824
|
const nextAction = mapJson(createStateFrom, filterTemplate);
|
|
1744
1825
|
yield put(nextAction);
|
|
1745
1826
|
}
|
|
1827
|
+
|
|
1746
1828
|
function* ensureSearch(action) {
|
|
1747
1829
|
const {
|
|
1748
1830
|
context,
|
|
1749
1831
|
facet,
|
|
1750
1832
|
debug
|
|
1751
1833
|
} = action;
|
|
1834
|
+
|
|
1752
1835
|
try {
|
|
1753
1836
|
const state = yield select();
|
|
1754
|
-
const nextAction = {
|
|
1755
|
-
...action,
|
|
1837
|
+
const nextAction = { ...action,
|
|
1756
1838
|
ogState: action.ogState || {
|
|
1757
1839
|
search: state.search
|
|
1758
1840
|
}
|
|
1759
1841
|
};
|
|
1760
1842
|
const [queryParams, runSearch] = generateQueryParams(nextAction, state);
|
|
1761
1843
|
if (debug && (debug === true || debug.executeSearch)) debugExecuteSearch(nextAction, state);
|
|
1844
|
+
|
|
1762
1845
|
if (runSearch) {
|
|
1763
1846
|
yield put({
|
|
1764
1847
|
type: EXECUTE_SEARCH,
|
|
1765
1848
|
facet,
|
|
1766
1849
|
context
|
|
1767
1850
|
});
|
|
1768
|
-
yield call(executeSearch, {
|
|
1769
|
-
...nextAction,
|
|
1851
|
+
yield call(executeSearch, { ...nextAction,
|
|
1770
1852
|
context,
|
|
1771
1853
|
facet,
|
|
1772
1854
|
queryParams,
|
|
@@ -1778,6 +1860,7 @@ function* ensureSearch(action) {
|
|
|
1778
1860
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1779
1861
|
}
|
|
1780
1862
|
}
|
|
1863
|
+
|
|
1781
1864
|
function* executeSearch(action) {
|
|
1782
1865
|
const {
|
|
1783
1866
|
context,
|
|
@@ -1785,12 +1868,14 @@ function* executeSearch(action) {
|
|
|
1785
1868
|
queryParams,
|
|
1786
1869
|
mappers
|
|
1787
1870
|
} = action;
|
|
1871
|
+
|
|
1788
1872
|
try {
|
|
1789
1873
|
const state = yield select();
|
|
1790
1874
|
let result = {};
|
|
1791
1875
|
let featuredResult;
|
|
1792
1876
|
let featuredQuery;
|
|
1793
1877
|
const customApi = getCustomApi(state, facet, context, 'js');
|
|
1878
|
+
|
|
1794
1879
|
if (customApi) {
|
|
1795
1880
|
const apiParams = typeof mappers === 'object' && typeof mappers.customApi === 'function' && mappers.customApi(queryParams) || mapQueryParamsToCustomApi(queryParams);
|
|
1796
1881
|
result.payload = yield callCustomApi(customApi, apiParams);
|
|
@@ -1798,16 +1883,19 @@ function* executeSearch(action) {
|
|
|
1798
1883
|
} else {
|
|
1799
1884
|
if (queryParams.featuredResults) {
|
|
1800
1885
|
featuredQuery = searchQuery(queryParams, true);
|
|
1801
|
-
featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1802
|
-
|
|
1886
|
+
featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env); // eslint-disable-next-line require-atomic-updates
|
|
1887
|
+
|
|
1803
1888
|
queryParams.excludeIds = getItemsFromResult(featuredResult).map(fi => {
|
|
1804
1889
|
var _fi$sys;
|
|
1890
|
+
|
|
1805
1891
|
return fi === null || fi === void 0 ? void 0 : (_fi$sys = fi.sys) === null || _fi$sys === void 0 ? void 0 : _fi$sys.id;
|
|
1806
1892
|
}).filter(fi => typeof fi === 'string');
|
|
1807
1893
|
}
|
|
1894
|
+
|
|
1808
1895
|
const query = searchQuery(queryParams);
|
|
1809
1896
|
result = yield timedSearch(query, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1810
1897
|
}
|
|
1898
|
+
|
|
1811
1899
|
const createStateFrom = {
|
|
1812
1900
|
action,
|
|
1813
1901
|
featuredResult,
|
|
@@ -1823,6 +1911,7 @@ function* executeSearch(action) {
|
|
|
1823
1911
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1824
1912
|
}
|
|
1825
1913
|
}
|
|
1914
|
+
|
|
1826
1915
|
function* preloadOtherFacets(action) {
|
|
1827
1916
|
const {
|
|
1828
1917
|
preload,
|
|
@@ -1832,19 +1921,18 @@ function* preloadOtherFacets(action) {
|
|
|
1832
1921
|
} = action;
|
|
1833
1922
|
const state = yield select();
|
|
1834
1923
|
const currentFacet = getCurrentFacet(state);
|
|
1924
|
+
|
|
1835
1925
|
if (!preload && facet === currentFacet && context !== Context.listings) {
|
|
1836
1926
|
const allFacets = getFacets(state, 'js');
|
|
1837
1927
|
const otherFacets = Object.keys(allFacets).filter(f => f !== currentFacet);
|
|
1838
1928
|
yield all(otherFacets.map((preloadFacet = '') => {
|
|
1839
|
-
const preloadAction = {
|
|
1840
|
-
...action,
|
|
1929
|
+
const preloadAction = { ...action,
|
|
1841
1930
|
facet: preloadFacet,
|
|
1842
1931
|
preload: true
|
|
1843
1932
|
};
|
|
1844
1933
|
const [queryParams, runSearch] = generateQueryParams(preloadAction, state);
|
|
1845
1934
|
if (debug && (debug === true || debug.preloadOtherFacets)) debugExecuteSearch(preloadAction, state);
|
|
1846
|
-
return runSearch && call(executeSearch, {
|
|
1847
|
-
...action,
|
|
1935
|
+
return runSearch && call(executeSearch, { ...action,
|
|
1848
1936
|
type: EXECUTE_SEARCH_PRELOAD,
|
|
1849
1937
|
preload: true,
|
|
1850
1938
|
facet: preloadFacet,
|
|
@@ -1853,6 +1941,7 @@ function* preloadOtherFacets(action) {
|
|
|
1853
1941
|
}));
|
|
1854
1942
|
}
|
|
1855
1943
|
}
|
|
1944
|
+
|
|
1856
1945
|
function* updateCurrentTab(action) {
|
|
1857
1946
|
const {
|
|
1858
1947
|
id,
|
|
@@ -1862,16 +1951,19 @@ function* updateCurrentTab(action) {
|
|
|
1862
1951
|
const facets = getFacets(state, 'js');
|
|
1863
1952
|
const tabs = getSearchTabs(state, 'js');
|
|
1864
1953
|
let nextFacet = tabs === null || tabs === void 0 ? void 0 : tabs[id].currentFacet;
|
|
1954
|
+
|
|
1865
1955
|
if (!nextFacet) {
|
|
1866
1956
|
Object.entries(facets).map(([facetName, facet]) => {
|
|
1867
1957
|
if (facet.tabId === id && (tabs === null || tabs === void 0 ? void 0 : tabs[id].defaultFacet) === facetName) nextFacet = facetName;
|
|
1868
1958
|
});
|
|
1869
|
-
}
|
|
1870
|
-
// If the next Tab does not have a defaultFacet,
|
|
1959
|
+
} // If the next Tab does not have a defaultFacet,
|
|
1871
1960
|
// take the first facet for that tab
|
|
1961
|
+
|
|
1962
|
+
|
|
1872
1963
|
if (!nextFacet) nextFacet = Object.entries(facets).filter(([, f]) => f.tabId === id)[0][0];
|
|
1873
1964
|
yield put(withMappers(updateCurrentFacet$1(nextFacet), mappers));
|
|
1874
1965
|
}
|
|
1966
|
+
|
|
1875
1967
|
function* clearFilters(action) {
|
|
1876
1968
|
const {
|
|
1877
1969
|
mappers
|
|
@@ -1879,6 +1971,7 @@ function* clearFilters(action) {
|
|
|
1879
1971
|
const uri = yield buildUri({}, mappers);
|
|
1880
1972
|
yield put(navigate(uri));
|
|
1881
1973
|
}
|
|
1974
|
+
|
|
1882
1975
|
function* updateCurrentFacet(action) {
|
|
1883
1976
|
const {
|
|
1884
1977
|
facet,
|
|
@@ -1891,6 +1984,7 @@ function* updateCurrentFacet(action) {
|
|
|
1891
1984
|
}, mappers);
|
|
1892
1985
|
yield put(navigate(uri));
|
|
1893
1986
|
}
|
|
1987
|
+
|
|
1894
1988
|
function* updateSearchTerm(action) {
|
|
1895
1989
|
const {
|
|
1896
1990
|
term,
|
|
@@ -1901,6 +1995,7 @@ function* updateSearchTerm(action) {
|
|
|
1901
1995
|
}, mappers);
|
|
1902
1996
|
yield put(navigate(uri));
|
|
1903
1997
|
}
|
|
1998
|
+
|
|
1904
1999
|
function* updateSortOrder(action) {
|
|
1905
2000
|
const {
|
|
1906
2001
|
orderBy,
|
|
@@ -1913,6 +2008,7 @@ function* updateSortOrder(action) {
|
|
|
1913
2008
|
}, mappers);
|
|
1914
2009
|
yield put(navigate(uri));
|
|
1915
2010
|
}
|
|
2011
|
+
|
|
1916
2012
|
function* updatePageIndex(action) {
|
|
1917
2013
|
const {
|
|
1918
2014
|
pageIndex,
|
|
@@ -1925,6 +2021,7 @@ function* updatePageIndex(action) {
|
|
|
1925
2021
|
yield put(navigate(uri));
|
|
1926
2022
|
if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
|
|
1927
2023
|
}
|
|
2024
|
+
|
|
1928
2025
|
function* updatePageSize(action) {
|
|
1929
2026
|
const {
|
|
1930
2027
|
pageSize,
|
|
@@ -1937,6 +2034,7 @@ function* updatePageSize(action) {
|
|
|
1937
2034
|
yield put(navigate(uri));
|
|
1938
2035
|
if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
|
|
1939
2036
|
}
|
|
2037
|
+
|
|
1940
2038
|
function* applySearchFilter(action) {
|
|
1941
2039
|
const {
|
|
1942
2040
|
mappers,
|
|
@@ -1946,6 +2044,7 @@ function* applySearchFilter(action) {
|
|
|
1946
2044
|
yield put(navigate(uri));
|
|
1947
2045
|
if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
|
|
1948
2046
|
}
|
|
2047
|
+
|
|
1949
2048
|
function* buildUri({
|
|
1950
2049
|
facet,
|
|
1951
2050
|
orderBy,
|
|
@@ -1962,10 +2061,11 @@ function* buildUri({
|
|
|
1962
2061
|
pageIndex,
|
|
1963
2062
|
pageSize,
|
|
1964
2063
|
term
|
|
1965
|
-
});
|
|
1966
|
-
|
|
2064
|
+
}); // return uri;
|
|
2065
|
+
|
|
1967
2066
|
return `${uri.path}${uri.search && `?${uri.search}` || ''}${uri.hash && `#${uri.hash}` || ''}`;
|
|
1968
2067
|
}
|
|
2068
|
+
|
|
1969
2069
|
function* triggerMinilistSsr(options) {
|
|
1970
2070
|
yield call(doSearch, {
|
|
1971
2071
|
type: DO_SEARCH,
|
|
@@ -1980,4 +2080,4 @@ function* triggerSearchSsr(options) {
|
|
|
1980
2080
|
}
|
|
1981
2081
|
|
|
1982
2082
|
export { EXECUTE_SEARCH as $, clearFilters$1 as A, updateCurrentFacet$1 as B, updateCurrentTab$1 as C, updatePageIndex$1 as D, updatePageSize$1 as E, updateSearchTerm$1 as F, updateSelectedFilters as G, updateSortOrder$1 as H, selectListing as I, mapStateToSearchUri as J, Context as K, selectFacets as L, triggerSearch as M, getFilters as N, toArray as O, UPDATE_SELECTED_FILTERS as P, UPDATE_SEARCH_TERM as Q, UPDATE_PAGE_SIZE as R, UPDATE_PAGE_INDEX as S, SET_SEARCH_FILTERS as T, UPDATE_SORT_ORDER as U, SET_SEARCH_ENTRIES as V, SET_ROUTE_FILTERS as W, LOAD_FILTERS_COMPLETE as X, LOAD_FILTERS_ERROR as Y, LOAD_FILTERS as Z, EXECUTE_SEARCH_ERROR as _, customWhereExpressions as a, CLEAR_FILTERS as a0, APPLY_CONFIG as a1, actions as a2, selectors as a3, types as a4, expressions as a5, queries as a6, doSearch as a7, setRouteFilters as a8, searchSagas as a9, triggerListingSsr as aa, triggerMinilistSsr as ab, triggerSearchSsr as ac, routeParams as ad, getPageIndex as b, contentTypeIdExpression as c, defaultExpressions as d, getCurrentTab as e, filterExpressions as f, getCurrentFacet as g, getFacet as h, getTabFacets as i, getFacetsTotalCount as j, getFacetTitles as k, getFeaturedResults as l, getRenderableFilters as m, getIsLoading as n, orderByExpression as o, getPaging as p, getPageIsLoading as q, getResults as r, getSearchTerm as s, termExpressions as t, getSearchTotalCount as u, getSelectedFilters as v, getQueryParameter as w, getTabsAndFacets as x, getTotalCount as y, withMappers as z };
|
|
1983
|
-
//# sourceMappingURL=sagas-
|
|
2083
|
+
//# sourceMappingURL=sagas-07e82e18.js.map
|