@blaze-cms/react-page-builder 0.113.0 → 0.114.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/README.md +5 -8
- package/lib/components/Card/CardRender.js +61 -17
- package/lib/components/Card/CardRender.js.map +1 -1
- package/lib/components/Card/helpers/filter-query-setup.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib/components/List/ListBuilder.js +11 -6
- package/lib/components/List/ListBuilder.js.map +1 -1
- package/lib/components/List/ListFactory.js +20 -7
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/List/helpers/get-sort-props.js +46 -0
- package/lib/components/List/helpers/get-sort-props.js.map +1 -0
- package/lib/components/List/helpers/index.js +8 -0
- package/lib/components/List/helpers/index.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/FiltersList.js +11 -5
- package/lib/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +57 -20
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +8 -4
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/components/Checkbox.js +5 -2
- package/lib/components/SearchFilter/components/Checkbox.js.map +1 -1
- package/lib/components/SearchFilter/components/Range.js +7 -3
- package/lib/components/SearchFilter/components/Range.js.map +1 -1
- package/lib/components/SearchFilter/components/Select.js +5 -2
- package/lib/components/SearchFilter/components/Select.js.map +1 -1
- package/lib/components/SearchFilter/constants.js +13 -1
- package/lib/components/SearchFilter/constants.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-query.js +6 -5
- package/lib/components/SearchFilter/helpers/build-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-range-value.js +6 -4
- package/lib/components/SearchFilter/helpers/get-range-value.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-responsive-filter-classnames.js +29 -0
- package/lib/components/SearchFilter/helpers/get-responsive-filter-classnames.js.map +1 -0
- package/lib/components/SearchFilter/helpers/index.js +8 -0
- package/lib/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib/components/SearchFilter/helpers/is-device-desktop.js +1 -1
- package/lib/components/SearchFilter/helpers/is-device-desktop.js.map +1 -1
- package/lib/helpers/get-generic-render-variables.js +32 -22
- package/lib/helpers/get-generic-render-variables.js.map +1 -1
- package/lib-es/components/Card/CardRender.js +32 -5
- package/lib-es/components/Card/CardRender.js.map +1 -1
- package/lib-es/components/Card/helpers/filter-query-setup.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +1 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib-es/components/List/ListBuilder.js +11 -6
- package/lib-es/components/List/ListBuilder.js.map +1 -1
- package/lib-es/components/List/ListFactory.js +20 -8
- package/lib-es/components/List/ListFactory.js.map +1 -1
- package/lib-es/components/List/helpers/get-sort-props.js +26 -0
- package/lib-es/components/List/helpers/get-sort-props.js.map +1 -0
- package/lib-es/components/List/helpers/index.js +1 -0
- package/lib-es/components/List/helpers/index.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js +11 -5
- package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +51 -21
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +8 -4
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Checkbox.js +5 -2
- package/lib-es/components/SearchFilter/components/Checkbox.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Range.js +7 -3
- package/lib-es/components/SearchFilter/components/Range.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Select.js +5 -2
- package/lib-es/components/SearchFilter/components/Select.js.map +1 -1
- package/lib-es/components/SearchFilter/constants.js +12 -1
- package/lib-es/components/SearchFilter/constants.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-query.js +5 -4
- package/lib-es/components/SearchFilter/helpers/build-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/get-range-value.js +1 -1
- package/lib-es/components/SearchFilter/helpers/get-range-value.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/get-responsive-filter-classnames.js +20 -0
- package/lib-es/components/SearchFilter/helpers/get-responsive-filter-classnames.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/index.js +2 -1
- package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/is-device-desktop.js +1 -1
- package/lib-es/components/SearchFilter/helpers/is-device-desktop.js.map +1 -1
- package/lib-es/helpers/get-generic-render-variables.js +22 -15
- package/lib-es/helpers/get-generic-render-variables.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Card/CardRender.js +24 -6
- package/src/components/Card/helpers/filter-query-setup.js +1 -0
- package/src/components/DataSummary/helpers/build-loop-props-content.js +1 -6
- package/src/components/List/ListBuilder.js +11 -6
- package/src/components/List/ListFactory.js +18 -8
- package/src/components/List/helpers/get-sort-props.js +17 -0
- package/src/components/List/helpers/index.js +1 -0
- package/src/components/SearchFilter/SearchFilter/FiltersList.js +15 -2
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +75 -25
- package/src/components/SearchFilter/SearchFilterContainer.js +8 -4
- package/src/components/SearchFilter/components/Checkbox.js +4 -2
- package/src/components/SearchFilter/components/Range.js +7 -3
- package/src/components/SearchFilter/components/Select.js +4 -2
- package/src/components/SearchFilter/constants.js +14 -1
- package/src/components/SearchFilter/helpers/build-query.js +5 -4
- package/src/components/SearchFilter/helpers/get-range-value.js +3 -1
- package/src/components/SearchFilter/helpers/get-responsive-filter-classnames.js +22 -0
- package/src/components/SearchFilter/helpers/index.js +2 -0
- package/src/components/SearchFilter/helpers/is-device-desktop.js +2 -1
- package/src/helpers/get-generic-render-variables.js +22 -12
- package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +24 -0
- package/tests/unit/src/components/List/helpers/get-sort-props.test.js +58 -0
- package/tests/unit/src/components/SearchFilter/SearchFilter/SearchFilter.test.js +29 -3
- package/tests/unit/src/components/SearchFilter/SearchFilter/__snapshots__/SearchFilter.test.js.snap +304 -6
- package/tests/unit/src/helpers/build-raw-query.test.js +2 -1
- package/tests/unit/src/helpers/get-generic-render-variables.test.js +5 -11
- package/lib/helpers/check-sort-by.js +0 -16
- package/lib/helpers/check-sort-by.js.map +0 -1
- package/lib-es/helpers/check-sort-by.js +0 -4
- package/lib-es/helpers/check-sort-by.js.map +0 -1
- package/src/helpers/check-sort-by.js +0 -4
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
const _excluded = ["limit", "offset"];
|
|
4
2
|
|
|
5
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
6
4
|
|
|
7
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
6
|
|
|
9
|
-
import checkSortby from './check-sort-by';
|
|
10
7
|
import getSortbyFieldName from './get-sort-by-field-name';
|
|
11
8
|
import { DEFAULT_LIMIT, DEFAULT_OFFSET } from '../constants';
|
|
12
9
|
|
|
10
|
+
const buildSortValues = (sortFilters, relations, stringProps) => {
|
|
11
|
+
if (!sortFilters || !sortFilters.length) return {
|
|
12
|
+
sort: []
|
|
13
|
+
};
|
|
14
|
+
const sortValues = sortFilters.map(({
|
|
15
|
+
sort,
|
|
16
|
+
propsToDisplay
|
|
17
|
+
}) => !!sort && !!propsToDisplay[0] && `${getSortbyFieldName(relations, propsToDisplay[0], stringProps)}:${sort.toLowerCase()}`).filter(Boolean).join(',');
|
|
18
|
+
return {
|
|
19
|
+
sort: sortValues
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
13
23
|
const getCorrectSort = (relations, filterProps, stringProps, isTextSearchApplied) => {
|
|
14
24
|
if (isTextSearchApplied) {
|
|
15
25
|
return {};
|
|
@@ -17,23 +27,20 @@ const getCorrectSort = (relations, filterProps, stringProps, isTextSearchApplied
|
|
|
17
27
|
|
|
18
28
|
const {
|
|
19
29
|
sort,
|
|
20
|
-
sortby
|
|
30
|
+
sortby,
|
|
31
|
+
sortProperties = []
|
|
21
32
|
} = filterProps;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
sort: sortValue
|
|
27
|
-
} : {};
|
|
33
|
+
return buildSortValues([{
|
|
34
|
+
sort,
|
|
35
|
+
propsToDisplay: [sortby]
|
|
36
|
+
}, ...sortProperties], relations, stringProps);
|
|
28
37
|
};
|
|
29
38
|
|
|
30
|
-
const getGenericRenderVariables = (relations,
|
|
31
|
-
|
|
39
|
+
const getGenericRenderVariables = (relations, filterProps = {}, stringProps = [], rawQueryStringified = '', isTextSearchFilterApplied = false) => {
|
|
40
|
+
const {
|
|
32
41
|
limit = DEFAULT_LIMIT,
|
|
33
42
|
offset
|
|
34
|
-
} =
|
|
35
|
-
filterProps = _objectWithoutProperties(_ref, _excluded);
|
|
36
|
-
|
|
43
|
+
} = filterProps;
|
|
37
44
|
const sort = getCorrectSort(relations, filterProps, stringProps, isTextSearchFilterApplied);
|
|
38
45
|
const raw = rawQueryStringified ? {
|
|
39
46
|
rawQueryStringified
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/get-generic-render-variables.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/get-generic-render-variables.js"],"names":["getSortbyFieldName","DEFAULT_LIMIT","DEFAULT_OFFSET","buildSortValues","sortFilters","relations","stringProps","length","sort","sortValues","map","propsToDisplay","toLowerCase","filter","Boolean","join","getCorrectSort","filterProps","isTextSearchApplied","sortby","sortProperties","getGenericRenderVariables","rawQueryStringified","isTextSearchFilterApplied","limit","offset","raw","Number"],"mappings":";;;;;;AAAA,OAAOA,kBAAP,MAA+B,0BAA/B;AACA,SAASC,aAAT,EAAwBC,cAAxB,QAA8C,cAA9C;;AAEA,MAAMC,eAAe,GAAG,CAACC,WAAD,EAAcC,SAAd,EAAyBC,WAAzB,KAAyC;AAC/D,MAAI,CAACF,WAAD,IAAgB,CAACA,WAAW,CAACG,MAAjC,EAAyC,OAAO;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAAP;AACzC,QAAMC,UAAU,GAAGL,WAAW,CAC3BM,GADgB,CAEf,CAAC;AAAEF,IAAAA,IAAF;AAAQG,IAAAA;AAAR,GAAD,KACE,CAAC,CAACH,IAAF,IACA,CAAC,CAACG,cAAc,CAAC,CAAD,CADhB,IAEC,GAAEX,kBAAkB,CAACK,SAAD,EAAYM,cAAc,CAAC,CAAD,CAA1B,EAA+BL,WAA/B,CAA4C,IAAGE,IAAI,CAACI,WAAL,EAAmB,EAL1E,EAOhBC,MAPgB,CAOTC,OAPS,EAQhBC,IARgB,CAQX,GARW,CAAnB;AAUA,SAAO;AAAEP,IAAAA,IAAI,EAAEC;AAAR,GAAP;AACD,CAbD;;AAcA,MAAMO,cAAc,GAAG,CAACX,SAAD,EAAYY,WAAZ,EAAyBX,WAAzB,EAAsCY,mBAAtC,KAA8D;AACnF,MAAIA,mBAAJ,EAAyB;AACvB,WAAO,EAAP;AACD;;AACD,QAAM;AAAEV,IAAAA,IAAF;AAAQW,IAAAA,MAAR;AAAgBC,IAAAA,cAAc,GAAG;AAAjC,MAAwCH,WAA9C;AAEA,SAAOd,eAAe,CACpB,CAAC;AAAEK,IAAAA,IAAF;AAAQG,IAAAA,cAAc,EAAE,CAACQ,MAAD;AAAxB,GAAD,EAAqC,GAAGC,cAAxC,CADoB,EAEpBf,SAFoB,EAGpBC,WAHoB,CAAtB;AAKD,CAXD;;AAaA,MAAMe,yBAAyB,GAAG,CAChChB,SADgC,EAEhCY,WAAW,GAAG,EAFkB,EAGhCX,WAAW,GAAG,EAHkB,EAIhCgB,mBAAmB,GAAG,EAJU,EAKhCC,yBAAyB,GAAG,KALI,KAM7B;AACH,QAAM;AAAEC,IAAAA,KAAK,GAAGvB,aAAV;AAAyBwB,IAAAA;AAAzB,MAAoCR,WAA1C;AACA,QAAMT,IAAI,GAAGQ,cAAc,CAACX,SAAD,EAAYY,WAAZ,EAAyBX,WAAzB,EAAsCiB,yBAAtC,CAA3B;AACA,QAAMG,GAAG,GAAGJ,mBAAmB,GAAG;AAAEA,IAAAA;AAAF,GAAH,GAA6B,EAA5D;AAEA;AACEE,IAAAA,KAAK,EAAEG,MAAM,CAACH,KAAK,IAAIvB,aAAV,CADf;AAEEwB,IAAAA,MAAM,EAAEE,MAAM,CAACF,MAAM,IAAIvB,cAAX;AAFhB,KAGKM,IAHL,GAIKkB,GAJL;AAMD,CAjBD;;AAmBA,eAAeL,yBAAf","sourcesContent":["import getSortbyFieldName from './get-sort-by-field-name';\nimport { DEFAULT_LIMIT, DEFAULT_OFFSET } from '../constants';\n\nconst buildSortValues = (sortFilters, relations, stringProps) => {\n if (!sortFilters || !sortFilters.length) return { sort: [] };\n const sortValues = sortFilters\n .map(\n ({ sort, propsToDisplay }) =>\n !!sort &&\n !!propsToDisplay[0] &&\n `${getSortbyFieldName(relations, propsToDisplay[0], stringProps)}:${sort.toLowerCase()}`\n )\n .filter(Boolean)\n .join(',');\n\n return { sort: sortValues };\n};\nconst getCorrectSort = (relations, filterProps, stringProps, isTextSearchApplied) => {\n if (isTextSearchApplied) {\n return {};\n }\n const { sort, sortby, sortProperties = [] } = filterProps;\n\n return buildSortValues(\n [{ sort, propsToDisplay: [sortby] }, ...sortProperties],\n relations,\n stringProps\n );\n};\n\nconst getGenericRenderVariables = (\n relations,\n filterProps = {},\n stringProps = [],\n rawQueryStringified = '',\n isTextSearchFilterApplied = false\n) => {\n const { limit = DEFAULT_LIMIT, offset } = filterProps;\n const sort = getCorrectSort(relations, filterProps, stringProps, isTextSearchFilterApplied);\n const raw = rawQueryStringified ? { rawQueryStringified } : {};\n\n return {\n limit: Number(limit || DEFAULT_LIMIT),\n offset: Number(offset || DEFAULT_OFFSET),\n ...sort,\n ...raw\n };\n};\n\nexport default getGenericRenderVariables;\n"],"file":"get-generic-render-variables.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaze-cms/react-page-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.114.0-alpha.2",
|
|
4
4
|
"description": "Blaze react page builder",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"lib/*",
|
|
89
89
|
"lib-es/*"
|
|
90
90
|
],
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "0124c8a97920cfb8a694958e6b5dd2c52724d13d"
|
|
92
92
|
}
|
|
@@ -9,26 +9,45 @@ import { useGetEntitySchemasAsObj, useGetImages } from '../../hooks';
|
|
|
9
9
|
import {
|
|
10
10
|
getUpdatedFilterBy,
|
|
11
11
|
getEntityData,
|
|
12
|
+
getRequiredSchemas,
|
|
12
13
|
sortResponseData,
|
|
13
14
|
getUnpublishedEntityName,
|
|
14
15
|
renderChildren,
|
|
15
16
|
splitChildren,
|
|
16
17
|
removeExtraItems,
|
|
17
|
-
getRequiredSchemas,
|
|
18
18
|
appendImages
|
|
19
19
|
} from '../../helpers';
|
|
20
20
|
import { filtersSetup, filterQuerySetup, shouldSkipSingleQuery, shouldReturn } from './helpers';
|
|
21
21
|
|
|
22
22
|
const CardContainer = dynamic(() => import('./CardContainer'));
|
|
23
23
|
|
|
24
|
-
const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...
|
|
24
|
+
const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...otherProps }) => {
|
|
25
25
|
const {
|
|
26
26
|
parent: { itemId, itemEntity },
|
|
27
27
|
filterBy = [],
|
|
28
28
|
filterByProperty = [],
|
|
29
|
-
sortby
|
|
29
|
+
sortby,
|
|
30
|
+
sort,
|
|
31
|
+
sortProperties = [],
|
|
30
32
|
operator: filterOperator = AND
|
|
31
|
-
} =
|
|
33
|
+
} = otherProps;
|
|
34
|
+
|
|
35
|
+
const updatedSortProperties = [...sortProperties];
|
|
36
|
+
if (!updatedSortProperties.length && sort) {
|
|
37
|
+
updatedSortProperties.unshift({ sort, propsToDisplay: sortby });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const sortbyFilters = updatedSortProperties
|
|
41
|
+
.map(({ propsToDisplay }) => propsToDisplay)
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.flat();
|
|
44
|
+
|
|
45
|
+
const variableProps = {
|
|
46
|
+
...otherProps,
|
|
47
|
+
sortProperties: updatedSortProperties,
|
|
48
|
+
sort: null,
|
|
49
|
+
sortby: null
|
|
50
|
+
};
|
|
32
51
|
|
|
33
52
|
const itemEntityUpdated = getUnpublishedEntityName(itemEntity);
|
|
34
53
|
const { data: mainSchemas = {}, loading: _loading, error: _error } = useGetEntitySchemasAsObj([
|
|
@@ -70,7 +89,7 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...variabl
|
|
|
70
89
|
loading: schemaLoading,
|
|
71
90
|
error: schemaError
|
|
72
91
|
} = useGetEntitySchemasAsObj(
|
|
73
|
-
getRequiredSchemas([...filterByProperty, ...
|
|
92
|
+
getRequiredSchemas([...filterByProperty, ...sortbyFilters], filterEntitySchema),
|
|
74
93
|
_loading
|
|
75
94
|
);
|
|
76
95
|
|
|
@@ -94,7 +113,6 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...variabl
|
|
|
94
113
|
itemsToDisplay,
|
|
95
114
|
entitySameAsCurrentItemEntity
|
|
96
115
|
});
|
|
97
|
-
|
|
98
116
|
const { data, error: cardsError, loading: cardsLoading } = useQuery(action, {
|
|
99
117
|
variables,
|
|
100
118
|
skip: shouldReturn(!updatedFilterBy, _loading, _load, schemaLoading, _error, _err, schemaError)
|
|
@@ -47,12 +47,7 @@ const buildLoopPropsContent = (loopProps = [], propsToDisplay = [], limit = 0, d
|
|
|
47
47
|
const propValue = loopValue ? getLoopValue(loopValue[i]) : regularValues[key];
|
|
48
48
|
if (!propValue) return null;
|
|
49
49
|
const linkToPublishedContent = getLinkToPublishedContent(key, data);
|
|
50
|
-
return [
|
|
51
|
-
upperFirst(label) || upperFirst(key),
|
|
52
|
-
propValue,
|
|
53
|
-
linkToPublishedContent,
|
|
54
|
-
modifier
|
|
55
|
-
];
|
|
50
|
+
return [upperFirst(label), propValue, linkToPublishedContent, modifier];
|
|
56
51
|
});
|
|
57
52
|
})
|
|
58
53
|
).filter(Boolean);
|
|
@@ -51,14 +51,15 @@ const ListBuilder = props => {
|
|
|
51
51
|
filterEntitySchema,
|
|
52
52
|
requiredSchema,
|
|
53
53
|
searchValues,
|
|
54
|
-
azFilter
|
|
54
|
+
azFilter,
|
|
55
|
+
sortProperties
|
|
55
56
|
} = props;
|
|
56
57
|
const isInfinite = paginationType === INFINITE;
|
|
57
58
|
const listComponent = getListComponent(isCard, paginationType);
|
|
58
59
|
const propsToDisplayValues = checkPropsToUse(propsToDisplay);
|
|
59
60
|
const entityFields = buildPropsQuery(entitySchema, propsToDisplayValues, props) || '';
|
|
60
61
|
const limitToUse = limit || itemsToDisplay.length;
|
|
61
|
-
const shouldApplyDefaultSort = !
|
|
62
|
+
const shouldApplyDefaultSort = !sortProperties || !sortProperties.length;
|
|
62
63
|
const itemsPerPageToUse = getItemsPerPageToUse(itemsPerPage, limitToUse);
|
|
63
64
|
const initialOffset = getCurrentOffset(offset, itemsPerPageToUse, paginationIndex, limitToUse);
|
|
64
65
|
const { entityType, docType } = getEntityData(entity);
|
|
@@ -105,7 +106,8 @@ const ListBuilder = props => {
|
|
|
105
106
|
limit: itemsPerPageToUse,
|
|
106
107
|
offset: initialOffset,
|
|
107
108
|
sort,
|
|
108
|
-
sortby
|
|
109
|
+
sortby,
|
|
110
|
+
sortProperties
|
|
109
111
|
},
|
|
110
112
|
stringProps,
|
|
111
113
|
JSON.stringify(azRawQuery),
|
|
@@ -147,7 +149,8 @@ const ListBuilder = props => {
|
|
|
147
149
|
limit: itemsPerPageToUse,
|
|
148
150
|
offset: initialOffset,
|
|
149
151
|
sort,
|
|
150
|
-
sortby
|
|
152
|
+
sortby,
|
|
153
|
+
sortProperties
|
|
151
154
|
},
|
|
152
155
|
stringProps,
|
|
153
156
|
JSON.stringify(rawQuery),
|
|
@@ -198,7 +201,8 @@ ListBuilder.propTypes = {
|
|
|
198
201
|
operator: PropTypes.string.isRequired,
|
|
199
202
|
filterOperator: PropTypes.string.isRequired,
|
|
200
203
|
paginationType: PropTypes.string,
|
|
201
|
-
azFilter: PropTypes.string
|
|
204
|
+
azFilter: PropTypes.string,
|
|
205
|
+
sortProperties: PropTypes.array
|
|
202
206
|
};
|
|
203
207
|
|
|
204
208
|
ListBuilder.defaultProps = {
|
|
@@ -209,7 +213,8 @@ ListBuilder.defaultProps = {
|
|
|
209
213
|
offset: 0,
|
|
210
214
|
paginationType: 'infinite',
|
|
211
215
|
inheritedFilters: [],
|
|
212
|
-
azFilter: ''
|
|
216
|
+
azFilter: '',
|
|
217
|
+
sortProperties: []
|
|
213
218
|
};
|
|
214
219
|
|
|
215
220
|
export default ListBuilder;
|
|
@@ -7,7 +7,7 @@ import { MainContext } from '@blaze-cms/nextjs-components';
|
|
|
7
7
|
import { getSingleEntitySchema, generateSingleItemQuery } from '../../application/query';
|
|
8
8
|
import ListBuilder from './ListBuilder';
|
|
9
9
|
import { AZ_LIST_TYPE } from './constants';
|
|
10
|
-
import { getAzQueryFilter } from './helpers';
|
|
10
|
+
import { getAzQueryFilter, getSortProps } from './helpers';
|
|
11
11
|
import {
|
|
12
12
|
getGenericProps,
|
|
13
13
|
getRequiredSchemas,
|
|
@@ -36,7 +36,8 @@ const ListFactory = props => {
|
|
|
36
36
|
sortby: defaultSortBy,
|
|
37
37
|
sort: defaultSort,
|
|
38
38
|
searchFilter,
|
|
39
|
-
operator: filterOperator
|
|
39
|
+
operator: filterOperator,
|
|
40
|
+
sortProperties
|
|
40
41
|
} = props;
|
|
41
42
|
|
|
42
43
|
const { isPreview } = useContext(MainContext);
|
|
@@ -46,8 +47,14 @@ const ListFactory = props => {
|
|
|
46
47
|
const { query, url, query: { sort: querySort, sortby: querySortBy } = {} } = parseUrl(
|
|
47
48
|
parsedQuery
|
|
48
49
|
);
|
|
49
|
-
const
|
|
50
|
-
|
|
50
|
+
const { sortbyFilters, updatedSortProperties } = getSortProps({
|
|
51
|
+
querySort,
|
|
52
|
+
sortProperties,
|
|
53
|
+
defaultSort,
|
|
54
|
+
querySortBy,
|
|
55
|
+
defaultSortBy
|
|
56
|
+
});
|
|
57
|
+
|
|
51
58
|
const { itemEntity, itemId } = parent;
|
|
52
59
|
const itemEntityUpdated = getUnpublishedEntityName(itemEntity);
|
|
53
60
|
const paginationIndex = getPaginationIndex(query, name);
|
|
@@ -75,7 +82,7 @@ const ListFactory = props => {
|
|
|
75
82
|
loading: requiredSchemaLoading,
|
|
76
83
|
error: requiredSchemaError
|
|
77
84
|
} = useGetEntitySchemasAsObj(
|
|
78
|
-
getRequiredSchemas([...filterByProperty, ...
|
|
85
|
+
getRequiredSchemas([...filterByProperty, ...sortbyFilters], filterEntitySchema),
|
|
79
86
|
schemasLoading
|
|
80
87
|
);
|
|
81
88
|
const inheritedFilters = getInheritedFilters(filterBy, filterByProperty);
|
|
@@ -126,8 +133,9 @@ const ListFactory = props => {
|
|
|
126
133
|
isAZ,
|
|
127
134
|
router,
|
|
128
135
|
entitySchema,
|
|
129
|
-
sort,
|
|
130
|
-
sortby,
|
|
136
|
+
sort: null,
|
|
137
|
+
sortby: null,
|
|
138
|
+
sortProperties: updatedSortProperties,
|
|
131
139
|
azFilter,
|
|
132
140
|
searchValues,
|
|
133
141
|
filterEntitySchema,
|
|
@@ -156,7 +164,8 @@ ListFactory.propTypes = {
|
|
|
156
164
|
name: PropTypes.string,
|
|
157
165
|
sortby: PropTypes.array,
|
|
158
166
|
sort: PropTypes.string,
|
|
159
|
-
searchFilter: PropTypes.object
|
|
167
|
+
searchFilter: PropTypes.object,
|
|
168
|
+
sortProperties: PropTypes.array
|
|
160
169
|
};
|
|
161
170
|
|
|
162
171
|
ListFactory.defaultProps = {
|
|
@@ -165,6 +174,7 @@ ListFactory.defaultProps = {
|
|
|
165
174
|
omitWrappers: false,
|
|
166
175
|
name: '',
|
|
167
176
|
sortby: [],
|
|
177
|
+
sortProperties: [],
|
|
168
178
|
sort: '',
|
|
169
179
|
operator: AND,
|
|
170
180
|
searchFilter: {}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const getSortProps = ({ querySort, sortProperties, defaultSort, querySortBy, defaultSortBy }) => {
|
|
2
|
+
const sort = querySort || (sortProperties.length ? null : defaultSort);
|
|
3
|
+
let sortby = null;
|
|
4
|
+
if (querySortBy) sortby = [querySortBy];
|
|
5
|
+
else if (!sortProperties.length) sortby = defaultSortBy;
|
|
6
|
+
|
|
7
|
+
const updatedSortProperties = [...sortProperties];
|
|
8
|
+
if (sort) updatedSortProperties.unshift({ sort, propsToDisplay: sortby });
|
|
9
|
+
|
|
10
|
+
const sortbyFilters = updatedSortProperties
|
|
11
|
+
.map(({ propsToDisplay: filterProps }) => filterProps)
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.flat();
|
|
14
|
+
return { sortbyFilters, updatedSortProperties };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default getSortProps;
|
|
@@ -4,3 +4,4 @@ export { default as buildAzAggregations } from './build-az-aggregations';
|
|
|
4
4
|
export { default as buildAzUrl } from './build-az-url';
|
|
5
5
|
export { default as sortAggs } from './sort-aggs';
|
|
6
6
|
export { default as getItemsPerPageToUse } from './get-items-per-page-to-use';
|
|
7
|
+
export { default as getSortProps } from './get-sort-props';
|
|
@@ -4,7 +4,15 @@ import { MainContext } from '@blaze-cms/nextjs-components';
|
|
|
4
4
|
import { TextSearch, Checkbox, SelectFilter, Range } from '../components';
|
|
5
5
|
import { CHECKBOX, SELECT, TEXT_SEARCH, RANGE, SEARCH_TERM } from '../constants';
|
|
6
6
|
|
|
7
|
-
const FiltersList = ({
|
|
7
|
+
const FiltersList = ({
|
|
8
|
+
data,
|
|
9
|
+
filters,
|
|
10
|
+
hasUrl,
|
|
11
|
+
entity,
|
|
12
|
+
filterValues,
|
|
13
|
+
updateFilterValues,
|
|
14
|
+
shouldSearch
|
|
15
|
+
}) => {
|
|
8
16
|
const { itemId } = useContext(MainContext);
|
|
9
17
|
|
|
10
18
|
return filters.map(({ type, label, propsToDisplay, rangeInterval, elementTitle }, index) => {
|
|
@@ -46,6 +54,7 @@ const FiltersList = ({ data, filters, hasUrl, entity, filterValues, updateFilter
|
|
|
46
54
|
hasUrl={hasUrl}
|
|
47
55
|
filterValues={filterValues}
|
|
48
56
|
updateFilterValues={updateFilterValues}
|
|
57
|
+
shouldSearch={shouldSearch}
|
|
49
58
|
/>
|
|
50
59
|
</div>
|
|
51
60
|
)
|
|
@@ -64,6 +73,7 @@ const FiltersList = ({ data, filters, hasUrl, entity, filterValues, updateFilter
|
|
|
64
73
|
hasUrl={hasUrl}
|
|
65
74
|
filterValues={filterValues}
|
|
66
75
|
updateFilterValues={updateFilterValues}
|
|
76
|
+
shouldSearch={shouldSearch}
|
|
67
77
|
/>
|
|
68
78
|
</div>
|
|
69
79
|
)
|
|
@@ -81,6 +91,7 @@ const FiltersList = ({ data, filters, hasUrl, entity, filterValues, updateFilter
|
|
|
81
91
|
entity={entity}
|
|
82
92
|
filterValues={filterValues}
|
|
83
93
|
updateFilterValues={updateFilterValues}
|
|
94
|
+
shouldSearch={shouldSearch}
|
|
84
95
|
/>
|
|
85
96
|
</div>
|
|
86
97
|
)
|
|
@@ -97,10 +108,12 @@ FiltersList.propTypes = {
|
|
|
97
108
|
filterValues: PropTypes.object.isRequired,
|
|
98
109
|
updateFilterValues: PropTypes.func.isRequired,
|
|
99
110
|
data: PropTypes.object,
|
|
100
|
-
filters: PropTypes.array
|
|
111
|
+
filters: PropTypes.array,
|
|
112
|
+
shouldSearch: PropTypes.bool
|
|
101
113
|
};
|
|
102
114
|
|
|
103
115
|
FiltersList.defaultProps = {
|
|
116
|
+
shouldSearch: false,
|
|
104
117
|
data: {},
|
|
105
118
|
filters: []
|
|
106
119
|
};
|
|
@@ -3,11 +3,16 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import debounce from 'lodash.debounce';
|
|
5
5
|
import FiltersList from './FiltersList';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
isDeviceDesktop,
|
|
8
|
+
buildQuery,
|
|
9
|
+
getInitialFilterValues,
|
|
10
|
+
getResponsiveFilterClassnames
|
|
11
|
+
} from '../helpers';
|
|
7
12
|
import CloseMobileForm from './CloseMobileForm';
|
|
8
13
|
import ResetDesktopForm from './ResetDesktopForm';
|
|
9
14
|
import MobileFormToolbar from './MobileFormToolbar';
|
|
10
|
-
import { SEARCH, REFINE } from '../constants';
|
|
15
|
+
import { SEARCH, REFINE, MORE_FILTERS_CLASSES } from '../constants';
|
|
11
16
|
|
|
12
17
|
const reducer = (state, action) => {
|
|
13
18
|
const { newValues, type, shouldSearch = true } = action;
|
|
@@ -36,11 +41,13 @@ const SearchFilter = ({
|
|
|
36
41
|
displaySearchFilter,
|
|
37
42
|
setDisplaySearchFilter,
|
|
38
43
|
initialFilterValues,
|
|
39
|
-
|
|
44
|
+
groupAfterDesktop,
|
|
45
|
+
groupAfterMobile
|
|
40
46
|
}) => {
|
|
41
47
|
const [isDesktop, setIsDesktop] = useState(true);
|
|
42
48
|
const [pageWidth, setPageWidth] = useState(null);
|
|
43
|
-
const [
|
|
49
|
+
const [moreFiltersMobileCollapsed, setMoreFiltersMobileCollapsed] = useState(true);
|
|
50
|
+
const [moreFiltersDesktopCollapsed, setMoreFiltersDesktopCollapsed] = useState(true);
|
|
44
51
|
const [filterValues, dispatch] = useReducer(reducer, initialFilterValues);
|
|
45
52
|
|
|
46
53
|
const handleSubmit = debounce(newValues => {
|
|
@@ -91,13 +98,12 @@ const SearchFilter = ({
|
|
|
91
98
|
'filter__form filter__form--mobile': isMobileFormDisplayed
|
|
92
99
|
});
|
|
93
100
|
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
+
const {
|
|
102
|
+
moreFiltersMobileWrapperClass,
|
|
103
|
+
moreFiltersMobileTogglerClass,
|
|
104
|
+
moreFiltersDesktopWrapperClass,
|
|
105
|
+
moreFiltersDesktopTogglerClass
|
|
106
|
+
} = getResponsiveFilterClassnames(moreFiltersDesktopCollapsed, moreFiltersMobileCollapsed);
|
|
101
107
|
|
|
102
108
|
const formId = `filter-${name}-form`;
|
|
103
109
|
|
|
@@ -111,6 +117,8 @@ const SearchFilter = ({
|
|
|
111
117
|
dispatch({ newValues, shouldSearch, type: 'update' });
|
|
112
118
|
};
|
|
113
119
|
|
|
120
|
+
const shouldGroup = !!(groupAfterDesktop || groupAfterMobile);
|
|
121
|
+
|
|
114
122
|
return (
|
|
115
123
|
<>
|
|
116
124
|
{isDesktopFormDisplayed || isMobileFormDisplayed ? (
|
|
@@ -132,8 +140,9 @@ const SearchFilter = ({
|
|
|
132
140
|
{isDesktopFormDisplayed && <ResetDesktopForm handleReset={handleReset} />}
|
|
133
141
|
|
|
134
142
|
<div className="filter__wrapper filter__wrapper--search-refine">
|
|
135
|
-
{!
|
|
143
|
+
{!shouldGroup && (
|
|
136
144
|
<FiltersList
|
|
145
|
+
shouldSearch
|
|
137
146
|
data={data}
|
|
138
147
|
filters={filters}
|
|
139
148
|
hasUrl={hasUrl}
|
|
@@ -143,37 +152,77 @@ const SearchFilter = ({
|
|
|
143
152
|
/>
|
|
144
153
|
)}
|
|
145
154
|
|
|
146
|
-
{
|
|
155
|
+
{shouldGroup && (
|
|
147
156
|
<>
|
|
148
157
|
<FiltersList
|
|
158
|
+
shouldSearch
|
|
149
159
|
data={data}
|
|
150
|
-
filters={filters.slice(0,
|
|
160
|
+
filters={filters.slice(0, groupAfterMobile)}
|
|
151
161
|
hasUrl={hasUrl}
|
|
152
162
|
entity={entity}
|
|
153
163
|
filterValues={filterValues}
|
|
154
164
|
updateFilterValues={updateFilterValues}
|
|
155
165
|
/>
|
|
156
166
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
{!!groupAfterMobile && (
|
|
168
|
+
<button
|
|
169
|
+
className={moreFiltersMobileTogglerClass}
|
|
170
|
+
type="button"
|
|
171
|
+
onClick={() => setMoreFiltersMobileCollapsed(!moreFiltersMobileCollapsed)}>
|
|
172
|
+
Filters
|
|
173
|
+
</button>
|
|
174
|
+
)}
|
|
163
175
|
|
|
164
|
-
<div className={
|
|
165
|
-
<div className=
|
|
176
|
+
<div className={moreFiltersMobileWrapperClass}>
|
|
177
|
+
<div className={MORE_FILTERS_CLASSES.MOBILE_CONTENT}>
|
|
166
178
|
<FiltersList
|
|
179
|
+
shouldSearch={isDeviceDesktop()}
|
|
167
180
|
data={data}
|
|
168
|
-
filters={filters.slice(
|
|
181
|
+
filters={filters.slice(
|
|
182
|
+
groupAfterMobile,
|
|
183
|
+
groupAfterDesktop ? groupAfterDesktop - 1 : 0
|
|
184
|
+
)}
|
|
169
185
|
hasUrl={hasUrl}
|
|
170
186
|
entity={entity}
|
|
171
187
|
filterValues={filterValues}
|
|
172
188
|
updateFilterValues={updateFilterValues}
|
|
173
189
|
/>
|
|
190
|
+
|
|
191
|
+
{!!groupAfterDesktop && (
|
|
192
|
+
<button
|
|
193
|
+
className={moreFiltersDesktopTogglerClass}
|
|
194
|
+
type="button"
|
|
195
|
+
onClick={() =>
|
|
196
|
+
setMoreFiltersDesktopCollapsed(!moreFiltersDesktopCollapsed)
|
|
197
|
+
}>
|
|
198
|
+
More filters
|
|
199
|
+
</button>
|
|
200
|
+
)}
|
|
201
|
+
|
|
202
|
+
<div className={moreFiltersDesktopWrapperClass}>
|
|
203
|
+
<div className={MORE_FILTERS_CLASSES.DESKTOP_CONTENT}>
|
|
204
|
+
<FiltersList
|
|
205
|
+
shouldSearch={false}
|
|
206
|
+
data={data}
|
|
207
|
+
filters={filters.slice(groupAfterDesktop)}
|
|
208
|
+
hasUrl={hasUrl}
|
|
209
|
+
entity={entity}
|
|
210
|
+
filterValues={filterValues}
|
|
211
|
+
updateFilterValues={updateFilterValues}
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<div className={MORE_FILTERS_CLASSES.DESKTOP_BUTTONS}>
|
|
216
|
+
<ResetDesktopForm handleReset={handleReset} />
|
|
217
|
+
|
|
218
|
+
<button className="button button--full-width" type="submit">
|
|
219
|
+
{SEARCH}
|
|
220
|
+
</button>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
174
223
|
</div>
|
|
175
224
|
|
|
176
|
-
<div className=
|
|
225
|
+
<div className={MORE_FILTERS_CLASSES.MOBILE_BUTTONS}>
|
|
177
226
|
<ResetDesktopForm handleReset={handleReset} />
|
|
178
227
|
|
|
179
228
|
<button className="button button--full-width" type="submit">
|
|
@@ -224,7 +273,8 @@ SearchFilter.propTypes = {
|
|
|
224
273
|
displaySearchFilter: PropTypes.bool.isRequired,
|
|
225
274
|
setDisplaySearchFilter: PropTypes.func.isRequired,
|
|
226
275
|
isCollapsedOnResponsive: PropTypes.bool.isRequired,
|
|
227
|
-
|
|
276
|
+
groupAfterDesktop: PropTypes.number.isRequired,
|
|
277
|
+
groupAfterMobile: PropTypes.number.isRequired,
|
|
228
278
|
initialFilterValues: PropTypes.object.isRequired
|
|
229
279
|
};
|
|
230
280
|
|
|
@@ -23,7 +23,8 @@ const SearchFilterContainer = ({
|
|
|
23
23
|
filters,
|
|
24
24
|
name,
|
|
25
25
|
isCollapsedOnResponsive,
|
|
26
|
-
|
|
26
|
+
groupAfterMobile,
|
|
27
|
+
groupAfterDesktop
|
|
27
28
|
}) => {
|
|
28
29
|
const router = useRouter();
|
|
29
30
|
const searchFilterRef = useRef(null);
|
|
@@ -113,7 +114,8 @@ const SearchFilterContainer = ({
|
|
|
113
114
|
isCollapsedOnResponsive={isCollapsedOnResponsive}
|
|
114
115
|
displaySearchFilter={displaySearchFilter}
|
|
115
116
|
setDisplaySearchFilter={setDisplaySearchFilter}
|
|
116
|
-
|
|
117
|
+
groupAfterMobile={groupAfterMobile}
|
|
118
|
+
groupAfterDesktop={groupAfterDesktop}
|
|
117
119
|
/>
|
|
118
120
|
);
|
|
119
121
|
};
|
|
@@ -124,7 +126,8 @@ SearchFilterContainer.propTypes = {
|
|
|
124
126
|
filters: PropTypes.array,
|
|
125
127
|
name: PropTypes.string.isRequired,
|
|
126
128
|
isCollapsedOnResponsive: PropTypes.bool,
|
|
127
|
-
|
|
129
|
+
groupAfterMobile: PropTypes.number,
|
|
130
|
+
groupAfterDesktop: PropTypes.number
|
|
128
131
|
};
|
|
129
132
|
|
|
130
133
|
SearchFilterContainer.defaultProps = {
|
|
@@ -132,7 +135,8 @@ SearchFilterContainer.defaultProps = {
|
|
|
132
135
|
filters: [],
|
|
133
136
|
entity: '',
|
|
134
137
|
isCollapsedOnResponsive: true,
|
|
135
|
-
|
|
138
|
+
groupAfterMobile: 0,
|
|
139
|
+
groupAfterDesktop: 0
|
|
136
140
|
};
|
|
137
141
|
|
|
138
142
|
export default withTitle(SearchFilterContainer);
|
|
@@ -8,7 +8,7 @@ import { LIMIT_MIN, LIMIT_MAX, MORE, LESS, DOWN, UP } from '../constants';
|
|
|
8
8
|
|
|
9
9
|
const getButtonInfo = isMore => (isMore ? { icon: DOWN, text: MORE } : { icon: UP, text: LESS });
|
|
10
10
|
|
|
11
|
-
const Checkbox = ({ data, prop, updateFilterValues, filterValues, label }) => {
|
|
11
|
+
const Checkbox = ({ data, prop, updateFilterValues, filterValues, label, shouldSearch }) => {
|
|
12
12
|
const [checkboxLimit, setCheckboxLimit] = useState(null);
|
|
13
13
|
|
|
14
14
|
const handleCheckboxOptions = () => {
|
|
@@ -64,7 +64,7 @@ const Checkbox = ({ data, prop, updateFilterValues, filterValues, label }) => {
|
|
|
64
64
|
const newCheckboxValues = eData
|
|
65
65
|
.filter(({ checked }) => checked)
|
|
66
66
|
.map(({ value }) => value);
|
|
67
|
-
updateFilterValues({ [prop]: newCheckboxValues },
|
|
67
|
+
updateFilterValues({ [prop]: newCheckboxValues }, shouldSearch);
|
|
68
68
|
}}
|
|
69
69
|
/>
|
|
70
70
|
{data[prop].buckets.length > LIMIT_MIN && (
|
|
@@ -82,10 +82,12 @@ Checkbox.propTypes = {
|
|
|
82
82
|
prop: PropTypes.string.isRequired,
|
|
83
83
|
filterValues: PropTypes.object.isRequired,
|
|
84
84
|
updateFilterValues: PropTypes.func.isRequired,
|
|
85
|
+
shouldSearch: PropTypes.bool,
|
|
85
86
|
label: PropTypes.string
|
|
86
87
|
};
|
|
87
88
|
|
|
88
89
|
Checkbox.defaultProps = {
|
|
90
|
+
shouldSearch: false,
|
|
89
91
|
label: ''
|
|
90
92
|
};
|
|
91
93
|
|