@blaze-cms/react-page-builder 0.133.0-admin-updates.8 → 0.133.0-admin-updates.11
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 +22 -0
- package/lib/components/Button.js +3 -1
- package/lib/components/Button.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +58 -22
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-filters-query.js +18 -16
- package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-url-query.js +0 -1
- package/lib/components/SearchFilter/helpers/build-url-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +33 -0
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -0
- package/lib/components/SearchFilter/helpers/get-updated-filter-by.js +38 -0
- package/lib/components/SearchFilter/helpers/get-updated-filter-by.js.map +1 -0
- package/lib/components/SearchFilter/helpers/index.js +8 -1
- package/lib/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib-es/components/Button.js +2 -1
- package/lib-es/components/Button.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +2 -2
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +54 -13
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js +18 -16
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-url-query.js +0 -1
- package/lib-es/components/SearchFilter/helpers/build-url-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +21 -0
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/get-updated-filter-by.js +19 -0
- package/lib-es/components/SearchFilter/helpers/get-updated-filter-by.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/index.js +3 -2
- package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Button.js +6 -1
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +5 -2
- package/src/components/SearchFilter/SearchFilterContainer.js +42 -14
- package/src/components/SearchFilter/helpers/build-filters-query.js +23 -20
- package/src/components/SearchFilter/helpers/build-url-query.js +0 -2
- package/src/components/SearchFilter/helpers/get-initial-filter-values.js +24 -0
- package/src/components/SearchFilter/helpers/get-updated-filter-by.js +18 -0
- package/src/components/SearchFilter/helpers/index.js +5 -3
- package/tests/unit/src/components/SearchFilter/helpers/get-updated-filter-by.test.js +28 -0
- /package/tests/unit/src/components/SearchFilter/helpers/{build-new-query.test.js → build-new-url.test.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-url-query.js","names":["SEARCH_TERM","TEXT_SEARCH","parseFilterValue","buildQueryKey","buildUrlQuery","filterValues","filters","listComponentName","query","newQuery","queryKeys","searchValue","searchKey","push","forEach","propsToDisplay","type","prop","value","filterKey","parsedValue","includes","Object","keys","key","indexOf","join"],"sources":["../../../../src/components/SearchFilter/helpers/build-url-query.js"],"sourcesContent":["import { SEARCH_TERM, TEXT_SEARCH } from '../constants';\nimport parseFilterValue from './parse-filter-value';\nimport { buildQueryKey } from '../../../helpers';\n\nconst buildUrlQuery = (filterValues, filters, listComponentName = '', query = {}) => {\n
|
|
1
|
+
{"version":3,"file":"build-url-query.js","names":["SEARCH_TERM","TEXT_SEARCH","parseFilterValue","buildQueryKey","buildUrlQuery","filterValues","filters","listComponentName","query","newQuery","queryKeys","searchValue","searchKey","push","forEach","propsToDisplay","type","prop","value","filterKey","parsedValue","includes","Object","keys","key","indexOf","join"],"sources":["../../../../src/components/SearchFilter/helpers/build-url-query.js"],"sourcesContent":["import { SEARCH_TERM, TEXT_SEARCH } from '../constants';\nimport parseFilterValue from './parse-filter-value';\nimport { buildQueryKey } from '../../../helpers';\n\nconst buildUrlQuery = (filterValues, filters, listComponentName = '', query = {}) => {\n const newQuery = [];\n const queryKeys = [];\n const searchValue = filterValues[SEARCH_TERM];\n const searchKey = buildQueryKey(SEARCH_TERM, listComponentName);\n queryKeys.push(searchKey);\n if (searchValue) newQuery.push(`${searchKey}=${searchValue}`);\n\n filters.forEach(({ propsToDisplay, type }) => {\n if (type === TEXT_SEARCH) return;\n propsToDisplay.forEach(prop => {\n const value = filterValues[prop];\n const filterKey = buildQueryKey(prop, listComponentName);\n queryKeys.push(filterKey);\n const parsedValue = parseFilterValue(filterKey, type, value, newQuery);\n if (parsedValue && !newQuery.includes(parsedValue)) newQuery.push(parsedValue);\n });\n });\n\n Object.keys(query).forEach(key => {\n if (queryKeys.indexOf(key) === -1) newQuery.push(`${key}=${query[key]}`);\n });\n\n return newQuery.join('&');\n};\n\nexport default buildUrlQuery;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,WAAW,QAAQ,cAAc;AACvD,OAAOC,gBAAgB,MAAM,sBAAsB;AACnD,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,aAAa,GAAGA,CAACC,YAAY,EAAEC,OAAO,EAAEC,iBAAiB,GAAG,EAAE,EAAEC,KAAK,GAAG,CAAC,CAAC,KAAK;EACnF,MAAMC,QAAQ,GAAG,EAAE;EACnB,MAAMC,SAAS,GAAG,EAAE;EACpB,MAAMC,WAAW,GAAGN,YAAY,CAACL,WAAW,CAAC;EAC7C,MAAMY,SAAS,GAAGT,aAAa,CAACH,WAAW,EAAEO,iBAAiB,CAAC;EAC/DG,SAAS,CAACG,IAAI,CAACD,SAAS,CAAC;EACzB,IAAID,WAAW,EAAEF,QAAQ,CAACI,IAAI,CAAE,GAAED,SAAU,IAAGD,WAAY,EAAC,CAAC;EAE7DL,OAAO,CAACQ,OAAO,CAAC,CAAC;IAAEC,cAAc;IAAEC;EAAK,CAAC,KAAK;IAC5C,IAAIA,IAAI,KAAKf,WAAW,EAAE;IAC1Bc,cAAc,CAACD,OAAO,CAACG,IAAI,IAAI;MAC7B,MAAMC,KAAK,GAAGb,YAAY,CAACY,IAAI,CAAC;MAChC,MAAME,SAAS,GAAGhB,aAAa,CAACc,IAAI,EAAEV,iBAAiB,CAAC;MACxDG,SAAS,CAACG,IAAI,CAACM,SAAS,CAAC;MACzB,MAAMC,WAAW,GAAGlB,gBAAgB,CAACiB,SAAS,EAAEH,IAAI,EAAEE,KAAK,EAAET,QAAQ,CAAC;MACtE,IAAIW,WAAW,IAAI,CAACX,QAAQ,CAACY,QAAQ,CAACD,WAAW,CAAC,EAAEX,QAAQ,CAACI,IAAI,CAACO,WAAW,CAAC;IAChF,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFE,MAAM,CAACC,IAAI,CAACf,KAAK,CAAC,CAACM,OAAO,CAACU,GAAG,IAAI;IAChC,IAAId,SAAS,CAACe,OAAO,CAACD,GAAG,CAAC,KAAK,CAAC,CAAC,EAAEf,QAAQ,CAACI,IAAI,CAAE,GAAEW,GAAI,IAAGhB,KAAK,CAACgB,GAAG,CAAE,EAAC,CAAC;EAC1E,CAAC,CAAC;EAEF,OAAOf,QAAQ,CAACiB,IAAI,CAAC,GAAG,CAAC;AAC3B,CAAC;AAED,eAAetB,aAAa"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SEARCH_TERM, TEXT_SEARCH } from '../constants';
|
|
2
|
+
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
3
|
+
import { buildQueryKey } from '../../../helpers';
|
|
4
|
+
const getInitialFilterValues = (filterData, filters, query, listComponentName) => {
|
|
5
|
+
const filterValues = {};
|
|
6
|
+
const searchQueryKey = buildQueryKey(SEARCH_TERM, listComponentName);
|
|
7
|
+
filterValues[SEARCH_TERM] = query[searchQueryKey] || '';
|
|
8
|
+
filters.forEach(filterProps => {
|
|
9
|
+
const {
|
|
10
|
+
propsToDisplay: [key],
|
|
11
|
+
type
|
|
12
|
+
} = filterProps;
|
|
13
|
+
if (type === TEXT_SEARCH) return;
|
|
14
|
+
const data = filterData && filterData[key] ? filterData[key] : {};
|
|
15
|
+
const queryKey = buildQueryKey(key, listComponentName);
|
|
16
|
+
filterValues[key] = getFilterValueFromQuery(queryKey, filterProps, data, query);
|
|
17
|
+
});
|
|
18
|
+
return filterValues;
|
|
19
|
+
};
|
|
20
|
+
export default getInitialFilterValues;
|
|
21
|
+
//# sourceMappingURL=get-initial-filter-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-initial-filter-values.js","names":["SEARCH_TERM","TEXT_SEARCH","getFilterValueFromQuery","buildQueryKey","getInitialFilterValues","filterData","filters","query","listComponentName","filterValues","searchQueryKey","forEach","filterProps","propsToDisplay","key","type","data","queryKey"],"sources":["../../../../src/components/SearchFilter/helpers/get-initial-filter-values.js"],"sourcesContent":["import { SEARCH_TERM, TEXT_SEARCH } from '../constants';\nimport getFilterValueFromQuery from './get-filter-value-from-query';\nimport { buildQueryKey } from '../../../helpers';\n\nconst getInitialFilterValues = (filterData, filters, query, listComponentName) => {\n const filterValues = {};\n const searchQueryKey = buildQueryKey(SEARCH_TERM, listComponentName);\n filterValues[SEARCH_TERM] = query[searchQueryKey] || '';\n\n filters.forEach(filterProps => {\n const {\n propsToDisplay: [key],\n type\n } = filterProps;\n if (type === TEXT_SEARCH) return;\n const data = filterData && filterData[key] ? filterData[key] : {};\n const queryKey = buildQueryKey(key, listComponentName);\n filterValues[key] = getFilterValueFromQuery(queryKey, filterProps, data, query);\n });\n\n return filterValues;\n};\n\nexport default getInitialFilterValues;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,WAAW,QAAQ,cAAc;AACvD,OAAOC,uBAAuB,MAAM,+BAA+B;AACnE,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,sBAAsB,GAAGA,CAACC,UAAU,EAAEC,OAAO,EAAEC,KAAK,EAAEC,iBAAiB,KAAK;EAChF,MAAMC,YAAY,GAAG,CAAC,CAAC;EACvB,MAAMC,cAAc,GAAGP,aAAa,CAACH,WAAW,EAAEQ,iBAAiB,CAAC;EACpEC,YAAY,CAACT,WAAW,CAAC,GAAGO,KAAK,CAACG,cAAc,CAAC,IAAI,EAAE;EAEvDJ,OAAO,CAACK,OAAO,CAACC,WAAW,IAAI;IAC7B,MAAM;MACJC,cAAc,EAAE,CAACC,GAAG,CAAC;MACrBC;IACF,CAAC,GAAGH,WAAW;IACf,IAAIG,IAAI,KAAKd,WAAW,EAAE;IAC1B,MAAMe,IAAI,GAAGX,UAAU,IAAIA,UAAU,CAACS,GAAG,CAAC,GAAGT,UAAU,CAACS,GAAG,CAAC,GAAG,CAAC,CAAC;IACjE,MAAMG,QAAQ,GAAGd,aAAa,CAACW,GAAG,EAAEN,iBAAiB,CAAC;IACtDC,YAAY,CAACK,GAAG,CAAC,GAAGZ,uBAAuB,CAACe,QAAQ,EAAEL,WAAW,EAAEI,IAAI,EAAET,KAAK,CAAC;EACjF,CAAC,CAAC;EAEF,OAAOE,YAAY;AACrB,CAAC;AAED,eAAeL,sBAAsB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const getUpdatedFilterBy = (filterBy, filterByProperty, parentData) => {
|
|
2
|
+
if (!parentData || filterBy && filterBy.length) return {
|
|
3
|
+
updatedFilterBy: filterBy,
|
|
4
|
+
updatedFilterByProperty: filterByProperty
|
|
5
|
+
};
|
|
6
|
+
const updatedFilterBy = [];
|
|
7
|
+
filterByProperty.forEach(property => {
|
|
8
|
+
const [key] = property.split('/');
|
|
9
|
+
const filterData = parentData[key];
|
|
10
|
+
if (!filterData) return;
|
|
11
|
+
if (Array.isArray(filterData)) filterData.forEach(dat => updatedFilterBy.push(`${key}/${dat}`));else updatedFilterBy.push(`${key}/${filterData}`);
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
updatedFilterBy,
|
|
15
|
+
updatedFilterByProperty: filterByProperty
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export default getUpdatedFilterBy;
|
|
19
|
+
//# sourceMappingURL=get-updated-filter-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-updated-filter-by.js","names":["getUpdatedFilterBy","filterBy","filterByProperty","parentData","length","updatedFilterBy","updatedFilterByProperty","forEach","property","key","split","filterData","Array","isArray","dat","push"],"sources":["../../../../src/components/SearchFilter/helpers/get-updated-filter-by.js"],"sourcesContent":["const getUpdatedFilterBy = (filterBy, filterByProperty, parentData) => {\n if (!parentData || (filterBy && filterBy.length))\n return { updatedFilterBy: filterBy, updatedFilterByProperty: filterByProperty };\n\n const updatedFilterBy = [];\n filterByProperty.forEach(property => {\n const [key] = property.split('/');\n const filterData = parentData[key];\n\n if (!filterData) return;\n if (Array.isArray(filterData)) filterData.forEach(dat => updatedFilterBy.push(`${key}/${dat}`));\n else updatedFilterBy.push(`${key}/${filterData}`);\n });\n\n return { updatedFilterBy, updatedFilterByProperty: filterByProperty };\n};\n\nexport default getUpdatedFilterBy;\n"],"mappings":"AAAA,MAAMA,kBAAkB,GAAGA,CAACC,QAAQ,EAAEC,gBAAgB,EAAEC,UAAU,KAAK;EACrE,IAAI,CAACA,UAAU,IAAKF,QAAQ,IAAIA,QAAQ,CAACG,MAAO,EAC9C,OAAO;IAAEC,eAAe,EAAEJ,QAAQ;IAAEK,uBAAuB,EAAEJ;EAAiB,CAAC;EAEjF,MAAMG,eAAe,GAAG,EAAE;EAC1BH,gBAAgB,CAACK,OAAO,CAACC,QAAQ,IAAI;IACnC,MAAM,CAACC,GAAG,CAAC,GAAGD,QAAQ,CAACE,KAAK,CAAC,GAAG,CAAC;IACjC,MAAMC,UAAU,GAAGR,UAAU,CAACM,GAAG,CAAC;IAElC,IAAI,CAACE,UAAU,EAAE;IACjB,IAAIC,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC,EAAEA,UAAU,CAACJ,OAAO,CAACO,GAAG,IAAIT,eAAe,CAACU,IAAI,CAAE,GAAEN,GAAI,IAAGK,GAAI,EAAC,CAAC,CAAC,CAAC,KAC3FT,eAAe,CAACU,IAAI,CAAE,GAAEN,GAAI,IAAGE,UAAW,EAAC,CAAC;EACnD,CAAC,CAAC;EAEF,OAAO;IAAEN,eAAe;IAAEC,uBAAuB,EAAEJ;EAAiB,CAAC;AACvE,CAAC;AAED,eAAeF,kBAAkB"}
|
|
@@ -12,8 +12,9 @@ import getSelectOptions from './get-select-options';
|
|
|
12
12
|
import isDeviceDesktop from './is-device-desktop';
|
|
13
13
|
import getFilterValues from './get-filter-values';
|
|
14
14
|
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
15
|
-
import buildUrlQuery from './build-url-query';
|
|
16
15
|
import buildFiltersQuery from './build-filters-query';
|
|
17
16
|
import getFilterRangesAndCheckboxesValues from './get-filter-ranges-and-checkboxes-values';
|
|
18
|
-
|
|
17
|
+
import getUpdatedFilterBy from './get-updated-filter-by';
|
|
18
|
+
import buildUrlQuery from './build-url-query';
|
|
19
|
+
export { buildNewUrl, buildRawQueryStringified, decodeValue, encodeValue, checkIfRangeUpdated, getResponsiveFilterClassnames, getDisplayValue, calculateStep, calculateMinMax, getIntersectedProp, getRangeValue, getSelectOptions, isDeviceDesktop, getFilterValues, getFilterValueFromQuery, buildFiltersQuery, getFilterRangesAndCheckboxesValues, getUpdatedFilterBy, buildUrlQuery };
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["buildNewUrl","buildRawQueryStringified","decodeValue","encodeValue","checkIfRangeUpdated","getResponsiveFilterClassnames","getDisplayValue","calculateStep","calculateMinMax","getIntersectedProp","getRangeValue","getSelectOptions","isDeviceDesktop","getFilterValues","getFilterValueFromQuery","
|
|
1
|
+
{"version":3,"file":"index.js","names":["buildNewUrl","buildRawQueryStringified","decodeValue","encodeValue","checkIfRangeUpdated","getResponsiveFilterClassnames","getDisplayValue","calculateStep","calculateMinMax","getIntersectedProp","getRangeValue","getSelectOptions","isDeviceDesktop","getFilterValues","getFilterValueFromQuery","buildFiltersQuery","getFilterRangesAndCheckboxesValues","getUpdatedFilterBy","buildUrlQuery"],"sources":["../../../../src/components/SearchFilter/helpers/index.js"],"sourcesContent":["import buildNewUrl from './build-new-url';\nimport buildRawQueryStringified from './build-raw-query-stringified';\nimport { decodeValue, encodeValue } from './decode-encode';\nimport checkIfRangeUpdated from './check-if-range-updated';\nimport getResponsiveFilterClassnames from './get-responsive-filter-classnames';\nimport getDisplayValue from './get-display-value';\nimport calculateStep from './calculate-step';\nimport calculateMinMax from './calculate-min-max';\nimport getIntersectedProp from './get-intersected-prop';\nimport getRangeValue from './get-range-value';\nimport getSelectOptions from './get-select-options';\nimport isDeviceDesktop from './is-device-desktop';\nimport getFilterValues from './get-filter-values';\nimport getFilterValueFromQuery from './get-filter-value-from-query';\nimport buildFiltersQuery from './build-filters-query';\nimport getFilterRangesAndCheckboxesValues from './get-filter-ranges-and-checkboxes-values';\nimport getUpdatedFilterBy from './get-updated-filter-by';\nimport buildUrlQuery from './build-url-query';\n\nexport {\n buildNewUrl,\n buildRawQueryStringified,\n decodeValue,\n encodeValue,\n checkIfRangeUpdated,\n getResponsiveFilterClassnames,\n getDisplayValue,\n calculateStep,\n calculateMinMax,\n getIntersectedProp,\n getRangeValue,\n getSelectOptions,\n isDeviceDesktop,\n getFilterValues,\n getFilterValueFromQuery,\n buildFiltersQuery,\n getFilterRangesAndCheckboxesValues,\n getUpdatedFilterBy,\n buildUrlQuery\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,iBAAiB;AACzC,OAAOC,wBAAwB,MAAM,+BAA+B;AACpE,SAASC,WAAW,EAAEC,WAAW,QAAQ,iBAAiB;AAC1D,OAAOC,mBAAmB,MAAM,0BAA0B;AAC1D,OAAOC,6BAA6B,MAAM,oCAAoC;AAC9E,OAAOC,eAAe,MAAM,qBAAqB;AACjD,OAAOC,aAAa,MAAM,kBAAkB;AAC5C,OAAOC,eAAe,MAAM,qBAAqB;AACjD,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,OAAOC,aAAa,MAAM,mBAAmB;AAC7C,OAAOC,gBAAgB,MAAM,sBAAsB;AACnD,OAAOC,eAAe,MAAM,qBAAqB;AACjD,OAAOC,eAAe,MAAM,qBAAqB;AACjD,OAAOC,uBAAuB,MAAM,+BAA+B;AACnE,OAAOC,iBAAiB,MAAM,uBAAuB;AACrD,OAAOC,kCAAkC,MAAM,2CAA2C;AAC1F,OAAOC,kBAAkB,MAAM,yBAAyB;AACxD,OAAOC,aAAa,MAAM,mBAAmB;AAE7C,SACElB,WAAW,EACXC,wBAAwB,EACxBC,WAAW,EACXC,WAAW,EACXC,mBAAmB,EACnBC,6BAA6B,EAC7BC,eAAe,EACfC,aAAa,EACbC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,EACbC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,uBAAuB,EACvBC,iBAAiB,EACjBC,kCAAkC,EAClCC,kBAAkB,EAClBC,aAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaze-cms/react-page-builder",
|
|
3
|
-
"version": "0.133.0-admin-updates.
|
|
3
|
+
"version": "0.133.0-admin-updates.11",
|
|
4
4
|
"description": "Blaze react page builder",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"lib/*",
|
|
90
90
|
"lib-es/*"
|
|
91
91
|
],
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "3b5697e929af52bb1db369586ea4c36112aa0554"
|
|
93
93
|
}
|
package/src/components/Button.js
CHANGED
|
@@ -60,7 +60,12 @@ const Button = props => {
|
|
|
60
60
|
const logout = () => {
|
|
61
61
|
handleLogout(client);
|
|
62
62
|
if (hasChildren(children)) return setShowChildren(true);
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
if (!urlToUse) return router.reload();
|
|
65
|
+
|
|
66
|
+
return urlToUse.startsWith('/')
|
|
67
|
+
? router.push('/Resolver', urlToUse)
|
|
68
|
+
: (window.location.href = urlToUse);
|
|
64
69
|
};
|
|
65
70
|
|
|
66
71
|
const handleClick = () => {
|
|
@@ -3,7 +3,8 @@ 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 { isDeviceDesktop,
|
|
6
|
+
import { isDeviceDesktop, getResponsiveFilterClassnames, buildUrlQuery } from '../helpers';
|
|
7
|
+
|
|
7
8
|
import CloseMobileForm from './CloseMobileForm';
|
|
8
9
|
import ResetDesktopForm from './ResetDesktopForm';
|
|
9
10
|
import MobileFormToolbar from './MobileFormToolbar';
|
|
@@ -31,7 +32,9 @@ const SearchFilter = ({
|
|
|
31
32
|
const [moreFiltersDesktopCollapsed, setMoreFiltersDesktopCollapsed] = useState(true);
|
|
32
33
|
|
|
33
34
|
const doSubmit = newValues => {
|
|
34
|
-
const newQuery =
|
|
35
|
+
const newQuery = filterValues
|
|
36
|
+
? buildUrlQuery(newValues, filters, listComponentName, query)
|
|
37
|
+
: '';
|
|
35
38
|
handleSearch(newQuery);
|
|
36
39
|
setMoreFiltersDesktopCollapsed(true);
|
|
37
40
|
setMoreFiltersMobileCollapsed(true);
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import React, { useState, useRef, useReducer,
|
|
1
|
+
import React, { useState, useEffect, useRef, useReducer, useContext } from 'react';
|
|
2
|
+
import { MainContext } from '@blaze-cms/nextjs-components';
|
|
2
3
|
import { useRouter } from 'next/router';
|
|
3
4
|
import { useQuery } from '@apollo/client';
|
|
4
5
|
import PropTypes from 'prop-types';
|
|
5
6
|
import { parseUrl } from 'query-string';
|
|
6
7
|
import SearchFilter from './SearchFilter';
|
|
7
8
|
import { withTitle } from '../../HOC';
|
|
8
|
-
import { getSearchPublishedContent } from '../../application/query';
|
|
9
|
+
import { getSearchPublishedContent, generateSingleItemQuery } from '../../application/query';
|
|
9
10
|
import {
|
|
10
11
|
buildNewUrl,
|
|
11
12
|
buildRawQueryStringified,
|
|
12
13
|
getFilterValues,
|
|
13
14
|
buildFiltersQuery,
|
|
14
|
-
getFilterRangesAndCheckboxesValues
|
|
15
|
+
getFilterRangesAndCheckboxesValues,
|
|
16
|
+
getUpdatedFilterBy
|
|
15
17
|
} from './helpers';
|
|
16
|
-
import { getEntityData } from '../../helpers';
|
|
18
|
+
import { getEntityData, getInheritedFilters, getQueryProps } from '../../helpers';
|
|
17
19
|
import { RAW_RESULTS } from './constants';
|
|
18
20
|
import { SCROLL_OFFSET } from '../../constants';
|
|
19
21
|
import searchFilterReducer from './searchFilterReducer';
|
|
22
|
+
import { useGetEntitySchemasAsObj } from '../../hooks';
|
|
20
23
|
|
|
21
24
|
const getFiltersUrlQuery = (query, listName) => {
|
|
22
25
|
if (!listName) return query;
|
|
@@ -46,18 +49,20 @@ const SearchFilterContainer = ({
|
|
|
46
49
|
filterBy,
|
|
47
50
|
filterByProperty,
|
|
48
51
|
shouldAddFilters,
|
|
49
|
-
listComponentName
|
|
52
|
+
listComponentName,
|
|
53
|
+
parent
|
|
50
54
|
}) => {
|
|
55
|
+
const { isPreview } = useContext(MainContext);
|
|
51
56
|
const router = useRouter();
|
|
52
57
|
const { asPath } = router;
|
|
53
58
|
const searchFilterRef = useRef(null);
|
|
54
59
|
const [key, setKey] = useState(`filter-${name}`);
|
|
55
60
|
const [displaySearchFilter, setDisplaySearchFilter] = useState(false);
|
|
56
61
|
const [urlPath, setUrlPath] = useState(asPath); // used as asPath can take too long to update
|
|
62
|
+
const [filterValues, dispatch] = useReducer(searchFilterReducer, null);
|
|
57
63
|
const { url: currentUrl, query } = parseUrl(urlPath);
|
|
58
64
|
const updatedQuery = getFiltersUrlQuery(query, listComponentName);
|
|
59
|
-
|
|
60
|
-
const [filterValues, dispatch] = useReducer(searchFilterReducer, null);
|
|
65
|
+
const { itemId: parentId, itemEntity: parentEntity } = parent;
|
|
61
66
|
|
|
62
67
|
useEffect(
|
|
63
68
|
() => {
|
|
@@ -65,6 +70,27 @@ const SearchFilterContainer = ({
|
|
|
65
70
|
},
|
|
66
71
|
[asPath]
|
|
67
72
|
);
|
|
73
|
+
const { data: mainSchemas = {}, loading: schemasLoading } = useGetEntitySchemasAsObj([
|
|
74
|
+
parentEntity,
|
|
75
|
+
entity
|
|
76
|
+
]);
|
|
77
|
+
const { [parentEntity]: parentSchema = {}, [entity]: filterEntitySchema = {} } = mainSchemas;
|
|
78
|
+
const { actions = {} } = parentSchema || {};
|
|
79
|
+
const getAction = isPreview ? actions.get : actions.getPublished;
|
|
80
|
+
const inheritedFilters = getInheritedFilters(filterBy, filterByProperty);
|
|
81
|
+
const queryProps = getQueryProps(inheritedFilters, parentSchema, filterEntitySchema);
|
|
82
|
+
const { data: { entityData: parentData } = {}, loading: parentQueryLoading } = useQuery(
|
|
83
|
+
generateSingleItemQuery(getAction, queryProps),
|
|
84
|
+
{
|
|
85
|
+
variables: { id: parentId },
|
|
86
|
+
skip: schemasLoading || !inheritedFilters.length
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
const { updatedFilterBy, updatedFilterByProperty } = getUpdatedFilterBy(
|
|
90
|
+
filterBy,
|
|
91
|
+
filterByProperty,
|
|
92
|
+
parentData
|
|
93
|
+
);
|
|
68
94
|
|
|
69
95
|
const action = getSearchPublishedContent(RAW_RESULTS);
|
|
70
96
|
const [checkboxSelectValues, rangeValues] = getFilterRangesAndCheckboxesValues(filters);
|
|
@@ -73,9 +99,9 @@ const SearchFilterContainer = ({
|
|
|
73
99
|
|
|
74
100
|
const filtersQuery = buildFiltersQuery({
|
|
75
101
|
shouldAddFilters,
|
|
76
|
-
query: filterValues
|
|
77
|
-
filterBy,
|
|
78
|
-
filterByProperty,
|
|
102
|
+
query: filterValues,
|
|
103
|
+
filterBy: updatedFilterBy,
|
|
104
|
+
filterByProperty: updatedFilterByProperty,
|
|
79
105
|
rangeValues,
|
|
80
106
|
queryKeys: Object.keys(updatedQuery)
|
|
81
107
|
});
|
|
@@ -89,7 +115,7 @@ const SearchFilterContainer = ({
|
|
|
89
115
|
|
|
90
116
|
const { data, error, loading } = useQuery(action, {
|
|
91
117
|
variables: { rawQueryStringified, limit: 0 }, // we only want aggs so limit=0 for no search results
|
|
92
|
-
skip: !rawQueryStringified
|
|
118
|
+
skip: !rawQueryStringified || parentQueryLoading
|
|
93
119
|
});
|
|
94
120
|
|
|
95
121
|
if (error) return error.message;
|
|
@@ -98,7 +124,7 @@ const SearchFilterContainer = ({
|
|
|
98
124
|
const { searchPublishedContent: { rawResults: { aggregations: filterData } = {} } = {} } =
|
|
99
125
|
data || {};
|
|
100
126
|
|
|
101
|
-
if (!filterValues && !loading && (filterData || !rawQueryStringified)) {
|
|
127
|
+
if (!filterValues && !loading && !parentQueryLoading && (filterData || !rawQueryStringified)) {
|
|
102
128
|
const newValues = getFilterValues(filterData, filters, updatedQuery);
|
|
103
129
|
dispatch({ newValues, shouldSearch: false, type: 'update' });
|
|
104
130
|
return null;
|
|
@@ -171,7 +197,8 @@ SearchFilterContainer.propTypes = {
|
|
|
171
197
|
filterBy: PropTypes.array,
|
|
172
198
|
filterByProperty: PropTypes.array,
|
|
173
199
|
shouldAddFilters: PropTypes.bool,
|
|
174
|
-
listComponentName: PropTypes.string
|
|
200
|
+
listComponentName: PropTypes.string,
|
|
201
|
+
parent: PropTypes.object
|
|
175
202
|
};
|
|
176
203
|
|
|
177
204
|
SearchFilterContainer.defaultProps = {
|
|
@@ -184,7 +211,8 @@ SearchFilterContainer.defaultProps = {
|
|
|
184
211
|
filterBy: [],
|
|
185
212
|
filterByProperty: [],
|
|
186
213
|
shouldAddFilters: false,
|
|
187
|
-
listComponentName: ''
|
|
214
|
+
listComponentName: '',
|
|
215
|
+
parent: {}
|
|
188
216
|
};
|
|
189
217
|
|
|
190
218
|
export default withTitle(SearchFilterContainer);
|
|
@@ -29,38 +29,41 @@ const builFilterObject = ({ queryKey, value, filters, isRange, isInQuery }) => {
|
|
|
29
29
|
filters.push({ match: { [key]: filterValue } });
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
+
|
|
32
33
|
const buildFiltersQuery = ({
|
|
33
34
|
shouldAddFilters,
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
filterBy,
|
|
36
37
|
filterByProperty,
|
|
37
38
|
rangeValues,
|
|
38
|
-
queryKeys
|
|
39
|
+
queryKeys,
|
|
40
|
+
query
|
|
39
41
|
}) => {
|
|
40
42
|
if (!shouldAddFilters) return [];
|
|
41
43
|
const mustFilters = [];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
if (query) {
|
|
45
|
+
Object.keys(query).forEach(queryKey => {
|
|
46
|
+
if (QUERY_KEYS_TO_IGNORE.includes(queryKey)) return;
|
|
47
|
+
if (!queryKey || !query[queryKey]) return;
|
|
48
|
+
const queryValue = query[queryKey];
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const isRange = rangeValues.includes(queryKey);
|
|
51
|
+
const isInQuery = queryKeys.includes(queryKey);
|
|
52
|
+
builFilterObject({ queryKey, value: queryValue, filters: mustFilters, isRange, isInQuery });
|
|
53
|
+
});
|
|
54
|
+
}
|
|
51
55
|
|
|
52
56
|
if (filterByProperty && filterByProperty.length) {
|
|
53
|
-
filterByProperty
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
mustFilters.push({ match: { [filterByKeyword]: filteryByValue } });
|
|
62
|
-
});
|
|
57
|
+
filterByProperty.forEach(filterByPropOption => {
|
|
58
|
+
const [filterByPropKey] = filterByPropOption.split('/');
|
|
59
|
+
filterBy.forEach(filterByOption => {
|
|
60
|
+
if (filterByOption.indexOf(filterByPropKey) === -1) return;
|
|
61
|
+
const [, filteryByValue] = filterByOption.split('/');
|
|
62
|
+
const filterByKeyword = `${filterByPropKey}.keyword`;
|
|
63
|
+
if (!filteryByValue) return;
|
|
64
|
+
mustFilters.push({ match: { [filterByKeyword]: filteryByValue } });
|
|
63
65
|
});
|
|
66
|
+
});
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
return mustFilters;
|
|
@@ -3,8 +3,6 @@ import parseFilterValue from './parse-filter-value';
|
|
|
3
3
|
import { buildQueryKey } from '../../../helpers';
|
|
4
4
|
|
|
5
5
|
const buildUrlQuery = (filterValues, filters, listComponentName = '', query = {}) => {
|
|
6
|
-
if (!filterValues) return '';
|
|
7
|
-
|
|
8
6
|
const newQuery = [];
|
|
9
7
|
const queryKeys = [];
|
|
10
8
|
const searchValue = filterValues[SEARCH_TERM];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SEARCH_TERM, TEXT_SEARCH } from '../constants';
|
|
2
|
+
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
3
|
+
import { buildQueryKey } from '../../../helpers';
|
|
4
|
+
|
|
5
|
+
const getInitialFilterValues = (filterData, filters, query, listComponentName) => {
|
|
6
|
+
const filterValues = {};
|
|
7
|
+
const searchQueryKey = buildQueryKey(SEARCH_TERM, listComponentName);
|
|
8
|
+
filterValues[SEARCH_TERM] = query[searchQueryKey] || '';
|
|
9
|
+
|
|
10
|
+
filters.forEach(filterProps => {
|
|
11
|
+
const {
|
|
12
|
+
propsToDisplay: [key],
|
|
13
|
+
type
|
|
14
|
+
} = filterProps;
|
|
15
|
+
if (type === TEXT_SEARCH) return;
|
|
16
|
+
const data = filterData && filterData[key] ? filterData[key] : {};
|
|
17
|
+
const queryKey = buildQueryKey(key, listComponentName);
|
|
18
|
+
filterValues[key] = getFilterValueFromQuery(queryKey, filterProps, data, query);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return filterValues;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default getInitialFilterValues;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const getUpdatedFilterBy = (filterBy, filterByProperty, parentData) => {
|
|
2
|
+
if (!parentData || (filterBy && filterBy.length))
|
|
3
|
+
return { updatedFilterBy: filterBy, updatedFilterByProperty: filterByProperty };
|
|
4
|
+
|
|
5
|
+
const updatedFilterBy = [];
|
|
6
|
+
filterByProperty.forEach(property => {
|
|
7
|
+
const [key] = property.split('/');
|
|
8
|
+
const filterData = parentData[key];
|
|
9
|
+
|
|
10
|
+
if (!filterData) return;
|
|
11
|
+
if (Array.isArray(filterData)) filterData.forEach(dat => updatedFilterBy.push(`${key}/${dat}`));
|
|
12
|
+
else updatedFilterBy.push(`${key}/${filterData}`);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return { updatedFilterBy, updatedFilterByProperty: filterByProperty };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default getUpdatedFilterBy;
|
|
@@ -12,12 +12,12 @@ import getSelectOptions from './get-select-options';
|
|
|
12
12
|
import isDeviceDesktop from './is-device-desktop';
|
|
13
13
|
import getFilterValues from './get-filter-values';
|
|
14
14
|
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
15
|
-
import buildUrlQuery from './build-url-query';
|
|
16
15
|
import buildFiltersQuery from './build-filters-query';
|
|
17
16
|
import getFilterRangesAndCheckboxesValues from './get-filter-ranges-and-checkboxes-values';
|
|
17
|
+
import getUpdatedFilterBy from './get-updated-filter-by';
|
|
18
|
+
import buildUrlQuery from './build-url-query';
|
|
18
19
|
|
|
19
20
|
export {
|
|
20
|
-
buildUrlQuery,
|
|
21
21
|
buildNewUrl,
|
|
22
22
|
buildRawQueryStringified,
|
|
23
23
|
decodeValue,
|
|
@@ -34,5 +34,7 @@ export {
|
|
|
34
34
|
getFilterValues,
|
|
35
35
|
getFilterValueFromQuery,
|
|
36
36
|
buildFiltersQuery,
|
|
37
|
-
getFilterRangesAndCheckboxesValues
|
|
37
|
+
getFilterRangesAndCheckboxesValues,
|
|
38
|
+
getUpdatedFilterBy,
|
|
39
|
+
buildUrlQuery
|
|
38
40
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import getUpdatedFilterBy from '../../../../../../src/components/SearchFilter/helpers/get-updated-filter-by';
|
|
2
|
+
|
|
3
|
+
const mockedFilterByProperty = ['categoryId/product', 'subjectIds/product'];
|
|
4
|
+
|
|
5
|
+
const mockedParentData = {
|
|
6
|
+
id: 'abc123d',
|
|
7
|
+
categoryId: null,
|
|
8
|
+
subjectIds: ['subjectid123s']
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe('getUpdatedFilterBy helper', () => {
|
|
12
|
+
const mockedFilterBy = [1, 2, 3];
|
|
13
|
+
const noParentData = getUpdatedFilterBy(mockedFilterBy, [], {});
|
|
14
|
+
const withFilterBy = getUpdatedFilterBy(mockedFilterBy, [], { id: '123' });
|
|
15
|
+
const withUpdatedFilterBy = getUpdatedFilterBy([], mockedFilterByProperty, mockedParentData);
|
|
16
|
+
|
|
17
|
+
it('should return current filterBy and filterByProperty if no parentData or if filterBy values exist', () => {
|
|
18
|
+
expect(noParentData).toEqual({ updatedFilterBy: mockedFilterBy, updatedFilterByProperty: [] });
|
|
19
|
+
expect(withFilterBy).toEqual({ updatedFilterBy: mockedFilterBy, updatedFilterByProperty: [] });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return updated filterBy based on parent data matchess', () => {
|
|
23
|
+
expect(withUpdatedFilterBy).toEqual({
|
|
24
|
+
updatedFilterBy: ['subjectIds/subjectid123s'],
|
|
25
|
+
updatedFilterByProperty: mockedFilterByProperty
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
File without changes
|