@blaze-cms/react-page-builder 0.119.1 → 0.120.0-alpha.3
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 +44 -0
- package/lib/components/Banner/Banner.js +26 -3
- package/lib/components/Banner/Banner.js.map +1 -1
- package/lib/components/Banner/BannerRender.js +7 -4
- package/lib/components/Banner/BannerRender.js.map +1 -1
- package/lib/components/Banner/helpers.js +81 -21
- package/lib/components/Banner/helpers.js.map +1 -1
- package/lib/components/BlazeLink.js +1 -0
- package/lib/components/BlazeLink.js.map +1 -1
- package/lib/components/Card/Card.js +1 -1
- package/lib/components/Card/Card.js.map +1 -1
- package/lib/components/Card/CardContainer.js +6 -2
- package/lib/components/Card/CardContainer.js.map +1 -1
- package/lib/components/Card/CardRender.js +27 -12
- package/lib/components/Card/CardRender.js.map +1 -1
- package/lib/components/Card/helpers/filter-query-setup.js +7 -3
- package/lib/components/Card/helpers/filter-query-setup.js.map +1 -1
- package/lib/components/Card/helpers/filters-setup.js +5 -16
- package/lib/components/Card/helpers/filters-setup.js.map +1 -1
- package/lib/components/List/ListBuilder.js +3 -3
- package/lib/components/List/ListBuilder.js.map +1 -1
- package/lib/helpers/build-props-query.js +15 -7
- package/lib/helpers/build-props-query.js.map +1 -1
- package/lib/helpers/get-entity-data.js +27 -5
- package/lib/helpers/get-entity-data.js.map +1 -1
- package/lib/helpers/get-generic-render-variables.js +29 -7
- package/lib/helpers/get-generic-render-variables.js.map +1 -1
- package/lib-es/components/Banner/Banner.js +24 -4
- package/lib-es/components/Banner/Banner.js.map +1 -1
- package/lib-es/components/Banner/BannerRender.js +8 -5
- package/lib-es/components/Banner/BannerRender.js.map +1 -1
- package/lib-es/components/Banner/helpers.js +53 -12
- package/lib-es/components/Banner/helpers.js.map +1 -1
- package/lib-es/components/BlazeLink.js +1 -0
- package/lib-es/components/BlazeLink.js.map +1 -1
- package/lib-es/components/Card/Card.js +1 -1
- package/lib-es/components/Card/Card.js.map +1 -1
- package/lib-es/components/Card/CardContainer.js +6 -2
- package/lib-es/components/Card/CardContainer.js.map +1 -1
- package/lib-es/components/Card/CardRender.js +19 -10
- package/lib-es/components/Card/CardRender.js.map +1 -1
- package/lib-es/components/Card/helpers/filter-query-setup.js +7 -3
- package/lib-es/components/Card/helpers/filter-query-setup.js.map +1 -1
- package/lib-es/components/Card/helpers/filters-setup.js +2 -7
- package/lib-es/components/Card/helpers/filters-setup.js.map +1 -1
- package/lib-es/components/List/ListBuilder.js +3 -3
- package/lib-es/components/List/ListBuilder.js.map +1 -1
- package/lib-es/helpers/build-props-query.js +11 -8
- package/lib-es/helpers/build-props-query.js.map +1 -1
- package/lib-es/helpers/get-entity-data.js +23 -5
- package/lib-es/helpers/get-entity-data.js.map +1 -1
- package/lib-es/helpers/get-generic-render-variables.js +28 -7
- package/lib-es/helpers/get-generic-render-variables.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Banner/Banner.js +13 -4
- package/src/components/Banner/BannerRender.js +6 -4
- package/src/components/Banner/helpers.js +58 -9
- package/src/components/BlazeLink.js +1 -0
- package/src/components/Card/Card.js +3 -5
- package/src/components/Card/CardContainer.js +6 -2
- package/src/components/Card/CardRender.js +15 -9
- package/src/components/Card/helpers/filter-query-setup.js +9 -3
- package/src/components/Card/helpers/filters-setup.js +2 -5
- package/src/components/List/ListBuilder.js +3 -3
- package/src/helpers/build-props-query.js +7 -10
- package/src/helpers/get-entity-data.js +12 -4
- package/src/helpers/get-generic-render-variables.js +30 -6
- package/tests/unit/src/components/Banner/helpers.test.js +2 -26
- package/tests/unit/src/components/List/components/Cards/__snapshots__/CardsRender.test.js.snap +18 -6
- package/tests/unit/src/helpers/build-props-query.test.js +28 -0
|
@@ -33,6 +33,7 @@ const BannerRender = ({
|
|
|
33
33
|
action,
|
|
34
34
|
actionKey,
|
|
35
35
|
cardBannerIndex,
|
|
36
|
+
userPropsData,
|
|
36
37
|
...otherProps
|
|
37
38
|
}) => {
|
|
38
39
|
const { id } = otherProps;
|
|
@@ -63,7 +64,6 @@ const BannerRender = ({
|
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
const parsedTargetings = buildContextualTargeting(actionKey, entityRecordData, propsToDisplay);
|
|
66
|
-
|
|
67
67
|
const { entityData } = bannerData;
|
|
68
68
|
const { sizes: bannerSizes } = entityData || {};
|
|
69
69
|
|
|
@@ -81,7 +81,7 @@ const BannerRender = ({
|
|
|
81
81
|
|
|
82
82
|
const customTargetings = setCustomTargetings(targetings, cardBannerIndex);
|
|
83
83
|
|
|
84
|
-
const targetingArguments = { ...parsedTargetings, ...customTargetings };
|
|
84
|
+
const targetingArguments = { ...parsedTargetings, ...customTargetings, ...userPropsData };
|
|
85
85
|
|
|
86
86
|
return (
|
|
87
87
|
<AdSlotRender
|
|
@@ -107,7 +107,8 @@ BannerRender.propTypes = {
|
|
|
107
107
|
entity: PropTypes.string,
|
|
108
108
|
targetings: PropTypes.string,
|
|
109
109
|
sizes: PropTypes.string,
|
|
110
|
-
cardBannerIndex: PropTypes.number
|
|
110
|
+
cardBannerIndex: PropTypes.number,
|
|
111
|
+
userPropsData: PropTypes.object
|
|
111
112
|
};
|
|
112
113
|
|
|
113
114
|
BannerRender.defaultProps = {
|
|
@@ -118,7 +119,8 @@ BannerRender.defaultProps = {
|
|
|
118
119
|
entity: '',
|
|
119
120
|
targetings: '',
|
|
120
121
|
sizes: '',
|
|
121
|
-
cardBannerIndex: null
|
|
122
|
+
cardBannerIndex: null,
|
|
123
|
+
userPropsData: {}
|
|
122
124
|
};
|
|
123
125
|
|
|
124
126
|
export default withTitle(BannerRender);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { parseUrl } from 'query-string';
|
|
2
|
-
import flatten from 'lodash.flatten';
|
|
3
|
-
import getPropValues from '../../helpers/get-prop-values';
|
|
4
2
|
import { END_ADUNIT, MAX_BANNER_HEIGHT, MIN_BANNER_HEIGHT } from '../../constants';
|
|
5
3
|
|
|
6
4
|
const getParsedSizes = (sizes = '') => {
|
|
@@ -82,12 +80,8 @@ const buildBannerSizes = (sizeId, bannerSizes, sizes) => {
|
|
|
82
80
|
|
|
83
81
|
const buildContextualTargeting = (actionKey, props = {}, propsToDisplay = []) => {
|
|
84
82
|
if (actionKey && props[actionKey] && props[actionKey][0]) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const parsedValue = Array.isArray(propValue) ? flatten(propValue) : propValue;
|
|
88
|
-
acc[label] = parsedValue;
|
|
89
|
-
return acc;
|
|
90
|
-
}, {});
|
|
83
|
+
const data = props[actionKey][0];
|
|
84
|
+
return buildPropsData(data, propsToDisplay);
|
|
91
85
|
}
|
|
92
86
|
return {};
|
|
93
87
|
};
|
|
@@ -135,6 +129,59 @@ const getMinBannerHeight = bannerSizes => {
|
|
|
135
129
|
return MIN_BANNER_HEIGHT;
|
|
136
130
|
};
|
|
137
131
|
|
|
132
|
+
const buildUserQuery = userProps => {
|
|
133
|
+
if (!userProps || !userProps.length) return '';
|
|
134
|
+
const basicProps = [];
|
|
135
|
+
const nestedProps = {};
|
|
136
|
+
userProps.forEach(({ propertiesToDisplay }) => {
|
|
137
|
+
const [propKey] = propertiesToDisplay;
|
|
138
|
+
if (!propKey || propKey === 'id') return;
|
|
139
|
+
if (propKey.indexOf('.') !== -1) {
|
|
140
|
+
const [baseProp, nestedProp] = propKey.split('.');
|
|
141
|
+
if (nestedProps[baseProp]) nestedProps[baseProp].push(nestedProp);
|
|
142
|
+
else nestedProps[baseProp] = [nestedProp];
|
|
143
|
+
} else basicProps.push(propKey);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
Object.keys(nestedProps).forEach(nestedKey => {
|
|
147
|
+
const nested = nestedProps[nestedKey];
|
|
148
|
+
basicProps.push(nestedKey);
|
|
149
|
+
basicProps.push('{');
|
|
150
|
+
nested.forEach(prop => basicProps.push(prop));
|
|
151
|
+
basicProps.push('}');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return basicProps.join(' ');
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const buildPropsData = (data, props) => {
|
|
158
|
+
if (!data || !props.length) return {};
|
|
159
|
+
const propsWithData = {};
|
|
160
|
+
|
|
161
|
+
props.forEach(({ propertiesToDisplay, label }) => {
|
|
162
|
+
const [key] = propertiesToDisplay;
|
|
163
|
+
const parsedKey = key.split('.');
|
|
164
|
+
const value = getNestedValue(parsedKey, data);
|
|
165
|
+
const labelToUse = label || key;
|
|
166
|
+
|
|
167
|
+
if (value) propsWithData[labelToUse] = value;
|
|
168
|
+
});
|
|
169
|
+
return propsWithData;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const parseArrayValues = (arr, key) =>
|
|
173
|
+
arr
|
|
174
|
+
.map(obj => obj[key])
|
|
175
|
+
.filter(Boolean)
|
|
176
|
+
.join(', ');
|
|
177
|
+
|
|
178
|
+
const getNestedValue = (keys, object) => {
|
|
179
|
+
const key = keys.shift();
|
|
180
|
+
const nestedValue = Array.isArray(object) ? parseArrayValues(object, key) : object[key];
|
|
181
|
+
if (!nestedValue) return null;
|
|
182
|
+
return keys.length ? getNestedValue(keys, nestedValue) : nestedValue;
|
|
183
|
+
};
|
|
184
|
+
|
|
138
185
|
export {
|
|
139
186
|
getParsedSizes,
|
|
140
187
|
setCustomTargetings,
|
|
@@ -143,5 +190,7 @@ export {
|
|
|
143
190
|
buildContextualTargeting,
|
|
144
191
|
buildSizeMapping,
|
|
145
192
|
getMaxBannerHeight,
|
|
146
|
-
getMinBannerHeight
|
|
193
|
+
getMinBannerHeight,
|
|
194
|
+
buildPropsData,
|
|
195
|
+
buildUserQuery
|
|
147
196
|
};
|
|
@@ -7,6 +7,7 @@ const BlazeLink = ({ children, className, name, href, as, shallow, scroll, gtmId
|
|
|
7
7
|
const { hasGTM } = useContext(MainContext);
|
|
8
8
|
const gtmProps = hasGTM && !!gtmId ? { gtmId } : {};
|
|
9
9
|
const linkExtraProps = buildLinkExtraProps({ className, name, as, ...gtmProps });
|
|
10
|
+
if (!href) return children;
|
|
10
11
|
|
|
11
12
|
return (
|
|
12
13
|
<Link href={href} shallow={shallow} scroll={scroll} onClick={onClick} {...linkExtraProps}>
|
|
@@ -93,11 +93,9 @@ const Card = ({
|
|
|
93
93
|
))}
|
|
94
94
|
{displayTitle && (
|
|
95
95
|
<h2 className={getModifiers('card__title', modifiers)}>
|
|
96
|
-
{url
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
</BlazeLink>
|
|
100
|
-
)}
|
|
96
|
+
<BlazeLink title={linkTitle} gtmId={gtmId} href={url} scroll>
|
|
97
|
+
{headline}
|
|
98
|
+
</BlazeLink>
|
|
101
99
|
</h2>
|
|
102
100
|
)}
|
|
103
101
|
{!!propsToDisplay.length && (
|
|
@@ -109,7 +109,9 @@ CardContainer.propTypes = {
|
|
|
109
109
|
itemsPerRow: PropTypes.number,
|
|
110
110
|
enableCarousel: PropTypes.bool,
|
|
111
111
|
bannerModifier: PropTypes.string,
|
|
112
|
-
priorityLimit: PropTypes.number
|
|
112
|
+
priorityLimit: PropTypes.number,
|
|
113
|
+
enableAutoScroll: PropTypes.bool,
|
|
114
|
+
autoScrollTimer: PropTypes.number
|
|
113
115
|
};
|
|
114
116
|
|
|
115
117
|
CardContainer.defaultProps = {
|
|
@@ -127,7 +129,9 @@ CardContainer.defaultProps = {
|
|
|
127
129
|
itemsPerRow: 1,
|
|
128
130
|
enableCarousel: false,
|
|
129
131
|
bannerModifier: '',
|
|
130
|
-
priorityLimit: 0
|
|
132
|
+
priorityLimit: 0,
|
|
133
|
+
enableAutoScroll: false,
|
|
134
|
+
autoScrollTimer: 0
|
|
131
135
|
};
|
|
132
136
|
|
|
133
137
|
export default withTitle(CardContainer);
|
|
@@ -22,6 +22,7 @@ import { filtersSetup, filterQuerySetup, shouldSkipSingleQuery, shouldReturn } f
|
|
|
22
22
|
const CardContainer = dynamic(() => import('./CardContainer'));
|
|
23
23
|
|
|
24
24
|
const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...otherProps }) => {
|
|
25
|
+
const { isPreview } = useContext(MainContext);
|
|
25
26
|
const {
|
|
26
27
|
parent: { itemId, itemEntity },
|
|
27
28
|
filterBy = [],
|
|
@@ -29,7 +30,8 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...otherPr
|
|
|
29
30
|
sortby,
|
|
30
31
|
sort,
|
|
31
32
|
sortProperties = [],
|
|
32
|
-
operator: filterOperator = AND
|
|
33
|
+
operator: filterOperator = AND,
|
|
34
|
+
useRandomSort
|
|
33
35
|
} = otherProps;
|
|
34
36
|
|
|
35
37
|
const updatedSortProperties = [...sortProperties];
|
|
@@ -55,14 +57,15 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...otherPr
|
|
|
55
57
|
entity
|
|
56
58
|
]);
|
|
57
59
|
|
|
58
|
-
const
|
|
59
|
-
const {
|
|
60
|
+
const schemas = Object.values(mainSchemas);
|
|
61
|
+
const currentSchema = schemas.find(({ identifier }) => identifier === itemEntityUpdated) || {};
|
|
62
|
+
const filterEntitySchema = schemas.find(({ id }) => entity === id) || {};
|
|
63
|
+
const { entityType, docType } = getEntityData(entity, filterEntitySchema);
|
|
64
|
+
|
|
60
65
|
const {
|
|
61
66
|
getAction,
|
|
62
67
|
queryProps,
|
|
63
68
|
inheritedFilters,
|
|
64
|
-
currentSchema,
|
|
65
|
-
filterEntitySchema,
|
|
66
69
|
entitySameAsCurrentItemEntity,
|
|
67
70
|
action,
|
|
68
71
|
filterEntityRelations
|
|
@@ -72,7 +75,8 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...otherPr
|
|
|
72
75
|
filterBy,
|
|
73
76
|
filterByProperty,
|
|
74
77
|
entity,
|
|
75
|
-
|
|
78
|
+
currentSchema,
|
|
79
|
+
filterEntitySchema,
|
|
76
80
|
isPreview,
|
|
77
81
|
itemEntityUpdated
|
|
78
82
|
});
|
|
@@ -111,12 +115,15 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...otherPr
|
|
|
111
115
|
filterOperator,
|
|
112
116
|
filterEntityRelations,
|
|
113
117
|
itemsToDisplay,
|
|
114
|
-
entitySameAsCurrentItemEntity
|
|
118
|
+
entitySameAsCurrentItemEntity,
|
|
119
|
+
useRandomSort
|
|
115
120
|
});
|
|
116
121
|
const { data, error: cardsError, loading: cardsLoading } = useQuery(action, {
|
|
117
122
|
variables,
|
|
123
|
+
fetchPolicy: useRandomSort ? 'cache-and-network' : 'cache-first',
|
|
118
124
|
skip: shouldReturn(!updatedFilterBy, _loading, _load, schemaLoading, _error, _err, schemaError)
|
|
119
125
|
});
|
|
126
|
+
|
|
120
127
|
const imageIds = itemsToDisplay.map(({ imageId }) => imageId).filter(Boolean);
|
|
121
128
|
const { data: imagesData, loading: imagesLoading } = useGetImages(imageIds, true);
|
|
122
129
|
const isLoading = shouldReturn(_loading, _load, schemaLoading, cardsLoading, imagesLoading);
|
|
@@ -126,11 +133,10 @@ const CardRender = ({ entity, entityFields, itemsToDisplay, children, ...otherPr
|
|
|
126
133
|
if (isLoading) return '';
|
|
127
134
|
if (hasError) return null;
|
|
128
135
|
if (cardsError) return cardsError.message;
|
|
129
|
-
|
|
130
136
|
let { results: cardData } = data[SEARCH_PUBLISHED_CONTENT];
|
|
131
137
|
if (!cardData || !cardData.length) return null;
|
|
132
138
|
cardData = entitySameAsCurrentItemEntity ? removeExtraItems(cardData, limit, itemId) : cardData;
|
|
133
|
-
const orderedData = sortResponseData(cardData, itemsToDisplay);
|
|
139
|
+
const orderedData = useRandomSort ? cardData : sortResponseData(cardData, itemsToDisplay);
|
|
134
140
|
const { regularChildren, gtmChildren } = splitChildren(children, cardData, entity, {
|
|
135
141
|
name: variableProps.name
|
|
136
142
|
});
|
|
@@ -11,7 +11,9 @@ const filterQuerySetup = ({
|
|
|
11
11
|
filterOperator,
|
|
12
12
|
filterEntityRelations,
|
|
13
13
|
itemsToDisplay,
|
|
14
|
-
entitySameAsCurrentItemEntity
|
|
14
|
+
entitySameAsCurrentItemEntity,
|
|
15
|
+
entitySchema,
|
|
16
|
+
useRandomSort
|
|
15
17
|
}) => {
|
|
16
18
|
const stringProps = getStringTypeProps(entity, filterEntityRelations, getEntitySchemas);
|
|
17
19
|
const filterValues =
|
|
@@ -27,7 +29,9 @@ const filterQuerySetup = ({
|
|
|
27
29
|
relations: filterEntityRelations,
|
|
28
30
|
stringProps,
|
|
29
31
|
itemsToDisplay,
|
|
30
|
-
addListFiltersToQuery: true
|
|
32
|
+
addListFiltersToQuery: true,
|
|
33
|
+
entity,
|
|
34
|
+
entitySchema
|
|
31
35
|
})
|
|
32
36
|
};
|
|
33
37
|
|
|
@@ -39,7 +43,9 @@ const filterQuerySetup = ({
|
|
|
39
43
|
filterEntityRelations,
|
|
40
44
|
{ ...variableProps, limit: requestLimit },
|
|
41
45
|
stringProps,
|
|
42
|
-
|
|
46
|
+
rawQuery,
|
|
47
|
+
false,
|
|
48
|
+
useRandomSort
|
|
43
49
|
);
|
|
44
50
|
|
|
45
51
|
return { variables, limit };
|
|
@@ -7,18 +7,15 @@ const filtersSetup = ({
|
|
|
7
7
|
filterBy,
|
|
8
8
|
filterByProperty,
|
|
9
9
|
entity,
|
|
10
|
-
|
|
10
|
+
currentSchema,
|
|
11
|
+
filterEntitySchema,
|
|
11
12
|
isPreview,
|
|
12
13
|
itemEntityUpdated
|
|
13
14
|
}) => {
|
|
14
15
|
const fields = buildQueryFields(entityFields, entityType);
|
|
15
16
|
const action = getSearchPublishedContent(fields);
|
|
16
17
|
const inheritedFilters = getInheritedFilters(filterBy, filterByProperty);
|
|
17
|
-
|
|
18
18
|
const entitySameAsCurrentItemEntity = itemEntityUpdated === entity;
|
|
19
|
-
const currentSchema =
|
|
20
|
-
getEntitySchemas.find(({ identifier }) => identifier === itemEntityUpdated) || {};
|
|
21
|
-
const filterEntitySchema = getEntitySchemas.find(({ id }) => entity === id) || {};
|
|
22
19
|
const { relations: filterEntityRelations = [] } = filterEntitySchema;
|
|
23
20
|
const queryProps = getQueryProps(inheritedFilters, currentSchema, filterEntitySchema);
|
|
24
21
|
const { actions = {} } = currentSchema || {};
|
|
@@ -62,7 +62,7 @@ const ListBuilder = props => {
|
|
|
62
62
|
const shouldApplyDefaultSort = !sortProperties || !sortProperties.length;
|
|
63
63
|
const itemsPerPageToUse = getItemsPerPageToUse(itemsPerPage, limitToUse);
|
|
64
64
|
const initialOffset = getCurrentOffset(offset, itemsPerPageToUse, paginationIndex, limitToUse);
|
|
65
|
-
const { entityType, docType } = getEntityData(entity);
|
|
65
|
+
const { entityType, docType } = getEntityData(entity, requiredSchema);
|
|
66
66
|
const fields = buildQueryFields(entityFields, entityType, !isCard);
|
|
67
67
|
const action = getSearchPublishedContent(fields);
|
|
68
68
|
const actionKey = SEARCH_PUBLISHED_CONTENT;
|
|
@@ -110,7 +110,7 @@ const ListBuilder = props => {
|
|
|
110
110
|
sortProperties
|
|
111
111
|
},
|
|
112
112
|
stringProps,
|
|
113
|
-
|
|
113
|
+
azRawQuery,
|
|
114
114
|
isTextSearchFilterApplied
|
|
115
115
|
);
|
|
116
116
|
|
|
@@ -153,7 +153,7 @@ const ListBuilder = props => {
|
|
|
153
153
|
sortProperties
|
|
154
154
|
},
|
|
155
155
|
stringProps,
|
|
156
|
-
|
|
156
|
+
rawQuery,
|
|
157
157
|
isTextSearchFilterApplied
|
|
158
158
|
);
|
|
159
159
|
|
|
@@ -59,7 +59,7 @@ const getTypeBaseProps = (data, cardOptions, extraPropsHaveCategory) => {
|
|
|
59
59
|
if (!isCard) return { typeBasedProps: [ID], shouldAddCategoryProps };
|
|
60
60
|
|
|
61
61
|
const { getEntitySchema } = data;
|
|
62
|
-
const { interfaces, properties, dynamicProperties } = getEntitySchema;
|
|
62
|
+
const { interfaces, properties, dynamicProperties, relations } = getEntitySchema;
|
|
63
63
|
|
|
64
64
|
const isContent = !!interfaces.includes('content/content');
|
|
65
65
|
const hasCategory = checkProps(properties) || checkProps(dynamicProperties);
|
|
@@ -68,19 +68,16 @@ const getTypeBaseProps = (data, cardOptions, extraPropsHaveCategory) => {
|
|
|
68
68
|
const typeBasedProps = [...defaultProps];
|
|
69
69
|
|
|
70
70
|
typeBasedProps.push(...getCategoyProps(shouldAddCategoryProps, hasCategory, hasPreheader));
|
|
71
|
-
typeBasedProps.push(...getContentProps(isContent
|
|
71
|
+
typeBasedProps.push(...getContentProps(isContent));
|
|
72
|
+
|
|
73
|
+
if (displayThumbnail && relations.find(({ localField }) => localField === 'image')) {
|
|
74
|
+
typeBasedProps.push('image.id', 'image.url', 'image.data');
|
|
75
|
+
}
|
|
72
76
|
|
|
73
77
|
return { typeBasedProps, shouldAddCategoryProps };
|
|
74
78
|
};
|
|
75
79
|
|
|
76
|
-
const getContentProps = (isContent,
|
|
77
|
-
if (!isContent) return [];
|
|
78
|
-
|
|
79
|
-
const props = ['url', 'sponsored', 'featured'];
|
|
80
|
-
if (displayThumbnail) props.push('image.id', 'image.url', 'image.data');
|
|
81
|
-
|
|
82
|
-
return props;
|
|
83
|
-
};
|
|
80
|
+
const getContentProps = isContent => (isContent ? ['url', 'sponsored', 'featured'] : []);
|
|
84
81
|
|
|
85
82
|
const getCategoyProps = (shouldAddCategoryProps, hasCategory, hasPreheader) => {
|
|
86
83
|
if (!shouldAddCategoryProps) return [];
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import upperFirst from 'lodash.upperfirst';
|
|
2
2
|
import camelcase from 'lodash.camelcase';
|
|
3
3
|
|
|
4
|
-
const getEntityData = entity => {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const getEntityData = (entity, schema) => {
|
|
5
|
+
const publishedDocType = `published_${entity}`;
|
|
6
|
+
const publishedEntityType = `Published${upperFirst(camelcase(entity))}`;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
if (schema) {
|
|
9
|
+
const { interfaces, [entity]: { interfaces: nestedInterfaces } = {} } = schema || {};
|
|
10
|
+
const interfacesToCheck = interfaces || nestedInterfaces;
|
|
11
|
+
if (interfacesToCheck && !interfacesToCheck.includes('publish/publishable')) {
|
|
12
|
+
return { docType: entity, entityType: upperFirst(camelcase(entity)) };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return { docType: publishedDocType, entityType: publishedEntityType };
|
|
9
17
|
};
|
|
10
18
|
|
|
11
19
|
export default getEntityData;
|
|
@@ -3,6 +3,7 @@ import { DEFAULT_LIMIT, DEFAULT_OFFSET } from '../constants';
|
|
|
3
3
|
|
|
4
4
|
const buildSortValues = (sortFilters, relations, stringProps) => {
|
|
5
5
|
if (!sortFilters || !sortFilters.length) return { sort: [] };
|
|
6
|
+
|
|
6
7
|
const sortValues = sortFilters
|
|
7
8
|
.map(({ sort, propsToDisplay }) => {
|
|
8
9
|
if (!sort) return null;
|
|
@@ -32,18 +33,41 @@ const getGenericRenderVariables = (
|
|
|
32
33
|
relations,
|
|
33
34
|
filterProps = {},
|
|
34
35
|
stringProps = [],
|
|
35
|
-
|
|
36
|
-
isTextSearchFilterApplied = false
|
|
36
|
+
rawQuery = {},
|
|
37
|
+
isTextSearchFilterApplied = false,
|
|
38
|
+
useRandomSort = false
|
|
37
39
|
) => {
|
|
38
40
|
const { limit = DEFAULT_LIMIT, offset } = filterProps;
|
|
41
|
+
const limitToUse = Number(limit || DEFAULT_LIMIT);
|
|
42
|
+
const offsetToUse = Number(offset || DEFAULT_OFFSET);
|
|
43
|
+
|
|
44
|
+
if (useRandomSort) {
|
|
45
|
+
const rawQueryStringified = JSON.stringify({
|
|
46
|
+
query: {
|
|
47
|
+
function_score: {
|
|
48
|
+
query: rawQuery,
|
|
49
|
+
random_score: {},
|
|
50
|
+
boost_mode: 'replace'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
limit: limitToUse,
|
|
57
|
+
offset: offsetToUse,
|
|
58
|
+
rawQueryStringified
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
39
62
|
const sort = getCorrectSort(relations, filterProps, stringProps, isTextSearchFilterApplied);
|
|
40
|
-
const raw = rawQueryStringified ? { rawQueryStringified } : {};
|
|
41
63
|
|
|
42
64
|
return {
|
|
43
|
-
limit:
|
|
44
|
-
offset:
|
|
65
|
+
limit: limitToUse,
|
|
66
|
+
offset: offsetToUse,
|
|
45
67
|
...sort,
|
|
46
|
-
|
|
68
|
+
rawQueryStringified: JSON.stringify({
|
|
69
|
+
query: rawQuery
|
|
70
|
+
})
|
|
47
71
|
};
|
|
48
72
|
};
|
|
49
73
|
|
|
@@ -17,10 +17,6 @@ const tagsTargetingResult = { tags: ['destinations', 'models'] };
|
|
|
17
17
|
|
|
18
18
|
describe('getParsedSizes helper', () => {
|
|
19
19
|
const sizes = getParsedSizes(mockedSizes);
|
|
20
|
-
it('should be a function', () => {
|
|
21
|
-
expect(typeof getParsedSizes).toEqual('function');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
20
|
it('should match snapshot', () => {
|
|
25
21
|
expect(getParsedSizes).toMatchSnapshot();
|
|
26
22
|
});
|
|
@@ -46,10 +42,6 @@ describe('getParsedSizes helper', () => {
|
|
|
46
42
|
describe('setCustomTargetings helper', () => {
|
|
47
43
|
const targetingsEmpty = setCustomTargetings('');
|
|
48
44
|
|
|
49
|
-
it('should be a function', () => {
|
|
50
|
-
expect(typeof setCustomTargetings).toEqual('function');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
45
|
it('should always return an object', () => {
|
|
54
46
|
expect(typeof targetingsEmpty).toBe('object');
|
|
55
47
|
});
|
|
@@ -85,10 +77,6 @@ describe('buildParsedAdunit helper', () => {
|
|
|
85
77
|
const parsedAdunit = buildParsedAdunit('/test-path/article', 0, '', '');
|
|
86
78
|
const parsedAdunitEmpty = buildParsedAdunit('/test-path/article', undefined, '', '');
|
|
87
79
|
|
|
88
|
-
it('should be a function', () => {
|
|
89
|
-
expect(typeof buildParsedAdunit).toEqual('function');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
80
|
it('should always return a string', () => {
|
|
93
81
|
expect(typeof parsedAdunit).toBe('string');
|
|
94
82
|
expect(typeof parsedAdunitEmpty).toBe('string');
|
|
@@ -125,10 +113,6 @@ describe('buildParsedAdunit helper', () => {
|
|
|
125
113
|
});
|
|
126
114
|
|
|
127
115
|
describe('buildBannerSizes helper', () => {
|
|
128
|
-
it('should be a function', () => {
|
|
129
|
-
expect(typeof buildBannerSizes).toEqual('function');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
116
|
it('should return an array of sizes based on given sizeId', () => {
|
|
133
117
|
const parsedSizes = buildBannerSizes(
|
|
134
118
|
'sizeId',
|
|
@@ -145,10 +129,6 @@ describe('buildBannerSizes helper', () => {
|
|
|
145
129
|
});
|
|
146
130
|
|
|
147
131
|
describe('buildContextualTargeting helper', () => {
|
|
148
|
-
it('should be a function', () => {
|
|
149
|
-
expect(typeof buildContextualTargeting).toEqual('function');
|
|
150
|
-
});
|
|
151
|
-
|
|
152
132
|
it('should return an empty object if no data received', () => {
|
|
153
133
|
const contextualTargeting = buildContextualTargeting('getPages', {}, []);
|
|
154
134
|
expect(contextualTargeting).toEqual({});
|
|
@@ -174,7 +154,7 @@ describe('buildContextualTargeting helper', () => {
|
|
|
174
154
|
{ getPages: [{ metaTitle: 'test' }] },
|
|
175
155
|
[{ label: 'definedKey', propertiesToDisplay: ['metaTitle'] }]
|
|
176
156
|
);
|
|
177
|
-
expect(contextualTargeting).toEqual({ definedKey:
|
|
157
|
+
expect(contextualTargeting).toEqual({ definedKey: 'test' });
|
|
178
158
|
});
|
|
179
159
|
|
|
180
160
|
it('should return an object with correct targeting when the selected prop value is array', () => {
|
|
@@ -183,15 +163,11 @@ describe('buildContextualTargeting helper', () => {
|
|
|
183
163
|
{ getPages: [{ tags: [{ name: 'tag1' }, { name: 'tag2' }] }] },
|
|
184
164
|
[{ label: 'tagKey', propertiesToDisplay: ['tags.name'] }]
|
|
185
165
|
);
|
|
186
|
-
expect(contextualTargeting).toEqual({ tagKey:
|
|
166
|
+
expect(contextualTargeting).toEqual({ tagKey: 'tag1, tag2' });
|
|
187
167
|
});
|
|
188
168
|
});
|
|
189
169
|
|
|
190
170
|
describe('buildSizeMapping helper', () => {
|
|
191
|
-
it('should be a function', () => {
|
|
192
|
-
expect(typeof buildSizeMapping).toEqual('function');
|
|
193
|
-
});
|
|
194
|
-
|
|
195
171
|
it('should always return an array', () => {
|
|
196
172
|
const sizeMapping = buildSizeMapping('id', [
|
|
197
173
|
{ width: 1, height: 1, viewport: [{ width: 1024, height: 0 }] }
|
package/tests/unit/src/components/List/components/Cards/__snapshots__/CardsRender.test.js.snap
CHANGED
|
@@ -27,7 +27,9 @@ exports[`CardsRender component should render based on listData received 1`] = `
|
|
|
27
27
|
>
|
|
28
28
|
<h2
|
|
29
29
|
class="card__title card__title--portrait"
|
|
30
|
-
|
|
30
|
+
>
|
|
31
|
+
item 1
|
|
32
|
+
</h2>
|
|
31
33
|
</div>
|
|
32
34
|
</div>
|
|
33
35
|
</div>
|
|
@@ -46,7 +48,9 @@ exports[`CardsRender component should render based on listData received 1`] = `
|
|
|
46
48
|
>
|
|
47
49
|
<h2
|
|
48
50
|
class="card__title card__title--portrait"
|
|
49
|
-
|
|
51
|
+
>
|
|
52
|
+
item 1
|
|
53
|
+
</h2>
|
|
50
54
|
</div>
|
|
51
55
|
</div>
|
|
52
56
|
</div>
|
|
@@ -65,7 +69,9 @@ exports[`CardsRender component should render based on listData received 1`] = `
|
|
|
65
69
|
>
|
|
66
70
|
<h2
|
|
67
71
|
class="card__title card__title--portrait"
|
|
68
|
-
|
|
72
|
+
>
|
|
73
|
+
item 1
|
|
74
|
+
</h2>
|
|
69
75
|
</div>
|
|
70
76
|
</div>
|
|
71
77
|
</div>
|
|
@@ -96,7 +102,9 @@ exports[`CardsRender component should render without wrapper, when requested 1`]
|
|
|
96
102
|
>
|
|
97
103
|
<h2
|
|
98
104
|
class="card__title card__title--portrait"
|
|
99
|
-
|
|
105
|
+
>
|
|
106
|
+
item 1
|
|
107
|
+
</h2>
|
|
100
108
|
</div>
|
|
101
109
|
</div>
|
|
102
110
|
</div>
|
|
@@ -115,7 +123,9 @@ exports[`CardsRender component should render without wrapper, when requested 1`]
|
|
|
115
123
|
>
|
|
116
124
|
<h2
|
|
117
125
|
class="card__title card__title--portrait"
|
|
118
|
-
|
|
126
|
+
>
|
|
127
|
+
item 1
|
|
128
|
+
</h2>
|
|
119
129
|
</div>
|
|
120
130
|
</div>
|
|
121
131
|
</div>
|
|
@@ -134,7 +144,9 @@ exports[`CardsRender component should render without wrapper, when requested 1`]
|
|
|
134
144
|
>
|
|
135
145
|
<h2
|
|
136
146
|
class="card__title card__title--portrait"
|
|
137
|
-
|
|
147
|
+
>
|
|
148
|
+
item 1
|
|
149
|
+
</h2>
|
|
138
150
|
</div>
|
|
139
151
|
</div>
|
|
140
152
|
</div>
|
|
@@ -6,6 +6,11 @@ import buildPropsQuery from '../../../../src/helpers/build-props-query';
|
|
|
6
6
|
const CONTENT_INTERFACE = 'content/content';
|
|
7
7
|
|
|
8
8
|
describe('get card render props', () => {
|
|
9
|
+
const relations = [
|
|
10
|
+
{
|
|
11
|
+
localField: 'image'
|
|
12
|
+
}
|
|
13
|
+
];
|
|
9
14
|
const data = {
|
|
10
15
|
getEntitySchema: {
|
|
11
16
|
interfaces: [CONTENT_INTERFACE],
|
|
@@ -13,6 +18,7 @@ describe('get card render props', () => {
|
|
|
13
18
|
id: 'id',
|
|
14
19
|
name: 'someName'
|
|
15
20
|
},
|
|
21
|
+
relations,
|
|
16
22
|
dynamicProperties: {}
|
|
17
23
|
}
|
|
18
24
|
};
|
|
@@ -23,6 +29,7 @@ describe('get card render props', () => {
|
|
|
23
29
|
id: 'id',
|
|
24
30
|
alternativePreHeader: { type: 'object ' }
|
|
25
31
|
},
|
|
32
|
+
relations,
|
|
26
33
|
dynamicProperties: {}
|
|
27
34
|
}
|
|
28
35
|
};
|
|
@@ -50,6 +57,7 @@ describe('get card render props', () => {
|
|
|
50
57
|
id: 'id',
|
|
51
58
|
categoryId: 'catId'
|
|
52
59
|
},
|
|
60
|
+
relations,
|
|
53
61
|
dynamicProperties: {}
|
|
54
62
|
}
|
|
55
63
|
};
|
|
@@ -78,6 +86,7 @@ describe('get card render props', () => {
|
|
|
78
86
|
alternativePreHeader: { type: 'object ' },
|
|
79
87
|
categoryId: { type: 'object ' }
|
|
80
88
|
},
|
|
89
|
+
relations,
|
|
81
90
|
dynamicProperties: {}
|
|
82
91
|
}
|
|
83
92
|
};
|
|
@@ -118,6 +127,7 @@ describe('get card render props', () => {
|
|
|
118
127
|
id: 'id',
|
|
119
128
|
categoryId: 'someName'
|
|
120
129
|
},
|
|
130
|
+
relations: [],
|
|
121
131
|
dynamicProperties: {}
|
|
122
132
|
}
|
|
123
133
|
};
|
|
@@ -131,4 +141,22 @@ describe('get card render props', () => {
|
|
|
131
141
|
const query = buildPropsQuery(data, [], { displayCategory: false, displayThumbnail: false });
|
|
132
142
|
expect(query).toEqual('id,name,url,sponsored,featured');
|
|
133
143
|
});
|
|
144
|
+
|
|
145
|
+
it('should not fetch image if the schema does not have imageId property', () => {
|
|
146
|
+
const _data = {
|
|
147
|
+
getEntitySchema: {
|
|
148
|
+
interfaces: [CONTENT_INTERFACE],
|
|
149
|
+
properties: {
|
|
150
|
+
id: 'id',
|
|
151
|
+
categoryId: 'catId'
|
|
152
|
+
},
|
|
153
|
+
relations: [{ localField: 'noImage' }],
|
|
154
|
+
dynamicProperties: {}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const query = buildPropsQuery(_data, [], cardProps);
|
|
158
|
+
expect(query).toEqual(
|
|
159
|
+
'id,name,url,sponsored,featured,category{name,listingPageId,listingPageEntity, id publishedListingPage{id, url}}'
|
|
160
|
+
);
|
|
161
|
+
});
|
|
134
162
|
});
|