@zengenti/contensis-react-base 3.0.2-beta.4 → 3.0.2-beta.6
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-a2783f8b.js → App-2a7a16ad.js} +110 -429
- package/cjs/App-2a7a16ad.js.map +1 -0
- package/cjs/ContensisDeliveryApi-de88df2a.js +231 -0
- package/cjs/ContensisDeliveryApi-de88df2a.js.map +1 -0
- package/cjs/{RouteLoader-3aa6456e.js → RouteLoader-47d70a26.js} +23 -37
- package/{esm/RouteLoader-5171c63f.js.map → cjs/RouteLoader-47d70a26.js.map} +1 -1
- package/cjs/{ToJs-a9a8522b.js → ToJs-61c03582.js} +3 -4
- package/cjs/{ToJs-a9a8522b.js.map → ToJs-61c03582.js.map} +1 -1
- package/cjs/client.js +20 -27
- package/cjs/client.js.map +1 -1
- package/cjs/contensis-react-base.js +124 -188
- package/cjs/contensis-react-base.js.map +1 -1
- package/cjs/forms.js +11 -153
- package/cjs/forms.js.map +1 -1
- package/cjs/{fromJSLeaveImmer-e74c673c.js → fromJSLeaveImmer-7c363211.js} +1 -4
- package/cjs/{fromJSLeaveImmer-e74c673c.js.map → fromJSLeaveImmer-7c363211.js.map} +1 -1
- package/cjs/{login-e711a19e.js → login-2ea569cc.js} +60 -112
- package/cjs/{login-e711a19e.js.map → login-2ea569cc.js.map} +1 -1
- package/cjs/{reducers-73a03ef4.js → reducers-9afb5f89.js} +10 -31
- package/{esm/reducers-aa8cef1e.js.map → cjs/reducers-9afb5f89.js.map} +1 -1
- package/cjs/redux.js +17 -17
- package/cjs/redux.js.map +1 -1
- package/cjs/routing.js +6 -7
- package/cjs/routing.js.map +1 -1
- package/cjs/{sagas-8a20e424.js → sagas-6d12e7ca.js} +182 -282
- package/{esm/sagas-e576b6f6.js.map → cjs/sagas-6d12e7ca.js.map} +1 -1
- package/cjs/search.js +56 -82
- package/cjs/search.js.map +1 -1
- package/cjs/{selectors-656da4b7.js → selectors-c76c2676.js} +84 -7
- package/cjs/selectors-c76c2676.js.map +1 -0
- package/cjs/urls-6fcaf4c6.js.map +1 -1
- package/cjs/user.js +4 -13
- package/cjs/user.js.map +1 -1
- package/cjs/util.js +45 -53
- package/cjs/util.js.map +1 -1
- package/cjs/{version-bf9ef45e.js → version-38afaf2a.js} +45 -158
- package/cjs/version-38afaf2a.js.map +1 -0
- package/cjs/version-886f49d8.js +98 -0
- package/cjs/version-886f49d8.js.map +1 -0
- package/esm/{App-17d1ac3c.js → App-4fb1fc44.js} +92 -409
- package/esm/App-4fb1fc44.js.map +1 -0
- package/esm/ContensisDeliveryApi-ad06857d.js +227 -0
- package/esm/ContensisDeliveryApi-ad06857d.js.map +1 -0
- package/esm/{RouteLoader-5171c63f.js → RouteLoader-f5d5f733.js} +22 -36
- package/{cjs/RouteLoader-3aa6456e.js.map → esm/RouteLoader-f5d5f733.js.map} +1 -1
- package/esm/{ToJs-4e02a04d.js → ToJs-0066e629.js} +3 -4
- package/esm/{ToJs-4e02a04d.js.map → ToJs-0066e629.js.map} +1 -1
- package/esm/client.js +15 -22
- package/esm/client.js.map +1 -1
- package/esm/contensis-react-base.js +119 -183
- package/esm/contensis-react-base.js.map +1 -1
- package/esm/forms.js +11 -153
- package/esm/forms.js.map +1 -1
- package/esm/{fromJSLeaveImmer-0114ffcf.js → fromJSLeaveImmer-e2dacd63.js} +1 -4
- package/esm/{fromJSLeaveImmer-0114ffcf.js.map → fromJSLeaveImmer-e2dacd63.js.map} +1 -1
- package/esm/{login-551d243a.js → login-bffb081f.js} +59 -111
- package/esm/{login-551d243a.js.map → login-bffb081f.js.map} +1 -1
- package/esm/{reducers-aa8cef1e.js → reducers-3d5c37d1.js} +10 -31
- package/{cjs/reducers-73a03ef4.js.map → esm/reducers-3d5c37d1.js.map} +1 -1
- package/esm/redux.js +9 -8
- package/esm/redux.js.map +1 -1
- package/esm/routing.js +3 -4
- package/esm/routing.js.map +1 -1
- package/esm/{sagas-e576b6f6.js → sagas-53d2aefb.js} +134 -235
- package/{cjs/sagas-8a20e424.js.map → esm/sagas-53d2aefb.js.map} +1 -1
- package/esm/search.js +57 -83
- package/esm/search.js.map +1 -1
- package/esm/{selectors-a5e5835b.js → selectors-3f0d804d.js} +70 -7
- package/esm/selectors-3f0d804d.js.map +1 -0
- package/esm/urls-eac9a747.js.map +1 -1
- package/esm/user.js +6 -15
- package/esm/user.js.map +1 -1
- package/esm/util.js +42 -53
- package/esm/util.js.map +1 -1
- package/esm/{version-72ca17f3.js → version-dd31c7f0.js} +32 -141
- package/esm/version-dd31c7f0.js.map +1 -0
- package/esm/version-f4629693.js +87 -0
- package/esm/version-f4629693.js.map +1 -0
- package/models/app/pages/VersionInfo/components/VersionInfo.styled.d.ts +2 -1
- package/models/user/components.styled/Login.styled.d.ts +1 -1
- package/models/user/components.styled/LoginForm.styled.d.ts +1 -1
- package/models/util/ContensisDeliveryApi.d.ts +6 -0
- package/models/util/index.d.ts +1 -0
- package/package.json +2 -2
- package/cjs/App-a2783f8b.js.map +0 -1
- package/cjs/actions-8dc9e8de.js +0 -87
- package/cjs/actions-8dc9e8de.js.map +0 -1
- package/cjs/selectors-656da4b7.js.map +0 -1
- package/cjs/version-bf9ef45e.js.map +0 -1
- package/cjs/version-eba6d09b.js +0 -20
- package/cjs/version-eba6d09b.js.map +0 -1
- package/esm/App-17d1ac3c.js.map +0 -1
- package/esm/actions-180948dd.js +0 -72
- package/esm/actions-180948dd.js.map +0 -1
- package/esm/selectors-a5e5835b.js.map +0 -1
- package/esm/version-2485e2fb.js +0 -15
- package/esm/version-2485e2fb.js.map +0 -1
- package/esm/version-72ca17f3.js.map +0 -1
|
@@ -55,7 +55,8 @@ var types = /*#__PURE__*/Object.freeze({
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
const withMappers = (action, mappers) => {
|
|
58
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
...action,
|
|
59
60
|
mappers
|
|
60
61
|
};
|
|
61
62
|
};
|
|
@@ -175,38 +176,33 @@ var actions = /*#__PURE__*/Object.freeze({
|
|
|
175
176
|
updateSortOrder: updateSortOrder$1
|
|
176
177
|
});
|
|
177
178
|
|
|
178
|
-
let Context
|
|
179
|
-
|
|
180
|
-
(function (Context) {
|
|
179
|
+
let Context = /*#__PURE__*/function (Context) {
|
|
181
180
|
Context["facets"] = "facets";
|
|
182
181
|
Context["listings"] = "listings";
|
|
183
182
|
Context["minilist"] = "minilist";
|
|
184
|
-
|
|
183
|
+
return Context;
|
|
184
|
+
}({});
|
|
185
|
+
// export type Context = 'facets' | 'listings' | 'minilist';
|
|
185
186
|
|
|
187
|
+
// Find a fromJS function from global that is dynamically loaded in createStore
|
|
186
188
|
// or replace with a stub function for non-immutable gets
|
|
187
|
-
|
|
188
189
|
const makeFromJS = (returnType = globalThis.STATE_TYPE || 'immutable') => {
|
|
189
190
|
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
|
-
|
|
194
193
|
const getImmutableOrJS = (state, stateKey, fallbackValue, returnType = globalThis.STATE_TYPE || 'immutable') => {
|
|
195
194
|
// Find a fromJS function from global that is dynamically loaded in createStore
|
|
196
195
|
// or replace with a stub function for non-immutable gets
|
|
197
196
|
const fromJS = makeFromJS(returnType);
|
|
198
|
-
|
|
199
197
|
if (state && 'get' in state && typeof state.get === 'function' && 'getIn' in state && typeof state.getIn === 'function' && 'toJS' in state && typeof state.toJS === 'function') {
|
|
200
198
|
if (Array.isArray(stateKey)) return fromJS(state.getIn(stateKey, fallbackValue));
|
|
201
199
|
return fromJS(state.get(stateKey, fallbackValue));
|
|
202
200
|
}
|
|
203
|
-
|
|
204
201
|
if (Array.isArray(stateKey) && state && typeof state === 'object') {
|
|
205
202
|
const result = jpath(stateKey.join('.'), state);
|
|
206
203
|
if (typeof result === 'undefined') return fallbackValue;
|
|
207
204
|
return result;
|
|
208
205
|
}
|
|
209
|
-
|
|
210
206
|
const result = state && typeof state === 'object' ? state[stateKey] : undefined;
|
|
211
207
|
if (typeof result === 'undefined') return fallbackValue;
|
|
212
208
|
return result;
|
|
@@ -221,7 +217,6 @@ const getFacets = (state, returnType) => getImmutableOrJS(state, ['search', Cont
|
|
|
221
217
|
const getTabFacets = state => Object.fromEntries(Object.entries(getFacets(state, 'js')).filter(([key]) => getImmutableOrJS(getFacets(state), [key, 'tabId'], 0) === getCurrentTab(state)));
|
|
222
218
|
const getFacetTitles = state => Object.entries(getFacets(state, 'js')).map(([key, facet = {}]) => {
|
|
223
219
|
var _facet$pagingInfo;
|
|
224
|
-
|
|
225
220
|
return {
|
|
226
221
|
isSelected: getCurrentFacet(state) === key,
|
|
227
222
|
key,
|
|
@@ -248,8 +243,9 @@ const getFiltersToLoad = (state, facet, context = Context.facets, returnType) =>
|
|
|
248
243
|
return typeof title !== 'undefined' && !!title;
|
|
249
244
|
}).length > 0 && (f.isError || false) === false]);
|
|
250
245
|
return loadedFilters.map(([filterKey, isLoaded]) => !isLoaded ? filterKey : null).filter(f => !!f);
|
|
251
|
-
};
|
|
246
|
+
};
|
|
252
247
|
|
|
248
|
+
// We lowercase the filter key unless it's an ISO date string where the T must be uppercase
|
|
253
249
|
const getSelectedFilters = (state, facet = '', context = Context.facets, returnType) => {
|
|
254
250
|
const filters = getFilters(state, facet, context, 'js');
|
|
255
251
|
const isoDateRegex = RegExp(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d/);
|
|
@@ -287,6 +283,7 @@ const getPageSize = (state, current = '', context = Context.facets) => {
|
|
|
287
283
|
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
|
|
288
284
|
);
|
|
289
285
|
};
|
|
286
|
+
|
|
290
287
|
const getPrevPageIndex = (state, current = '', context = Context.facets) => {
|
|
291
288
|
return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'prevPageIndex']);
|
|
292
289
|
};
|
|
@@ -329,7 +326,8 @@ const getTabsAndFacets = (state, returnType) => {
|
|
|
329
326
|
if (!countFields || countFields.find((f = []) => (f === null || f === void 0 ? void 0 : f[0]) === facetName)) return getImmutableOrJS(facet, ['pagingInfo', 'totalCount']);
|
|
330
327
|
return 0;
|
|
331
328
|
}).reduce((a, b) => a + b, 0);
|
|
332
|
-
return {
|
|
329
|
+
return {
|
|
330
|
+
...tab,
|
|
333
331
|
[Context.facets]: Object.fromEntries(thisTabFacets),
|
|
334
332
|
totalCount: thisTabTotal
|
|
335
333
|
};
|
|
@@ -346,12 +344,12 @@ const getFacetsTotalCount = state => {
|
|
|
346
344
|
const facets = getFacets(state);
|
|
347
345
|
const wholeSearchTotal = Object.entries(facets).map(([, t = {}]) => {
|
|
348
346
|
var _t$pagingInfo;
|
|
349
|
-
|
|
350
347
|
return ((_t$pagingInfo = t.pagingInfo) === null || _t$pagingInfo === void 0 ? void 0 : _t$pagingInfo.totalCount) || 0;
|
|
351
348
|
}).reduce((a, b) => a + b, 0);
|
|
352
349
|
return wholeSearchTotal;
|
|
353
|
-
};
|
|
350
|
+
};
|
|
354
351
|
|
|
352
|
+
// An exported copy of the relevant selectors scoped by default to a facets context
|
|
355
353
|
const selectFacets = {
|
|
356
354
|
getCurrent: getCurrentFacet,
|
|
357
355
|
getCurrentTab,
|
|
@@ -388,8 +386,9 @@ const selectFacets = {
|
|
|
388
386
|
getSearchTerm,
|
|
389
387
|
getSearchTotalCount,
|
|
390
388
|
getSelectedFilters
|
|
391
|
-
};
|
|
389
|
+
};
|
|
392
390
|
|
|
391
|
+
// An exported copy of the relevant selectors pre-scoped to a listing context
|
|
393
392
|
const selectListing = {
|
|
394
393
|
getCurrent: getCurrentListing,
|
|
395
394
|
getFeaturedResults: (state, listing = '') => getFeaturedResults(state, listing, Context.listings, 'js'),
|
|
@@ -470,31 +469,23 @@ const now = () => {
|
|
|
470
469
|
if (typeof window == 'undefined') {
|
|
471
470
|
return Date.now();
|
|
472
471
|
}
|
|
473
|
-
|
|
474
472
|
return window.performance.now();
|
|
475
473
|
};
|
|
476
474
|
|
|
477
475
|
const getClientConfig = (project, env) => {
|
|
478
|
-
let config = DELIVERY_API_CONFIG;
|
|
479
|
-
/* global DELIVERY_API_CONFIG */
|
|
480
|
-
|
|
476
|
+
let config = DELIVERY_API_CONFIG; /* global DELIVERY_API_CONFIG */
|
|
481
477
|
if (project) {
|
|
482
478
|
config.projectId = project;
|
|
483
479
|
}
|
|
484
|
-
|
|
485
|
-
if (typeof window != 'undefined' && PROXY_DELIVERY_API
|
|
486
|
-
/* global PROXY_DELIVERY_API */
|
|
487
|
-
) {
|
|
480
|
+
if (typeof window != 'undefined' && PROXY_DELIVERY_API /* global PROXY_DELIVERY_API */) {
|
|
488
481
|
// ensure a relative url is used to bypass the need for CORS (separate OPTIONS calls)
|
|
489
482
|
config.rootUrl = env || '';
|
|
490
483
|
config.responseHandler = {
|
|
491
484
|
404: () => null
|
|
492
485
|
};
|
|
493
486
|
}
|
|
494
|
-
|
|
495
487
|
return config;
|
|
496
488
|
};
|
|
497
|
-
|
|
498
489
|
class CacheNode {
|
|
499
490
|
constructor(key, value) {
|
|
500
491
|
this.key = key;
|
|
@@ -502,9 +493,7 @@ class CacheNode {
|
|
|
502
493
|
this.next = null;
|
|
503
494
|
this.prev = null;
|
|
504
495
|
}
|
|
505
|
-
|
|
506
496
|
}
|
|
507
|
-
|
|
508
497
|
class LruCache {
|
|
509
498
|
constructor(limit = 100) {
|
|
510
499
|
this.map = {};
|
|
@@ -513,7 +502,6 @@ class LruCache {
|
|
|
513
502
|
this.limit = limit || 100;
|
|
514
503
|
this.size = 0;
|
|
515
504
|
}
|
|
516
|
-
|
|
517
505
|
get(key) {
|
|
518
506
|
if (this.map[key]) {
|
|
519
507
|
let value = this.map[key].value;
|
|
@@ -523,10 +511,8 @@ class LruCache {
|
|
|
523
511
|
return value;
|
|
524
512
|
}
|
|
525
513
|
}
|
|
526
|
-
|
|
527
514
|
set(key, value) {
|
|
528
515
|
let node = new CacheNode(key, value);
|
|
529
|
-
|
|
530
516
|
if (this.map[key]) {
|
|
531
517
|
this.remove(key);
|
|
532
518
|
} else {
|
|
@@ -537,60 +523,46 @@ class LruCache {
|
|
|
537
523
|
this.tail.next = null;
|
|
538
524
|
}
|
|
539
525
|
}
|
|
540
|
-
|
|
541
526
|
this.setHead(node);
|
|
542
527
|
}
|
|
543
|
-
|
|
544
528
|
setHead(node) {
|
|
545
529
|
node.next = this.head;
|
|
546
530
|
node.prev = null;
|
|
547
|
-
|
|
548
531
|
if (this.head) {
|
|
549
532
|
this.head.prev = node;
|
|
550
533
|
}
|
|
551
|
-
|
|
552
534
|
this.head = node;
|
|
553
|
-
|
|
554
535
|
if (!this.tail) {
|
|
555
536
|
this.tail = node;
|
|
556
537
|
}
|
|
557
|
-
|
|
558
538
|
this.size++;
|
|
559
539
|
this.map[node.key] = node;
|
|
560
540
|
}
|
|
561
|
-
|
|
562
541
|
remove(key) {
|
|
563
542
|
let node = this.map[key];
|
|
564
|
-
|
|
565
543
|
if (node.prev) {
|
|
566
544
|
node.prev.next = node.next;
|
|
567
545
|
} else {
|
|
568
546
|
this.head = node.next;
|
|
569
547
|
}
|
|
570
|
-
|
|
571
548
|
if (node.next) {
|
|
572
549
|
node.next.prev = node.prev;
|
|
573
550
|
} else {
|
|
574
551
|
this.tail = node.prev;
|
|
575
552
|
}
|
|
576
|
-
|
|
577
553
|
delete this.map[key];
|
|
578
554
|
this.size--;
|
|
579
555
|
}
|
|
580
|
-
|
|
581
556
|
}
|
|
582
|
-
|
|
583
557
|
class CachedSearch {
|
|
584
558
|
constructor() {
|
|
585
559
|
this.cache = new LruCache();
|
|
586
560
|
this.taxonomyLookup = {};
|
|
587
561
|
}
|
|
588
|
-
|
|
589
562
|
search(query, linkDepth, project, env) {
|
|
590
563
|
const client = Client.create(getClientConfig(project, env));
|
|
591
564
|
return this.request(project + JSON.stringify(query) + linkDepth.toString(), () => client.entries.search(query, linkDepth));
|
|
592
565
|
}
|
|
593
|
-
|
|
594
566
|
getTaxonomyNodeByPath(path, project, env) {
|
|
595
567
|
const client = Client.create(getClientConfig(project, env));
|
|
596
568
|
return this.request(`[TAXONOMY NODE] ${path}`, () => client.taxonomy.getNodeByPath({
|
|
@@ -599,7 +571,6 @@ class CachedSearch {
|
|
|
599
571
|
childDepth: 2
|
|
600
572
|
}).then(node => this.extendTaxonomyNode(node)));
|
|
601
573
|
}
|
|
602
|
-
|
|
603
574
|
request(key, execute) {
|
|
604
575
|
if (!this.cache.get(key) || typeof window == 'undefined') {
|
|
605
576
|
let promise = execute();
|
|
@@ -608,41 +579,36 @@ class CachedSearch {
|
|
|
608
579
|
this.cache.remove(key);
|
|
609
580
|
});
|
|
610
581
|
}
|
|
611
|
-
|
|
612
582
|
return this.cache.get(key);
|
|
613
583
|
}
|
|
614
|
-
|
|
615
584
|
extendTaxonomyNode(node) {
|
|
616
585
|
let id = this.getTaxonomyId(node);
|
|
617
586
|
this.taxonomyLookup[id] = node.key;
|
|
618
|
-
return {
|
|
587
|
+
return {
|
|
588
|
+
...node,
|
|
619
589
|
id,
|
|
620
590
|
children: node.children ? node.children.map(n => this.extendTaxonomyNode(n)) : null
|
|
621
591
|
};
|
|
622
592
|
}
|
|
623
|
-
|
|
624
593
|
getTaxonomyId(node) {
|
|
625
594
|
if (node.key) {
|
|
626
595
|
let parts = node.key.split('/');
|
|
627
596
|
return parts[parts.length - 1];
|
|
628
597
|
}
|
|
629
|
-
|
|
630
598
|
return '';
|
|
631
599
|
}
|
|
632
|
-
|
|
633
600
|
fetch(uri, opts = {}) {
|
|
634
601
|
return this.request(`[FETCH] ${uri} ${JSON.stringify(opts)}`, () => fetch(uri, opts));
|
|
635
602
|
}
|
|
636
|
-
|
|
637
603
|
}
|
|
638
|
-
|
|
639
604
|
const cachedSearch = new CachedSearch();
|
|
640
605
|
|
|
641
606
|
// eslint-disable-next-line import/default
|
|
642
607
|
function fixFreeTextForElastic(s) {
|
|
643
608
|
const illegalChars = ['>', '<', '=', '|', '!', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', '/'];
|
|
644
609
|
const illegalRegEx = new RegExp(illegalChars.map(c => '\\' + c).join('|'), 'g');
|
|
645
|
-
s = s.replace(illegalRegEx, '');
|
|
610
|
+
s = s.replace(illegalRegEx, '');
|
|
611
|
+
// s = s.replace(encodedRegEx, ''); // (m) => '\\\\' + m);
|
|
646
612
|
|
|
647
613
|
return s;
|
|
648
614
|
}
|
|
@@ -662,13 +628,11 @@ const getItemsFromResult = result => {
|
|
|
662
628
|
const {
|
|
663
629
|
payload
|
|
664
630
|
} = result || {};
|
|
665
|
-
|
|
666
631
|
if (payload) {
|
|
667
632
|
if (Array.isArray(payload)) return payload;
|
|
668
633
|
if (Array.isArray(payload.items)) return payload.items;
|
|
669
634
|
return payload;
|
|
670
635
|
}
|
|
671
|
-
|
|
672
636
|
return [];
|
|
673
637
|
};
|
|
674
638
|
const extractQuotedPhrases = searchTerm => {
|
|
@@ -680,6 +644,7 @@ const buildUrl = (route, params) => {
|
|
|
680
644
|
const path = qs ? `${route}${route.includes('?') ? '&' : '?'}${qs}` : route;
|
|
681
645
|
return path;
|
|
682
646
|
};
|
|
647
|
+
|
|
683
648
|
/**
|
|
684
649
|
* Returns all params from the current route query string or static route
|
|
685
650
|
* Supply static route argument if reading parameters from the route path
|
|
@@ -688,15 +653,14 @@ const buildUrl = (route, params) => {
|
|
|
688
653
|
* @param location location object containing at least pathname and search
|
|
689
654
|
* @returns Keyed params object
|
|
690
655
|
*/
|
|
691
|
-
|
|
692
656
|
const routeParams = (staticRoute, location) => {
|
|
693
657
|
var _staticRoute$match;
|
|
694
|
-
|
|
695
658
|
// match.params is react-router-config/react-router@5 style
|
|
696
659
|
// params is supplied with RouteObject in react-router@6
|
|
697
660
|
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) || {};
|
|
698
661
|
const queryParams = parse(typeof window !== 'undefined' ? window.location.search : (location === null || location === void 0 ? void 0 : location.search) || '');
|
|
699
|
-
return {
|
|
662
|
+
return {
|
|
663
|
+
...pathParams,
|
|
700
664
|
...queryParams
|
|
701
665
|
};
|
|
702
666
|
};
|
|
@@ -704,13 +668,11 @@ const callCustomApi = async (customApi, filters) => {
|
|
|
704
668
|
const apiUri = customApi.uri || '';
|
|
705
669
|
let uri = buildUrl(apiUri, filters);
|
|
706
670
|
if (!uri) throw new Error('uri is required to use customApi');
|
|
707
|
-
|
|
708
671
|
if (typeof window == 'undefined') {
|
|
709
672
|
if (!uri.startsWith('http')) uri = `http://localhost:3001${uri}`;
|
|
710
673
|
const response = await fetch(uri);
|
|
711
674
|
return await response.json();
|
|
712
675
|
}
|
|
713
|
-
|
|
714
676
|
const response = await cachedSearch.fetch(uri);
|
|
715
677
|
return await response.clone().json();
|
|
716
678
|
};
|
|
@@ -718,32 +680,27 @@ const removeEmptyAttributes = obj => {
|
|
|
718
680
|
Object.entries(obj).forEach(([key, val]) => val && typeof val === 'object' && removeEmptyAttributes(val) || (typeof val === 'undefined' || val === null || val === '') && delete obj[key]);
|
|
719
681
|
return obj;
|
|
720
682
|
};
|
|
721
|
-
const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator);
|
|
683
|
+
const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator);
|
|
722
684
|
|
|
685
|
+
// assumes array elements are primitive types
|
|
723
686
|
const areArraysEqualSets = (a1, a2) => {
|
|
724
687
|
const superSet = {};
|
|
725
|
-
|
|
726
688
|
for (const ai of a1) {
|
|
727
689
|
const e = ai + typeof ai;
|
|
728
690
|
superSet[e] = 1;
|
|
729
691
|
}
|
|
730
|
-
|
|
731
692
|
for (const ai of a2) {
|
|
732
693
|
const e = ai + typeof ai;
|
|
733
|
-
|
|
734
694
|
if (!superSet[e]) {
|
|
735
695
|
return false;
|
|
736
696
|
}
|
|
737
|
-
|
|
738
697
|
superSet[e] = 2;
|
|
739
698
|
}
|
|
740
|
-
|
|
741
699
|
for (const e in superSet) {
|
|
742
700
|
if (superSet[e] === 1) {
|
|
743
701
|
return false;
|
|
744
702
|
}
|
|
745
703
|
}
|
|
746
|
-
|
|
747
704
|
return true;
|
|
748
705
|
};
|
|
749
706
|
|
|
@@ -754,12 +711,12 @@ const searchUriTemplate = {
|
|
|
754
711
|
}) => {
|
|
755
712
|
const context = getSearchContext(state);
|
|
756
713
|
const currentPath = selectCurrentPath(state) || '/search';
|
|
757
|
-
|
|
758
714
|
if (context !== 'listings') {
|
|
759
715
|
const currentFacet = facet || getCurrentFacet(state);
|
|
760
716
|
const filters = getSelectedFilters(state, facet, context);
|
|
761
|
-
const currentFilter = filters.contentTypeId;
|
|
717
|
+
const currentFilter = filters.contentTypeId;
|
|
762
718
|
|
|
719
|
+
// Check if we have a filter first
|
|
763
720
|
const newPath = (currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.length) > 0 && currentFacet ? `${currentPath}/${currentFacet}/${currentFilter}` : currentFacet ? `${currentPath}/${currentFacet}` : currentPath;
|
|
764
721
|
return newPath;
|
|
765
722
|
} else {
|
|
@@ -774,29 +731,29 @@ const searchUriTemplate = {
|
|
|
774
731
|
pageIndex,
|
|
775
732
|
pageSize
|
|
776
733
|
}) => {
|
|
777
|
-
const searchContext = getSearchContext(state);
|
|
734
|
+
const searchContext = getSearchContext(state);
|
|
735
|
+
// Lose stateFilters and currentSearch if a new
|
|
778
736
|
// term is passed via an argument
|
|
779
|
-
|
|
780
737
|
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(',')]));
|
|
781
738
|
const currentSearch = !term && getImmutableOrJS(state, ['routing', 'location', 'search']);
|
|
782
739
|
const currentQs = removeEmptyAttributes(parse(currentSearch));
|
|
783
740
|
if (orderBy) currentQs.orderBy = orderBy;
|
|
784
|
-
const searchTerm = getSearchTerm(state);
|
|
741
|
+
const searchTerm = getSearchTerm(state);
|
|
742
|
+
// Use Immutable's merge to merge the stateFilters with any current Qs
|
|
785
743
|
// to build the new Qs.
|
|
786
|
-
|
|
787
744
|
const mergedSearch = removeEmptyAttributes(merge(currentQs, stateFilters));
|
|
788
745
|
if (searchTerm) mergedSearch.term = searchTerm;
|
|
789
746
|
if (pageIndex) mergedSearch.pageIndex = pageIndex + 1;
|
|
790
747
|
if (pageIndex === 0) mergedSearch.pageIndex = undefined;
|
|
791
|
-
if (pageSize) mergedSearch.pageSize = pageSize;
|
|
748
|
+
if (pageSize) mergedSearch.pageSize = pageSize;
|
|
792
749
|
|
|
750
|
+
// We don't want these as search params in the url, we just need the search package to see them
|
|
793
751
|
return stringify(mergedSearch);
|
|
794
752
|
},
|
|
795
753
|
hash: ({
|
|
796
754
|
state
|
|
797
755
|
}) => getImmutableOrJS(state, ['routing', 'location', 'hash'], '').replace('#', '')
|
|
798
756
|
};
|
|
799
|
-
|
|
800
757
|
const mapStateToSearchUri = state => mapJson(state, searchUriTemplate);
|
|
801
758
|
|
|
802
759
|
const DataFormats = {
|
|
@@ -831,7 +788,8 @@ const Fields = {
|
|
|
831
788
|
|
|
832
789
|
const fieldExpression = (field, value, operator = 'equalTo', weight, fuzzySearch = false) => {
|
|
833
790
|
if (!field || !value || Array.isArray(value) && value.length === 0) return [];
|
|
834
|
-
if (Array.isArray(field))
|
|
791
|
+
if (Array.isArray(field))
|
|
792
|
+
// If an array of fieldIds have been provided, call self for each fieldId
|
|
835
793
|
// to generate expressions that are combined with an 'or' operator
|
|
836
794
|
return [Op.or(...field.map(fieldId => fieldExpression(fieldId, value, operator, weight, fuzzySearch)).flat())];
|
|
837
795
|
if (operator === 'between') return between(field, value);
|
|
@@ -840,19 +798,15 @@ const fieldExpression = (field, value, operator = 'equalTo', weight, fuzzySearch
|
|
|
840
798
|
const contentTypeIdExpression = (contentTypeIds, webpageTemplates, assetTypes) => {
|
|
841
799
|
const expressions = [];
|
|
842
800
|
if (!contentTypeIds && !webpageTemplates && !assetTypes) return expressions;
|
|
843
|
-
|
|
844
801
|
if (contentTypeIds && contentTypeIds.length > 0) {
|
|
845
802
|
expressions.push(...dataFormatExpression(contentTypeIds, DataFormats.entry));
|
|
846
803
|
}
|
|
847
|
-
|
|
848
804
|
if (webpageTemplates && webpageTemplates.length > 0) {
|
|
849
805
|
expressions.push(...dataFormatExpression(webpageTemplates, DataFormats.webpage));
|
|
850
806
|
}
|
|
851
|
-
|
|
852
807
|
if (assetTypes && assetTypes.length > 0) {
|
|
853
808
|
expressions.push(...dataFormatExpression(assetTypes, DataFormats.asset));
|
|
854
809
|
}
|
|
855
|
-
|
|
856
810
|
if (expressions.length > 1) return [Op.or(...expressions)];
|
|
857
811
|
return expressions;
|
|
858
812
|
};
|
|
@@ -860,14 +814,16 @@ const filterExpressions = (filters, isOptional = false) => {
|
|
|
860
814
|
if (!filters) return [];
|
|
861
815
|
const expressions = [];
|
|
862
816
|
filters.map(selectedFilter => {
|
|
863
|
-
if (selectedFilter.logicOperator === 'and')
|
|
817
|
+
if (selectedFilter.logicOperator === 'and')
|
|
818
|
+
// using 'and' logic operator we loop through each filter
|
|
864
819
|
// and loop through all values to add an expression for each filter value
|
|
865
820
|
selectedFilter.values.forEach(value => expressions.push(...fieldExpression(selectedFilter.key, value, selectedFilter.fieldOperator || 'equalTo')));else if (selectedFilter.logicOperator === 'not') {
|
|
866
821
|
const fieldExpressions = fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in');
|
|
867
822
|
fieldExpressions.forEach(expr => {
|
|
868
823
|
expressions.push(Op.not(expr));
|
|
869
824
|
});
|
|
870
|
-
}
|
|
825
|
+
}
|
|
826
|
+
// using 'or' logic operator we loop over each filter
|
|
871
827
|
// and simply add the array of values to an expression with an 'in' operator
|
|
872
828
|
else expressions.push(...fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in'));
|
|
873
829
|
if (isOptional) expressions.push(Op.not(fieldExpression(selectedFilter.key, true, 'exists')[0]));
|
|
@@ -891,7 +847,6 @@ const dataFormatExpression = (contentTypeIds, dataFormat = DataFormats.entry) =>
|
|
|
891
847
|
if (notContentTypeIds.length > 0 && notExpr) andExpr.add(notExpr);
|
|
892
848
|
return [andExpr];
|
|
893
849
|
}
|
|
894
|
-
|
|
895
850
|
return [];
|
|
896
851
|
};
|
|
897
852
|
const featuredResultsExpression = ({
|
|
@@ -900,24 +855,22 @@ const featuredResultsExpression = ({
|
|
|
900
855
|
fieldValue = true
|
|
901
856
|
} = {}) => {
|
|
902
857
|
const expressions = [];
|
|
903
|
-
|
|
904
858
|
if (contentTypeId) {
|
|
905
859
|
expressions.push(...contentTypeIdExpression(Array.isArray(contentTypeId) ? contentTypeId : [contentTypeId]));
|
|
906
860
|
}
|
|
907
|
-
|
|
908
861
|
if (fieldId && fieldValue) {
|
|
909
862
|
expressions.push(...fieldExpression(fieldId, fieldValue));
|
|
910
863
|
}
|
|
911
|
-
|
|
912
864
|
return expressions;
|
|
913
865
|
};
|
|
914
866
|
const languagesExpression = languages => fieldExpression(Fields.sys.language, languages);
|
|
915
867
|
const includeInSearchExpressions = (webpageTemplates, includeInSearchFields) => {
|
|
916
|
-
const expressions = [];
|
|
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))));
|
|
917
871
|
|
|
918
|
-
|
|
872
|
+
// If webpageTemplates have been specified, include this expression
|
|
919
873
|
// with the default includeInSearch field from classic Contensis.
|
|
920
|
-
|
|
921
874
|
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)));
|
|
922
875
|
return expressions;
|
|
923
876
|
};
|
|
@@ -937,69 +890,52 @@ const excludeIdsExpression = excludeIds => {
|
|
|
937
890
|
};
|
|
938
891
|
const orderByExpression = orderBy => {
|
|
939
892
|
let expression;
|
|
940
|
-
|
|
941
893
|
if (orderBy && orderBy.length > 0) {
|
|
942
894
|
expression = OrderBy;
|
|
943
|
-
|
|
944
895
|
for (const ob of orderBy) {
|
|
945
896
|
var _expression, _expression2;
|
|
946
|
-
|
|
947
897
|
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);
|
|
948
898
|
}
|
|
949
899
|
}
|
|
950
|
-
|
|
951
900
|
return expression;
|
|
952
901
|
};
|
|
953
|
-
|
|
954
902
|
const equalToOrIn = (field, value, operator = 'equalTo', fuzzySearch = false) => {
|
|
955
903
|
if (value.length === 0) return [];
|
|
956
|
-
|
|
957
904
|
if (Array.isArray(value)) {
|
|
958
905
|
if (operator === 'equalTo' || operator === 'in') return [Op.in(field, ...value)];
|
|
959
906
|
const expressions = value.map(innerValue => {
|
|
960
907
|
var _between, _distanceWithin;
|
|
961
|
-
|
|
962
908
|
switch (operator) {
|
|
963
909
|
case 'between':
|
|
964
910
|
return (_between = between(field, innerValue)) === null || _between === void 0 ? void 0 : _between[0];
|
|
965
|
-
|
|
966
911
|
case 'distanceWithin':
|
|
967
912
|
return (_distanceWithin = distanceWithin(field, innerValue)) === null || _distanceWithin === void 0 ? void 0 : _distanceWithin[0];
|
|
968
|
-
|
|
969
913
|
case 'exists':
|
|
970
914
|
return Op.exists(field, innerValue);
|
|
971
|
-
|
|
972
915
|
case 'freeText':
|
|
973
916
|
// TODO: Potentially needs further implementation of new options
|
|
974
917
|
return Op[operator](field, innerValue, fuzzySearch, undefined);
|
|
975
|
-
|
|
976
918
|
default:
|
|
977
919
|
return Op[operator](field, innerValue);
|
|
978
920
|
}
|
|
979
921
|
});
|
|
980
922
|
return (expressions === null || expressions === void 0 ? void 0 : expressions.length) > 1 ? [Op.or(...expressions)] : expressions || [];
|
|
981
923
|
}
|
|
982
|
-
|
|
983
924
|
switch (operator) {
|
|
984
925
|
case 'between':
|
|
985
926
|
return between(field, value);
|
|
986
|
-
|
|
987
927
|
case 'distanceWithin':
|
|
988
928
|
return distanceWithin(field, value);
|
|
989
|
-
|
|
990
929
|
case 'freeText':
|
|
991
930
|
// TODO: Potentially needs further implementation of new options
|
|
992
931
|
return [Op.freeText(field, value, fuzzySearch, undefined)];
|
|
993
|
-
|
|
994
932
|
default:
|
|
995
933
|
return [Op[operator](field, value)];
|
|
996
934
|
}
|
|
997
935
|
};
|
|
998
|
-
|
|
999
936
|
const between = (field, value) => {
|
|
1000
937
|
const handle = betweenValue => {
|
|
1001
938
|
const valArr = betweenValue.split('--');
|
|
1002
|
-
|
|
1003
939
|
if (valArr.length > 1) {
|
|
1004
940
|
const [minimum, maximum] = valArr;
|
|
1005
941
|
return Op.between(field, minimum, maximum);
|
|
@@ -1009,17 +945,14 @@ const between = (field, value) => {
|
|
|
1009
945
|
return false;
|
|
1010
946
|
}
|
|
1011
947
|
};
|
|
1012
|
-
|
|
1013
948
|
if (value.length === 0) return [];
|
|
1014
949
|
if (Array.isArray(value)) return [Op.or(...value.map(handle).filter(bc => bc !== false))];
|
|
1015
950
|
const op = handle(value);
|
|
1016
951
|
return op ? [op] : [];
|
|
1017
952
|
};
|
|
1018
|
-
|
|
1019
953
|
const distanceWithin = (field, value) => {
|
|
1020
954
|
const handle = distanceValue => {
|
|
1021
955
|
const valArr = distanceValue.split(' ');
|
|
1022
|
-
|
|
1023
956
|
if (valArr.length > 1) {
|
|
1024
957
|
const [lat, lon] = valArr;
|
|
1025
958
|
return Op.distanceWithin(field, Number(lat), Number(lon), (valArr === null || valArr === void 0 ? void 0 : valArr[2]) || '10mi');
|
|
@@ -1029,28 +962,27 @@ const distanceWithin = (field, value) => {
|
|
|
1029
962
|
return false;
|
|
1030
963
|
}
|
|
1031
964
|
};
|
|
1032
|
-
|
|
1033
965
|
if (value.length === 0) return [];
|
|
1034
966
|
if (Array.isArray(value)) return [Op.or(...value.map(handle).filter(bc => bc !== false))];
|
|
1035
967
|
const op = handle(value);
|
|
1036
968
|
return op ? [op] : [];
|
|
1037
969
|
};
|
|
970
|
+
|
|
1038
971
|
/**
|
|
1039
972
|
* Accept HTTP style objects and map them to
|
|
1040
973
|
* their equivalent JS client "Op" expressions
|
|
1041
974
|
* @param {array} where the where array as you'd provide it to the HTTP API
|
|
1042
975
|
* @returns {array} array of constructed Delivery API Operators
|
|
1043
976
|
*/
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
977
|
const customWhereExpressions = where => {
|
|
1047
|
-
if (!where || !Array.isArray(where)) return [];
|
|
978
|
+
if (!where || !Array.isArray(where)) return [];
|
|
1048
979
|
|
|
980
|
+
// Map each clause inside the where array
|
|
1049
981
|
return where.map(clause => {
|
|
1050
|
-
let expression;
|
|
982
|
+
let expression;
|
|
983
|
+
// Map through each property in the clause so we can
|
|
1051
984
|
// capture the values required and reconstruct them as
|
|
1052
985
|
// a Delivery API expression
|
|
1053
|
-
|
|
1054
986
|
let operator;
|
|
1055
987
|
Object.keys(clause).map((key, idx) => {
|
|
1056
988
|
// The clause may contain only one key
|
|
@@ -1058,7 +990,6 @@ const customWhereExpressions = where => {
|
|
|
1058
990
|
const field = clause.field;
|
|
1059
991
|
const value = clause[Object.keys(clause).find(k => !['field', 'weight'].includes(k)) || ''];
|
|
1060
992
|
const weight = clause.weight;
|
|
1061
|
-
|
|
1062
993
|
if (idx === 0) {
|
|
1063
994
|
if (operator === 'and' || operator === 'or') {
|
|
1064
995
|
// These are array expressions so we can call ourself recursively
|
|
@@ -1066,24 +997,21 @@ const customWhereExpressions = where => {
|
|
|
1066
997
|
const recurseExpr = customWhereExpressions(clause[operator]);
|
|
1067
998
|
expression = Op[operator](...recurseExpr);
|
|
1068
999
|
}
|
|
1069
|
-
|
|
1070
1000
|
if (['not'].includes(operator)) {
|
|
1071
1001
|
// A 'not' expression is an object with only one inner field and inner operator
|
|
1072
1002
|
Object.keys(value).map((notKey, notIdx) => {
|
|
1073
1003
|
const innerOperator = notKey;
|
|
1074
1004
|
const innerValue = value[notKey];
|
|
1075
|
-
const innerField = value.field;
|
|
1005
|
+
const innerField = value.field;
|
|
1006
|
+
// Map the expression when we've looped and scoped to
|
|
1076
1007
|
// the second property inside the clause
|
|
1077
|
-
|
|
1078
1008
|
if (notIdx === 1) expression = Op.not(makeJsExpression(innerOperator, innerField, innerValue));
|
|
1079
1009
|
});
|
|
1080
1010
|
}
|
|
1081
|
-
}
|
|
1011
|
+
}
|
|
1012
|
+
// Map the expression when we've looped and scoped to
|
|
1082
1013
|
// the second property inside the clause
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
1014
|
operator = Object.keys(clause).find(clauseKey => !['field', 'weight'].includes(clauseKey));
|
|
1086
|
-
|
|
1087
1015
|
if (idx === 1) {
|
|
1088
1016
|
expression = makeJsExpression(operator, field, value);
|
|
1089
1017
|
if (typeof weight === 'number') expression = expression.weight(weight);
|
|
@@ -1092,28 +1020,29 @@ const customWhereExpressions = where => {
|
|
|
1092
1020
|
return expression;
|
|
1093
1021
|
});
|
|
1094
1022
|
};
|
|
1095
|
-
|
|
1096
1023
|
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
|
-
|
|
1098
1024
|
const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch) => {
|
|
1099
1025
|
if (searchTerm && weightedSearchFields && weightedSearchFields.length > 0) {
|
|
1100
1026
|
// Extract any phrases in quotes to array
|
|
1101
|
-
const quotedPhrases = extractQuotedPhrases(searchTerm);
|
|
1027
|
+
const quotedPhrases = extractQuotedPhrases(searchTerm);
|
|
1102
1028
|
|
|
1029
|
+
// Modify the search term to remove any quoted phrases to leave any remaining terms
|
|
1103
1030
|
let modifiedSearchTerm = searchTerm;
|
|
1104
|
-
quotedPhrases.forEach(qp => modifiedSearchTerm = modifiedSearchTerm.replace(qp, '').replace('""', '').trim());
|
|
1031
|
+
quotedPhrases.forEach(qp => modifiedSearchTerm = modifiedSearchTerm.replace(qp, '').replace('""', '').trim());
|
|
1105
1032
|
|
|
1106
|
-
|
|
1033
|
+
// Push to the operators array to include in the query
|
|
1034
|
+
const operators = [];
|
|
1107
1035
|
|
|
1036
|
+
// Helper functions to generate Op expressions
|
|
1108
1037
|
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);
|
|
1109
1039
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1040
|
+
// For each weighted search field
|
|
1113
1041
|
weightedSearchFields.forEach(wsf => {
|
|
1114
1042
|
// Push to field operators
|
|
1115
|
-
const fieldOperators = [];
|
|
1043
|
+
const fieldOperators = [];
|
|
1116
1044
|
|
|
1045
|
+
// Add operator expressions for modified search term
|
|
1117
1046
|
if (modifiedSearchTerm) {
|
|
1118
1047
|
if ([Fields.keywords, Fields.sys.filename, Fields.sys.uri].includes(wsf.fieldId)) {
|
|
1119
1048
|
fieldOperators.push(...containsOp(wsf, modifiedSearchTerm));
|
|
@@ -1124,20 +1053,22 @@ const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch) => {
|
|
|
1124
1053
|
fieldOperators.push(...freeTextOp(wsf, modifiedSearchTerm));
|
|
1125
1054
|
}
|
|
1126
1055
|
}
|
|
1127
|
-
}
|
|
1056
|
+
}
|
|
1128
1057
|
|
|
1058
|
+
// Add operator expressions for any quoted phrases
|
|
1059
|
+
quotedPhrases.forEach(qp => fieldOperators.push(...containsOp(wsf, qp)));
|
|
1129
1060
|
|
|
1130
|
-
|
|
1061
|
+
// If we are using multiple operators for a field we will
|
|
1131
1062
|
// wrap each field inside an And operator so we will match
|
|
1132
1063
|
// all terms/phrases rather than any terms/phrases
|
|
1133
|
-
|
|
1134
1064
|
if (fieldOperators.length > 1) {
|
|
1135
1065
|
operators.push(Op.and(...fieldOperators));
|
|
1136
1066
|
} else {
|
|
1137
1067
|
operators.push(...fieldOperators);
|
|
1138
1068
|
}
|
|
1139
|
-
});
|
|
1069
|
+
});
|
|
1140
1070
|
|
|
1071
|
+
// Wrap operators in an Or operator
|
|
1141
1072
|
return [Op.or().addRange(operators).add(Op.freeText(Fields.searchContent, searchTerm, fuzzySearch))];
|
|
1142
1073
|
} else if (searchTerm) {
|
|
1143
1074
|
// Searching without weightedSearchFields defined will fall back
|
|
@@ -1197,11 +1128,9 @@ const searchQuery = ({
|
|
|
1197
1128
|
const query = new Query(...expressions);
|
|
1198
1129
|
if (!searchTerm) query.orderBy = orderByExpression(orderBy);
|
|
1199
1130
|
if (dynamicOrderBy && dynamicOrderBy.length) query.orderBy = orderByExpression(dynamicOrderBy);
|
|
1200
|
-
|
|
1201
1131
|
if (fields && fields.length > 0 && !isFeatured) {
|
|
1202
1132
|
query.fields = fields;
|
|
1203
1133
|
}
|
|
1204
|
-
|
|
1205
1134
|
query.pageIndex = isFeatured ? 0 : pageIndex;
|
|
1206
1135
|
query.pageSize = isFeatured && typeof featuredResults.count === 'number' ? featuredResults.count : pageSize;
|
|
1207
1136
|
return query;
|
|
@@ -1222,7 +1151,6 @@ const mapEntriesToSearchResults = ({
|
|
|
1222
1151
|
const mapperFunc = mapper || mappers && mappers.results;
|
|
1223
1152
|
return items && typeof mapperFunc === 'function' ? mapperFunc(items, facet, context, state) : [];
|
|
1224
1153
|
};
|
|
1225
|
-
|
|
1226
1154
|
const facetTemplate = {
|
|
1227
1155
|
type: () => SET_SEARCH_ENTRIES,
|
|
1228
1156
|
context: 'action.context',
|
|
@@ -1265,11 +1193,9 @@ const facetTemplate = {
|
|
|
1265
1193
|
pagesLoaded
|
|
1266
1194
|
}) => {
|
|
1267
1195
|
const loaded = [...(pagesLoaded || [])];
|
|
1268
|
-
|
|
1269
1196
|
if (isNaN(loaded.find(l => l === pageIndex))) {
|
|
1270
1197
|
loaded.push(pageIndex);
|
|
1271
1198
|
}
|
|
1272
|
-
|
|
1273
1199
|
return loaded.sort((a, b) => a - b);
|
|
1274
1200
|
}
|
|
1275
1201
|
},
|
|
@@ -1292,18 +1218,21 @@ const facetTemplate = {
|
|
|
1292
1218
|
prevPageIndex
|
|
1293
1219
|
} = action.queryParams;
|
|
1294
1220
|
const results = mapEntriesToSearchResults(action, getItemsFromResult(result), state);
|
|
1295
|
-
if (!loadMorePaging) return results;
|
|
1221
|
+
if (!loadMorePaging) return results;
|
|
1296
1222
|
|
|
1223
|
+
// add a _pageIndex property to the returned results to help us later
|
|
1297
1224
|
const nextResults = results.map((r, idx) => ({
|
|
1298
1225
|
_pageIndex: pageIndex,
|
|
1299
1226
|
_pagePosition: idx,
|
|
1300
1227
|
...r
|
|
1301
1228
|
}));
|
|
1302
|
-
const loadedPages = pagesLoaded || [];
|
|
1229
|
+
const loadedPages = pagesLoaded || [];
|
|
1303
1230
|
|
|
1304
|
-
if
|
|
1305
|
-
|
|
1231
|
+
// if pageIndex is found in loadedPages, we have already loaded this page
|
|
1232
|
+
if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults;
|
|
1306
1233
|
|
|
1234
|
+
// Determine where we put the results depending on if we
|
|
1235
|
+
// are paging forwards, backwards, or doing a new search
|
|
1307
1236
|
const firstResultSet = pageIndex > prevPageIndex ? prevResults || [] : nextResults;
|
|
1308
1237
|
const secondResultSet = pageIndex > prevPageIndex ? nextResults : prevResults || [];
|
|
1309
1238
|
const onlyResultSet = loadedPages.length === 0 ? nextResults : false;
|
|
@@ -1334,13 +1263,11 @@ const filterTemplate = {
|
|
|
1334
1263
|
if (payload && (payload.items || payload.children)) {
|
|
1335
1264
|
const items = (payload.items || payload.children).map(item => {
|
|
1336
1265
|
var _item$sys;
|
|
1337
|
-
|
|
1338
1266
|
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);
|
|
1339
1267
|
return item;
|
|
1340
1268
|
});
|
|
1341
1269
|
return mapper(items);
|
|
1342
1270
|
}
|
|
1343
|
-
|
|
1344
1271
|
return [];
|
|
1345
1272
|
}
|
|
1346
1273
|
},
|
|
@@ -1363,22 +1290,22 @@ const filterExpressionMapper = {
|
|
|
1363
1290
|
fieldOperator: 'fieldOperator',
|
|
1364
1291
|
logicOperator: 'logicOperator'
|
|
1365
1292
|
};
|
|
1366
|
-
|
|
1367
1293
|
const mapFilterToFilterExpression = filter => mapJson(filter, filterExpressionMapper);
|
|
1368
1294
|
|
|
1369
1295
|
const mapFiltersToFilterExpression = (filters, selectedFilters) => {
|
|
1370
1296
|
if (!selectedFilters || Object.keys(selectedFilters).length === 0) return [];
|
|
1371
|
-
const filterExpressions = [];
|
|
1372
|
-
// the items that are selected and queryable
|
|
1297
|
+
const filterExpressions = [];
|
|
1373
1298
|
|
|
1299
|
+
// Iterate through the keys in selectedFilters and locate
|
|
1300
|
+
// the items that are selected and queryable
|
|
1374
1301
|
Object.entries(selectedFilters).map(([fkey, selectedValues]) => {
|
|
1375
1302
|
const filter = filters[fkey];
|
|
1376
|
-
|
|
1377
1303
|
if (selectedValues && filter) {
|
|
1378
1304
|
// Where we have a value for a selectedFilter
|
|
1379
1305
|
// and a filter is found for the current key
|
|
1380
1306
|
// map the filter to a filterExpression object
|
|
1381
|
-
const expr = mapFilterToFilterExpression({
|
|
1307
|
+
const expr = mapFilterToFilterExpression({
|
|
1308
|
+
...filter,
|
|
1382
1309
|
selectedValues
|
|
1383
1310
|
});
|
|
1384
1311
|
filterExpressions.push(expr);
|
|
@@ -1414,8 +1341,8 @@ const queryParamsTemplate = {
|
|
|
1414
1341
|
context
|
|
1415
1342
|
}) => {
|
|
1416
1343
|
const stateFilters = getFilters(state, facet, context, 'js');
|
|
1417
|
-
const selectedFilters = getSelectedFilters(state, facet, context, 'js');
|
|
1418
|
-
|
|
1344
|
+
const selectedFilters = getSelectedFilters(state, facet, context, 'js');
|
|
1345
|
+
// Use another mapping function to map the filter parameters for the query
|
|
1419
1346
|
const filterParams = mapFiltersToFilterExpression(stateFilters, selectedFilters);
|
|
1420
1347
|
return filterParams;
|
|
1421
1348
|
},
|
|
@@ -1464,7 +1391,6 @@ const queryParamsTemplate = {
|
|
|
1464
1391
|
context
|
|
1465
1392
|
}) => {
|
|
1466
1393
|
var _getFacet;
|
|
1467
|
-
|
|
1468
1394
|
return ((_getFacet = getFacet(state, facet, context)) === null || _getFacet === void 0 ? void 0 : _getFacet.projectId) || selectCurrentProject(state);
|
|
1469
1395
|
},
|
|
1470
1396
|
searchTerm: root => root.context !== Context.minilist || getQueryParameter(root, 'useSearchTerm', false) ? getSearchTerm(root.state) : '',
|
|
@@ -1479,11 +1405,12 @@ const queryParamsTemplate = {
|
|
|
1479
1405
|
weightedSearchFields: root => {
|
|
1480
1406
|
const wsf = getQueryParameter(root, 'weightedSearchFields', []);
|
|
1481
1407
|
const deduped = wsf.filter((v, i, a) => a.findIndex(t => t.fieldId === v.fieldId) === i);
|
|
1482
|
-
return deduped;
|
|
1408
|
+
return deduped;
|
|
1409
|
+
// return wsf;
|
|
1483
1410
|
},
|
|
1411
|
+
|
|
1484
1412
|
webpageTemplates: root => getQueryParameter(root, 'webpageTemplates', [])
|
|
1485
1413
|
};
|
|
1486
|
-
|
|
1487
1414
|
const mapStateToQueryParams = sourceJson => mapJson(sourceJson, queryParamsTemplate);
|
|
1488
1415
|
|
|
1489
1416
|
/**
|
|
@@ -1497,9 +1424,9 @@ const generateQueryParams = (action, state) => {
|
|
|
1497
1424
|
const {
|
|
1498
1425
|
context,
|
|
1499
1426
|
facet
|
|
1500
|
-
} = action;
|
|
1427
|
+
} = action;
|
|
1428
|
+
// Map parameters using state and some additional
|
|
1501
1429
|
// inputs from the action
|
|
1502
|
-
|
|
1503
1430
|
const queryParams = mapStateToQueryParams({
|
|
1504
1431
|
context,
|
|
1505
1432
|
facet,
|
|
@@ -1508,12 +1435,12 @@ const generateQueryParams = (action, state) => {
|
|
|
1508
1435
|
});
|
|
1509
1436
|
return [queryParams, runSearch(action, state, queryParams)];
|
|
1510
1437
|
};
|
|
1438
|
+
|
|
1511
1439
|
/**
|
|
1512
1440
|
* Checks if we have already loaded everything we're asking for and tells us to run the search or not
|
|
1513
1441
|
* @param action
|
|
1514
1442
|
* @param state
|
|
1515
1443
|
*/
|
|
1516
|
-
|
|
1517
1444
|
const runSearch = (action, state, queryParams) => {
|
|
1518
1445
|
const {
|
|
1519
1446
|
context,
|
|
@@ -1525,13 +1452,14 @@ const runSearch = (action, state, queryParams) => {
|
|
|
1525
1452
|
} = action;
|
|
1526
1453
|
let willRun = false;
|
|
1527
1454
|
const facetIsLoaded = defaultLang ? false : getIsLoaded(state, context, facet);
|
|
1528
|
-
const stateParams = {
|
|
1455
|
+
const stateParams = {
|
|
1456
|
+
...getQueryParams(ogState, facet, context)
|
|
1529
1457
|
};
|
|
1530
1458
|
stateParams.pageIndex = getPageIndex(ogState, facet, context);
|
|
1531
1459
|
stateParams.searchTerm = getSearchTerm(ogState);
|
|
1532
1460
|
stateParams.pageSize = getPageSize(ogState, facet, context);
|
|
1533
|
-
|
|
1534
|
-
|
|
1461
|
+
if (context === Context.facets && ssr ||
|
|
1462
|
+
// context === Context.minilist ||
|
|
1535
1463
|
preload || !facetIsLoaded || filterParamsChanged(action) || defaultLang) {
|
|
1536
1464
|
willRun = true;
|
|
1537
1465
|
} else {
|
|
@@ -1539,28 +1467,24 @@ const runSearch = (action, state, queryParams) => {
|
|
|
1539
1467
|
// are the same as what we already have in state
|
|
1540
1468
|
Object.entries(stateParams).forEach(([param, value]) => {
|
|
1541
1469
|
const queryParam = queryParams[param];
|
|
1542
|
-
|
|
1543
1470
|
if (JSON.stringify(value) !== JSON.stringify(queryParam)) {
|
|
1544
1471
|
willRun = true;
|
|
1545
1472
|
}
|
|
1546
1473
|
});
|
|
1547
1474
|
}
|
|
1548
|
-
|
|
1549
1475
|
const internalPaging = getIsInternalPaging(ogState, facet, context);
|
|
1550
|
-
|
|
1551
1476
|
if (internalPaging && facetIsLoaded) {
|
|
1552
1477
|
willRun = false;
|
|
1553
1478
|
}
|
|
1554
|
-
|
|
1555
1479
|
return willRun;
|
|
1556
1480
|
};
|
|
1481
|
+
|
|
1557
1482
|
/**
|
|
1558
1483
|
* This will tell us if filter parameters have been
|
|
1559
1484
|
* changed by some external event such as a route change
|
|
1560
1485
|
* @param action
|
|
1561
1486
|
* @returns true or false
|
|
1562
1487
|
*/
|
|
1563
|
-
|
|
1564
1488
|
const filterParamsChanged = (action, state) => {
|
|
1565
1489
|
const {
|
|
1566
1490
|
context,
|
|
@@ -1575,12 +1499,13 @@ const filterParamsChanged = (action, state) => {
|
|
|
1575
1499
|
});
|
|
1576
1500
|
return paramsChanged.filter(f => f === true).length > 0;
|
|
1577
1501
|
};
|
|
1578
|
-
/* eslint-disable no-console */
|
|
1579
1502
|
|
|
1503
|
+
/* eslint-disable no-console */
|
|
1580
1504
|
const debugExecuteSearch = (action, state) => {
|
|
1581
1505
|
const [queryParams, runSearch] = generateQueryParams(action, state);
|
|
1582
1506
|
console.log('runSearch', runSearch, 'action', action, 'filterParamsChanged', filterParamsChanged(action, state), 'getIsLoaded(state, context, facet)', getIsLoaded(state, action.context, action.facet));
|
|
1583
|
-
const stateParams = {
|
|
1507
|
+
const stateParams = {
|
|
1508
|
+
...getQueryParams(action.ogState || state, action.facet, action.context),
|
|
1584
1509
|
pageIndex: getPageIndex(action.ogState || state, action.facet, action.context),
|
|
1585
1510
|
searchTerm: getSearchTerm(action.ogState || state)
|
|
1586
1511
|
};
|
|
@@ -1591,10 +1516,11 @@ const scrollTop = scrollYPos => {
|
|
|
1591
1516
|
if (typeof window !== 'undefined') window.scrollTo(0, scrollYPos);
|
|
1592
1517
|
};
|
|
1593
1518
|
|
|
1519
|
+
// *** FILTER ITEM MAPPING ***
|
|
1520
|
+
|
|
1594
1521
|
// Base mapping, fields that are the same across all mappings
|
|
1595
1522
|
// to save repeating these elements in every mapper, spread this
|
|
1596
1523
|
// into your discrete mappings
|
|
1597
|
-
|
|
1598
1524
|
const base = {
|
|
1599
1525
|
contentTypeId: Fields.sys.contentTypeId,
|
|
1600
1526
|
title: 'entryTitle',
|
|
@@ -1602,16 +1528,13 @@ const base = {
|
|
|
1602
1528
|
path: 'sys.slug',
|
|
1603
1529
|
isSelected: 'isSelected'
|
|
1604
1530
|
};
|
|
1605
|
-
|
|
1606
1531
|
const mapEntriesToFilterItems = entries => {
|
|
1607
1532
|
if (!entries) return [];
|
|
1608
1533
|
return entries.map(entry => {
|
|
1609
1534
|
const template = base;
|
|
1610
|
-
|
|
1611
1535
|
if (template) {
|
|
1612
1536
|
return mapJson(entry, template);
|
|
1613
1537
|
}
|
|
1614
|
-
|
|
1615
1538
|
return entry;
|
|
1616
1539
|
});
|
|
1617
1540
|
};
|
|
@@ -1641,9 +1564,7 @@ const mapQueryParamsToCustomApi = queryParams => {
|
|
|
1641
1564
|
};
|
|
1642
1565
|
|
|
1643
1566
|
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)];
|
|
1644
|
-
|
|
1645
1567
|
const toJS = obj => obj && 'toJS' in obj && typeof obj.toJS === 'function' ? obj.toJS() : obj;
|
|
1646
|
-
|
|
1647
1568
|
function* setRouteFilters(action) {
|
|
1648
1569
|
const {
|
|
1649
1570
|
mappers,
|
|
@@ -1654,17 +1575,17 @@ function* setRouteFilters(action) {
|
|
|
1654
1575
|
} = action;
|
|
1655
1576
|
const context = listingType ? Context.listings : Context.facets;
|
|
1656
1577
|
const state = toJS(yield select());
|
|
1657
|
-
const ssr = getIsSsr(state);
|
|
1578
|
+
const ssr = getIsSsr(state);
|
|
1658
1579
|
|
|
1659
|
-
|
|
1580
|
+
// Get current facet from params or state
|
|
1581
|
+
let currentFacet = params && params.facet || listingType;
|
|
1660
1582
|
|
|
1583
|
+
// Pick the default facet from initialState
|
|
1661
1584
|
if (!currentFacet) {
|
|
1662
1585
|
var _Object$keys;
|
|
1663
|
-
|
|
1664
1586
|
const tabs = getSearchTabs(state, 'js');
|
|
1665
1587
|
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]) || '';
|
|
1666
1588
|
}
|
|
1667
|
-
|
|
1668
1589
|
const nextAction = {
|
|
1669
1590
|
type: SET_ROUTE_FILTERS,
|
|
1670
1591
|
context,
|
|
@@ -1675,48 +1596,50 @@ function* setRouteFilters(action) {
|
|
|
1675
1596
|
ssr,
|
|
1676
1597
|
debug
|
|
1677
1598
|
};
|
|
1678
|
-
yield put(nextAction);
|
|
1599
|
+
yield put(nextAction);
|
|
1679
1600
|
|
|
1601
|
+
// keep track of this state ref for comparing changes to params later
|
|
1680
1602
|
const ogState = {
|
|
1681
1603
|
search: state.search
|
|
1682
|
-
};
|
|
1683
|
-
// to allow this exported saga to continue during SSR
|
|
1604
|
+
};
|
|
1684
1605
|
|
|
1685
|
-
|
|
1606
|
+
// Using call instead of triggering from the put
|
|
1607
|
+
// to allow this exported saga to continue during SSR
|
|
1608
|
+
yield call(ensureSearch, {
|
|
1609
|
+
...nextAction,
|
|
1686
1610
|
ogState
|
|
1687
1611
|
});
|
|
1688
1612
|
}
|
|
1689
1613
|
function* doSearch(action) {
|
|
1690
1614
|
var _action$params;
|
|
1691
|
-
|
|
1692
1615
|
const state = toJS(yield select());
|
|
1693
|
-
|
|
1694
1616
|
if (action.config) {
|
|
1695
1617
|
// If the action contains a config object, we can add this to the
|
|
1696
1618
|
// state at runtime
|
|
1697
|
-
yield put({
|
|
1619
|
+
yield put({
|
|
1620
|
+
...action,
|
|
1698
1621
|
type: APPLY_CONFIG
|
|
1699
1622
|
});
|
|
1700
1623
|
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1624
|
+
const nextAction = {
|
|
1625
|
+
...action,
|
|
1703
1626
|
type: SET_SEARCH_FILTERS,
|
|
1704
1627
|
ssr: getIsSsr(state),
|
|
1705
1628
|
facet: action.facet || ((_action$params = action.params) === null || _action$params === void 0 ? void 0 : _action$params.facet)
|
|
1706
1629
|
};
|
|
1707
|
-
|
|
1708
1630
|
if (nextAction.facet && (action.config || Object.keys(getFacet(state, nextAction.facet, action.context, 'js')).length > 0)) {
|
|
1709
|
-
yield put(nextAction);
|
|
1631
|
+
yield put(nextAction);
|
|
1710
1632
|
|
|
1633
|
+
// keep track of this state ref for comparing changes to params later
|
|
1711
1634
|
const ogState = {
|
|
1712
1635
|
search: state.search
|
|
1713
1636
|
};
|
|
1714
|
-
yield call(ensureSearch, {
|
|
1637
|
+
yield call(ensureSearch, {
|
|
1638
|
+
...nextAction,
|
|
1715
1639
|
ogState
|
|
1716
1640
|
});
|
|
1717
1641
|
}
|
|
1718
1642
|
}
|
|
1719
|
-
|
|
1720
1643
|
function* loadFilters(action) {
|
|
1721
1644
|
const {
|
|
1722
1645
|
facet: facetKey,
|
|
@@ -1724,7 +1647,6 @@ function* loadFilters(action) {
|
|
|
1724
1647
|
mappers = {}
|
|
1725
1648
|
} = action;
|
|
1726
1649
|
const filtersToLoad = yield select(getFiltersToLoad, facetKey, context, 'js');
|
|
1727
|
-
|
|
1728
1650
|
if (filtersToLoad.length > 0) {
|
|
1729
1651
|
yield put({
|
|
1730
1652
|
type: LOAD_FILTERS,
|
|
@@ -1750,7 +1672,6 @@ function* loadFilters(action) {
|
|
|
1750
1672
|
if (filtersToLoadSagas) yield all(filtersToLoadSagas);
|
|
1751
1673
|
}
|
|
1752
1674
|
}
|
|
1753
|
-
|
|
1754
1675
|
function* loadFilter(action) {
|
|
1755
1676
|
const {
|
|
1756
1677
|
facetKey,
|
|
@@ -1776,7 +1697,6 @@ function* loadFilter(action) {
|
|
|
1776
1697
|
selectedKeys,
|
|
1777
1698
|
mapper
|
|
1778
1699
|
};
|
|
1779
|
-
|
|
1780
1700
|
try {
|
|
1781
1701
|
if (contentTypeId) {
|
|
1782
1702
|
const versionStatus = yield select(selectVersionStatus);
|
|
@@ -1786,7 +1706,6 @@ function* loadFilter(action) {
|
|
|
1786
1706
|
if (payload.type === 'error') throw payload;
|
|
1787
1707
|
createStateFrom.payload = payload;
|
|
1788
1708
|
}
|
|
1789
|
-
|
|
1790
1709
|
if (path) {
|
|
1791
1710
|
const payload = yield cachedSearch.getTaxonomyNodeByPath(path, projectId);
|
|
1792
1711
|
if (!payload) throw new Error(`No payload returned for taxonomy path: '${path}'`);
|
|
@@ -1797,35 +1716,33 @@ function* loadFilter(action) {
|
|
|
1797
1716
|
createStateFrom.type = LOAD_FILTERS_ERROR;
|
|
1798
1717
|
createStateFrom.error = error;
|
|
1799
1718
|
}
|
|
1800
|
-
|
|
1801
1719
|
const nextAction = mapJson(createStateFrom, filterTemplate);
|
|
1802
1720
|
yield put(nextAction);
|
|
1803
1721
|
}
|
|
1804
|
-
|
|
1805
1722
|
function* ensureSearch(action) {
|
|
1806
1723
|
const {
|
|
1807
1724
|
context,
|
|
1808
1725
|
facet,
|
|
1809
1726
|
debug
|
|
1810
1727
|
} = action;
|
|
1811
|
-
|
|
1812
1728
|
try {
|
|
1813
1729
|
const state = yield select();
|
|
1814
|
-
const nextAction = {
|
|
1730
|
+
const nextAction = {
|
|
1731
|
+
...action,
|
|
1815
1732
|
ogState: action.ogState || {
|
|
1816
1733
|
search: state.search
|
|
1817
1734
|
}
|
|
1818
1735
|
};
|
|
1819
1736
|
const [queryParams, runSearch] = generateQueryParams(nextAction, state);
|
|
1820
1737
|
if (debug && (debug === true || debug.executeSearch)) debugExecuteSearch(nextAction, state);
|
|
1821
|
-
|
|
1822
1738
|
if (runSearch) {
|
|
1823
1739
|
yield put({
|
|
1824
1740
|
type: EXECUTE_SEARCH,
|
|
1825
1741
|
facet,
|
|
1826
1742
|
context
|
|
1827
1743
|
});
|
|
1828
|
-
yield call(executeSearch, {
|
|
1744
|
+
yield call(executeSearch, {
|
|
1745
|
+
...nextAction,
|
|
1829
1746
|
context,
|
|
1830
1747
|
facet,
|
|
1831
1748
|
queryParams,
|
|
@@ -1837,7 +1754,6 @@ function* ensureSearch(action) {
|
|
|
1837
1754
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1838
1755
|
}
|
|
1839
1756
|
}
|
|
1840
|
-
|
|
1841
1757
|
function* executeSearch(action) {
|
|
1842
1758
|
const {
|
|
1843
1759
|
context,
|
|
@@ -1845,14 +1761,12 @@ function* executeSearch(action) {
|
|
|
1845
1761
|
queryParams,
|
|
1846
1762
|
mappers
|
|
1847
1763
|
} = action;
|
|
1848
|
-
|
|
1849
1764
|
try {
|
|
1850
1765
|
const state = yield select();
|
|
1851
1766
|
let result = {};
|
|
1852
1767
|
let featuredResult;
|
|
1853
1768
|
let featuredQuery;
|
|
1854
1769
|
const customApi = getCustomApi(state, facet, context, 'js');
|
|
1855
|
-
|
|
1856
1770
|
if (customApi) {
|
|
1857
1771
|
const apiParams = typeof mappers === 'object' && typeof mappers.customApi === 'function' && mappers.customApi(queryParams) || mapQueryParamsToCustomApi(queryParams);
|
|
1858
1772
|
result.payload = yield callCustomApi(customApi, apiParams);
|
|
@@ -1860,19 +1774,16 @@ function* executeSearch(action) {
|
|
|
1860
1774
|
} else {
|
|
1861
1775
|
if (queryParams.featuredResults) {
|
|
1862
1776
|
featuredQuery = searchQuery(queryParams, true);
|
|
1863
|
-
featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1864
|
-
|
|
1777
|
+
featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1778
|
+
// eslint-disable-next-line require-atomic-updates
|
|
1865
1779
|
queryParams.excludeIds = getItemsFromResult(featuredResult).map(fi => {
|
|
1866
1780
|
var _fi$sys;
|
|
1867
|
-
|
|
1868
1781
|
return fi === null || fi === void 0 ? void 0 : (_fi$sys = fi.sys) === null || _fi$sys === void 0 ? void 0 : _fi$sys.id;
|
|
1869
1782
|
}).filter(fi => typeof fi === 'string');
|
|
1870
1783
|
}
|
|
1871
|
-
|
|
1872
1784
|
const query = searchQuery(queryParams);
|
|
1873
1785
|
result = yield timedSearch(query, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1874
1786
|
}
|
|
1875
|
-
|
|
1876
1787
|
const createStateFrom = {
|
|
1877
1788
|
action,
|
|
1878
1789
|
featuredResult,
|
|
@@ -1888,7 +1799,6 @@ function* executeSearch(action) {
|
|
|
1888
1799
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1889
1800
|
}
|
|
1890
1801
|
}
|
|
1891
|
-
|
|
1892
1802
|
function* preloadOtherFacets(action) {
|
|
1893
1803
|
const {
|
|
1894
1804
|
preload,
|
|
@@ -1898,18 +1808,19 @@ function* preloadOtherFacets(action) {
|
|
|
1898
1808
|
} = action;
|
|
1899
1809
|
const state = yield select();
|
|
1900
1810
|
const currentFacet = getCurrentFacet(state);
|
|
1901
|
-
|
|
1902
1811
|
if (!preload && facet === currentFacet && context !== Context.listings) {
|
|
1903
1812
|
const allFacets = getFacets(state, 'js');
|
|
1904
1813
|
const otherFacets = Object.keys(allFacets).filter(f => f !== currentFacet);
|
|
1905
1814
|
yield all(otherFacets.map((preloadFacet = '') => {
|
|
1906
|
-
const preloadAction = {
|
|
1815
|
+
const preloadAction = {
|
|
1816
|
+
...action,
|
|
1907
1817
|
facet: preloadFacet,
|
|
1908
1818
|
preload: true
|
|
1909
1819
|
};
|
|
1910
1820
|
const [queryParams, runSearch] = generateQueryParams(preloadAction, state);
|
|
1911
1821
|
if (debug && (debug === true || debug.preloadOtherFacets)) debugExecuteSearch(preloadAction, state);
|
|
1912
|
-
return runSearch && call(executeSearch, {
|
|
1822
|
+
return runSearch && call(executeSearch, {
|
|
1823
|
+
...action,
|
|
1913
1824
|
type: EXECUTE_SEARCH_PRELOAD,
|
|
1914
1825
|
preload: true,
|
|
1915
1826
|
facet: preloadFacet,
|
|
@@ -1918,7 +1829,6 @@ function* preloadOtherFacets(action) {
|
|
|
1918
1829
|
}));
|
|
1919
1830
|
}
|
|
1920
1831
|
}
|
|
1921
|
-
|
|
1922
1832
|
function* updateCurrentTab(action) {
|
|
1923
1833
|
const {
|
|
1924
1834
|
id,
|
|
@@ -1928,19 +1838,16 @@ function* updateCurrentTab(action) {
|
|
|
1928
1838
|
const facets = getFacets(state, 'js');
|
|
1929
1839
|
const tabs = getSearchTabs(state, 'js');
|
|
1930
1840
|
let nextFacet = tabs === null || tabs === void 0 ? void 0 : tabs[id].currentFacet;
|
|
1931
|
-
|
|
1932
1841
|
if (!nextFacet) {
|
|
1933
1842
|
Object.entries(facets).map(([facetName, facet]) => {
|
|
1934
1843
|
if (facet.tabId === id && (tabs === null || tabs === void 0 ? void 0 : tabs[id].defaultFacet) === facetName) nextFacet = facetName;
|
|
1935
1844
|
});
|
|
1936
|
-
}
|
|
1845
|
+
}
|
|
1846
|
+
// If the next Tab does not have a defaultFacet,
|
|
1937
1847
|
// take the first facet for that tab
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
1848
|
if (!nextFacet) nextFacet = Object.entries(facets).filter(([, f]) => f.tabId === id)[0][0];
|
|
1941
1849
|
yield put(withMappers(updateCurrentFacet$1(nextFacet), mappers));
|
|
1942
1850
|
}
|
|
1943
|
-
|
|
1944
1851
|
function* clearFilters(action) {
|
|
1945
1852
|
const {
|
|
1946
1853
|
mappers
|
|
@@ -1948,7 +1855,6 @@ function* clearFilters(action) {
|
|
|
1948
1855
|
const uri = yield buildUri({}, mappers);
|
|
1949
1856
|
yield put(navigate(uri));
|
|
1950
1857
|
}
|
|
1951
|
-
|
|
1952
1858
|
function* updateCurrentFacet(action) {
|
|
1953
1859
|
const {
|
|
1954
1860
|
facet,
|
|
@@ -1961,7 +1867,6 @@ function* updateCurrentFacet(action) {
|
|
|
1961
1867
|
}, mappers);
|
|
1962
1868
|
yield put(navigate(uri));
|
|
1963
1869
|
}
|
|
1964
|
-
|
|
1965
1870
|
function* updateSearchTerm(action) {
|
|
1966
1871
|
const {
|
|
1967
1872
|
term,
|
|
@@ -1972,7 +1877,6 @@ function* updateSearchTerm(action) {
|
|
|
1972
1877
|
}, mappers);
|
|
1973
1878
|
yield put(navigate(uri));
|
|
1974
1879
|
}
|
|
1975
|
-
|
|
1976
1880
|
function* updateSortOrder(action) {
|
|
1977
1881
|
const {
|
|
1978
1882
|
orderBy,
|
|
@@ -1985,7 +1889,6 @@ function* updateSortOrder(action) {
|
|
|
1985
1889
|
}, mappers);
|
|
1986
1890
|
yield put(navigate(uri));
|
|
1987
1891
|
}
|
|
1988
|
-
|
|
1989
1892
|
function* updatePageIndex(action) {
|
|
1990
1893
|
const {
|
|
1991
1894
|
pageIndex,
|
|
@@ -1998,7 +1901,6 @@ function* updatePageIndex(action) {
|
|
|
1998
1901
|
yield put(navigate(uri));
|
|
1999
1902
|
if (typeof scrollYPos !== 'undefined') scrollTop(scrollYPos);
|
|
2000
1903
|
}
|
|
2001
|
-
|
|
2002
1904
|
function* updatePageSize(action) {
|
|
2003
1905
|
const {
|
|
2004
1906
|
pageSize,
|
|
@@ -2011,7 +1913,6 @@ function* updatePageSize(action) {
|
|
|
2011
1913
|
yield put(navigate(uri));
|
|
2012
1914
|
if (typeof scrollYPos !== 'undefined') scrollTop(scrollYPos);
|
|
2013
1915
|
}
|
|
2014
|
-
|
|
2015
1916
|
function* applySearchFilter(action) {
|
|
2016
1917
|
const {
|
|
2017
1918
|
mappers,
|
|
@@ -2021,7 +1922,6 @@ function* applySearchFilter(action) {
|
|
|
2021
1922
|
yield put(navigate(uri));
|
|
2022
1923
|
if (typeof scrollYPos !== 'undefined') scrollTop(scrollYPos);
|
|
2023
1924
|
}
|
|
2024
|
-
|
|
2025
1925
|
function* buildUri({
|
|
2026
1926
|
facet,
|
|
2027
1927
|
orderBy,
|
|
@@ -2038,11 +1938,10 @@ function* buildUri({
|
|
|
2038
1938
|
pageIndex,
|
|
2039
1939
|
pageSize,
|
|
2040
1940
|
term
|
|
2041
|
-
});
|
|
2042
|
-
|
|
1941
|
+
});
|
|
1942
|
+
// return uri;
|
|
2043
1943
|
return `${uri.path}${uri.search && `?${uri.search}` || ''}${uri.hash && `#${uri.hash}` || ''}`;
|
|
2044
1944
|
}
|
|
2045
|
-
|
|
2046
1945
|
function* triggerMinilistSsr(options) {
|
|
2047
1946
|
yield call(doSearch, {
|
|
2048
1947
|
type: DO_SEARCH,
|
|
@@ -2057,4 +1956,4 @@ function* triggerSearchSsr(options) {
|
|
|
2057
1956
|
}
|
|
2058
1957
|
|
|
2059
1958
|
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 };
|
|
2060
|
-
//# sourceMappingURL=sagas-
|
|
1959
|
+
//# sourceMappingURL=sagas-53d2aefb.js.map
|