@blaze-cms/react-page-builder 0.132.0 → 0.133.0-alpha.0
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/CHANGELOG.md +12 -0
- package/lib/components/Banner/BannerRender.js +2 -2
- package/lib/components/Banner/BannerRender.js.map +1 -1
- package/lib/components/Banner/helpers.js +2 -2
- package/lib/components/Banner/helpers.js.map +1 -1
- package/lib/components/BlazeLink.js +2 -2
- package/lib/components/BlazeLink.js.map +1 -1
- package/lib/components/Button.js +2 -2
- package/lib/components/Button.js.map +1 -1
- package/lib/components/Card/CardsContainer.js +2 -2
- package/lib/components/Card/CardsContainer.js.map +1 -1
- package/lib/components/Card/CardsRender.js +2 -2
- package/lib/components/Card/CardsRender.js.map +1 -1
- package/lib/components/Card/helpers/filter-query-setup.js +11 -5
- package/lib/components/Card/helpers/filter-query-setup.js.map +1 -1
- package/lib/components/ClickWrapper.js +2 -2
- package/lib/components/ClickWrapper.js.map +1 -1
- package/lib/components/Code/Code.js +2 -2
- package/lib/components/Code/Code.js.map +1 -1
- package/lib/components/Image/Image.js +2 -2
- package/lib/components/Image/Image.js.map +1 -1
- package/lib/components/Layout/Layout.js +2 -2
- package/lib/components/Layout/Layout.js.map +1 -1
- package/lib/components/List/ListBuilder.js +46 -26
- package/lib/components/List/ListBuilder.js.map +1 -1
- package/lib/components/List/ListFactory.js +5 -5
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRender.js +2 -2
- package/lib/components/List/components/Cards/CardsRender.js.map +1 -1
- package/lib/components/List/components/Full/FullRender.js +2 -2
- package/lib/components/List/components/Full/FullRender.js.map +1 -1
- package/lib/components/List/components/Full/FullRenderItem.js +2 -2
- package/lib/components/List/components/Full/FullRenderItem.js.map +1 -1
- package/lib/components/List/components/Pagination/ListPagination.js +2 -2
- package/lib/components/List/components/Pagination/ListPagination.js.map +1 -1
- package/lib/components/List/helpers/build-az-url.js +2 -2
- package/lib/components/List/helpers/build-az-url.js.map +1 -1
- package/lib/components/List/helpers/build-pagination-url.js +2 -2
- package/lib/components/List/helpers/build-pagination-url.js.map +1 -1
- package/lib/components/List/helpers/get-list-query.js +6 -2
- package/lib/components/List/helpers/get-list-query.js.map +1 -1
- package/lib/components/List/helpers/get-sort-props.js +5 -1
- package/lib/components/List/helpers/get-sort-props.js.map +1 -1
- package/lib/components/SearchFilter/components/Range.js +2 -2
- package/lib/components/SearchFilter/components/Range.js.map +1 -1
- package/lib/components/SearchFilter/searchFilterReducer.js +2 -2
- package/lib/components/SearchFilterSort/helpers/update-sort.js +2 -2
- package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
- package/lib/components/TextBlock/index.js +2 -2
- package/lib/components/TextBlock/index.js.map +1 -1
- package/lib/components/Video/Video.js +2 -2
- package/lib/components/Video/Video.js.map +1 -1
- package/lib/components/Video/providers/JWPlayer/JWPlayerProvider.js +2 -2
- package/lib/components/Video/providers/JWPlayer/JWPlayerProvider.js.map +1 -1
- package/lib/constants/index.js +4 -34
- package/lib/constants/index.js.map +1 -1
- package/lib/helpers/append-images.js +2 -2
- package/lib/helpers/build-az-filter.js +8 -7
- package/lib/helpers/build-az-filter.js.map +1 -1
- package/lib/helpers/build-raw-query-base.js +2 -2
- package/lib/helpers/build-raw-query-base.js.map +1 -1
- package/lib/helpers/build-raw-query.js +29 -8
- package/lib/helpers/build-raw-query.js.map +1 -1
- package/lib/helpers/build-sort-values.js +49 -0
- package/lib/helpers/build-sort-values.js.map +1 -0
- package/lib/helpers/get-banner-data.js +2 -2
- package/lib/helpers/get-click-wrapper-options.js +2 -2
- package/lib/helpers/get-click-wrapper-options.js.map +1 -1
- package/lib/helpers/get-entities-with-banner.js +2 -2
- package/lib/helpers/get-entities-with-banner.js.map +1 -1
- package/lib/helpers/get-extra-az-bits.js +46 -3
- package/lib/helpers/get-extra-az-bits.js.map +1 -1
- package/lib/helpers/get-generic-props.js +2 -2
- package/lib/helpers/get-generic-props.js.map +1 -1
- package/lib/helpers/get-generic-render-variables.js +30 -37
- package/lib/helpers/get-generic-render-variables.js.map +1 -1
- package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js +2 -2
- package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js.map +1 -1
- package/lib/helpers/process-data-summary-value.js +2 -2
- package/lib/helpers/process-data-summary-value.js.map +1 -1
- package/lib/helpers/remove-unwanted-characters.js +2 -2
- package/lib/helpers/render-children.js +2 -2
- package/lib/helpers/render-children.js.map +1 -1
- package/lib/helpers/split-children.js +2 -2
- package/lib/helpers/update-childrens-parent.js +2 -2
- package/lib/hooks/helpers/append-gtm-classname.js +2 -2
- package/lib/hooks/helpers/append-gtm-classname.js.map +1 -1
- package/lib/hooks/helpers/buildPBComponents.js +2 -2
- package/lib/hooks/helpers/buildPBComponents.js.map +1 -1
- package/lib/hooks/helpers/get-lightbox-images.js +2 -2
- package/lib/hooks/helpers/get-lightbox-images.js.map +1 -1
- package/lib/hooks/helpers/inject-element-banners.js +2 -2
- package/lib/hooks/helpers/inject-element-banners.js.map +1 -1
- package/lib/hooks/helpers/inject-textblock-banners.js +2 -2
- package/lib/hooks/helpers/inject-textblock-banners.js.map +1 -1
- package/lib/utils/get-class-modifiers.js +2 -2
- package/lib/utils/get-class-modifiers.js.map +1 -1
- package/lib-es/components/Banner/BannerRender.js +2 -2
- package/lib-es/components/Banner/helpers.js +2 -2
- package/lib-es/components/BlazeLink.js +2 -2
- package/lib-es/components/Button.js +2 -2
- package/lib-es/components/Card/CardsContainer.js +2 -2
- package/lib-es/components/Card/CardsRender.js +2 -2
- package/lib-es/components/Card/helpers/filter-query-setup.js +11 -5
- package/lib-es/components/Card/helpers/filter-query-setup.js.map +1 -1
- package/lib-es/components/ClickWrapper.js +2 -2
- package/lib-es/components/Code/Code.js +2 -2
- package/lib-es/components/Image/Image.js +2 -2
- package/lib-es/components/Layout/Layout.js +2 -2
- package/lib-es/components/List/ListBuilder.js +46 -26
- package/lib-es/components/List/ListBuilder.js.map +1 -1
- package/lib-es/components/List/ListFactory.js +5 -5
- package/lib-es/components/List/ListFactory.js.map +1 -1
- package/lib-es/components/List/components/Cards/CardsRender.js +2 -2
- package/lib-es/components/List/components/Full/FullRender.js +2 -2
- package/lib-es/components/List/components/Full/FullRenderItem.js +2 -2
- package/lib-es/components/List/components/Pagination/ListPagination.js +2 -2
- package/lib-es/components/List/helpers/build-az-url.js +2 -2
- package/lib-es/components/List/helpers/build-pagination-url.js +2 -2
- package/lib-es/components/List/helpers/get-list-query.js +5 -2
- package/lib-es/components/List/helpers/get-list-query.js.map +1 -1
- package/lib-es/components/List/helpers/get-sort-props.js +5 -1
- package/lib-es/components/List/helpers/get-sort-props.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Range.js +2 -2
- package/lib-es/components/SearchFilter/searchFilterReducer.js +2 -2
- package/lib-es/components/SearchFilterSort/helpers/update-sort.js +2 -2
- package/lib-es/components/TextBlock/index.js +2 -2
- package/lib-es/components/Video/Video.js +2 -2
- package/lib-es/components/Video/providers/JWPlayer/JWPlayerProvider.js +2 -2
- package/lib-es/constants/index.js +2 -31
- package/lib-es/constants/index.js.map +1 -1
- package/lib-es/helpers/append-images.js +2 -2
- package/lib-es/helpers/build-az-filter.js +3 -2
- package/lib-es/helpers/build-az-filter.js.map +1 -1
- package/lib-es/helpers/build-raw-query-base.js +2 -2
- package/lib-es/helpers/build-raw-query.js +26 -8
- package/lib-es/helpers/build-raw-query.js.map +1 -1
- package/lib-es/helpers/build-sort-values.js +34 -0
- package/lib-es/helpers/build-sort-values.js.map +1 -0
- package/lib-es/helpers/get-banner-data.js +2 -2
- package/lib-es/helpers/get-click-wrapper-options.js +2 -2
- package/lib-es/helpers/get-entities-with-banner.js +2 -2
- package/lib-es/helpers/get-extra-az-bits.js +48 -2
- package/lib-es/helpers/get-extra-az-bits.js.map +1 -1
- package/lib-es/helpers/get-generic-props.js +2 -2
- package/lib-es/helpers/get-generic-render-variables.js +24 -28
- package/lib-es/helpers/get-generic-render-variables.js.map +1 -1
- package/lib-es/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js +2 -2
- package/lib-es/helpers/process-data-summary-value.js +2 -2
- package/lib-es/helpers/remove-unwanted-characters.js +2 -2
- package/lib-es/helpers/render-children.js +2 -2
- package/lib-es/helpers/split-children.js +2 -2
- package/lib-es/helpers/update-childrens-parent.js +2 -2
- package/lib-es/hooks/helpers/append-gtm-classname.js +2 -2
- package/lib-es/hooks/helpers/buildPBComponents.js +2 -2
- package/lib-es/hooks/helpers/get-lightbox-images.js +2 -2
- package/lib-es/hooks/helpers/inject-element-banners.js +2 -2
- package/lib-es/hooks/helpers/inject-textblock-banners.js +2 -2
- package/lib-es/utils/get-class-modifiers.js +2 -2
- package/package.json +2 -2
- package/src/components/Card/helpers/filter-query-setup.js +4 -5
- package/src/components/List/ListBuilder.js +46 -55
- package/src/components/List/ListFactory.js +9 -7
- package/src/components/List/helpers/get-list-query.js +5 -2
- package/src/components/List/helpers/get-sort-props.js +9 -1
- package/src/constants/index.js +2 -32
- package/src/helpers/build-az-filter.js +3 -2
- package/src/helpers/build-raw-query.js +9 -7
- package/src/helpers/build-sort-values.js +32 -0
- package/src/helpers/get-extra-az-bits.js +40 -2
- package/src/helpers/get-generic-render-variables.js +20 -27
- package/tests/unit/src/components/List/helpers/get-list-query.test.js +55 -0
- package/tests/unit/src/components/List/helpers/get-sort-props.test.js +18 -0
- package/tests/unit/src/constants/__snapshots__/index.test.js.snap +3 -0
- package/tests/unit/src/constants/index.test.js +7 -0
- package/tests/unit/src/helpers/__snapshots__/get-extra-az-bits.test.js.snap +137 -0
- package/tests/unit/src/helpers/build-az-query.test.js +4 -3
- package/tests/unit/src/helpers/build-raw-query.test.js +82 -58
- package/tests/unit/src/helpers/build-sort-values.test.js +34 -0
- package/tests/unit/src/helpers/get-extra-az-bits.test.js +36 -6
- package/tests/unit/src/helpers/get-generic-render-variables.test.js +50 -53
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { AZ_QUERY_CONST, PB_QUERY_CONST } from '../../../constants';
|
|
1
2
|
import stripQueryKey from './strip-query-key';
|
|
2
3
|
|
|
3
4
|
const getListQuery = (query, hasListSpecificFilters, name) => {
|
|
4
5
|
const updatedQuery = {};
|
|
5
|
-
const listKey =
|
|
6
|
+
const listKey = `${PB_QUERY_CONST}[${name}]`;
|
|
6
7
|
const paginationKey = `${listKey}[page]`;
|
|
8
|
+
const azFilterKey = `${listKey}${AZ_QUERY_CONST}`;
|
|
7
9
|
const sortKey = `${listKey}[sort]`;
|
|
8
10
|
const sortByKey = `${listKey}[sortby]`;
|
|
9
11
|
|
|
@@ -16,8 +18,9 @@ const getListQuery = (query, hasListSpecificFilters, name) => {
|
|
|
16
18
|
const strippedKey = stripQueryKey(queryKey, listKey, paginationKey);
|
|
17
19
|
if (isListKey) updatedQuery[strippedKey] = decodedQueryValue;
|
|
18
20
|
} else {
|
|
19
|
-
if (queryKey.indexOf(
|
|
21
|
+
if (queryKey.indexOf(`${PB_QUERY_CONST}[`) === -1) updatedQuery[queryKey] = decodedQueryValue;
|
|
20
22
|
if (queryKey.indexOf(paginationKey) !== -1) updatedQuery[queryKey] = decodedQueryValue;
|
|
23
|
+
if (queryKey.indexOf(azFilterKey) !== -1) updatedQuery[queryKey] = decodedQueryValue;
|
|
21
24
|
}
|
|
22
25
|
});
|
|
23
26
|
updatedQuery.sort = query[sortKey] || query.sort;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
const getSortProps = ({
|
|
1
|
+
const getSortProps = ({
|
|
2
|
+
querySort,
|
|
3
|
+
sortProperties,
|
|
4
|
+
defaultSort,
|
|
5
|
+
querySortBy,
|
|
6
|
+
defaultSortBy,
|
|
7
|
+
isTextSearchFilterApplied
|
|
8
|
+
}) => {
|
|
2
9
|
const sort = querySort || (sortProperties.length ? null : defaultSort);
|
|
3
10
|
let sortby = null;
|
|
4
11
|
if (querySortBy) sortby = [querySortBy];
|
|
5
12
|
else if (!sortProperties.length) sortby = defaultSortBy;
|
|
6
13
|
|
|
7
14
|
const updatedSortProperties = [...sortProperties];
|
|
15
|
+
if (isTextSearchFilterApplied) updatedSortProperties.unshift({ isScore: true });
|
|
8
16
|
if (sort) updatedSortProperties.unshift({ sort, propsToDisplay: sortby });
|
|
9
17
|
|
|
10
18
|
const sortbyFilters = updatedSortProperties
|
package/src/constants/index.js
CHANGED
|
@@ -161,36 +161,7 @@ const AZ = [
|
|
|
161
161
|
'Z'
|
|
162
162
|
];
|
|
163
163
|
|
|
164
|
-
const
|
|
165
|
-
aggs: {
|
|
166
|
-
azCount: {
|
|
167
|
-
terms: {
|
|
168
|
-
script: "doc['name.keyword'].getValue().substring(0,1).toUpperCase()",
|
|
169
|
-
size: 500
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
sort: [{ 'name.keyword': 'asc' }]
|
|
174
|
-
};
|
|
175
|
-
const ALL_AZ_SORT = {
|
|
176
|
-
sort: [
|
|
177
|
-
{
|
|
178
|
-
_script: {
|
|
179
|
-
type: 'number',
|
|
180
|
-
script: {
|
|
181
|
-
lang: 'painless',
|
|
182
|
-
source:
|
|
183
|
-
"int charPos = params.letters.indexOf(doc['name.keyword'].value.substring(0,1).toUpperCase()); charPos > -1 ? charPos : 100",
|
|
184
|
-
params: {
|
|
185
|
-
letters: AZ
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
order: 'asc'
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
{ 'name.keyword': 'asc' }
|
|
192
|
-
]
|
|
193
|
-
};
|
|
164
|
+
const AZ_DEFAULT_PROP = 'name';
|
|
194
165
|
|
|
195
166
|
const SCROLL_OFFSET = process.env.BLAZE_SCROLL_OFFSET || 50;
|
|
196
167
|
|
|
@@ -302,8 +273,7 @@ export {
|
|
|
302
273
|
PREHEADER_PROP,
|
|
303
274
|
HEADLINE_PROP,
|
|
304
275
|
AZ_QUERY_CONST,
|
|
305
|
-
|
|
306
|
-
ALL_AZ_SORT,
|
|
276
|
+
AZ_DEFAULT_PROP,
|
|
307
277
|
AZ,
|
|
308
278
|
SCROLL_OFFSET,
|
|
309
279
|
ANCHOR_TAG,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const buildAzFilter = (azFilter, mustFilters) => {
|
|
1
|
+
const buildAzFilter = (azFilter, mustFilters, azSortProperty) => {
|
|
2
2
|
if (!azFilter) return;
|
|
3
3
|
const filterValue = azFilter === '0' ? '[^a-zA-Z]' : azFilter;
|
|
4
|
+
const azSortProp = `${azSortProperty}.keyword`;
|
|
4
5
|
const azQuery = {
|
|
5
6
|
regexp: {
|
|
6
|
-
|
|
7
|
+
[azSortProp]: {
|
|
7
8
|
value: `${filterValue}.*`,
|
|
8
9
|
case_insensitive: true
|
|
9
10
|
}
|
|
@@ -2,9 +2,9 @@ import buildRawQueryBase from './build-raw-query-base';
|
|
|
2
2
|
import getItemsToDisplayIds from './get-items-to-display-ids';
|
|
3
3
|
import getExtraAzBits from './get-extra-az-bits';
|
|
4
4
|
import buildAzFilter from './build-az-filter';
|
|
5
|
-
import { AND_OPERATOR } from '../constants';
|
|
5
|
+
import { AND_OPERATOR, AZ_DEFAULT_PROP } from '../constants';
|
|
6
6
|
|
|
7
|
-
const buildRawQuery = (
|
|
7
|
+
const buildRawQuery = ({
|
|
8
8
|
docType,
|
|
9
9
|
operator,
|
|
10
10
|
searchValues,
|
|
@@ -13,15 +13,17 @@ const buildRawQuery = (
|
|
|
13
13
|
itemsToDisplay,
|
|
14
14
|
shouldApplySort,
|
|
15
15
|
azOptions
|
|
16
|
-
) => {
|
|
16
|
+
}) => {
|
|
17
17
|
const {
|
|
18
18
|
searchValuesText,
|
|
19
19
|
searchValuesCheckboxSelectRange,
|
|
20
20
|
searchValuesCheckboxOr
|
|
21
21
|
} = searchValues;
|
|
22
|
-
|
|
23
22
|
const { filterValues, filterOperator, relations, stringProps, azFilter } = filterData;
|
|
24
|
-
const {
|
|
23
|
+
const { isAZ, sortProperties = [] } = azOptions || {};
|
|
24
|
+
const [{ propsToDisplay: [azSortProp] } = { propsToDisplay: [] }] = sortProperties;
|
|
25
|
+
const azSortProperty = azSortProp || AZ_DEFAULT_PROP;
|
|
26
|
+
|
|
25
27
|
const searchValuesTextCheckboxSelectJoined =
|
|
26
28
|
operator === AND_OPERATOR ? [...searchValuesText, ...searchValuesCheckboxSelectRange] : [];
|
|
27
29
|
let searchValuesTextCheckboxOr = searchValuesText;
|
|
@@ -50,7 +52,7 @@ const buildRawQuery = (
|
|
|
50
52
|
}
|
|
51
53
|
];
|
|
52
54
|
|
|
53
|
-
buildAzFilter(azFilter, mustValues);
|
|
55
|
+
buildAzFilter(azFilter, mustValues, azSortProperty);
|
|
54
56
|
|
|
55
57
|
const query = {
|
|
56
58
|
bool: {
|
|
@@ -58,7 +60,7 @@ const buildRawQuery = (
|
|
|
58
60
|
...buildRawQueryBase({ docType, id, filterValues, filterOperator, relations, stringProps })
|
|
59
61
|
}
|
|
60
62
|
};
|
|
61
|
-
const azQueryBits = getExtraAzBits(
|
|
63
|
+
const azQueryBits = getExtraAzBits({ ...azOptions, azSortProperty, azFilter });
|
|
62
64
|
|
|
63
65
|
if (itemsToDisplay && itemsToDisplay.length) {
|
|
64
66
|
const itemsToDisplayIds = getItemsToDisplayIds(itemsToDisplay);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import getSortbyFieldName from './get-sort-by-field-name';
|
|
2
|
+
|
|
3
|
+
const buildAzSort = (sortFilters, relations, stringProps) => {
|
|
4
|
+
const sortValues = {};
|
|
5
|
+
sortFilters.forEach(({ sort, propsToDisplay }) => {
|
|
6
|
+
if (!sort) return;
|
|
7
|
+
const sortFieldName = getSortbyFieldName(relations, propsToDisplay, stringProps);
|
|
8
|
+
if (sortFieldName) sortValues[sortFieldName] = sort.toLowerCase();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return sortValues;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const buildSortValues = (sortFilters, relations, stringProps, useSortObject) => {
|
|
15
|
+
if (!sortFilters || !sortFilters.length) return useSortObject ? null : { sort: [] };
|
|
16
|
+
if (useSortObject) return buildAzSort(sortFilters, relations, stringProps);
|
|
17
|
+
|
|
18
|
+
const sortValues = sortFilters
|
|
19
|
+
.map(({ sort, propsToDisplay, isScore }) => {
|
|
20
|
+
if (isScore) return '_score';
|
|
21
|
+
if (!sort) return null;
|
|
22
|
+
|
|
23
|
+
const sortFieldName = getSortbyFieldName(relations, propsToDisplay, stringProps);
|
|
24
|
+
return sortFieldName ? `${sortFieldName}:${sort.toLowerCase()}` : null;
|
|
25
|
+
})
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join(',');
|
|
28
|
+
|
|
29
|
+
return { sort: sortValues };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default buildSortValues;
|
|
@@ -1,7 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AZ, AZ_DEFAULT_PROP } from '../constants';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function getAzArgs(azSortProperty) {
|
|
4
|
+
const azProp = `${azSortProperty}.keyword`;
|
|
5
|
+
|
|
6
|
+
const AZ_AGGS = {
|
|
7
|
+
aggs: {
|
|
8
|
+
azCount: {
|
|
9
|
+
terms: {
|
|
10
|
+
script: `doc['${azProp}'].getValue().substring(0,1).toUpperCase()`,
|
|
11
|
+
size: 500
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
sort: [{ [azProp]: 'asc' }]
|
|
16
|
+
};
|
|
17
|
+
const ALL_AZ_SORT = {
|
|
18
|
+
sort: [
|
|
19
|
+
{
|
|
20
|
+
_script: {
|
|
21
|
+
type: 'number',
|
|
22
|
+
script: {
|
|
23
|
+
lang: 'painless',
|
|
24
|
+
source: `int charPos = params.letters.indexOf(doc['${azProp}'].value.substring(0,1).toUpperCase()); charPos > -1 ? charPos : 100`,
|
|
25
|
+
params: {
|
|
26
|
+
letters: AZ
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
order: 'asc'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{ [azProp]: 'asc' }
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return { ALL_AZ_SORT, AZ_AGGS };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getExtraAzBits = ({ shouldReturnAggs, isAZ, azSortProperty = AZ_DEFAULT_PROP, azFilter }) => {
|
|
4
40
|
if (!isAZ || (isAZ && azFilter)) return {};
|
|
41
|
+
|
|
42
|
+
const { AZ_AGGS, ALL_AZ_SORT } = getAzArgs(azSortProperty);
|
|
5
43
|
if (shouldReturnAggs) return AZ_AGGS;
|
|
6
44
|
|
|
7
45
|
return ALL_AZ_SORT;
|
|
@@ -1,42 +1,25 @@
|
|
|
1
|
-
import getSortbyFieldName from './get-sort-by-field-name';
|
|
2
1
|
import { DEFAULT_LIMIT, DEFAULT_OFFSET } from '../constants';
|
|
2
|
+
import buildSortValues from './build-sort-values';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
if (!sortFilters || !sortFilters.length) return { sort: [] };
|
|
6
|
-
|
|
7
|
-
const sortValues = sortFilters
|
|
8
|
-
.map(({ sort, propsToDisplay }) => {
|
|
9
|
-
if (!sort) return null;
|
|
10
|
-
|
|
11
|
-
const sortFieldName = getSortbyFieldName(relations, propsToDisplay, stringProps);
|
|
12
|
-
return sortFieldName ? `${sortFieldName}:${sort.toLowerCase()}` : null;
|
|
13
|
-
})
|
|
14
|
-
.filter(Boolean)
|
|
15
|
-
.join(',');
|
|
16
|
-
|
|
17
|
-
return { sort: sortValues };
|
|
18
|
-
};
|
|
19
|
-
const getCorrectSort = (relations, filterProps, stringProps, isTextSearchApplied) => {
|
|
20
|
-
if (isTextSearchApplied) {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
4
|
+
const getCorrectSort = (relations, filterProps, stringProps, useSortObject) => {
|
|
23
5
|
const { sort, sortby, sortProperties = [] } = filterProps;
|
|
24
6
|
|
|
25
7
|
return buildSortValues(
|
|
26
8
|
[{ sort, propsToDisplay: sortby }, ...sortProperties],
|
|
27
9
|
relations,
|
|
28
|
-
stringProps
|
|
10
|
+
stringProps,
|
|
11
|
+
useSortObject
|
|
29
12
|
);
|
|
30
13
|
};
|
|
31
14
|
|
|
32
|
-
const getGenericRenderVariables = (
|
|
15
|
+
const getGenericRenderVariables = ({
|
|
33
16
|
relations,
|
|
34
17
|
filterProps = {},
|
|
35
18
|
stringProps = [],
|
|
36
19
|
rawQuery = {},
|
|
37
|
-
isTextSearchFilterApplied = false,
|
|
38
20
|
useRandomSort = false
|
|
39
|
-
) => {
|
|
21
|
+
}) => {
|
|
22
|
+
const rawQueryCopy = { ...rawQuery };
|
|
40
23
|
const { limit = DEFAULT_LIMIT, offset } = filterProps;
|
|
41
24
|
const limitToUse = Number(limit || DEFAULT_LIMIT);
|
|
42
25
|
const offsetToUse = Number(offset || DEFAULT_OFFSET);
|
|
@@ -45,7 +28,7 @@ const getGenericRenderVariables = (
|
|
|
45
28
|
const rawQueryStringified = JSON.stringify({
|
|
46
29
|
query: {
|
|
47
30
|
function_score: {
|
|
48
|
-
query:
|
|
31
|
+
query: rawQueryCopy && rawQueryCopy.query ? rawQueryCopy.query : rawQueryCopy,
|
|
49
32
|
random_score: {},
|
|
50
33
|
boost_mode: 'replace'
|
|
51
34
|
}
|
|
@@ -59,13 +42,23 @@ const getGenericRenderVariables = (
|
|
|
59
42
|
};
|
|
60
43
|
}
|
|
61
44
|
|
|
62
|
-
const sort = getCorrectSort(relations, filterProps, stringProps,
|
|
45
|
+
const sort = getCorrectSort(relations, filterProps, stringProps, !!rawQueryCopy.sort);
|
|
46
|
+
|
|
47
|
+
if (rawQueryCopy.sort && sort) {
|
|
48
|
+
rawQueryCopy.sort = [...rawQueryCopy.sort, sort];
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
limit: limitToUse,
|
|
52
|
+
offset: offsetToUse,
|
|
53
|
+
rawQueryStringified: JSON.stringify(rawQueryCopy)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
63
56
|
|
|
64
57
|
return {
|
|
65
58
|
limit: limitToUse,
|
|
66
59
|
offset: offsetToUse,
|
|
67
60
|
...sort,
|
|
68
|
-
rawQueryStringified: JSON.stringify(
|
|
61
|
+
rawQueryStringified: JSON.stringify(rawQueryCopy)
|
|
69
62
|
};
|
|
70
63
|
};
|
|
71
64
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import getListQuery from '../../../../../../src/components/List/helpers/get-list-query';
|
|
2
|
+
|
|
3
|
+
describe('getListQuery', () => {
|
|
4
|
+
it('should handle empty query', () => {
|
|
5
|
+
const query = {};
|
|
6
|
+
const hasListSpecificFilters = false;
|
|
7
|
+
const name = 'testList';
|
|
8
|
+
|
|
9
|
+
const result = getListQuery(query, hasListSpecificFilters, name);
|
|
10
|
+
|
|
11
|
+
expect(result).toEqual({});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should handle query without list-specific filters', () => {
|
|
15
|
+
const query = {
|
|
16
|
+
param1: 'value1',
|
|
17
|
+
param2: 'value2',
|
|
18
|
+
otherParam: 'otherValue',
|
|
19
|
+
'pb[testList][page]': '2',
|
|
20
|
+
'pb[testList][sort]': 'date',
|
|
21
|
+
'pb[testList][sortby]': 'asc'
|
|
22
|
+
};
|
|
23
|
+
const hasListSpecificFilters = false;
|
|
24
|
+
const name = 'testList';
|
|
25
|
+
|
|
26
|
+
const result = getListQuery(query, hasListSpecificFilters, name);
|
|
27
|
+
|
|
28
|
+
expect(result).toEqual({
|
|
29
|
+
param1: 'value1',
|
|
30
|
+
param2: 'value2',
|
|
31
|
+
otherParam: 'otherValue',
|
|
32
|
+
sort: 'date',
|
|
33
|
+
sortby: 'asc',
|
|
34
|
+
'pb[testList][page]': '2'
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should handle query with list-specific filters', () => {
|
|
39
|
+
const query = {
|
|
40
|
+
'pb[testList][filter1]': 'filterValue1',
|
|
41
|
+
'pb[testList][page]': '3',
|
|
42
|
+
'pb[testList][sort]': 'name'
|
|
43
|
+
};
|
|
44
|
+
const hasListSpecificFilters = true;
|
|
45
|
+
const name = 'testList';
|
|
46
|
+
|
|
47
|
+
const result = getListQuery(query, hasListSpecificFilters, name);
|
|
48
|
+
|
|
49
|
+
expect(result).toEqual({
|
|
50
|
+
filter1: 'filterValue1',
|
|
51
|
+
sort: 'name',
|
|
52
|
+
'pb[testList][page]': '3'
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -42,6 +42,24 @@ describe('getSortProps helper function', () => {
|
|
|
42
42
|
]);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
it('should add score sort as second value if has textSearch', () => {
|
|
46
|
+
const { sortbyFilters, updatedSortProperties } = getSortProps({
|
|
47
|
+
...props,
|
|
48
|
+
querySortBy,
|
|
49
|
+
querySort: desc,
|
|
50
|
+
isTextSearchFilterApplied: true
|
|
51
|
+
});
|
|
52
|
+
expect(sortbyFilters).toEqual([querySortBy, property]);
|
|
53
|
+
expect(updatedSortProperties).toEqual([
|
|
54
|
+
{
|
|
55
|
+
propsToDisplay: [querySortBy],
|
|
56
|
+
sort: desc
|
|
57
|
+
},
|
|
58
|
+
{ isScore: true },
|
|
59
|
+
...sortProperties
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
|
|
45
63
|
it('should use old style sort', () => {
|
|
46
64
|
const { sortbyFilters, updatedSortProperties } = getSortProps({
|
|
47
65
|
...props,
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`getExtraAzBits helper function should return ALL_AZ_SORT if shouldReturnAggs is false and is Az and no Az filter is passed 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"sort": Array [
|
|
6
|
+
Object {
|
|
7
|
+
"_script": Object {
|
|
8
|
+
"order": "asc",
|
|
9
|
+
"script": Object {
|
|
10
|
+
"lang": "painless",
|
|
11
|
+
"params": Object {
|
|
12
|
+
"letters": Array [
|
|
13
|
+
"A",
|
|
14
|
+
"B",
|
|
15
|
+
"C",
|
|
16
|
+
"D",
|
|
17
|
+
"E",
|
|
18
|
+
"F",
|
|
19
|
+
"G",
|
|
20
|
+
"H",
|
|
21
|
+
"I",
|
|
22
|
+
"J",
|
|
23
|
+
"K",
|
|
24
|
+
"L",
|
|
25
|
+
"M",
|
|
26
|
+
"N",
|
|
27
|
+
"O",
|
|
28
|
+
"P",
|
|
29
|
+
"Q",
|
|
30
|
+
"R",
|
|
31
|
+
"S",
|
|
32
|
+
"T",
|
|
33
|
+
"U",
|
|
34
|
+
"V",
|
|
35
|
+
"W",
|
|
36
|
+
"X",
|
|
37
|
+
"Y",
|
|
38
|
+
"Z",
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
"source": "int charPos = params.letters.indexOf(doc['name.keyword'].value.substring(0,1).toUpperCase()); charPos > -1 ? charPos : 100",
|
|
42
|
+
},
|
|
43
|
+
"type": "number",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
Object {
|
|
47
|
+
"name.keyword": "asc",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
exports[`getExtraAzBits helper function should return ALL_AZ_SORT if shouldReturnAggs is false and is Az and no Az filter is passed with custom property 1`] = `
|
|
54
|
+
Object {
|
|
55
|
+
"sort": Array [
|
|
56
|
+
Object {
|
|
57
|
+
"_script": Object {
|
|
58
|
+
"order": "asc",
|
|
59
|
+
"script": Object {
|
|
60
|
+
"lang": "painless",
|
|
61
|
+
"params": Object {
|
|
62
|
+
"letters": Array [
|
|
63
|
+
"A",
|
|
64
|
+
"B",
|
|
65
|
+
"C",
|
|
66
|
+
"D",
|
|
67
|
+
"E",
|
|
68
|
+
"F",
|
|
69
|
+
"G",
|
|
70
|
+
"H",
|
|
71
|
+
"I",
|
|
72
|
+
"J",
|
|
73
|
+
"K",
|
|
74
|
+
"L",
|
|
75
|
+
"M",
|
|
76
|
+
"N",
|
|
77
|
+
"O",
|
|
78
|
+
"P",
|
|
79
|
+
"Q",
|
|
80
|
+
"R",
|
|
81
|
+
"S",
|
|
82
|
+
"T",
|
|
83
|
+
"U",
|
|
84
|
+
"V",
|
|
85
|
+
"W",
|
|
86
|
+
"X",
|
|
87
|
+
"Y",
|
|
88
|
+
"Z",
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
"source": "int charPos = params.letters.indexOf(doc['lastname.keyword'].value.substring(0,1).toUpperCase()); charPos > -1 ? charPos : 100",
|
|
92
|
+
},
|
|
93
|
+
"type": "number",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
Object {
|
|
97
|
+
"lastname.keyword": "asc",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
exports[`getExtraAzBits helper function should return AZ_AGGS if shouldReturnAggs and isAz is true 1`] = `
|
|
104
|
+
Object {
|
|
105
|
+
"aggs": Object {
|
|
106
|
+
"azCount": Object {
|
|
107
|
+
"terms": Object {
|
|
108
|
+
"script": "doc['name.keyword'].getValue().substring(0,1).toUpperCase()",
|
|
109
|
+
"size": 500,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
"sort": Array [
|
|
114
|
+
Object {
|
|
115
|
+
"name.keyword": "asc",
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
|
|
121
|
+
exports[`getExtraAzBits helper function should return AZ_AGGS if shouldReturnAggs and isAz is true with custom property 1`] = `
|
|
122
|
+
Object {
|
|
123
|
+
"aggs": Object {
|
|
124
|
+
"azCount": Object {
|
|
125
|
+
"terms": Object {
|
|
126
|
+
"script": "doc['lastname.keyword'].getValue().substring(0,1).toUpperCase()",
|
|
127
|
+
"size": 500,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
"sort": Array [
|
|
132
|
+
Object {
|
|
133
|
+
"lastname.keyword": "asc",
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
}
|
|
137
|
+
`;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import buildAzFilter from '../../../../src/helpers/build-az-filter';
|
|
2
|
+
import { AZ_DEFAULT_PROP } from '../../../../src/constants';
|
|
2
3
|
|
|
3
4
|
const mockFilters = [{ must: ['this'] }];
|
|
4
5
|
const mockedResult = [
|
|
5
6
|
{ must: ['this'] },
|
|
6
7
|
{
|
|
7
8
|
regexp: {
|
|
8
|
-
|
|
9
|
+
[`${AZ_DEFAULT_PROP}.keyword`]: {
|
|
9
10
|
value: `b.*`,
|
|
10
11
|
case_insensitive: true
|
|
11
12
|
}
|
|
@@ -14,12 +15,12 @@ const mockedResult = [
|
|
|
14
15
|
];
|
|
15
16
|
describe('buildAzFilter helper function', () => {
|
|
16
17
|
it('should leave unchanged filters if no az is passed', () => {
|
|
17
|
-
buildAzFilter('', mockFilters);
|
|
18
|
+
buildAzFilter('', mockFilters, AZ_DEFAULT_PROP);
|
|
18
19
|
expect(mockFilters).toEqual(mockFilters);
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
it('should update filters if az is passed', () => {
|
|
22
|
-
buildAzFilter('b', mockFilters);
|
|
23
|
+
buildAzFilter('b', mockFilters, AZ_DEFAULT_PROP);
|
|
23
24
|
expect(mockFilters).toEqual(mockedResult);
|
|
24
25
|
});
|
|
25
26
|
});
|