@blaze-cms/react-page-builder 0.114.0-alpha.0 → 0.114.0-alpha.1

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +5 -8
  3. package/lib/components/Card/CardRender.js +61 -17
  4. package/lib/components/Card/CardRender.js.map +1 -1
  5. package/lib/components/Card/helpers/filter-query-setup.js.map +1 -1
  6. package/lib/components/List/ListBuilder.js +11 -6
  7. package/lib/components/List/ListBuilder.js.map +1 -1
  8. package/lib/components/List/ListFactory.js +20 -7
  9. package/lib/components/List/ListFactory.js.map +1 -1
  10. package/lib/components/List/helpers/get-sort-props.js +46 -0
  11. package/lib/components/List/helpers/get-sort-props.js.map +1 -0
  12. package/lib/components/List/helpers/index.js +8 -0
  13. package/lib/components/List/helpers/index.js.map +1 -1
  14. package/lib/components/SearchFilter/helpers/build-query.js +1 -5
  15. package/lib/components/SearchFilter/helpers/build-query.js.map +1 -1
  16. package/lib/helpers/get-generic-render-variables.js +32 -22
  17. package/lib/helpers/get-generic-render-variables.js.map +1 -1
  18. package/lib-es/components/Card/CardRender.js +32 -5
  19. package/lib-es/components/Card/CardRender.js.map +1 -1
  20. package/lib-es/components/Card/helpers/filter-query-setup.js.map +1 -1
  21. package/lib-es/components/List/ListBuilder.js +11 -6
  22. package/lib-es/components/List/ListBuilder.js.map +1 -1
  23. package/lib-es/components/List/ListFactory.js +20 -8
  24. package/lib-es/components/List/ListFactory.js.map +1 -1
  25. package/lib-es/components/List/helpers/get-sort-props.js +26 -0
  26. package/lib-es/components/List/helpers/get-sort-props.js.map +1 -0
  27. package/lib-es/components/List/helpers/index.js +1 -0
  28. package/lib-es/components/List/helpers/index.js.map +1 -1
  29. package/lib-es/components/SearchFilter/helpers/build-query.js +1 -3
  30. package/lib-es/components/SearchFilter/helpers/build-query.js.map +1 -1
  31. package/lib-es/helpers/get-generic-render-variables.js +22 -15
  32. package/lib-es/helpers/get-generic-render-variables.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/components/Card/CardRender.js +24 -6
  35. package/src/components/Card/helpers/filter-query-setup.js +1 -0
  36. package/src/components/List/ListBuilder.js +11 -6
  37. package/src/components/List/ListFactory.js +18 -8
  38. package/src/components/List/helpers/get-sort-props.js +17 -0
  39. package/src/components/List/helpers/index.js +1 -0
  40. package/src/components/SearchFilter/helpers/build-query.js +2 -3
  41. package/src/helpers/get-generic-render-variables.js +22 -12
  42. package/tests/unit/src/components/List/helpers/get-sort-props.test.js +58 -0
  43. package/tests/unit/src/helpers/build-raw-query.test.js +2 -1
  44. package/tests/unit/src/helpers/get-generic-render-variables.test.js +5 -11
  45. package/lib/helpers/check-sort-by.js +0 -16
  46. package/lib/helpers/check-sort-by.js.map +0 -1
  47. package/lib-es/helpers/check-sort-by.js +0 -4
  48. package/lib-es/helpers/check-sort-by.js.map +0 -1
  49. package/src/helpers/check-sort-by.js +0 -4
@@ -10,12 +10,10 @@ const buildQuery = (filterValues, filters) => {
10
10
  type
11
11
  }) => {
12
12
  if (type === TEXT_SEARCH) return;
13
- propsToDisplay.map(prop => {
13
+ propsToDisplay.forEach(prop => {
14
14
  const value = filterValues[prop];
15
15
  const parsedValue = parseFilterValue(prop, type, value);
16
- if (!parsedValue) return null;
17
16
  if (parsedValue) newQuery.push(parsedValue);
18
- return parsedValue;
19
17
  });
20
18
  });
21
19
  return newQuery.join('&');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/SearchFilter/helpers/build-query.js"],"names":["SEARCH_TERM","TEXT_SEARCH","parseFilterValue","buildQuery","filterValues","filters","newQuery","searchValue","push","forEach","propsToDisplay","type","map","prop","value","parsedValue","join"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,WAAtB,QAAyC,cAAzC;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;;AAEA,MAAMC,UAAU,GAAG,CAACC,YAAD,EAAeC,OAAf,KAA2B;AAC5C,QAAMC,QAAQ,GAAG,EAAjB;AACA,QAAMC,WAAW,GAAGH,YAAY,CAACJ,WAAD,CAAhC;AACA,MAAIO,WAAJ,EAAiBD,QAAQ,CAACE,IAAT,CAAe,GAAER,WAAY,IAAGO,WAAY,EAA5C;AAEjBF,EAAAA,OAAO,CAACI,OAAR,CAAgB,CAAC;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA;AAAlB,GAAD,KAA8B;AAC5C,QAAIA,IAAI,KAAKV,WAAb,EAA0B;AAC1BS,IAAAA,cAAc,CAACE,GAAf,CAAmBC,IAAI,IAAI;AACzB,YAAMC,KAAK,GAAGV,YAAY,CAACS,IAAD,CAA1B;AACA,YAAME,WAAW,GAAGb,gBAAgB,CAACW,IAAD,EAAOF,IAAP,EAAaG,KAAb,CAApC;AACA,UAAI,CAACC,WAAL,EAAkB,OAAO,IAAP;AAClB,UAAIA,WAAJ,EAAiBT,QAAQ,CAACE,IAAT,CAAcO,WAAd;AACjB,aAAOA,WAAP;AACD,KAND;AAOD,GATD;AAWA,SAAOT,QAAQ,CAACU,IAAT,CAAc,GAAd,CAAP;AACD,CAjBD;;AAmBA,eAAeb,UAAf","sourcesContent":["import { SEARCH_TERM, TEXT_SEARCH } from '../constants';\nimport parseFilterValue from './parse-filter-value';\n\nconst buildQuery = (filterValues, filters) => {\n const newQuery = [];\n const searchValue = filterValues[SEARCH_TERM];\n if (searchValue) newQuery.push(`${SEARCH_TERM}=${searchValue}`);\n\n filters.forEach(({ propsToDisplay, type }) => {\n if (type === TEXT_SEARCH) return;\n propsToDisplay.map(prop => {\n const value = filterValues[prop];\n const parsedValue = parseFilterValue(prop, type, value);\n if (!parsedValue) return null;\n if (parsedValue) newQuery.push(parsedValue);\n return parsedValue;\n });\n });\n\n return newQuery.join('&');\n};\n\nexport default buildQuery;\n"],"file":"build-query.js"}
1
+ {"version":3,"sources":["../../../../src/components/SearchFilter/helpers/build-query.js"],"names":["SEARCH_TERM","TEXT_SEARCH","parseFilterValue","buildQuery","filterValues","filters","newQuery","searchValue","push","forEach","propsToDisplay","type","prop","value","parsedValue","join"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,WAAtB,QAAyC,cAAzC;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;;AAEA,MAAMC,UAAU,GAAG,CAACC,YAAD,EAAeC,OAAf,KAA2B;AAC5C,QAAMC,QAAQ,GAAG,EAAjB;AACA,QAAMC,WAAW,GAAGH,YAAY,CAACJ,WAAD,CAAhC;AACA,MAAIO,WAAJ,EAAiBD,QAAQ,CAACE,IAAT,CAAe,GAAER,WAAY,IAAGO,WAAY,EAA5C;AAEjBF,EAAAA,OAAO,CAACI,OAAR,CAAgB,CAAC;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA;AAAlB,GAAD,KAA8B;AAC5C,QAAIA,IAAI,KAAKV,WAAb,EAA0B;AAE1BS,IAAAA,cAAc,CAACD,OAAf,CAAuBG,IAAI,IAAI;AAC7B,YAAMC,KAAK,GAAGT,YAAY,CAACQ,IAAD,CAA1B;AACA,YAAME,WAAW,GAAGZ,gBAAgB,CAACU,IAAD,EAAOD,IAAP,EAAaE,KAAb,CAApC;AACA,UAAIC,WAAJ,EAAiBR,QAAQ,CAACE,IAAT,CAAcM,WAAd;AAClB,KAJD;AAKD,GARD;AAUA,SAAOR,QAAQ,CAACS,IAAT,CAAc,GAAd,CAAP;AACD,CAhBD;;AAkBA,eAAeZ,UAAf","sourcesContent":["import { SEARCH_TERM, TEXT_SEARCH } from '../constants';\nimport parseFilterValue from './parse-filter-value';\n\nconst buildQuery = (filterValues, filters) => {\n const newQuery = [];\n const searchValue = filterValues[SEARCH_TERM];\n if (searchValue) newQuery.push(`${SEARCH_TERM}=${searchValue}`);\n\n filters.forEach(({ propsToDisplay, type }) => {\n if (type === TEXT_SEARCH) return;\n\n propsToDisplay.forEach(prop => {\n const value = filterValues[prop];\n const parsedValue = parseFilterValue(prop, type, value);\n if (parsedValue) newQuery.push(parsedValue);\n });\n });\n\n return newQuery.join('&');\n};\n\nexport default buildQuery;\n"],"file":"build-query.js"}
@@ -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
- const isSortbyArray = Array.isArray(sortby);
23
- const hasSortFields = sort && checkSortby(sortby, isSortbyArray);
24
- const sortValue = hasSortFields ? `${getSortbyFieldName(relations, sortby, stringProps, isSortbyArray)}:${sort.toLowerCase()}` : '';
25
- return sortValue ? {
26
- sort: sortValue
27
- } : {};
33
+ return buildSortValues([{
34
+ sort,
35
+ propsToDisplay: [sortby]
36
+ }, ...sortProperties], relations, stringProps);
28
37
  };
29
38
 
30
- const getGenericRenderVariables = (relations, _ref = {}, stringProps = [], rawQueryStringified = '', isTextSearchFilterApplied = false) => {
31
- let {
39
+ const getGenericRenderVariables = (relations, filterProps = {}, stringProps = [], rawQueryStringified = '', isTextSearchFilterApplied = false) => {
40
+ const {
32
41
  limit = DEFAULT_LIMIT,
33
42
  offset
34
- } = _ref,
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":["checkSortby","getSortbyFieldName","DEFAULT_LIMIT","DEFAULT_OFFSET","getCorrectSort","relations","filterProps","stringProps","isTextSearchApplied","sort","sortby","isSortbyArray","Array","isArray","hasSortFields","sortValue","toLowerCase","getGenericRenderVariables","rawQueryStringified","isTextSearchFilterApplied","limit","offset","raw","Number"],"mappings":";;;;;;;;AAAA,OAAOA,WAAP,MAAwB,iBAAxB;AACA,OAAOC,kBAAP,MAA+B,0BAA/B;AACA,SAASC,aAAT,EAAwBC,cAAxB,QAA8C,cAA9C;;AAEA,MAAMC,cAAc,GAAG,CAACC,SAAD,EAAYC,WAAZ,EAAyBC,WAAzB,EAAsCC,mBAAtC,KAA8D;AACnF,MAAIA,mBAAJ,EAAyB;AACvB,WAAO,EAAP;AACD;;AACD,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAmBJ,WAAzB;AAEA,QAAMK,aAAa,GAAGC,KAAK,CAACC,OAAN,CAAcH,MAAd,CAAtB;AAEA,QAAMI,aAAa,GAAGL,IAAI,IAAIT,WAAW,CAACU,MAAD,EAASC,aAAT,CAAzC;AAEA,QAAMI,SAAS,GAAGD,aAAa,GAC1B,GAAEb,kBAAkB,CAACI,SAAD,EAAYK,MAAZ,EAAoBH,WAApB,EAAiCI,aAAjC,CAAgD,IAAGF,IAAI,CAACO,WAAL,EAAmB,EADhE,GAE3B,EAFJ;AAIA,SAAOD,SAAS,GAAG;AAAEN,IAAAA,IAAI,EAAEM;AAAR,GAAH,GAAyB,EAAzC;AACD,CAfD;;AAiBA,MAAME,yBAAyB,GAAG,CAChCZ,SADgC,EAEhC,OAAoD,EAFpB,EAGhCE,WAAW,GAAG,EAHkB,EAIhCW,mBAAmB,GAAG,EAJU,EAKhCC,yBAAyB,GAAG,KALI,KAM7B;AAAA,MAJH;AAAEC,IAAAA,KAAK,GAAGlB,aAAV;AAAyBmB,IAAAA;AAAzB,GAIG;AAAA,MAJiCf,WAIjC;;AACH,QAAMG,IAAI,GAAGL,cAAc,CAACC,SAAD,EAAYC,WAAZ,EAAyBC,WAAzB,EAAsCY,yBAAtC,CAA3B;AACA,QAAMG,GAAG,GAAGJ,mBAAmB,GAAG;AAAEA,IAAAA;AAAF,GAAH,GAA6B,EAA5D;AAEA;AACEE,IAAAA,KAAK,EAAEG,MAAM,CAACH,KAAK,IAAIlB,aAAV,CADf;AAEEmB,IAAAA,MAAM,EAAEE,MAAM,CAACF,MAAM,IAAIlB,cAAX;AAFhB,KAGKM,IAHL,GAIKa,GAJL;AAMD,CAhBD;;AAkBA,eAAeL,yBAAf","sourcesContent":["import checkSortby from './check-sort-by';\nimport getSortbyFieldName from './get-sort-by-field-name';\nimport { DEFAULT_LIMIT, DEFAULT_OFFSET } from '../constants';\n\nconst getCorrectSort = (relations, filterProps, stringProps, isTextSearchApplied) => {\n if (isTextSearchApplied) {\n return {};\n }\n const { sort, sortby } = filterProps;\n\n const isSortbyArray = Array.isArray(sortby);\n\n const hasSortFields = sort && checkSortby(sortby, isSortbyArray);\n\n const sortValue = hasSortFields\n ? `${getSortbyFieldName(relations, sortby, stringProps, isSortbyArray)}:${sort.toLowerCase()}`\n : '';\n\n return sortValue ? { sort: sortValue } : {};\n};\n\nconst getGenericRenderVariables = (\n relations,\n { limit = DEFAULT_LIMIT, offset, ...filterProps } = {},\n stringProps = [],\n rawQueryStringified = '',\n isTextSearchFilterApplied = false\n) => {\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"}
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.114.0-alpha.0",
3
+ "version": "0.114.0-alpha.1",
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": "28a128c55187783ae2f1ed47eda71e4d94b72109"
91
+ "gitHead": "afa1f76f62004ccdd452d59043ac378a87e08be1"
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, ...variableProps }) => {
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
- } = variableProps;
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, ...sortby], filterEntitySchema),
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)
@@ -41,6 +41,7 @@ const filterQuerySetup = ({
41
41
  stringProps,
42
42
  JSON.stringify(rawQuery)
43
43
  );
44
+
44
45
  return { variables, limit };
45
46
  };
46
47
 
@@ -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 = !sortby || !sortby.length;
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 sort = querySort || defaultSort;
50
- const sortby = querySortBy ? [querySortBy] : defaultSortBy || [];
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, ...sortby], filterEntitySchema),
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';
@@ -8,12 +8,11 @@ const buildQuery = (filterValues, filters) => {
8
8
 
9
9
  filters.forEach(({ propsToDisplay, type }) => {
10
10
  if (type === TEXT_SEARCH) return;
11
- propsToDisplay.map(prop => {
11
+
12
+ propsToDisplay.forEach(prop => {
12
13
  const value = filterValues[prop];
13
14
  const parsedValue = parseFilterValue(prop, type, value);
14
- if (!parsedValue) return null;
15
15
  if (parsedValue) newQuery.push(parsedValue);
16
- return parsedValue;
17
16
  });
18
17
  });
19
18
 
@@ -1,31 +1,41 @@
1
- import checkSortby from './check-sort-by';
2
1
  import getSortbyFieldName from './get-sort-by-field-name';
3
2
  import { DEFAULT_LIMIT, DEFAULT_OFFSET } from '../constants';
4
3
 
4
+ const buildSortValues = (sortFilters, relations, stringProps) => {
5
+ if (!sortFilters || !sortFilters.length) return { sort: [] };
6
+ const sortValues = sortFilters
7
+ .map(
8
+ ({ sort, propsToDisplay }) =>
9
+ !!sort &&
10
+ !!propsToDisplay[0] &&
11
+ `${getSortbyFieldName(relations, propsToDisplay[0], stringProps)}:${sort.toLowerCase()}`
12
+ )
13
+ .filter(Boolean)
14
+ .join(',');
15
+
16
+ return { sort: sortValues };
17
+ };
5
18
  const getCorrectSort = (relations, filterProps, stringProps, isTextSearchApplied) => {
6
19
  if (isTextSearchApplied) {
7
20
  return {};
8
21
  }
9
- const { sort, sortby } = filterProps;
10
-
11
- const isSortbyArray = Array.isArray(sortby);
12
-
13
- const hasSortFields = sort && checkSortby(sortby, isSortbyArray);
14
-
15
- const sortValue = hasSortFields
16
- ? `${getSortbyFieldName(relations, sortby, stringProps, isSortbyArray)}:${sort.toLowerCase()}`
17
- : '';
22
+ const { sort, sortby, sortProperties = [] } = filterProps;
18
23
 
19
- return sortValue ? { sort: sortValue } : {};
24
+ return buildSortValues(
25
+ [{ sort, propsToDisplay: [sortby] }, ...sortProperties],
26
+ relations,
27
+ stringProps
28
+ );
20
29
  };
21
30
 
22
31
  const getGenericRenderVariables = (
23
32
  relations,
24
- { limit = DEFAULT_LIMIT, offset, ...filterProps } = {},
33
+ filterProps = {},
25
34
  stringProps = [],
26
35
  rawQueryStringified = '',
27
36
  isTextSearchFilterApplied = false
28
37
  ) => {
38
+ const { limit = DEFAULT_LIMIT, offset } = filterProps;
29
39
  const sort = getCorrectSort(relations, filterProps, stringProps, isTextSearchFilterApplied);
30
40
  const raw = rawQueryStringified ? { rawQueryStringified } : {};
31
41
 
@@ -0,0 +1,58 @@
1
+ import getSortProps from '../../../../../../src/components/List/helpers/get-sort-props';
2
+
3
+ const property = 'updated';
4
+ const defaultProperty = 'name';
5
+ const asc = 'asc';
6
+ const desc = 'desc';
7
+ const sortProperties = [
8
+ {
9
+ propsToDisplay: [property],
10
+ sort: asc
11
+ }
12
+ ];
13
+ const querySortBy = 'date';
14
+ const props = {
15
+ querySort: '',
16
+ sortProperties,
17
+ defaultSort: desc,
18
+ querySortBy: '',
19
+ defaultSortBy: [defaultProperty]
20
+ };
21
+
22
+ describe('getSortProps helper function', () => {
23
+ it('should ignore old sortby/sort and use sortProperties', () => {
24
+ const { sortbyFilters, updatedSortProperties } = getSortProps(props);
25
+ expect(sortbyFilters).toEqual([property]);
26
+ expect(updatedSortProperties).toEqual(sortProperties);
27
+ });
28
+
29
+ it('should add query sort', () => {
30
+ const { sortbyFilters, updatedSortProperties } = getSortProps({
31
+ ...props,
32
+ querySortBy,
33
+ querySort: desc
34
+ });
35
+ expect(sortbyFilters).toEqual([querySortBy, property]);
36
+ expect(updatedSortProperties).toEqual([
37
+ {
38
+ propsToDisplay: [querySortBy],
39
+ sort: desc
40
+ },
41
+ ...sortProperties
42
+ ]);
43
+ });
44
+
45
+ it('should use old style sort', () => {
46
+ const { sortbyFilters, updatedSortProperties } = getSortProps({
47
+ ...props,
48
+ sortProperties: []
49
+ });
50
+ expect(sortbyFilters).toEqual([defaultProperty]);
51
+ expect(updatedSortProperties).toEqual([
52
+ {
53
+ propsToDisplay: [defaultProperty],
54
+ sort: desc
55
+ }
56
+ ]);
57
+ });
58
+ });
@@ -304,6 +304,7 @@ describe('build raw query', () => {
304
304
  id,
305
305
  itemsToDisplay
306
306
  );
307
+
307
308
  expect(rawQueryOneCheckboxFilterMoreItemsToDisplayValues).toEqual(
308
309
  RAW_QUERY_OR_OPERATOR_ITEMS_TO_DISPLAY
309
310
  );
@@ -347,7 +348,7 @@ describe('build raw query', () => {
347
348
  filterData,
348
349
  id,
349
350
  [],
350
- false,
351
+ true,
351
352
  { shouldReturnAggs: true, isAZ: true }
352
353
  );
353
354
  expect(queryWithAggs).toEqual(RAW_QUERY_WITH_AGGS);
@@ -17,11 +17,7 @@ const mockedProps = overrides => ({
17
17
  });
18
18
 
19
19
  describe('get card/list render variables', () => {
20
- it('should be a function', () => {
21
- expect(typeof getGenericRenderVariables).toEqual('function');
22
- });
23
-
24
- it('should return always an object', () => {
20
+ it('should always return an object', () => {
25
21
  const variables = getGenericRenderVariables();
26
22
  const variablesWithProps = getGenericRenderVariables([], mockedProps(), STRING_PROPS_EMPTY);
27
23
 
@@ -78,20 +74,18 @@ describe('get card/list render variables', () => {
78
74
  mockedProps({ sortby: ['length'] }),
79
75
  STRING_PROPS_EMPTY
80
76
  );
81
-
82
77
  expect(sort).toEqual('length:desc');
83
78
  });
84
79
 
85
80
  it('should return correct sort data when when there is a prop that is of type string', () => {
86
- const { sort } = getGenericRenderVariables([], mockedProps({ sortby: ['name'] }), STRING_PROPS);
87
-
81
+ const { sort } = getGenericRenderVariables([], mockedProps({ sortby: 'name' }), STRING_PROPS);
88
82
  expect(sort).toEqual('name.keyword:desc');
89
83
  });
90
84
 
91
85
  it("should return correct sort data when when there is a prop that is of type string and it's also a relation prop", () => {
92
86
  const { sort } = getGenericRenderVariables(
93
87
  [{ localField: 'entity', entityIdentifier: 'entity' }],
94
- mockedProps({ sortby: ['entity.name'], sort: 'ASC' }),
88
+ mockedProps({ sortby: 'entity.name', sort: 'ASC' }),
95
89
  ['entity.name']
96
90
  );
97
91
 
@@ -103,7 +97,7 @@ describe('get card/list render variables', () => {
103
97
  const sortby = `${localField}.length`;
104
98
  const { sort } = getGenericRenderVariables(
105
99
  [{ localField, entityIdentifier: 'entity' }],
106
- mockedProps({ sortby: [sortby], sort: 'ASC' }),
100
+ mockedProps({ sortby, sort: 'ASC' }),
107
101
  []
108
102
  );
109
103
 
@@ -113,7 +107,7 @@ describe('get card/list render variables', () => {
113
107
  it('should return correct sort data when when there is a relation prop that is of type string but with updated value', () => {
114
108
  const { sort } = getGenericRenderVariables(
115
109
  [{ localField: 'tag', entityIdentifier: 'tags' }],
116
- mockedProps({ sortby: ['tag.name'], sort: 'ASC' }),
110
+ mockedProps({ sortby: 'tag.name', sort: 'ASC' }),
117
111
  ['tags.name']
118
112
  );
119
113
 
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.object.define-property.js");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var checkSortby = function checkSortby(sortby, isSortbyArray) {
11
- return isSortbyArray && sortby.length || !isSortbyArray && sortby;
12
- };
13
-
14
- var _default = checkSortby;
15
- exports["default"] = _default;
16
- //# sourceMappingURL=check-sort-by.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/helpers/check-sort-by.js"],"names":["checkSortby","sortby","isSortbyArray","length"],"mappings":";;;;;;;;;AAAA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,MAAD,EAASC,aAAT;AAAA,SACjBA,aAAa,IAAID,MAAM,CAACE,MAAzB,IAAqC,CAACD,aAAD,IAAkBD,MADrC;AAAA,CAApB;;eAGeD,W","sourcesContent":["const checkSortby = (sortby, isSortbyArray) =>\n (isSortbyArray && sortby.length) || (!isSortbyArray && sortby);\n\nexport default checkSortby;\n"],"file":"check-sort-by.js"}
@@ -1,4 +0,0 @@
1
- const checkSortby = (sortby, isSortbyArray) => isSortbyArray && sortby.length || !isSortbyArray && sortby;
2
-
3
- export default checkSortby;
4
- //# sourceMappingURL=check-sort-by.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/helpers/check-sort-by.js"],"names":["checkSortby","sortby","isSortbyArray","length"],"mappings":"AAAA,MAAMA,WAAW,GAAG,CAACC,MAAD,EAASC,aAAT,KACjBA,aAAa,IAAID,MAAM,CAACE,MAAzB,IAAqC,CAACD,aAAD,IAAkBD,MADzD;;AAGA,eAAeD,WAAf","sourcesContent":["const checkSortby = (sortby, isSortbyArray) =>\n (isSortbyArray && sortby.length) || (!isSortbyArray && sortby);\n\nexport default checkSortby;\n"],"file":"check-sort-by.js"}
@@ -1,4 +0,0 @@
1
- const checkSortby = (sortby, isSortbyArray) =>
2
- (isSortbyArray && sortby.length) || (!isSortbyArray && sortby);
3
-
4
- export default checkSortby;