@zengenti/contensis-react-base 3.0.2-beta.2 → 3.0.2-beta.21
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-ee485b92.js → App-21a7d836.js} +120 -432
- package/cjs/App-21a7d836.js.map +1 -0
- package/cjs/ContensisDeliveryApi-c079b03a.js +231 -0
- package/cjs/ContensisDeliveryApi-c079b03a.js.map +1 -0
- package/cjs/{RouteLoader-3aa6456e.js → RouteLoader-7f0d107a.js} +23 -37
- package/{esm/RouteLoader-5171c63f.js.map → cjs/RouteLoader-7f0d107a.js.map} +1 -1
- package/cjs/{ToJs-a9a8522b.js → ToJs-6e9cfa69.js} +3 -4
- package/cjs/{ToJs-a9a8522b.js.map → ToJs-6e9cfa69.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 +1488 -272
- 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-840860bc.js → login-2a6b5be0.js} +64 -113
- package/cjs/login-2a6b5be0.js.map +1 -0
- package/cjs/{reducers-3a4f8971.js → reducers-9afb5f89.js} +14 -31
- package/cjs/reducers-9afb5f89.js.map +1 -0
- 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-e04b94c1.js} +225 -301
- package/cjs/sagas-e04b94c1.js.map +1 -0
- package/cjs/search.js +68 -94
- package/cjs/search.js.map +1 -1
- package/cjs/{selectors-656da4b7.js → selectors-bcca60f4.js} +89 -8
- package/cjs/selectors-bcca60f4.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-78dfc3bd.js → version-4077e706.js} +50 -159
- package/cjs/version-4077e706.js.map +1 -0
- package/cjs/version-fe28099e.js +98 -0
- package/cjs/version-fe28099e.js.map +1 -0
- package/esm/{App-640239d2.js → App-2af18a99.js} +102 -412
- package/esm/App-2af18a99.js.map +1 -0
- package/esm/ContensisDeliveryApi-5660ee0e.js +227 -0
- package/esm/ContensisDeliveryApi-5660ee0e.js.map +1 -0
- package/esm/{RouteLoader-5171c63f.js → RouteLoader-6eac364e.js} +22 -36
- package/{cjs/RouteLoader-3aa6456e.js.map → esm/RouteLoader-6eac364e.js.map} +1 -1
- package/esm/{ToJs-4e02a04d.js → ToJs-9b30636a.js} +3 -4
- package/esm/{ToJs-4e02a04d.js.map → ToJs-9b30636a.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 +1490 -274
- 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-57395c9c.js → login-71ff3fcb.js} +63 -112
- package/esm/login-71ff3fcb.js.map +1 -0
- package/esm/{reducers-8e5d6232.js → reducers-3d5c37d1.js} +14 -31
- package/esm/reducers-3d5c37d1.js.map +1 -0
- 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-933a8fc8.js} +177 -254
- package/esm/sagas-933a8fc8.js.map +1 -0
- package/esm/search.js +69 -95
- package/esm/search.js.map +1 -1
- package/esm/{selectors-a5e5835b.js → selectors-74de49a3.js} +75 -8
- package/esm/selectors-74de49a3.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-b15807c5.js +87 -0
- package/esm/version-b15807c5.js.map +1 -0
- package/esm/{version-e3a5ec66.js → version-ef107106.js} +37 -142
- package/esm/version-ef107106.js.map +1 -0
- package/models/redux/appstate.d.ts +1 -0
- package/models/routing/redux/selectors.d.ts +2 -1
- package/models/search/models/Queries.d.ts +2 -1
- package/models/search/models/Search.d.ts +2 -0
- package/models/search/models/SearchActions.d.ts +3 -3
- package/models/search/redux/actions.d.ts +6 -6
- package/models/search/redux/util.d.ts +1 -1
- package/models/search/search/expressions.d.ts +1 -1
- package/models/server/features/linkdepth-api/search.d.ts +1 -1
- package/models/util/ContensisDeliveryApi.d.ts +6 -0
- package/models/util/index.d.ts +1 -0
- package/package.json +1 -1
- package/cjs/App-ee485b92.js.map +0 -1
- package/cjs/actions-8dc9e8de.js +0 -87
- package/cjs/actions-8dc9e8de.js.map +0 -1
- package/cjs/login-840860bc.js.map +0 -1
- package/cjs/reducers-3a4f8971.js.map +0 -1
- package/cjs/sagas-8a20e424.js.map +0 -1
- package/cjs/selectors-656da4b7.js.map +0 -1
- package/cjs/version-78dfc3bd.js.map +0 -1
- package/cjs/version-eba6d09b.js +0 -20
- package/cjs/version-eba6d09b.js.map +0 -1
- package/esm/App-640239d2.js.map +0 -1
- package/esm/actions-180948dd.js +0 -72
- package/esm/actions-180948dd.js.map +0 -1
- package/esm/login-57395c9c.js.map +0 -1
- package/esm/reducers-8e5d6232.js.map +0 -1
- package/esm/sagas-e576b6f6.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-e3a5ec66.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
|
};
|
|
@@ -110,18 +111,18 @@ const clearFilters$1 = filterKey => {
|
|
|
110
111
|
filterKey
|
|
111
112
|
};
|
|
112
113
|
};
|
|
113
|
-
const updatePageIndex$1 = (pageIndex,
|
|
114
|
+
const updatePageIndex$1 = (pageIndex, scrollToElement) => {
|
|
114
115
|
return {
|
|
115
116
|
type: UPDATE_PAGE_INDEX,
|
|
116
117
|
pageIndex,
|
|
117
|
-
|
|
118
|
+
scrollToElement
|
|
118
119
|
};
|
|
119
120
|
};
|
|
120
|
-
const updatePageSize$1 = (pageSize,
|
|
121
|
+
const updatePageSize$1 = (pageSize, scrollToElement) => {
|
|
121
122
|
return {
|
|
122
123
|
type: UPDATE_PAGE_SIZE,
|
|
123
124
|
pageSize,
|
|
124
|
-
|
|
125
|
+
scrollToElement
|
|
125
126
|
};
|
|
126
127
|
};
|
|
127
128
|
const updateCurrentFacet$1 = facet => {
|
|
@@ -142,13 +143,13 @@ const updateSearchTerm$1 = term => {
|
|
|
142
143
|
term
|
|
143
144
|
};
|
|
144
145
|
};
|
|
145
|
-
const updateSelectedFilters = (filter, key, isUnknownItem = false,
|
|
146
|
+
const updateSelectedFilters = (filter, key, isUnknownItem = false, scrollToElement) => {
|
|
146
147
|
return {
|
|
147
148
|
type: UPDATE_SELECTED_FILTERS,
|
|
148
149
|
filter,
|
|
149
150
|
key,
|
|
150
151
|
isUnknownItem,
|
|
151
|
-
|
|
152
|
+
scrollToElement
|
|
152
153
|
};
|
|
153
154
|
};
|
|
154
155
|
const updateSortOrder$1 = (orderBy, facet) => {
|
|
@@ -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
|
-
const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch) => {
|
|
1024
|
+
const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch, omitSearchFields = []) => {
|
|
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,25 +1053,41 @@ 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
|
|
|
1141
|
-
|
|
1071
|
+
// Wrap operators in an Or operator
|
|
1072
|
+
const expressions = Op.or().addRange(operators);
|
|
1073
|
+
if (!omitSearchFields.find(sf => sf === Fields.searchContent))
|
|
1074
|
+
// include "searchContent" field by default unless omitted
|
|
1075
|
+
return [expressions.add(Op.freeText(Fields.searchContent, searchTerm, fuzzySearch))];else return [expressions];
|
|
1142
1076
|
} else if (searchTerm) {
|
|
1143
1077
|
// Searching without weightedSearchFields defined will fall back
|
|
1144
1078
|
// to a default set of search fields with arbritary weights set.
|
|
1145
|
-
|
|
1079
|
+
|
|
1080
|
+
const exp = [];
|
|
1081
|
+
if (!omitSearchFields.find(sf => sf === Fields.entryTitle)) {
|
|
1082
|
+
exp.push(Op.equalTo(Fields.entryTitle, searchTerm).weight(10));
|
|
1083
|
+
exp.push(Op.freeText(Fields.entryTitle, searchTerm, fuzzySearch).weight(2));
|
|
1084
|
+
}
|
|
1085
|
+
if (!omitSearchFields.find(sf => sf === Fields.entryDescription)) exp.push(Op.freeText(Fields.entryDescription, searchTerm, fuzzySearch).weight(2));
|
|
1086
|
+
if (!omitSearchFields.find(sf => sf === Fields.keywords)) exp.push(Op.contains(Fields.keywords, searchTerm).weight(2));
|
|
1087
|
+
if (!omitSearchFields.find(sf => sf === Fields.sys.uri)) exp.push(Op.contains(Fields.sys.uri, searchTerm).weight(2));
|
|
1088
|
+
if (!omitSearchFields.find(sf => sf === Fields.sys.allUris)) exp.push(Op.contains(Fields.sys.allUris, searchTerm));
|
|
1089
|
+
if (!omitSearchFields.find(sf => sf === Fields.searchContent)) exp.push(Op.freeText(Fields.searchContent, searchTerm, fuzzySearch));
|
|
1090
|
+
return [Op.or(...exp)];
|
|
1146
1091
|
} else {
|
|
1147
1092
|
return [];
|
|
1148
1093
|
}
|
|
@@ -1185,23 +1130,22 @@ const searchQuery = ({
|
|
|
1185
1130
|
languages,
|
|
1186
1131
|
pageSize,
|
|
1187
1132
|
pageIndex,
|
|
1133
|
+
omitDefaultSearchFields,
|
|
1188
1134
|
orderBy,
|
|
1189
1135
|
searchTerm,
|
|
1190
1136
|
versionStatus,
|
|
1191
1137
|
webpageTemplates,
|
|
1192
1138
|
weightedSearchFields
|
|
1193
1139
|
}, isFeatured = false) => {
|
|
1194
|
-
let expressions = [...termExpressions(searchTerm, weightedSearchFields, fuzzySearch), ...defaultExpressions(versionStatus), ...includeInSearchExpressions(webpageTemplates, includeInSearchFields), ...languagesExpression(languages), ...customWhereExpressions(customWhere), ...excludeIdsExpression(excludeIds)];
|
|
1140
|
+
let expressions = [...termExpressions(searchTerm, weightedSearchFields, fuzzySearch, omitDefaultSearchFields), ...defaultExpressions(versionStatus), ...includeInSearchExpressions(webpageTemplates, includeInSearchFields), ...languagesExpression(languages), ...customWhereExpressions(customWhere), ...excludeIdsExpression(excludeIds)];
|
|
1195
1141
|
if (isFeatured) expressions = [...expressions, ...featuredResultsExpression(featuredResults)];
|
|
1196
1142
|
if (!isFeatured || featuredResults && !featuredResults.contentTypeId) expressions = [...expressions, ...filterExpressions(filters), ...contentTypeIdExpression(contentTypeIds, webpageTemplates, assetTypes)];
|
|
1197
1143
|
const query = new Query(...expressions);
|
|
1198
1144
|
if (!searchTerm) query.orderBy = orderByExpression(orderBy);
|
|
1199
1145
|
if (dynamicOrderBy && dynamicOrderBy.length) query.orderBy = orderByExpression(dynamicOrderBy);
|
|
1200
|
-
|
|
1201
1146
|
if (fields && fields.length > 0 && !isFeatured) {
|
|
1202
1147
|
query.fields = fields;
|
|
1203
1148
|
}
|
|
1204
|
-
|
|
1205
1149
|
query.pageIndex = isFeatured ? 0 : pageIndex;
|
|
1206
1150
|
query.pageSize = isFeatured && typeof featuredResults.count === 'number' ? featuredResults.count : pageSize;
|
|
1207
1151
|
return query;
|
|
@@ -1222,7 +1166,6 @@ const mapEntriesToSearchResults = ({
|
|
|
1222
1166
|
const mapperFunc = mapper || mappers && mappers.results;
|
|
1223
1167
|
return items && typeof mapperFunc === 'function' ? mapperFunc(items, facet, context, state) : [];
|
|
1224
1168
|
};
|
|
1225
|
-
|
|
1226
1169
|
const facetTemplate = {
|
|
1227
1170
|
type: () => SET_SEARCH_ENTRIES,
|
|
1228
1171
|
context: 'action.context',
|
|
@@ -1265,11 +1208,9 @@ const facetTemplate = {
|
|
|
1265
1208
|
pagesLoaded
|
|
1266
1209
|
}) => {
|
|
1267
1210
|
const loaded = [...(pagesLoaded || [])];
|
|
1268
|
-
|
|
1269
1211
|
if (isNaN(loaded.find(l => l === pageIndex))) {
|
|
1270
1212
|
loaded.push(pageIndex);
|
|
1271
1213
|
}
|
|
1272
|
-
|
|
1273
1214
|
return loaded.sort((a, b) => a - b);
|
|
1274
1215
|
}
|
|
1275
1216
|
},
|
|
@@ -1292,18 +1233,21 @@ const facetTemplate = {
|
|
|
1292
1233
|
prevPageIndex
|
|
1293
1234
|
} = action.queryParams;
|
|
1294
1235
|
const results = mapEntriesToSearchResults(action, getItemsFromResult(result), state);
|
|
1295
|
-
if (!loadMorePaging) return results;
|
|
1236
|
+
if (!loadMorePaging) return results;
|
|
1296
1237
|
|
|
1238
|
+
// add a _pageIndex property to the returned results to help us later
|
|
1297
1239
|
const nextResults = results.map((r, idx) => ({
|
|
1298
1240
|
_pageIndex: pageIndex,
|
|
1299
1241
|
_pagePosition: idx,
|
|
1300
1242
|
...r
|
|
1301
1243
|
}));
|
|
1302
|
-
const loadedPages = pagesLoaded || [];
|
|
1244
|
+
const loadedPages = pagesLoaded || [];
|
|
1303
1245
|
|
|
1304
|
-
if
|
|
1305
|
-
|
|
1246
|
+
// if pageIndex is found in loadedPages, we have already loaded this page
|
|
1247
|
+
if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults;
|
|
1306
1248
|
|
|
1249
|
+
// Determine where we put the results depending on if we
|
|
1250
|
+
// are paging forwards, backwards, or doing a new search
|
|
1307
1251
|
const firstResultSet = pageIndex > prevPageIndex ? prevResults || [] : nextResults;
|
|
1308
1252
|
const secondResultSet = pageIndex > prevPageIndex ? nextResults : prevResults || [];
|
|
1309
1253
|
const onlyResultSet = loadedPages.length === 0 ? nextResults : false;
|
|
@@ -1334,13 +1278,11 @@ const filterTemplate = {
|
|
|
1334
1278
|
if (payload && (payload.items || payload.children)) {
|
|
1335
1279
|
const items = (payload.items || payload.children).map(item => {
|
|
1336
1280
|
var _item$sys;
|
|
1337
|
-
|
|
1338
1281
|
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
1282
|
return item;
|
|
1340
1283
|
});
|
|
1341
1284
|
return mapper(items);
|
|
1342
1285
|
}
|
|
1343
|
-
|
|
1344
1286
|
return [];
|
|
1345
1287
|
}
|
|
1346
1288
|
},
|
|
@@ -1363,22 +1305,22 @@ const filterExpressionMapper = {
|
|
|
1363
1305
|
fieldOperator: 'fieldOperator',
|
|
1364
1306
|
logicOperator: 'logicOperator'
|
|
1365
1307
|
};
|
|
1366
|
-
|
|
1367
1308
|
const mapFilterToFilterExpression = filter => mapJson(filter, filterExpressionMapper);
|
|
1368
1309
|
|
|
1369
1310
|
const mapFiltersToFilterExpression = (filters, selectedFilters) => {
|
|
1370
1311
|
if (!selectedFilters || Object.keys(selectedFilters).length === 0) return [];
|
|
1371
|
-
const filterExpressions = [];
|
|
1372
|
-
// the items that are selected and queryable
|
|
1312
|
+
const filterExpressions = [];
|
|
1373
1313
|
|
|
1314
|
+
// Iterate through the keys in selectedFilters and locate
|
|
1315
|
+
// the items that are selected and queryable
|
|
1374
1316
|
Object.entries(selectedFilters).map(([fkey, selectedValues]) => {
|
|
1375
1317
|
const filter = filters[fkey];
|
|
1376
|
-
|
|
1377
1318
|
if (selectedValues && filter) {
|
|
1378
1319
|
// Where we have a value for a selectedFilter
|
|
1379
1320
|
// and a filter is found for the current key
|
|
1380
1321
|
// map the filter to a filterExpression object
|
|
1381
|
-
const expr = mapFilterToFilterExpression({
|
|
1322
|
+
const expr = mapFilterToFilterExpression({
|
|
1323
|
+
...filter,
|
|
1382
1324
|
selectedValues
|
|
1383
1325
|
});
|
|
1384
1326
|
filterExpressions.push(expr);
|
|
@@ -1414,8 +1356,8 @@ const queryParamsTemplate = {
|
|
|
1414
1356
|
context
|
|
1415
1357
|
}) => {
|
|
1416
1358
|
const stateFilters = getFilters(state, facet, context, 'js');
|
|
1417
|
-
const selectedFilters = getSelectedFilters(state, facet, context, 'js');
|
|
1418
|
-
|
|
1359
|
+
const selectedFilters = getSelectedFilters(state, facet, context, 'js');
|
|
1360
|
+
// Use another mapping function to map the filter parameters for the query
|
|
1419
1361
|
const filterParams = mapFiltersToFilterExpression(stateFilters, selectedFilters);
|
|
1420
1362
|
return filterParams;
|
|
1421
1363
|
},
|
|
@@ -1431,6 +1373,7 @@ const queryParamsTemplate = {
|
|
|
1431
1373
|
}) => action.defaultLang ? [action.defaultLang] : [],
|
|
1432
1374
|
linkDepth: root => getQueryParameter(root, 'linkDepth', 0),
|
|
1433
1375
|
loadMorePaging: root => getQueryParameter(root, 'loadMorePaging', false),
|
|
1376
|
+
omitDefaultSearchFields: root => getQueryParameter(root, 'omitDefaultSearchFields', []),
|
|
1434
1377
|
orderBy: root => getQueryParameter(root, 'orderBy', []),
|
|
1435
1378
|
pageIndex: root => {
|
|
1436
1379
|
const {
|
|
@@ -1464,8 +1407,7 @@ const queryParamsTemplate = {
|
|
|
1464
1407
|
context
|
|
1465
1408
|
}) => {
|
|
1466
1409
|
var _getFacet;
|
|
1467
|
-
|
|
1468
|
-
return ((_getFacet = getFacet(state, facet, context)) === null || _getFacet === void 0 ? void 0 : _getFacet.projectId) || selectCurrentProject(state);
|
|
1410
|
+
return ((_getFacet = getFacet(state, facet, context, 'js')) === null || _getFacet === void 0 ? void 0 : _getFacet.projectId) || selectCurrentProject(state);
|
|
1469
1411
|
},
|
|
1470
1412
|
searchTerm: root => root.context !== Context.minilist || getQueryParameter(root, 'useSearchTerm', false) ? getSearchTerm(root.state) : '',
|
|
1471
1413
|
selectedFilters: ({
|
|
@@ -1479,11 +1421,12 @@ const queryParamsTemplate = {
|
|
|
1479
1421
|
weightedSearchFields: root => {
|
|
1480
1422
|
const wsf = getQueryParameter(root, 'weightedSearchFields', []);
|
|
1481
1423
|
const deduped = wsf.filter((v, i, a) => a.findIndex(t => t.fieldId === v.fieldId) === i);
|
|
1482
|
-
return deduped;
|
|
1424
|
+
return deduped;
|
|
1425
|
+
// return wsf;
|
|
1483
1426
|
},
|
|
1427
|
+
|
|
1484
1428
|
webpageTemplates: root => getQueryParameter(root, 'webpageTemplates', [])
|
|
1485
1429
|
};
|
|
1486
|
-
|
|
1487
1430
|
const mapStateToQueryParams = sourceJson => mapJson(sourceJson, queryParamsTemplate);
|
|
1488
1431
|
|
|
1489
1432
|
/**
|
|
@@ -1497,9 +1440,9 @@ const generateQueryParams = (action, state) => {
|
|
|
1497
1440
|
const {
|
|
1498
1441
|
context,
|
|
1499
1442
|
facet
|
|
1500
|
-
} = action;
|
|
1443
|
+
} = action;
|
|
1444
|
+
// Map parameters using state and some additional
|
|
1501
1445
|
// inputs from the action
|
|
1502
|
-
|
|
1503
1446
|
const queryParams = mapStateToQueryParams({
|
|
1504
1447
|
context,
|
|
1505
1448
|
facet,
|
|
@@ -1508,12 +1451,12 @@ const generateQueryParams = (action, state) => {
|
|
|
1508
1451
|
});
|
|
1509
1452
|
return [queryParams, runSearch(action, state, queryParams)];
|
|
1510
1453
|
};
|
|
1454
|
+
|
|
1511
1455
|
/**
|
|
1512
1456
|
* Checks if we have already loaded everything we're asking for and tells us to run the search or not
|
|
1513
1457
|
* @param action
|
|
1514
1458
|
* @param state
|
|
1515
1459
|
*/
|
|
1516
|
-
|
|
1517
1460
|
const runSearch = (action, state, queryParams) => {
|
|
1518
1461
|
const {
|
|
1519
1462
|
context,
|
|
@@ -1525,13 +1468,14 @@ const runSearch = (action, state, queryParams) => {
|
|
|
1525
1468
|
} = action;
|
|
1526
1469
|
let willRun = false;
|
|
1527
1470
|
const facetIsLoaded = defaultLang ? false : getIsLoaded(state, context, facet);
|
|
1528
|
-
const stateParams = {
|
|
1471
|
+
const stateParams = {
|
|
1472
|
+
...getQueryParams(ogState, facet, context)
|
|
1529
1473
|
};
|
|
1530
1474
|
stateParams.pageIndex = getPageIndex(ogState, facet, context);
|
|
1531
1475
|
stateParams.searchTerm = getSearchTerm(ogState);
|
|
1532
1476
|
stateParams.pageSize = getPageSize(ogState, facet, context);
|
|
1533
|
-
|
|
1534
|
-
|
|
1477
|
+
if (context === Context.facets && ssr ||
|
|
1478
|
+
// context === Context.minilist ||
|
|
1535
1479
|
preload || !facetIsLoaded || filterParamsChanged(action) || defaultLang) {
|
|
1536
1480
|
willRun = true;
|
|
1537
1481
|
} else {
|
|
@@ -1539,28 +1483,24 @@ const runSearch = (action, state, queryParams) => {
|
|
|
1539
1483
|
// are the same as what we already have in state
|
|
1540
1484
|
Object.entries(stateParams).forEach(([param, value]) => {
|
|
1541
1485
|
const queryParam = queryParams[param];
|
|
1542
|
-
|
|
1543
1486
|
if (JSON.stringify(value) !== JSON.stringify(queryParam)) {
|
|
1544
1487
|
willRun = true;
|
|
1545
1488
|
}
|
|
1546
1489
|
});
|
|
1547
1490
|
}
|
|
1548
|
-
|
|
1549
1491
|
const internalPaging = getIsInternalPaging(ogState, facet, context);
|
|
1550
|
-
|
|
1551
1492
|
if (internalPaging && facetIsLoaded) {
|
|
1552
1493
|
willRun = false;
|
|
1553
1494
|
}
|
|
1554
|
-
|
|
1555
1495
|
return willRun;
|
|
1556
1496
|
};
|
|
1497
|
+
|
|
1557
1498
|
/**
|
|
1558
1499
|
* This will tell us if filter parameters have been
|
|
1559
1500
|
* changed by some external event such as a route change
|
|
1560
1501
|
* @param action
|
|
1561
1502
|
* @returns true or false
|
|
1562
1503
|
*/
|
|
1563
|
-
|
|
1564
1504
|
const filterParamsChanged = (action, state) => {
|
|
1565
1505
|
const {
|
|
1566
1506
|
context,
|
|
@@ -1575,26 +1515,36 @@ const filterParamsChanged = (action, state) => {
|
|
|
1575
1515
|
});
|
|
1576
1516
|
return paramsChanged.filter(f => f === true).length > 0;
|
|
1577
1517
|
};
|
|
1578
|
-
/* eslint-disable no-console */
|
|
1579
1518
|
|
|
1519
|
+
/* eslint-disable no-console */
|
|
1580
1520
|
const debugExecuteSearch = (action, state) => {
|
|
1581
1521
|
const [queryParams, runSearch] = generateQueryParams(action, state);
|
|
1582
1522
|
console.log('runSearch', runSearch, 'action', action, 'filterParamsChanged', filterParamsChanged(action, state), 'getIsLoaded(state, context, facet)', getIsLoaded(state, action.context, action.facet));
|
|
1583
|
-
const stateParams = {
|
|
1523
|
+
const stateParams = {
|
|
1524
|
+
...getQueryParams(action.ogState || state, action.facet, action.context),
|
|
1584
1525
|
pageIndex: getPageIndex(action.ogState || state, action.facet, action.context),
|
|
1585
1526
|
searchTerm: getSearchTerm(action.ogState || state)
|
|
1586
1527
|
};
|
|
1587
1528
|
console.log(stateParams, queryParams);
|
|
1588
1529
|
console.log('getSelectedFilters', getSelectedFilters(action.ogState || state, action.facet, action.context, 'js'), 'params', action.params);
|
|
1589
1530
|
};
|
|
1590
|
-
const
|
|
1591
|
-
if (typeof window !== 'undefined')
|
|
1531
|
+
const scrollTo = scrollToElement => {
|
|
1532
|
+
if (typeof window !== 'undefined') {
|
|
1533
|
+
if (typeof scrollToElement === 'number')
|
|
1534
|
+
// Used to be Y coordinate, deprecated, because it's not accessible
|
|
1535
|
+
console.warn('updatePageIndex arg2 needs string');else if (typeof scrollToElement === 'string') {
|
|
1536
|
+
/* Effectively simulates an anchor link. Needed for accessibility, as window.scrollTo
|
|
1537
|
+
does not change focus, only scrolls the screen */
|
|
1538
|
+
window.location.href = `${location.pathname}${location.search}#${scrollToElement}`;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1592
1541
|
};
|
|
1593
1542
|
|
|
1543
|
+
// *** FILTER ITEM MAPPING ***
|
|
1544
|
+
|
|
1594
1545
|
// Base mapping, fields that are the same across all mappings
|
|
1595
1546
|
// to save repeating these elements in every mapper, spread this
|
|
1596
1547
|
// into your discrete mappings
|
|
1597
|
-
|
|
1598
1548
|
const base = {
|
|
1599
1549
|
contentTypeId: Fields.sys.contentTypeId,
|
|
1600
1550
|
title: 'entryTitle',
|
|
@@ -1602,16 +1552,13 @@ const base = {
|
|
|
1602
1552
|
path: 'sys.slug',
|
|
1603
1553
|
isSelected: 'isSelected'
|
|
1604
1554
|
};
|
|
1605
|
-
|
|
1606
1555
|
const mapEntriesToFilterItems = entries => {
|
|
1607
1556
|
if (!entries) return [];
|
|
1608
1557
|
return entries.map(entry => {
|
|
1609
1558
|
const template = base;
|
|
1610
|
-
|
|
1611
1559
|
if (template) {
|
|
1612
1560
|
return mapJson(entry, template);
|
|
1613
1561
|
}
|
|
1614
|
-
|
|
1615
1562
|
return entry;
|
|
1616
1563
|
});
|
|
1617
1564
|
};
|
|
@@ -1641,9 +1588,7 @@ const mapQueryParamsToCustomApi = queryParams => {
|
|
|
1641
1588
|
};
|
|
1642
1589
|
|
|
1643
1590
|
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
1591
|
const toJS = obj => obj && 'toJS' in obj && typeof obj.toJS === 'function' ? obj.toJS() : obj;
|
|
1646
|
-
|
|
1647
1592
|
function* setRouteFilters(action) {
|
|
1648
1593
|
const {
|
|
1649
1594
|
mappers,
|
|
@@ -1654,17 +1599,17 @@ function* setRouteFilters(action) {
|
|
|
1654
1599
|
} = action;
|
|
1655
1600
|
const context = listingType ? Context.listings : Context.facets;
|
|
1656
1601
|
const state = toJS(yield select());
|
|
1657
|
-
const ssr = getIsSsr(state);
|
|
1602
|
+
const ssr = getIsSsr(state);
|
|
1658
1603
|
|
|
1659
|
-
|
|
1604
|
+
// Get current facet from params or state
|
|
1605
|
+
let currentFacet = params && params.facet || listingType;
|
|
1660
1606
|
|
|
1607
|
+
// Pick the default facet from initialState
|
|
1661
1608
|
if (!currentFacet) {
|
|
1662
1609
|
var _Object$keys;
|
|
1663
|
-
|
|
1664
1610
|
const tabs = getSearchTabs(state, 'js');
|
|
1665
1611
|
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
1612
|
}
|
|
1667
|
-
|
|
1668
1613
|
const nextAction = {
|
|
1669
1614
|
type: SET_ROUTE_FILTERS,
|
|
1670
1615
|
context,
|
|
@@ -1675,48 +1620,50 @@ function* setRouteFilters(action) {
|
|
|
1675
1620
|
ssr,
|
|
1676
1621
|
debug
|
|
1677
1622
|
};
|
|
1678
|
-
yield put(nextAction);
|
|
1623
|
+
yield put(nextAction);
|
|
1679
1624
|
|
|
1625
|
+
// keep track of this state ref for comparing changes to params later
|
|
1680
1626
|
const ogState = {
|
|
1681
1627
|
search: state.search
|
|
1682
|
-
};
|
|
1683
|
-
// to allow this exported saga to continue during SSR
|
|
1628
|
+
};
|
|
1684
1629
|
|
|
1685
|
-
|
|
1630
|
+
// Using call instead of triggering from the put
|
|
1631
|
+
// to allow this exported saga to continue during SSR
|
|
1632
|
+
yield call(ensureSearch, {
|
|
1633
|
+
...nextAction,
|
|
1686
1634
|
ogState
|
|
1687
1635
|
});
|
|
1688
1636
|
}
|
|
1689
1637
|
function* doSearch(action) {
|
|
1690
1638
|
var _action$params;
|
|
1691
|
-
|
|
1692
1639
|
const state = toJS(yield select());
|
|
1693
|
-
|
|
1694
1640
|
if (action.config) {
|
|
1695
1641
|
// If the action contains a config object, we can add this to the
|
|
1696
1642
|
// state at runtime
|
|
1697
|
-
yield put({
|
|
1643
|
+
yield put({
|
|
1644
|
+
...action,
|
|
1698
1645
|
type: APPLY_CONFIG
|
|
1699
1646
|
});
|
|
1700
1647
|
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1648
|
+
const nextAction = {
|
|
1649
|
+
...action,
|
|
1703
1650
|
type: SET_SEARCH_FILTERS,
|
|
1704
1651
|
ssr: getIsSsr(state),
|
|
1705
1652
|
facet: action.facet || ((_action$params = action.params) === null || _action$params === void 0 ? void 0 : _action$params.facet)
|
|
1706
1653
|
};
|
|
1707
|
-
|
|
1708
1654
|
if (nextAction.facet && (action.config || Object.keys(getFacet(state, nextAction.facet, action.context, 'js')).length > 0)) {
|
|
1709
|
-
yield put(nextAction);
|
|
1655
|
+
yield put(nextAction);
|
|
1710
1656
|
|
|
1657
|
+
// keep track of this state ref for comparing changes to params later
|
|
1711
1658
|
const ogState = {
|
|
1712
1659
|
search: state.search
|
|
1713
1660
|
};
|
|
1714
|
-
yield call(ensureSearch, {
|
|
1661
|
+
yield call(ensureSearch, {
|
|
1662
|
+
...nextAction,
|
|
1715
1663
|
ogState
|
|
1716
1664
|
});
|
|
1717
1665
|
}
|
|
1718
1666
|
}
|
|
1719
|
-
|
|
1720
1667
|
function* loadFilters(action) {
|
|
1721
1668
|
const {
|
|
1722
1669
|
facet: facetKey,
|
|
@@ -1724,7 +1671,6 @@ function* loadFilters(action) {
|
|
|
1724
1671
|
mappers = {}
|
|
1725
1672
|
} = action;
|
|
1726
1673
|
const filtersToLoad = yield select(getFiltersToLoad, facetKey, context, 'js');
|
|
1727
|
-
|
|
1728
1674
|
if (filtersToLoad.length > 0) {
|
|
1729
1675
|
yield put({
|
|
1730
1676
|
type: LOAD_FILTERS,
|
|
@@ -1750,7 +1696,6 @@ function* loadFilters(action) {
|
|
|
1750
1696
|
if (filtersToLoadSagas) yield all(filtersToLoadSagas);
|
|
1751
1697
|
}
|
|
1752
1698
|
}
|
|
1753
|
-
|
|
1754
1699
|
function* loadFilter(action) {
|
|
1755
1700
|
const {
|
|
1756
1701
|
facetKey,
|
|
@@ -1776,7 +1721,6 @@ function* loadFilter(action) {
|
|
|
1776
1721
|
selectedKeys,
|
|
1777
1722
|
mapper
|
|
1778
1723
|
};
|
|
1779
|
-
|
|
1780
1724
|
try {
|
|
1781
1725
|
if (contentTypeId) {
|
|
1782
1726
|
const versionStatus = yield select(selectVersionStatus);
|
|
@@ -1786,7 +1730,6 @@ function* loadFilter(action) {
|
|
|
1786
1730
|
if (payload.type === 'error') throw payload;
|
|
1787
1731
|
createStateFrom.payload = payload;
|
|
1788
1732
|
}
|
|
1789
|
-
|
|
1790
1733
|
if (path) {
|
|
1791
1734
|
const payload = yield cachedSearch.getTaxonomyNodeByPath(path, projectId);
|
|
1792
1735
|
if (!payload) throw new Error(`No payload returned for taxonomy path: '${path}'`);
|
|
@@ -1797,35 +1740,33 @@ function* loadFilter(action) {
|
|
|
1797
1740
|
createStateFrom.type = LOAD_FILTERS_ERROR;
|
|
1798
1741
|
createStateFrom.error = error;
|
|
1799
1742
|
}
|
|
1800
|
-
|
|
1801
1743
|
const nextAction = mapJson(createStateFrom, filterTemplate);
|
|
1802
1744
|
yield put(nextAction);
|
|
1803
1745
|
}
|
|
1804
|
-
|
|
1805
1746
|
function* ensureSearch(action) {
|
|
1806
1747
|
const {
|
|
1807
1748
|
context,
|
|
1808
1749
|
facet,
|
|
1809
1750
|
debug
|
|
1810
1751
|
} = action;
|
|
1811
|
-
|
|
1812
1752
|
try {
|
|
1813
1753
|
const state = yield select();
|
|
1814
|
-
const nextAction = {
|
|
1754
|
+
const nextAction = {
|
|
1755
|
+
...action,
|
|
1815
1756
|
ogState: action.ogState || {
|
|
1816
1757
|
search: state.search
|
|
1817
1758
|
}
|
|
1818
1759
|
};
|
|
1819
1760
|
const [queryParams, runSearch] = generateQueryParams(nextAction, state);
|
|
1820
1761
|
if (debug && (debug === true || debug.executeSearch)) debugExecuteSearch(nextAction, state);
|
|
1821
|
-
|
|
1822
1762
|
if (runSearch) {
|
|
1823
1763
|
yield put({
|
|
1824
1764
|
type: EXECUTE_SEARCH,
|
|
1825
1765
|
facet,
|
|
1826
1766
|
context
|
|
1827
1767
|
});
|
|
1828
|
-
yield call(executeSearch, {
|
|
1768
|
+
yield call(executeSearch, {
|
|
1769
|
+
...nextAction,
|
|
1829
1770
|
context,
|
|
1830
1771
|
facet,
|
|
1831
1772
|
queryParams,
|
|
@@ -1837,7 +1778,6 @@ function* ensureSearch(action) {
|
|
|
1837
1778
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1838
1779
|
}
|
|
1839
1780
|
}
|
|
1840
|
-
|
|
1841
1781
|
function* executeSearch(action) {
|
|
1842
1782
|
const {
|
|
1843
1783
|
context,
|
|
@@ -1845,14 +1785,12 @@ function* executeSearch(action) {
|
|
|
1845
1785
|
queryParams,
|
|
1846
1786
|
mappers
|
|
1847
1787
|
} = action;
|
|
1848
|
-
|
|
1849
1788
|
try {
|
|
1850
1789
|
const state = yield select();
|
|
1851
1790
|
let result = {};
|
|
1852
1791
|
let featuredResult;
|
|
1853
1792
|
let featuredQuery;
|
|
1854
1793
|
const customApi = getCustomApi(state, facet, context, 'js');
|
|
1855
|
-
|
|
1856
1794
|
if (customApi) {
|
|
1857
1795
|
const apiParams = typeof mappers === 'object' && typeof mappers.customApi === 'function' && mappers.customApi(queryParams) || mapQueryParamsToCustomApi(queryParams);
|
|
1858
1796
|
result.payload = yield callCustomApi(customApi, apiParams);
|
|
@@ -1860,19 +1798,16 @@ function* executeSearch(action) {
|
|
|
1860
1798
|
} else {
|
|
1861
1799
|
if (queryParams.featuredResults) {
|
|
1862
1800
|
featuredQuery = searchQuery(queryParams, true);
|
|
1863
|
-
featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1864
|
-
|
|
1801
|
+
featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1802
|
+
// eslint-disable-next-line require-atomic-updates
|
|
1865
1803
|
queryParams.excludeIds = getItemsFromResult(featuredResult).map(fi => {
|
|
1866
1804
|
var _fi$sys;
|
|
1867
|
-
|
|
1868
1805
|
return fi === null || fi === void 0 ? void 0 : (_fi$sys = fi.sys) === null || _fi$sys === void 0 ? void 0 : _fi$sys.id;
|
|
1869
1806
|
}).filter(fi => typeof fi === 'string');
|
|
1870
1807
|
}
|
|
1871
|
-
|
|
1872
1808
|
const query = searchQuery(queryParams);
|
|
1873
1809
|
result = yield timedSearch(query, queryParams.linkDepth, queryParams.projectId, queryParams.env);
|
|
1874
1810
|
}
|
|
1875
|
-
|
|
1876
1811
|
const createStateFrom = {
|
|
1877
1812
|
action,
|
|
1878
1813
|
featuredResult,
|
|
@@ -1888,7 +1823,6 @@ function* executeSearch(action) {
|
|
|
1888
1823
|
log.error(...['Error running search saga:', error, error.stack]);
|
|
1889
1824
|
}
|
|
1890
1825
|
}
|
|
1891
|
-
|
|
1892
1826
|
function* preloadOtherFacets(action) {
|
|
1893
1827
|
const {
|
|
1894
1828
|
preload,
|
|
@@ -1898,18 +1832,19 @@ function* preloadOtherFacets(action) {
|
|
|
1898
1832
|
} = action;
|
|
1899
1833
|
const state = yield select();
|
|
1900
1834
|
const currentFacet = getCurrentFacet(state);
|
|
1901
|
-
|
|
1902
1835
|
if (!preload && facet === currentFacet && context !== Context.listings) {
|
|
1903
1836
|
const allFacets = getFacets(state, 'js');
|
|
1904
1837
|
const otherFacets = Object.keys(allFacets).filter(f => f !== currentFacet);
|
|
1905
1838
|
yield all(otherFacets.map((preloadFacet = '') => {
|
|
1906
|
-
const preloadAction = {
|
|
1839
|
+
const preloadAction = {
|
|
1840
|
+
...action,
|
|
1907
1841
|
facet: preloadFacet,
|
|
1908
1842
|
preload: true
|
|
1909
1843
|
};
|
|
1910
1844
|
const [queryParams, runSearch] = generateQueryParams(preloadAction, state);
|
|
1911
1845
|
if (debug && (debug === true || debug.preloadOtherFacets)) debugExecuteSearch(preloadAction, state);
|
|
1912
|
-
return runSearch && call(executeSearch, {
|
|
1846
|
+
return runSearch && call(executeSearch, {
|
|
1847
|
+
...action,
|
|
1913
1848
|
type: EXECUTE_SEARCH_PRELOAD,
|
|
1914
1849
|
preload: true,
|
|
1915
1850
|
facet: preloadFacet,
|
|
@@ -1918,7 +1853,6 @@ function* preloadOtherFacets(action) {
|
|
|
1918
1853
|
}));
|
|
1919
1854
|
}
|
|
1920
1855
|
}
|
|
1921
|
-
|
|
1922
1856
|
function* updateCurrentTab(action) {
|
|
1923
1857
|
const {
|
|
1924
1858
|
id,
|
|
@@ -1928,19 +1862,16 @@ function* updateCurrentTab(action) {
|
|
|
1928
1862
|
const facets = getFacets(state, 'js');
|
|
1929
1863
|
const tabs = getSearchTabs(state, 'js');
|
|
1930
1864
|
let nextFacet = tabs === null || tabs === void 0 ? void 0 : tabs[id].currentFacet;
|
|
1931
|
-
|
|
1932
1865
|
if (!nextFacet) {
|
|
1933
1866
|
Object.entries(facets).map(([facetName, facet]) => {
|
|
1934
1867
|
if (facet.tabId === id && (tabs === null || tabs === void 0 ? void 0 : tabs[id].defaultFacet) === facetName) nextFacet = facetName;
|
|
1935
1868
|
});
|
|
1936
|
-
}
|
|
1869
|
+
}
|
|
1870
|
+
// If the next Tab does not have a defaultFacet,
|
|
1937
1871
|
// take the first facet for that tab
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
1872
|
if (!nextFacet) nextFacet = Object.entries(facets).filter(([, f]) => f.tabId === id)[0][0];
|
|
1941
1873
|
yield put(withMappers(updateCurrentFacet$1(nextFacet), mappers));
|
|
1942
1874
|
}
|
|
1943
|
-
|
|
1944
1875
|
function* clearFilters(action) {
|
|
1945
1876
|
const {
|
|
1946
1877
|
mappers
|
|
@@ -1948,7 +1879,6 @@ function* clearFilters(action) {
|
|
|
1948
1879
|
const uri = yield buildUri({}, mappers);
|
|
1949
1880
|
yield put(navigate(uri));
|
|
1950
1881
|
}
|
|
1951
|
-
|
|
1952
1882
|
function* updateCurrentFacet(action) {
|
|
1953
1883
|
const {
|
|
1954
1884
|
facet,
|
|
@@ -1961,7 +1891,6 @@ function* updateCurrentFacet(action) {
|
|
|
1961
1891
|
}, mappers);
|
|
1962
1892
|
yield put(navigate(uri));
|
|
1963
1893
|
}
|
|
1964
|
-
|
|
1965
1894
|
function* updateSearchTerm(action) {
|
|
1966
1895
|
const {
|
|
1967
1896
|
term,
|
|
@@ -1972,7 +1901,6 @@ function* updateSearchTerm(action) {
|
|
|
1972
1901
|
}, mappers);
|
|
1973
1902
|
yield put(navigate(uri));
|
|
1974
1903
|
}
|
|
1975
|
-
|
|
1976
1904
|
function* updateSortOrder(action) {
|
|
1977
1905
|
const {
|
|
1978
1906
|
orderBy,
|
|
@@ -1985,43 +1913,39 @@ function* updateSortOrder(action) {
|
|
|
1985
1913
|
}, mappers);
|
|
1986
1914
|
yield put(navigate(uri));
|
|
1987
1915
|
}
|
|
1988
|
-
|
|
1989
1916
|
function* updatePageIndex(action) {
|
|
1990
1917
|
const {
|
|
1991
1918
|
pageIndex,
|
|
1992
1919
|
mappers,
|
|
1993
|
-
|
|
1920
|
+
scrollToElement
|
|
1994
1921
|
} = action;
|
|
1995
1922
|
const uri = yield buildUri({
|
|
1996
1923
|
pageIndex
|
|
1997
1924
|
}, mappers);
|
|
1998
1925
|
yield put(navigate(uri));
|
|
1999
|
-
if (typeof
|
|
1926
|
+
if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
|
|
2000
1927
|
}
|
|
2001
|
-
|
|
2002
1928
|
function* updatePageSize(action) {
|
|
2003
1929
|
const {
|
|
2004
1930
|
pageSize,
|
|
2005
1931
|
mappers,
|
|
2006
|
-
|
|
1932
|
+
scrollToElement
|
|
2007
1933
|
} = action;
|
|
2008
1934
|
const uri = yield buildUri({
|
|
2009
1935
|
pageSize
|
|
2010
1936
|
}, mappers);
|
|
2011
1937
|
yield put(navigate(uri));
|
|
2012
|
-
if (typeof
|
|
1938
|
+
if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
|
|
2013
1939
|
}
|
|
2014
|
-
|
|
2015
1940
|
function* applySearchFilter(action) {
|
|
2016
1941
|
const {
|
|
2017
1942
|
mappers,
|
|
2018
|
-
|
|
1943
|
+
scrollToElement
|
|
2019
1944
|
} = action;
|
|
2020
1945
|
const uri = yield buildUri({}, mappers);
|
|
2021
1946
|
yield put(navigate(uri));
|
|
2022
|
-
if (typeof
|
|
1947
|
+
if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
|
|
2023
1948
|
}
|
|
2024
|
-
|
|
2025
1949
|
function* buildUri({
|
|
2026
1950
|
facet,
|
|
2027
1951
|
orderBy,
|
|
@@ -2038,11 +1962,10 @@ function* buildUri({
|
|
|
2038
1962
|
pageIndex,
|
|
2039
1963
|
pageSize,
|
|
2040
1964
|
term
|
|
2041
|
-
});
|
|
2042
|
-
|
|
1965
|
+
});
|
|
1966
|
+
// return uri;
|
|
2043
1967
|
return `${uri.path}${uri.search && `?${uri.search}` || ''}${uri.hash && `#${uri.hash}` || ''}`;
|
|
2044
1968
|
}
|
|
2045
|
-
|
|
2046
1969
|
function* triggerMinilistSsr(options) {
|
|
2047
1970
|
yield call(doSearch, {
|
|
2048
1971
|
type: DO_SEARCH,
|
|
@@ -2057,4 +1980,4 @@ function* triggerSearchSsr(options) {
|
|
|
2057
1980
|
}
|
|
2058
1981
|
|
|
2059
1982
|
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-
|
|
1983
|
+
//# sourceMappingURL=sagas-933a8fc8.js.map
|