@blaze-cms/react-page-builder 0.106.0-alpha.0 → 0.107.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/lib/components/Card/CardRender.js +3 -2
- package/lib/components/Card/CardRender.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryFactory.js +12 -3
- package/lib/components/DataSummary/DataSummaryFactory.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryRender.js +11 -4
- package/lib/components/DataSummary/DataSummaryRender.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js +102 -0
- package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -0
- package/lib/components/DataSummary/helpers/get-loop-props-limit.js +31 -0
- package/lib/components/DataSummary/helpers/get-loop-props-limit.js.map +1 -0
- package/lib/components/DataSummary/helpers/get-prop-value.js.map +1 -1
- package/lib/components/DataSummary/helpers/index.js +8 -0
- package/lib/components/DataSummary/helpers/index.js.map +1 -1
- package/lib/hooks/helpers/buildPBComponents.js +1 -1
- package/lib/hooks/helpers/buildPBComponents.js.map +1 -1
- package/lib-es/components/Card/CardRender.js +3 -2
- package/lib-es/components/Card/CardRender.js.map +1 -1
- package/lib-es/components/DataSummary/DataSummaryFactory.js +13 -4
- package/lib-es/components/DataSummary/DataSummaryFactory.js.map +1 -1
- package/lib-es/components/DataSummary/DataSummaryRender.js +13 -6
- package/lib-es/components/DataSummary/DataSummaryRender.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +63 -0
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -0
- package/lib-es/components/DataSummary/helpers/get-loop-props-limit.js +13 -0
- package/lib-es/components/DataSummary/helpers/get-loop-props-limit.js.map +1 -0
- package/lib-es/components/DataSummary/helpers/get-prop-value.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/index.js +2 -1
- package/lib-es/components/DataSummary/helpers/index.js.map +1 -1
- package/lib-es/hooks/helpers/buildPBComponents.js +1 -1
- package/lib-es/hooks/helpers/buildPBComponents.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Card/CardRender.js +10 -10
- package/src/components/DataSummary/DataSummaryFactory.js +11 -3
- package/src/components/DataSummary/DataSummaryRender.js +19 -4
- package/src/components/DataSummary/helpers/build-loop-props-content.js +60 -0
- package/src/components/DataSummary/helpers/get-loop-props-limit.js +12 -0
- package/src/components/DataSummary/helpers/get-prop-value.js +1 -1
- package/src/components/DataSummary/helpers/index.js +3 -1
- package/src/hooks/helpers/buildPBComponents.js +1 -1
- package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +60 -0
- package/tests/unit/src/components/DataSummary/{DataSummaryTypes/helpers → helpers}/build-props-to-display-with-content.test.js +1 -1
- package/tests/unit/src/components/DataSummary/{DataSummaryTypes/helpers → helpers}/get-data-summary-query.test.js +1 -1
- package/tests/unit/src/components/DataSummary/{DataSummaryTypes/helpers → helpers}/get-link-to-published-content.test.js +1 -1
- package/tests/unit/src/components/DataSummary/helpers/get-loop-props-limit.test.js +32 -0
- package/tests/unit/src/components/DataSummary/{DataSummaryTypes/helpers → helpers}/get-prop-value.test.js +1 -1
- package/tests/unit/src/components/DataSummary/{DataSummaryTypes/helpers → helpers}/get-value-from-array.test.js +1 -1
- package/tests/unit/src/components/DataSummary/helpers/mocks.js +88 -0
- package/tests/unit/src/components/DataSummary/{DataSummaryTypes/helpers → helpers}/strip-summary-props-content.test.js +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
-
const _excluded = ["entity", "dataRecordId", "propsToDisplay", "type", "useSelectedEntity", "elementTitle", "modifier", "headingStyle"];
|
|
2
|
+
const _excluded = ["entity", "dataRecordId", "propsToDisplay", "type", "useSelectedEntity", "elementTitle", "modifier", "headingStyle", "loopProperties", "loopLimit"];
|
|
3
3
|
import React, { useContext } from 'react';
|
|
4
4
|
import { useQuery } from '@apollo/react-hooks';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
@@ -18,7 +18,9 @@ const DataSummaryFactory = _ref => {
|
|
|
18
18
|
useSelectedEntity,
|
|
19
19
|
elementTitle,
|
|
20
20
|
modifier,
|
|
21
|
-
headingStyle
|
|
21
|
+
headingStyle,
|
|
22
|
+
loopProperties,
|
|
23
|
+
loopLimit
|
|
22
24
|
} = _ref,
|
|
23
25
|
dataSummaryProps = _objectWithoutProperties(_ref, _excluded);
|
|
24
26
|
|
|
@@ -38,6 +40,7 @@ const DataSummaryFactory = _ref => {
|
|
|
38
40
|
if (loading) return '';
|
|
39
41
|
if (error) return error.message;
|
|
40
42
|
if (!data) return null;
|
|
43
|
+
if (!propsToDisplay || !propsToDisplay.length) return null;
|
|
41
44
|
const propsToDisplayValues = checkPropsToUse(propsToDisplay);
|
|
42
45
|
const propsQueryString = buildPropsQuery(data, propsToDisplayValues);
|
|
43
46
|
const dataSummaryQuery = getDataSummaryQuery(data, isPreview, propsQueryString);
|
|
@@ -45,6 +48,8 @@ const DataSummaryFactory = _ref => {
|
|
|
45
48
|
return /*#__PURE__*/React.createElement(DataSummaryRender, {
|
|
46
49
|
recordId: recordId,
|
|
47
50
|
propsToDisplay: propsToDisplay,
|
|
51
|
+
loopProperties: loopProperties,
|
|
52
|
+
loopLimit: loopLimit,
|
|
48
53
|
query: dataSummaryQuery,
|
|
49
54
|
type: type,
|
|
50
55
|
elementTitle: elementTitle,
|
|
@@ -61,7 +66,9 @@ DataSummaryFactory.propTypes = {
|
|
|
61
66
|
useSelectedEntity: PropTypes.bool,
|
|
62
67
|
elementTitle: PropTypes.string,
|
|
63
68
|
modifier: PropTypes.string,
|
|
64
|
-
headingStyle: PropTypes.string
|
|
69
|
+
headingStyle: PropTypes.string,
|
|
70
|
+
loopProperties: PropTypes.array,
|
|
71
|
+
loopLimit: PropTypes.number
|
|
65
72
|
};
|
|
66
73
|
DataSummaryFactory.defaultProps = {
|
|
67
74
|
type: 'text',
|
|
@@ -71,7 +78,9 @@ DataSummaryFactory.defaultProps = {
|
|
|
71
78
|
entity: '',
|
|
72
79
|
elementTitle: '',
|
|
73
80
|
modifier: '',
|
|
74
|
-
headingStyle: 'h2'
|
|
81
|
+
headingStyle: 'h2',
|
|
82
|
+
loopProperties: [],
|
|
83
|
+
loopLimit: 0
|
|
75
84
|
};
|
|
76
85
|
export default DataSummaryFactory;
|
|
77
86
|
//# sourceMappingURL=DataSummaryFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/DataSummary/DataSummaryFactory.js"],"names":["React","useContext","useQuery","PropTypes","MainContext","getSingleEntitySchema","buildPropsQuery","checkPropsToUse","getDataSummaryQuery","DataSummaryRender","DataSummaryFactory","entity","dataRecordId","propsToDisplay","type","useSelectedEntity","elementTitle","modifier","headingStyle","dataSummaryProps","entityForQuery","parent","itemEntity","data","error","loading","variables","id","isPreview","message","propsToDisplayValues","propsQueryString","dataSummaryQuery","recordId","itemId","propTypes","string","array","bool","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,QAAkC,OAAlC;AACA,SAASC,QAAT,QAAyB,qBAAzB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,WAAT,QAA4B,8BAA5B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,eAAT,EAA0BC,eAA1B,QAAiD,eAAjD;AACA,SAASC,mBAAT,QAAoC,WAApC;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;;AAEA,MAAMC,kBAAkB,GAAG,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/DataSummary/DataSummaryFactory.js"],"names":["React","useContext","useQuery","PropTypes","MainContext","getSingleEntitySchema","buildPropsQuery","checkPropsToUse","getDataSummaryQuery","DataSummaryRender","DataSummaryFactory","entity","dataRecordId","propsToDisplay","type","useSelectedEntity","elementTitle","modifier","headingStyle","loopProperties","loopLimit","dataSummaryProps","entityForQuery","parent","itemEntity","data","error","loading","variables","id","isPreview","message","length","propsToDisplayValues","propsQueryString","dataSummaryQuery","recordId","itemId","propTypes","string","array","bool","number","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,QAAkC,OAAlC;AACA,SAASC,QAAT,QAAyB,qBAAzB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,WAAT,QAA4B,8BAA5B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,eAAT,EAA0BC,eAA1B,QAAiD,eAAjD;AACA,SAASC,mBAAT,QAAoC,WAApC;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;;AAEA,MAAMC,kBAAkB,GAAG,QAYrB;AAAA,MAZsB;AAC1BC,IAAAA,MAD0B;AAE1BC,IAAAA,YAF0B;AAG1BC,IAAAA,cAH0B;AAI1BC,IAAAA,IAJ0B;AAK1BC,IAAAA,iBAL0B;AAM1BC,IAAAA,YAN0B;AAO1BC,IAAAA,QAP0B;AAQ1BC,IAAAA,YAR0B;AAS1BC,IAAAA,cAT0B;AAU1BC,IAAAA;AAV0B,GAYtB;AAAA,MADDC,gBACC;;AACJ,QAAMC,cAAc,GAAGP,iBAAiB,GAAGJ,MAAH,GAAYU,gBAAgB,CAACE,MAAjB,CAAwBC,UAA5E;AACA,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA;AAAf,MAA2BzB,QAAQ,CAACG,qBAAD,EAAwB;AAC/DuB,IAAAA,SAAS,EAAE;AAAEC,MAAAA,EAAE,EAAEP;AAAN;AADoD,GAAxB,CAAzC;AAGA,QAAM;AAAEQ,IAAAA;AAAF,MAAgB7B,UAAU,CAACG,WAAD,CAAhC;AAEA,MAAIuB,OAAJ,EAAa,OAAO,EAAP;AACb,MAAID,KAAJ,EAAW,OAAOA,KAAK,CAACK,OAAb;AACX,MAAI,CAACN,IAAL,EAAW,OAAO,IAAP;AACX,MAAI,CAACZ,cAAD,IA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AAaAhC,kBAAkB,CAACiC,YAAnB,GAAkC;AAChC7B,EAAAA,IAAI,EAAE,MAD0B;AAEhCF,EAAAA,YAAY,EAAE,EAFkB;AAGhCC,EAAAA,cAAc,EAAE,EAHgB;AAIhCE,EAAAA,iBAAiB,EAAE,IAJa;AAKhCJ,EAAAA,MAAM,EAAE,EALwB;AAMhCK,EAAAA,YAAY,EAAE,EANkB;AAOhCC,EAAAA,QAAQ,EAAE,EAPsB;AAQhCC,EAAAA,YAAY,EAAE,IARkB;AAShCC,EAAAA,cAAc,EAAE,EATgB;AAUhCC,EAAAA,SAAS,EAAE;AAVqB,CAAlC;AAaA,eAAeV,kBAAf","sourcesContent":["import React, { useContext } from 'react';\nimport { useQuery } from '@apollo/react-hooks';\nimport PropTypes from 'prop-types';\nimport { MainContext } from '@blaze-cms/nextjs-components';\nimport { getSingleEntitySchema } from '../../application/query';\nimport { buildPropsQuery, checkPropsToUse } from '../../helpers';\nimport { getDataSummaryQuery } from './helpers';\nimport DataSummaryRender from './DataSummaryRender';\n\nconst DataSummaryFactory = ({\n entity,\n dataRecordId,\n propsToDisplay,\n type,\n useSelectedEntity,\n elementTitle,\n modifier,\n headingStyle,\n loopProperties,\n loopLimit,\n ...dataSummaryProps\n}) => {\n const entityForQuery = useSelectedEntity ? entity : dataSummaryProps.parent.itemEntity;\n const { data, error, loading } = useQuery(getSingleEntitySchema, {\n variables: { id: entityForQuery }\n });\n const { isPreview } = useContext(MainContext);\n\n if (loading) return '';\n if (error) return error.message;\n if (!data) return null;\n if (!propsToDisplay || !propsToDisplay.length) return null;\n const propsToDisplayValues = checkPropsToUse(propsToDisplay);\n const propsQueryString = buildPropsQuery(data, propsToDisplayValues);\n const dataSummaryQuery = getDataSummaryQuery(data, isPreview, propsQueryString);\n const recordId = dataRecordId[0] || dataSummaryProps.parent.itemId;\n\n return (\n <DataSummaryRender\n recordId={recordId}\n propsToDisplay={propsToDisplay}\n loopProperties={loopProperties}\n loopLimit={loopLimit}\n query={dataSummaryQuery}\n type={type}\n elementTitle={elementTitle}\n modifier={modifier}\n htmlTag={headingStyle}\n />\n );\n};\n\nDataSummaryFactory.propTypes = {\n type: PropTypes.string,\n dataRecordId: PropTypes.array,\n propsToDisplay: PropTypes.array,\n entity: PropTypes.string,\n useSelectedEntity: PropTypes.bool,\n elementTitle: PropTypes.string,\n modifier: PropTypes.string,\n headingStyle: PropTypes.string,\n loopProperties: PropTypes.array,\n loopLimit: PropTypes.number\n};\n\nDataSummaryFactory.defaultProps = {\n type: 'text',\n dataRecordId: [],\n propsToDisplay: [],\n useSelectedEntity: true,\n entity: '',\n elementTitle: '',\n modifier: '',\n headingStyle: 'h2',\n loopProperties: [],\n loopLimit: 0\n};\n\nexport default DataSummaryFactory;\n"],"file":"DataSummaryFactory.js"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
-
const _excluded = ["type", "htmlTag", "recordId", "query", "propsToDisplay", "elementTitle"];
|
|
2
|
+
const _excluded = ["type", "htmlTag", "recordId", "query", "propsToDisplay", "elementTitle", "loopProperties", "loopLimit"];
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { useQuery } from '@apollo/react-hooks';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { summaryComponents } from './DataSummaryTypes';
|
|
7
7
|
import { getClassModifiers, getPropsToDisplayModifiers } from '../../utils';
|
|
8
|
-
import { buildPropsToDisplayWithContent, stripSummaryPropsContent } from './helpers';
|
|
8
|
+
import { buildPropsToDisplayWithContent, stripSummaryPropsContent, buildLoopPropsContent } from './helpers';
|
|
9
9
|
|
|
10
10
|
const DataSummaryRender = _ref => {
|
|
11
11
|
let {
|
|
@@ -14,7 +14,9 @@ const DataSummaryRender = _ref => {
|
|
|
14
14
|
recordId,
|
|
15
15
|
query,
|
|
16
16
|
propsToDisplay,
|
|
17
|
-
elementTitle
|
|
17
|
+
elementTitle,
|
|
18
|
+
loopProperties,
|
|
19
|
+
loopLimit
|
|
18
20
|
} = _ref,
|
|
19
21
|
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
20
22
|
|
|
@@ -33,8 +35,9 @@ const DataSummaryRender = _ref => {
|
|
|
33
35
|
const {
|
|
34
36
|
entityData
|
|
35
37
|
} = data;
|
|
38
|
+
const shouldLoop = loopProperties && loopProperties.length;
|
|
36
39
|
const modifier = getClassModifiers('list', otherProps);
|
|
37
|
-
const summaryPropsWithContent = buildPropsToDisplayWithContent(entityData, propsToDisplay);
|
|
40
|
+
const summaryPropsWithContent = shouldLoop ? buildLoopPropsContent(loopProperties, propsToDisplay, loopLimit, entityData) : buildPropsToDisplayWithContent(entityData, propsToDisplay);
|
|
38
41
|
const propsToDisplayModifiers = getPropsToDisplayModifiers(propsToDisplay);
|
|
39
42
|
const summaryPropsWithCleanContent = stripSummaryPropsContent(propsToDisplay, summaryPropsWithContent);
|
|
40
43
|
const SummaryComponent = summaryComponents[type];
|
|
@@ -54,7 +57,9 @@ DataSummaryRender.propTypes = {
|
|
|
54
57
|
recordId: PropTypes.string,
|
|
55
58
|
propsToDisplay: PropTypes.array,
|
|
56
59
|
elementTitle: PropTypes.string,
|
|
57
|
-
htmlTag: PropTypes.string
|
|
60
|
+
htmlTag: PropTypes.string,
|
|
61
|
+
loopProperties: PropTypes.array,
|
|
62
|
+
loopLimit: PropTypes.number
|
|
58
63
|
};
|
|
59
64
|
DataSummaryRender.defaultProps = {
|
|
60
65
|
type: 'text',
|
|
@@ -62,7 +67,9 @@ DataSummaryRender.defaultProps = {
|
|
|
62
67
|
recordId: '',
|
|
63
68
|
propsToDisplay: [],
|
|
64
69
|
elementTitle: '',
|
|
65
|
-
htmlTag: 'h2'
|
|
70
|
+
htmlTag: 'h2',
|
|
71
|
+
loopProperties: [],
|
|
72
|
+
loopLimit: 0
|
|
66
73
|
};
|
|
67
74
|
export default DataSummaryRender;
|
|
68
75
|
//# sourceMappingURL=DataSummaryRender.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/DataSummary/DataSummaryRender.js"],"names":["React","useQuery","PropTypes","summaryComponents","getClassModifiers","getPropsToDisplayModifiers","buildPropsToDisplayWithContent","stripSummaryPropsContent","DataSummaryRender","type","htmlTag","recordId","query","propsToDisplay","elementTitle","otherProps","data","error","loading","variables","id","message","entityData","modifier","summaryPropsWithContent","propsToDisplayModifiers","summaryPropsWithCleanContent","SummaryComponent","
|
|
1
|
+
{"version":3,"sources":["../../../src/components/DataSummary/DataSummaryRender.js"],"names":["React","useQuery","PropTypes","summaryComponents","getClassModifiers","getPropsToDisplayModifiers","buildPropsToDisplayWithContent","stripSummaryPropsContent","buildLoopPropsContent","DataSummaryRender","type","htmlTag","recordId","query","propsToDisplay","elementTitle","loopProperties","loopLimit","otherProps","data","error","loading","variables","id","message","entityData","shouldLoop","length","modifier","summaryPropsWithContent","propsToDisplayModifiers","summaryPropsWithCleanContent","SummaryComponent","propTypes","string","object","array","number","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,QAAT,QAAyB,qBAAzB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,iBAAT,QAAkC,oBAAlC;AACA,SAASC,iBAAT,EAA4BC,0BAA5B,QAA8D,aAA9D;AACA,SACEC,8BADF,EAEEC,wBAFF,EAGEC,qBAHF,QAIO,WAJP;;AAMA,MAAMC,iBAAiB,GAAG,QAUpB;AAAA,MAVqB;AACzBC,IAAAA,IADyB;AAEzBC,IAAAA,OAFyB;AAGzBC,IAAAA,QAHyB;AAIzBC,IAAAA,KAJyB;AAKzBC,IAAAA,cALyB;AAMzBC,IAAAA,YANyB;AAOzBC,IAAAA,cAPyB;AAQzBC,IAAAA;AARyB,GAUrB;AAAA,MADDC,UACC;;AACJ,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA;AAAf,MAA2BpB,QAAQ,CAACY,KAAD,EAAQ;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AHQ;AAI5BpB,EAAAA,cAAc,EAAEZ,SAAS,CAACkC,KAJE;AAK5BrB,EAAAA,YAAY,EAAEb,SAAS,CAACgC,MALI;AAM5BvB,EAAAA,OAAO,EAAET,SAAS,CAACgC,MANS;AAO5BlB,EAAAA,cAAc,EAAEd,SAAS,CAACkC,KAPE;AAQ5BnB,EAAAA,SAAS,EAAEf,SAAS,CAACmC;AARO,CAA9B;AAWA5B,iBAAiB,CAAC6B,YAAlB,GAAiC;AAC/B5B,EAAAA,IAAI,EAAE,MADyB;AAE/BG,EAAAA,KAAK,EAAE,EAFwB;AAG/BD,EAAAA,QAAQ,EAAE,EAHqB;AAI/BE,EAAAA,cAAc,EAAE,EAJe;AAK/BC,EAAAA,YAAY,EAAE,EALiB;AAM/BJ,EAAAA,OAAO,EAAE,IANsB;AAO/BK,EAAAA,cAAc,EAAE,EAPe;AAQ/BC,EAAAA,SAAS,EAAE;AARoB,CAAjC;AAWA,eAAeR,iBAAf","sourcesContent":["import React from 'react';\nimport { useQuery } from '@apollo/react-hooks';\nimport PropTypes from 'prop-types';\nimport { summaryComponents } from './DataSummaryTypes';\nimport { getClassModifiers, getPropsToDisplayModifiers } from '../../utils';\nimport {\n buildPropsToDisplayWithContent,\n stripSummaryPropsContent,\n buildLoopPropsContent\n} from './helpers';\n\nconst DataSummaryRender = ({\n type,\n htmlTag,\n recordId,\n query,\n propsToDisplay,\n elementTitle,\n loopProperties,\n loopLimit,\n ...otherProps\n}) => {\n const { data, error, loading } = useQuery(query, {\n variables: { id: recordId }\n });\n\n if (loading) return '';\n if (error) return error.message;\n if (!data || !data.entityData) return null;\n\n const { entityData } = data;\n const shouldLoop = loopProperties && loopProperties.length;\n const modifier = getClassModifiers('list', otherProps);\n const summaryPropsWithContent = shouldLoop\n ? buildLoopPropsContent(loopProperties, propsToDisplay, loopLimit, entityData)\n : buildPropsToDisplayWithContent(entityData, propsToDisplay);\n\n const propsToDisplayModifiers = getPropsToDisplayModifiers(propsToDisplay);\n const summaryPropsWithCleanContent = stripSummaryPropsContent(\n propsToDisplay,\n summaryPropsWithContent\n );\n const SummaryComponent = summaryComponents[type];\n if (!summaryPropsWithCleanContent.length) return null;\n\n return (\n <SummaryComponent\n modifier={modifier}\n elementTitle={elementTitle}\n summaryPropsWithContent={summaryPropsWithCleanContent}\n propsToDisplayModifiers={propsToDisplayModifiers}\n htmlTag={htmlTag}\n />\n );\n};\n\nDataSummaryRender.propTypes = {\n type: PropTypes.string,\n query: PropTypes.object,\n recordId: PropTypes.string,\n propsToDisplay: PropTypes.array,\n elementTitle: PropTypes.string,\n htmlTag: PropTypes.string,\n loopProperties: PropTypes.array,\n loopLimit: PropTypes.number\n};\n\nDataSummaryRender.defaultProps = {\n type: 'text',\n query: {},\n recordId: '',\n propsToDisplay: [],\n elementTitle: '',\n htmlTag: 'h2',\n loopProperties: [],\n loopLimit: 0\n};\n\nexport default DataSummaryRender;\n"],"file":"DataSummaryRender.js"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import upperFirst from 'lodash.upperfirst';
|
|
2
|
+
import flatten from 'lodash.flatten';
|
|
3
|
+
import getLinkToPublishedContent from './get-link-to-published-content';
|
|
4
|
+
import getLoopPropsLimit from './get-loop-props-limit';
|
|
5
|
+
import getPropValue from './get-prop-value';
|
|
6
|
+
|
|
7
|
+
const getLoopValue = value => {
|
|
8
|
+
const {
|
|
9
|
+
keyField
|
|
10
|
+
} = value;
|
|
11
|
+
return value[keyField];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const separateValues = (propsToDisplay, loopProps, data) => {
|
|
15
|
+
const regularValues = {};
|
|
16
|
+
const loopValues = {};
|
|
17
|
+
propsToDisplay.forEach(options => {
|
|
18
|
+
const {
|
|
19
|
+
propertiesToDisplay
|
|
20
|
+
} = options;
|
|
21
|
+
propertiesToDisplay.forEach(prop => {
|
|
22
|
+
const value = getPropValue(prop, data, options);
|
|
23
|
+
const isArrayValue = Array.isArray(value);
|
|
24
|
+
if (!value) return;
|
|
25
|
+
const isLoopableProp = loopProps.includes(prop) && isArrayValue;
|
|
26
|
+
|
|
27
|
+
if (isLoopableProp) {
|
|
28
|
+
loopValues[prop] = value;
|
|
29
|
+
} else {
|
|
30
|
+
regularValues[prop] = value;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return [regularValues, loopValues];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const buildLoopPropsContent = (loopProps = [], propsToDisplay = [], limit = 0, data = {}) => {
|
|
38
|
+
const loopPropsWithContent = [];
|
|
39
|
+
const [regularValues, loopValues] = separateValues(propsToDisplay, loopProps, data);
|
|
40
|
+
const loopLimit = getLoopPropsLimit(loopValues, limit);
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < loopLimit; i += 1) {
|
|
43
|
+
const propsArray = flatten(propsToDisplay.map(options => {
|
|
44
|
+
const {
|
|
45
|
+
propertiesToDisplay,
|
|
46
|
+
label
|
|
47
|
+
} = options;
|
|
48
|
+
return propertiesToDisplay.map(key => {
|
|
49
|
+
const loopValue = loopValues[key];
|
|
50
|
+
const propValue = loopValue ? getLoopValue(loopValue[i]) : regularValues[key];
|
|
51
|
+
if (!propValue) return null;
|
|
52
|
+
const linkToPublishedContent = getLinkToPublishedContent(key, data);
|
|
53
|
+
return [upperFirst(label), propValue, linkToPublishedContent];
|
|
54
|
+
});
|
|
55
|
+
})).filter(Boolean);
|
|
56
|
+
loopPropsWithContent.push(propsArray);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return flatten(loopPropsWithContent);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default buildLoopPropsContent;
|
|
63
|
+
//# sourceMappingURL=build-loop-props-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/DataSummary/helpers/build-loop-props-content.js"],"names":["upperFirst","flatten","getLinkToPublishedContent","getLoopPropsLimit","getPropValue","getLoopValue","value","keyField","separateValues","propsToDisplay","loopProps","data","regularValues","loopValues","forEach","options","propertiesToDisplay","prop","isArrayValue","Array","isArray","isLoopableProp","includes","buildLoopPropsContent","limit","loopPropsWithContent","loopLimit","i","propsArray","map","label","key","loopValue","propValue","linkToPublishedContent","filter","Boolean","push"],"mappings":"AAAA,OAAOA,UAAP,MAAuB,mBAAvB;AACA,OAAOC,OAAP,MAAoB,gBAApB;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AACA,OAAOC,iBAAP,MAA8B,wBAA9B;AACA,OAAOC,YAAP,MAAyB,kBAAzB;;AAEA,MAAMC,YAAY,GAAGC,KAAK,IAAI;AAC5B,QAAM;AAAEC,IAAAA;AAAF,MAAeD,KAArB;AACA,SAAOA,KAAK,CAACC,QAAD,CAAZ;AACD,CAHD;;AAKA,MAAMC,cAAc,GAAG,CAACC,cAAD,EAAiBC,SAAjB,EAA4BC,IAA5B,KAAqC;AAC1D,QAAMC,aAAa,GAAG,EAAtB;AACA,QAAMC,UAAU,GAAG,EAAnB;AAEAJ,EAAAA,cAAc,CAACK,OAAf,CAAuBC,OAAO,IAAI;AAChC,UAAM;AAAEC,MAAAA;AAAF,QAA0BD,OAAhC;AACAC,IAAAA,mBAAmB,CAACF,OAApB,CAA4BG,IAAI,IAAI;AAClC,YAAMX,KAAK,GAAGF,YAAY,CAACa,IAAD,EAAON,IAAP,EAAaI,OAAb,CAA1B;AACA,YAAMG,YAAY,GAAGC,KAAK,CAACC,OAAN,CAAcd,KAAd,CAArB;AACA,UAAI,CAACA,KAAL,EAAY;AACZ,YAAMe,cAAc,GAAGX,SAAS,CAACY,QAAV,CAAmBL,IAAnB,KAA4BC,YAAnD;;AAEA,UAAIG,cAAJ,EAAoB;AAClBR,QAAAA,UAAU,CAACI,IAAD,CAAV,GAAmBX,KAAnB;AACD,OAFD,MAEO;AACLM,QAAAA,aAAa,CAACK,IAAD,CAAb,GAAsBX,KAAtB;AACD;AACF,KAXD;AAYD,GAdD;AAeA,SAAO,CAACM,aAAD,EAAgBC,U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CAxBD;;AA0BA,eAAeF,qBAAf","sourcesContent":["import upperFirst from 'lodash.upperfirst';\nimport flatten from 'lodash.flatten';\nimport getLinkToPublishedContent from './get-link-to-published-content';\nimport getLoopPropsLimit from './get-loop-props-limit';\nimport getPropValue from './get-prop-value';\n\nconst getLoopValue = value => {\n const { keyField } = value;\n return value[keyField];\n};\n\nconst separateValues = (propsToDisplay, loopProps, data) => {\n const regularValues = {};\n const loopValues = {};\n\n propsToDisplay.forEach(options => {\n const { propertiesToDisplay } = options;\n propertiesToDisplay.forEach(prop => {\n const value = getPropValue(prop, data, options);\n const isArrayValue = Array.isArray(value);\n if (!value) return;\n const isLoopableProp = loopProps.includes(prop) && isArrayValue;\n\n if (isLoopableProp) {\n loopValues[prop] = value;\n } else {\n regularValues[prop] = value;\n }\n });\n });\n return [regularValues, loopValues];\n};\n\nconst buildLoopPropsContent = (loopProps = [], propsToDisplay = [], limit = 0, data = {}) => {\n const loopPropsWithContent = [];\n const [regularValues, loopValues] = separateValues(propsToDisplay, loopProps, data);\n\n const loopLimit = getLoopPropsLimit(loopValues, limit);\n\n for (let i = 0; i < loopLimit; i += 1) {\n const propsArray = flatten(\n propsToDisplay.map(options => {\n const { propertiesToDisplay, label } = options;\n return propertiesToDisplay.map(key => {\n const loopValue = loopValues[key];\n const propValue = loopValue ? getLoopValue(loopValue[i]) : regularValues[key];\n if (!propValue) return null;\n const linkToPublishedContent = getLinkToPublishedContent(key, data);\n\n return [upperFirst(label), propValue, linkToPublishedContent];\n });\n })\n ).filter(Boolean);\n loopPropsWithContent.push(propsArray);\n }\n\n return flatten(loopPropsWithContent);\n};\n\nexport default buildLoopPropsContent;\n"],"file":"build-loop-props-content.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const getLoopPropsLimit = (values, limit) => {
|
|
2
|
+
let valuesLimit = 1;
|
|
3
|
+
if (!values) return valuesLimit;
|
|
4
|
+
Object.keys(values).forEach(key => {
|
|
5
|
+
const value = values[key];
|
|
6
|
+
if (value && Array.isArray(value) && value.length > valuesLimit) valuesLimit = value.length;
|
|
7
|
+
});
|
|
8
|
+
if (!limit || valuesLimit < limit) return valuesLimit;
|
|
9
|
+
return limit;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default getLoopPropsLimit;
|
|
13
|
+
//# sourceMappingURL=get-loop-props-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/DataSummary/helpers/get-loop-props-limit.js"],"names":["getLoopPropsLimit","values","limit","valuesLimit","Object","keys","forEach","key","value","Array","isArray","length"],"mappings":"AAAA,MAAMA,iBAAiB,GAAG,CAACC,MAAD,EAASC,KAAT,KAAmB;AAC3C,MAAIC,WAAW,GAAG,CAAlB;AACA,MAAI,CAACF,MAAL,EAAa,OAAOE,WAAP;AACbC,EAAAA,MAAM,CAACC,IAAP,CAAYJ,MAAZ,EAAoBK,OAApB,CAA4BC,GAAG,IAAI;AACjC,UAAMC,KAAK,GAAGP,MAAM,CAACM,GAAD,CAApB;AACA,QAAIC,KAAK,IAAIC,KAAK,CAACC,OAAN,CAAcF,KAAd,CAAT,IAAiCA,KAAK,CAACG,MAAN,GAAeR,WAApD,EAAiEA,WAAW,GAAGK,KAAK,CAACG,MAApB;AAClE,GAHD;AAIA,MAAI,CAACT,KAAD,IAAUC,WAAW,GAAGD,KAA5B,EAAmC,OAAOC,WAAP;AACnC,SAAOD,KAAP;AACD,CATD;;AAWA,eAAeF,iBAAf","sourcesContent":["const getLoopPropsLimit = (values, limit) => {\n let valuesLimit = 1;\n if (!values) return valuesLimit;\n Object.keys(values).forEach(key => {\n const value = values[key];\n if (value && Array.isArray(value) && value.length > valuesLimit) valuesLimit = value.length;\n });\n if (!limit || valuesLimit < limit) return valuesLimit;\n return limit;\n};\n\nexport default getLoopPropsLimit;\n"],"file":"get-loop-props-limit.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/DataSummary/helpers/get-prop-value.js"],"names":["getValueFromArray","getPropValue","key","props","options","baseKey","split","nestedKey","filter","_","i","join","prefix","suffix","value","valueIsArray","Array","isArray","nestedValue","trim"],"mappings":"AAAA,OAAOA,iBAAP,MAA8B,wBAA9B;;AAEA,MAAMC,YAAY,GAAG,CAACC,GAAD,EAAMC,KAAN,EAAaC,OAAO,GAAG,EAAvB,KAA8B;AACjD,QAAMC,OAAO,GAAGH,GAAG,CAACI,KAAJ,CAAU,GAAV,EAAe,CAAf,CAAhB;AACA,QAAMC,SAAS,GAAGL,GAAG,CAClBI,KADe,CACT,GADS,EAEfE,MAFe,CAER,CAACC,CAAD,EAAIC,CAAJ,KAAUA,CAAC,KAAK,CAFR,EAGfC,IAHe,CAGV,GAHU,CAAlB;AAIA,QAAM;AAAEC,IAAAA,MAAM,GAAG,EAAX;AAAeC,IAAAA,MAAM,GAAG;AAAxB,MAA+BT,OAArC;AACA,QAAMU,KAAK,GAAGX,KAAK,CAACE,OAAD,CAAnB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/DataSummary/helpers/get-prop-value.js"],"names":["getValueFromArray","getPropValue","key","props","options","baseKey","split","nestedKey","filter","_","i","join","prefix","suffix","value","valueIsArray","Array","isArray","nestedValue","trim"],"mappings":"AAAA,OAAOA,iBAAP,MAA8B,wBAA9B;;AAEA,MAAMC,YAAY,GAAG,CAACC,GAAD,EAAMC,KAAN,EAAaC,OAAO,GAAG,EAAvB,KAA8B;AACjD,QAAMC,OAAO,GAAGH,GAAG,CAACI,KAAJ,CAAU,GAAV,EAAe,CAAf,CAAhB;AACA,QAAMC,SAAS,GAAGL,GAAG,CAClBI,KADe,CACT,GADS,EAEfE,MAFe,CAER,CAACC,CAAD,EAAIC,CAAJ,KAAUA,CAAC,KAAK,CAFR,EAGfC,IAHe,CAGV,GAHU,CAAlB;AAIA,QAAM;AAAEC,IAAAA,MAAM,GAAG,EAAX;AAAeC,IAAAA,MAAM,GAAG;AAAxB,MAA+BT,OAArC;AACA,QAAMU,KAAK,GAAGX,KAAK,CAACE,OAAD,CAAnB;AAEA,MAAI,OAAOS,KAAP,KAAiB,SAAjB,IAA8B,CAACA,KAAnC,EAA0C,OAAO,IAAP;;AAE1C,MAAIP,SAAJ,EAAe;AACb,UAAMQ,YAAY,GAAGC,KAAK,CAACC,OAAN,CAAcH,KAAd,CAArB;AACA,UAAMI,WAAW,GAAG,CAACH,YAAD,GAAgBD,KAAK,CAACP,SAAD,CAArB,GAAmC,EAAvD;AACA,QAAIQ,YAAJ,EAAkB,OAAOf,iBAAiB,CAACO,SAAD,EAAYO,KAAZ,EAAmBF,MAAnB,EAA2BC,MAA3B,CAAxB;AAClB,WAAOK,WAAW,GAAI,GAAEN,MAAO,IAAGM,WAAY,IAAGL,MAAO,EAAnC,CAAqCM,IAArC,EAAH,GAAiD,IAAnE;AACD;;AAED,SAAQ,GAAEP,MAAO,IAAGE,KAAM,IAAGD,MAAO,EAA7B,CAA+BM,IAA/B,EAAP;AACD,CAnBD;;AAqBA,eAAelB,YAAf","sourcesContent":["import getValueFromArray from './get-value-from-array';\n\nconst getPropValue = (key, props, options = {}) => {\n const baseKey = key.split('.')[0];\n const nestedKey = key\n .split('.')\n .filter((_, i) => i !== 0)\n .join('.');\n const { prefix = '', suffix = '' } = options;\n const value = props[baseKey];\n\n if (typeof value !== 'boolean' && !value) return null;\n\n if (nestedKey) {\n const valueIsArray = Array.isArray(value);\n const nestedValue = !valueIsArray ? value[nestedKey] : '';\n if (valueIsArray) return getValueFromArray(nestedKey, value, prefix, suffix);\n return nestedValue ? `${prefix} ${nestedValue} ${suffix}`.trim() : null;\n }\n\n return `${prefix} ${value} ${suffix}`.trim();\n};\n\nexport default getPropValue;\n"],"file":"get-prop-value.js"}
|
|
@@ -2,5 +2,6 @@ import getDataSummaryQuery from './get-data-summary-query';
|
|
|
2
2
|
import buildPropsToDisplayWithContent from './build-props-to-display-with-content';
|
|
3
3
|
import getLinkToPublishedContent from './get-link-to-published-content';
|
|
4
4
|
import stripSummaryPropsContent from './strip-summary-props-content';
|
|
5
|
-
|
|
5
|
+
import buildLoopPropsContent from './build-loop-props-content';
|
|
6
|
+
export { getDataSummaryQuery, buildPropsToDisplayWithContent, getLinkToPublishedContent, stripSummaryPropsContent, buildLoopPropsContent };
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/DataSummary/helpers/index.js"],"names":["getDataSummaryQuery","buildPropsToDisplayWithContent","getLinkToPublishedContent","stripSummaryPropsContent"],"mappings":"AAAA,OAAOA,mBAAP,MAAgC,0BAAhC;AACA,OAAOC,8BAAP,MAA2C,uCAA3C;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AACA,OAAOC,wBAAP,MAAqC,+BAArC;AAEA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/DataSummary/helpers/index.js"],"names":["getDataSummaryQuery","buildPropsToDisplayWithContent","getLinkToPublishedContent","stripSummaryPropsContent","buildLoopPropsContent"],"mappings":"AAAA,OAAOA,mBAAP,MAAgC,0BAAhC;AACA,OAAOC,8BAAP,MAA2C,uCAA3C;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AACA,OAAOC,wBAAP,MAAqC,+BAArC;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AAEA,SACEJ,mBADF,EAEEC,8BAFF,EAGEC,yBAHF,EAIEC,wBAJF,EAKEC,qBALF","sourcesContent":["import getDataSummaryQuery from './get-data-summary-query';\nimport buildPropsToDisplayWithContent from './build-props-to-display-with-content';\nimport getLinkToPublishedContent from './get-link-to-published-content';\nimport stripSummaryPropsContent from './strip-summary-props-content';\nimport buildLoopPropsContent from './build-loop-props-content';\n\nexport {\n getDataSummaryQuery,\n buildPropsToDisplayWithContent,\n getLinkToPublishedContent,\n stripSummaryPropsContent,\n buildLoopPropsContent\n};\n"],"file":"index.js"}
|
|
@@ -35,7 +35,7 @@ function BuildPBComponents(components, options = {}, rootLevel = false) {
|
|
|
35
35
|
parent,
|
|
36
36
|
name: parentName
|
|
37
37
|
} = options;
|
|
38
|
-
if (rootLevel) StoreImages.resetImages();
|
|
38
|
+
if (rootLevel && !open) StoreImages.resetImages();
|
|
39
39
|
StoreImages.addImages(getLightboxImages(components).concat(lightboxImages), options);
|
|
40
40
|
StoreImages.setHandlers({
|
|
41
41
|
toggleModal,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/helpers/buildPBComponents.js"],"names":["React","cloneDeep","GlobalLightbox","RenderComponent","getBannersByType","injectElementBanners","StoreImages","getLightboxImages","insertBanners","checkBannerInsertionSet","getBannerIndex","ELEMENT","PB_TYPE_TEXTBLOCK","renderChildComponents","options","items","length","BuildPBComponents","components","rootLevel","isArray","Array","metaTitle","lightboxImages","toggleModal","open","selectedImage","setSelectedImage","parent","name","parentName","resetImages","addImages","concat","setHandlers","imageProps","handleSelectedImage","images","map","image","component","hasElementBanners","banners","hasTextBlockBanners","textBlockBanners","updatedChildren","filter","settings","insertionType","bannerToInject","bannerIndex","hasComponentItems","childComponents","id"],"mappings":";;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,kBAAtB;AACA,OAAOC,cAAP,MAA2B,uCAA3B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,gBAAP,MAA6B,uBAA7B;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,OAAOC,uBAAP,MAAoC,8BAApC;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,OAAT,QAAwB,iBAAxB;AACA,SAASC,iBAAT,QAAkC,aAAlC;;AAEA,SAASC,qBAAT,CAA+BC,OAA/B,EAAwCC,KAAK,GAAG,EAAhD,EAAoD;AAClD,SAAOA,KAAK,IAAIA,KAAK,CAACC,MAAf,GAAwBC,iBAAiB,CAACF,KAAD,EAAQD,OAAR,CAAzC,GAA4D,EAAnE;AACD;;AAED,SAASG,iBAAT,CAA2BC,UAA3B,EAAuCJ,OAAO,GAAG,EAAjD,EAAqDK,SAAS,GAAG,KAAjE,EAAwE;AACtE,QAAMC,OAAO,GAAGC,KAAK,CAACD,OAAN,CAAcF,UAAd,CAAhB;AACA,MAAI,CAACE,OAAL,EAAc,OAAO,EAAP;AAEd,QAAM;AACJE,IAAAA,SADI;AAEJC,IAAAA,cAAc,GAAG,EAFb;AAGJC,IAAAA,WAHI;AAIJC,IAAAA,IAJI;AAKJC,IAAAA,aALI;AAMJC,IAAAA,gBANI;AAOJC,IAAAA,MAPI;AAQJC,IAAAA,IAAI,EAAEC;AARF,MASFhB,OATJ;AAWA,MAAIK,
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/helpers/buildPBComponents.js"],"names":["React","cloneDeep","GlobalLightbox","RenderComponent","getBannersByType","injectElementBanners","StoreImages","getLightboxImages","insertBanners","checkBannerInsertionSet","getBannerIndex","ELEMENT","PB_TYPE_TEXTBLOCK","renderChildComponents","options","items","length","BuildPBComponents","components","rootLevel","isArray","Array","metaTitle","lightboxImages","toggleModal","open","selectedImage","setSelectedImage","parent","name","parentName","resetImages","addImages","concat","setHandlers","imageProps","handleSelectedImage","images","map","image","component","hasElementBanners","banners","hasTextBlockBanners","textBlockBanners","updatedChildren","filter","settings","insertionType","bannerToInject","bannerIndex","hasComponentItems","childComponents","id"],"mappings":";;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,kBAAtB;AACA,OAAOC,cAAP,MAA2B,uCAA3B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,gBAAP,MAA6B,uBAA7B;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,aAAP,MAA0B,kBA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WAAlB,EAA+BD,cAA/B,CAA/B;AACD;AACF;;AAED,UAAMG,eAAe,GAAGvC,qBAAqB,CAACC,OAAD,EAAU+B,eAAV,CAA7C;AAEA,wBACE,oBAAC,eAAD;AACE,MAAA,SAAS,EAAEL,SADb;AAEE,MAAA,QAAQ,EAAEK,eAFZ;AAGE,MAAA,eAAe,EAAEO,eAHnB;AAIE,MAAA,UAAU,EAAEjB,UAJd;AAKE,MAAA,OAAO,oBAAOrB,OAAP,CALT;AAME,MAAA,MAAM,EAAEuB,MANV;AAOE,MAAA,GAAG,EAAG,GAAEG,SAAS,CAACa,EAAG,EAPvB;AAQE,MAAA,mBAAmB,EAAEV,mBARvB;AASE,MAAA,gBAAgB,EAAEC;AATpB,MADF;AAaD,GAtCA,CAXH,CADF;AAqDD;;AAED,eAAe3B,iBAAf","sourcesContent":["import React from 'react';\nimport cloneDeep from 'lodash.clonedeep';\nimport GlobalLightbox from '../../components/Image/GlobalLightbox';\nimport RenderComponent from './RenderComponent';\nimport getBannersByType from './get-banners-by-type';\nimport injectElementBanners from './inject-element-banners';\nimport StoreImages from './StoreImages';\nimport getLightboxImages from './get-lightbox-images';\nimport insertBanners from './insert-banners';\nimport checkBannerInsertionSet from './check-banner-insertion-set';\nimport getBannerIndex from './get-banner-index';\nimport { ELEMENT } from '../../constants';\nimport { PB_TYPE_TEXTBLOCK } from './constants';\n\nfunction renderChildComponents(options, items = []) {\n return items && items.length ? BuildPBComponents(items, options) : [];\n}\n\nfunction BuildPBComponents(components, options = {}, rootLevel = false) {\n const isArray = Array.isArray(components);\n if (!isArray) return [];\n\n const {\n metaTitle,\n lightboxImages = [],\n toggleModal,\n open,\n selectedImage,\n setSelectedImage,\n parent,\n name: parentName\n } = options;\n\n if (rootLevel && !open) StoreImages.resetImages();\n\n StoreImages.addImages(getLightboxImages(components).concat(lightboxImages), options);\n StoreImages.setHandlers({ toggleModal, setSelectedImage });\n\n const imageProps = {\n toggleModal: StoreImages.toggleModal,\n handleSelectedImage: StoreImages.handleSelectedImage\n };\n\n const images = StoreImages.images.map(image => ({ ...image, ...imageProps }));\n\n return (\n <>\n {open && (\n <GlobalLightbox\n images={images}\n onClose={StoreImages.toggleModal}\n selectedImage={selectedImage}\n metaTitle={metaTitle}\n parentName={parentName}\n parent={parent}\n />\n )}\n {components.map(component => {\n const { items = [] } = component;\n const [hasElementBanners, banners] = getBannersByType(items, ELEMENT);\n const [hasTextBlockBanners, textBlockBanners] = getBannersByType(items, PB_TYPE_TEXTBLOCK);\n let updatedChildren =\n items &&\n cloneDeep(items).filter(\n ({ settings: { insertionType } = {} }) => insertionType !== PB_TYPE_TEXTBLOCK\n );\n\n if (hasElementBanners) {\n updatedChildren = injectElementBanners(banners, updatedChildren);\n } else {\n // TODO: this block is for banner retrocompatibility, once completly migrated remove it as well as all related helpers\n const bannerToInject = checkBannerInsertionSet(updatedChildren);\n const bannerIndex = getBannerIndex(updatedChildren, bannerToInject);\n const hasComponentItems = !!(updatedChildren && updatedChildren.length);\n\n if (hasComponentItems && bannerIndex > -1) {\n updatedChildren = insertBanners(updatedChildren, bannerIndex, bannerToInject);\n }\n }\n\n const childComponents = renderChildComponents(options, updatedChildren);\n\n return (\n <RenderComponent\n component={component}\n siblings={updatedChildren}\n childComponents={childComponents}\n imageProps={imageProps}\n options={{ ...options }}\n images={images}\n key={`${component.id}`}\n hasTextBlockBanners={hasTextBlockBanners}\n textBlockBanners={textBlockBanners}\n />\n );\n })}\n </>\n );\n}\n\nexport default BuildPBComponents;\n"],"file":"buildPBComponents.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.107.0-alpha.0",
|
|
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": "fb86622f935fc0cbf63381aec468ed0dd31cca03"
|
|
92
92
|
}
|
|
@@ -74,15 +74,14 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...variabl
|
|
|
74
74
|
_loading
|
|
75
75
|
);
|
|
76
76
|
|
|
77
|
-
const updatedFilterBy =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
) || [];
|
|
77
|
+
const updatedFilterBy = getUpdatedFilterBy(
|
|
78
|
+
inheritedFilters,
|
|
79
|
+
entityData,
|
|
80
|
+
currentSchema,
|
|
81
|
+
filterEntitySchema,
|
|
82
|
+
itemId,
|
|
83
|
+
variableProps
|
|
84
|
+
);
|
|
86
85
|
|
|
87
86
|
const { limit, variables } = filterQuerySetup({
|
|
88
87
|
getEntitySchemas: Object.values(requiredSchema),
|
|
@@ -98,13 +97,14 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...variabl
|
|
|
98
97
|
|
|
99
98
|
const { data, error: cardsError, loading: cardsLoading } = useQuery(action, {
|
|
100
99
|
variables,
|
|
101
|
-
skip: shouldReturn(_loading, _load, schemaLoading, _error, _err, schemaError)
|
|
100
|
+
skip: shouldReturn(!updatedFilterBy, _loading, _load, schemaLoading, _error, _err, schemaError)
|
|
102
101
|
});
|
|
103
102
|
const imageIds = itemsToDisplay.map(({ imageId }) => imageId).filter(Boolean);
|
|
104
103
|
const { data: imagesData, loading: imagesLoading } = useGetImages(imageIds, true);
|
|
105
104
|
const isLoading = shouldReturn(_loading, _load, schemaLoading, cardsLoading, imagesLoading);
|
|
106
105
|
const hasError = shouldReturn(_error, _err, schemaError);
|
|
107
106
|
|
|
107
|
+
if (!updatedFilterBy) return null;
|
|
108
108
|
if (isLoading) return '';
|
|
109
109
|
if (hasError) return null;
|
|
110
110
|
if (cardsError) return cardsError.message;
|
|
@@ -16,6 +16,8 @@ const DataSummaryFactory = ({
|
|
|
16
16
|
elementTitle,
|
|
17
17
|
modifier,
|
|
18
18
|
headingStyle,
|
|
19
|
+
loopProperties,
|
|
20
|
+
loopLimit,
|
|
19
21
|
...dataSummaryProps
|
|
20
22
|
}) => {
|
|
21
23
|
const entityForQuery = useSelectedEntity ? entity : dataSummaryProps.parent.itemEntity;
|
|
@@ -27,7 +29,7 @@ const DataSummaryFactory = ({
|
|
|
27
29
|
if (loading) return '';
|
|
28
30
|
if (error) return error.message;
|
|
29
31
|
if (!data) return null;
|
|
30
|
-
|
|
32
|
+
if (!propsToDisplay || !propsToDisplay.length) return null;
|
|
31
33
|
const propsToDisplayValues = checkPropsToUse(propsToDisplay);
|
|
32
34
|
const propsQueryString = buildPropsQuery(data, propsToDisplayValues);
|
|
33
35
|
const dataSummaryQuery = getDataSummaryQuery(data, isPreview, propsQueryString);
|
|
@@ -37,6 +39,8 @@ const DataSummaryFactory = ({
|
|
|
37
39
|
<DataSummaryRender
|
|
38
40
|
recordId={recordId}
|
|
39
41
|
propsToDisplay={propsToDisplay}
|
|
42
|
+
loopProperties={loopProperties}
|
|
43
|
+
loopLimit={loopLimit}
|
|
40
44
|
query={dataSummaryQuery}
|
|
41
45
|
type={type}
|
|
42
46
|
elementTitle={elementTitle}
|
|
@@ -54,7 +58,9 @@ DataSummaryFactory.propTypes = {
|
|
|
54
58
|
useSelectedEntity: PropTypes.bool,
|
|
55
59
|
elementTitle: PropTypes.string,
|
|
56
60
|
modifier: PropTypes.string,
|
|
57
|
-
headingStyle: PropTypes.string
|
|
61
|
+
headingStyle: PropTypes.string,
|
|
62
|
+
loopProperties: PropTypes.array,
|
|
63
|
+
loopLimit: PropTypes.number
|
|
58
64
|
};
|
|
59
65
|
|
|
60
66
|
DataSummaryFactory.defaultProps = {
|
|
@@ -65,7 +71,9 @@ DataSummaryFactory.defaultProps = {
|
|
|
65
71
|
entity: '',
|
|
66
72
|
elementTitle: '',
|
|
67
73
|
modifier: '',
|
|
68
|
-
headingStyle: 'h2'
|
|
74
|
+
headingStyle: 'h2',
|
|
75
|
+
loopProperties: [],
|
|
76
|
+
loopLimit: 0
|
|
69
77
|
};
|
|
70
78
|
|
|
71
79
|
export default DataSummaryFactory;
|
|
@@ -3,7 +3,11 @@ import { useQuery } from '@apollo/react-hooks';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { summaryComponents } from './DataSummaryTypes';
|
|
5
5
|
import { getClassModifiers, getPropsToDisplayModifiers } from '../../utils';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
buildPropsToDisplayWithContent,
|
|
8
|
+
stripSummaryPropsContent,
|
|
9
|
+
buildLoopPropsContent
|
|
10
|
+
} from './helpers';
|
|
7
11
|
|
|
8
12
|
const DataSummaryRender = ({
|
|
9
13
|
type,
|
|
@@ -12,6 +16,8 @@ const DataSummaryRender = ({
|
|
|
12
16
|
query,
|
|
13
17
|
propsToDisplay,
|
|
14
18
|
elementTitle,
|
|
19
|
+
loopProperties,
|
|
20
|
+
loopLimit,
|
|
15
21
|
...otherProps
|
|
16
22
|
}) => {
|
|
17
23
|
const { data, error, loading } = useQuery(query, {
|
|
@@ -21,9 +27,14 @@ const DataSummaryRender = ({
|
|
|
21
27
|
if (loading) return '';
|
|
22
28
|
if (error) return error.message;
|
|
23
29
|
if (!data || !data.entityData) return null;
|
|
30
|
+
|
|
24
31
|
const { entityData } = data;
|
|
32
|
+
const shouldLoop = loopProperties && loopProperties.length;
|
|
25
33
|
const modifier = getClassModifiers('list', otherProps);
|
|
26
|
-
const summaryPropsWithContent =
|
|
34
|
+
const summaryPropsWithContent = shouldLoop
|
|
35
|
+
? buildLoopPropsContent(loopProperties, propsToDisplay, loopLimit, entityData)
|
|
36
|
+
: buildPropsToDisplayWithContent(entityData, propsToDisplay);
|
|
37
|
+
|
|
27
38
|
const propsToDisplayModifiers = getPropsToDisplayModifiers(propsToDisplay);
|
|
28
39
|
const summaryPropsWithCleanContent = stripSummaryPropsContent(
|
|
29
40
|
propsToDisplay,
|
|
@@ -49,7 +60,9 @@ DataSummaryRender.propTypes = {
|
|
|
49
60
|
recordId: PropTypes.string,
|
|
50
61
|
propsToDisplay: PropTypes.array,
|
|
51
62
|
elementTitle: PropTypes.string,
|
|
52
|
-
htmlTag: PropTypes.string
|
|
63
|
+
htmlTag: PropTypes.string,
|
|
64
|
+
loopProperties: PropTypes.array,
|
|
65
|
+
loopLimit: PropTypes.number
|
|
53
66
|
};
|
|
54
67
|
|
|
55
68
|
DataSummaryRender.defaultProps = {
|
|
@@ -58,7 +71,9 @@ DataSummaryRender.defaultProps = {
|
|
|
58
71
|
recordId: '',
|
|
59
72
|
propsToDisplay: [],
|
|
60
73
|
elementTitle: '',
|
|
61
|
-
htmlTag: 'h2'
|
|
74
|
+
htmlTag: 'h2',
|
|
75
|
+
loopProperties: [],
|
|
76
|
+
loopLimit: 0
|
|
62
77
|
};
|
|
63
78
|
|
|
64
79
|
export default DataSummaryRender;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import upperFirst from 'lodash.upperfirst';
|
|
2
|
+
import flatten from 'lodash.flatten';
|
|
3
|
+
import getLinkToPublishedContent from './get-link-to-published-content';
|
|
4
|
+
import getLoopPropsLimit from './get-loop-props-limit';
|
|
5
|
+
import getPropValue from './get-prop-value';
|
|
6
|
+
|
|
7
|
+
const getLoopValue = value => {
|
|
8
|
+
const { keyField } = value;
|
|
9
|
+
return value[keyField];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const separateValues = (propsToDisplay, loopProps, data) => {
|
|
13
|
+
const regularValues = {};
|
|
14
|
+
const loopValues = {};
|
|
15
|
+
|
|
16
|
+
propsToDisplay.forEach(options => {
|
|
17
|
+
const { propertiesToDisplay } = options;
|
|
18
|
+
propertiesToDisplay.forEach(prop => {
|
|
19
|
+
const value = getPropValue(prop, data, options);
|
|
20
|
+
const isArrayValue = Array.isArray(value);
|
|
21
|
+
if (!value) return;
|
|
22
|
+
const isLoopableProp = loopProps.includes(prop) && isArrayValue;
|
|
23
|
+
|
|
24
|
+
if (isLoopableProp) {
|
|
25
|
+
loopValues[prop] = value;
|
|
26
|
+
} else {
|
|
27
|
+
regularValues[prop] = value;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return [regularValues, loopValues];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const buildLoopPropsContent = (loopProps = [], propsToDisplay = [], limit = 0, data = {}) => {
|
|
35
|
+
const loopPropsWithContent = [];
|
|
36
|
+
const [regularValues, loopValues] = separateValues(propsToDisplay, loopProps, data);
|
|
37
|
+
|
|
38
|
+
const loopLimit = getLoopPropsLimit(loopValues, limit);
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < loopLimit; i += 1) {
|
|
41
|
+
const propsArray = flatten(
|
|
42
|
+
propsToDisplay.map(options => {
|
|
43
|
+
const { propertiesToDisplay, label } = options;
|
|
44
|
+
return propertiesToDisplay.map(key => {
|
|
45
|
+
const loopValue = loopValues[key];
|
|
46
|
+
const propValue = loopValue ? getLoopValue(loopValue[i]) : regularValues[key];
|
|
47
|
+
if (!propValue) return null;
|
|
48
|
+
const linkToPublishedContent = getLinkToPublishedContent(key, data);
|
|
49
|
+
|
|
50
|
+
return [upperFirst(label), propValue, linkToPublishedContent];
|
|
51
|
+
});
|
|
52
|
+
})
|
|
53
|
+
).filter(Boolean);
|
|
54
|
+
loopPropsWithContent.push(propsArray);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return flatten(loopPropsWithContent);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default buildLoopPropsContent;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const getLoopPropsLimit = (values, limit) => {
|
|
2
|
+
let valuesLimit = 1;
|
|
3
|
+
if (!values) return valuesLimit;
|
|
4
|
+
Object.keys(values).forEach(key => {
|
|
5
|
+
const value = values[key];
|
|
6
|
+
if (value && Array.isArray(value) && value.length > valuesLimit) valuesLimit = value.length;
|
|
7
|
+
});
|
|
8
|
+
if (!limit || valuesLimit < limit) return valuesLimit;
|
|
9
|
+
return limit;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default getLoopPropsLimit;
|
|
@@ -8,13 +8,13 @@ const getPropValue = (key, props, options = {}) => {
|
|
|
8
8
|
.join('.');
|
|
9
9
|
const { prefix = '', suffix = '' } = options;
|
|
10
10
|
const value = props[baseKey];
|
|
11
|
+
|
|
11
12
|
if (typeof value !== 'boolean' && !value) return null;
|
|
12
13
|
|
|
13
14
|
if (nestedKey) {
|
|
14
15
|
const valueIsArray = Array.isArray(value);
|
|
15
16
|
const nestedValue = !valueIsArray ? value[nestedKey] : '';
|
|
16
17
|
if (valueIsArray) return getValueFromArray(nestedKey, value, prefix, suffix);
|
|
17
|
-
|
|
18
18
|
return nestedValue ? `${prefix} ${nestedValue} ${suffix}`.trim() : null;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -2,10 +2,12 @@ import getDataSummaryQuery from './get-data-summary-query';
|
|
|
2
2
|
import buildPropsToDisplayWithContent from './build-props-to-display-with-content';
|
|
3
3
|
import getLinkToPublishedContent from './get-link-to-published-content';
|
|
4
4
|
import stripSummaryPropsContent from './strip-summary-props-content';
|
|
5
|
+
import buildLoopPropsContent from './build-loop-props-content';
|
|
5
6
|
|
|
6
7
|
export {
|
|
7
8
|
getDataSummaryQuery,
|
|
8
9
|
buildPropsToDisplayWithContent,
|
|
9
10
|
getLinkToPublishedContent,
|
|
10
|
-
stripSummaryPropsContent
|
|
11
|
+
stripSummaryPropsContent,
|
|
12
|
+
buildLoopPropsContent
|
|
11
13
|
};
|
|
@@ -31,7 +31,7 @@ function BuildPBComponents(components, options = {}, rootLevel = false) {
|
|
|
31
31
|
name: parentName
|
|
32
32
|
} = options;
|
|
33
33
|
|
|
34
|
-
if (rootLevel) StoreImages.resetImages();
|
|
34
|
+
if (rootLevel && !open) StoreImages.resetImages();
|
|
35
35
|
|
|
36
36
|
StoreImages.addImages(getLightboxImages(components).concat(lightboxImages), options);
|
|
37
37
|
StoreImages.setHandlers({ toggleModal, setSelectedImage });
|