@blaze-cms/react-page-builder 0.130.0-admin-updates.6 → 0.130.0-admin-updates.9

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 (43) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/components/Card/CardsRender.js +13 -6
  3. package/lib/components/Card/CardsRender.js.map +1 -1
  4. package/lib/components/Card/helpers/get-updated-items-to-display.js +55 -0
  5. package/lib/components/Card/helpers/get-updated-items-to-display.js.map +1 -0
  6. package/lib/components/Card/helpers/index.js +7 -0
  7. package/lib/components/Card/helpers/index.js.map +1 -1
  8. package/lib/components/SearchContent/SearchContentItems.js +1 -1
  9. package/lib/components/SearchContent/SearchContentItems.js.map +1 -1
  10. package/lib/helpers/build-inherited-filters.js +2 -0
  11. package/lib/helpers/build-inherited-filters.js.map +1 -1
  12. package/lib/helpers/build-props-query.js +5 -2
  13. package/lib/helpers/build-props-query.js.map +1 -1
  14. package/lib/helpers/build-set-filters.js +5 -1
  15. package/lib/helpers/build-set-filters.js.map +1 -1
  16. package/lib/helpers/get-query-props.js +13 -2
  17. package/lib/helpers/get-query-props.js.map +1 -1
  18. package/lib-es/components/Card/CardsRender.js +14 -7
  19. package/lib-es/components/Card/CardsRender.js.map +1 -1
  20. package/lib-es/components/Card/helpers/get-updated-items-to-display.js +32 -0
  21. package/lib-es/components/Card/helpers/get-updated-items-to-display.js.map +1 -0
  22. package/lib-es/components/Card/helpers/index.js +1 -0
  23. package/lib-es/components/Card/helpers/index.js.map +1 -1
  24. package/lib-es/components/SearchContent/SearchContentItems.js +1 -1
  25. package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -1
  26. package/lib-es/helpers/build-inherited-filters.js +2 -0
  27. package/lib-es/helpers/build-inherited-filters.js.map +1 -1
  28. package/lib-es/helpers/build-props-query.js +4 -2
  29. package/lib-es/helpers/build-props-query.js.map +1 -1
  30. package/lib-es/helpers/build-set-filters.js +5 -1
  31. package/lib-es/helpers/build-set-filters.js.map +1 -1
  32. package/lib-es/helpers/get-query-props.js +10 -2
  33. package/lib-es/helpers/get-query-props.js.map +1 -1
  34. package/package.json +3 -3
  35. package/src/components/Card/CardsRender.js +27 -7
  36. package/src/components/Card/helpers/get-updated-items-to-display.js +32 -0
  37. package/src/components/Card/helpers/index.js +1 -0
  38. package/src/helpers/build-inherited-filters.js +3 -1
  39. package/src/helpers/build-props-query.js +4 -2
  40. package/src/helpers/build-set-filters.js +2 -1
  41. package/src/helpers/get-query-props.js +12 -4
  42. package/tests/unit/src/components/Card/helpers/get-updated-items-to-display.test.js +72 -0
  43. package/tests/unit/src/helpers/build-props-query.test.js +25 -0
@@ -44,19 +44,21 @@ const buildPropsQuery = (entitySchema, extraProps = [], cardOptions = null, link
44
44
  const buildComplexProps = (
45
45
  shouldAddCategoryProps,
46
46
  props,
47
- { relations = [], dynamicProperties = {} },
47
+ { relations = [], dynamicProperties = {}, properties = {} },
48
48
  linkProps
49
49
  ) =>
50
50
  Object.keys(props).map(base => {
51
51
  const nestedProps = props[base];
52
52
  const hasLink = !!linkProps.find(linkProp => linkProp.includes(base));
53
+ const matchingProperty = !!properties[base];
53
54
  const matchingRelation = relations.find(({ localField }) => localField === base);
54
55
  const matchingDynamicProp = Object.keys(dynamicProperties).find(
55
56
  dynamicKey => dynamicKey === base
56
57
  );
57
58
 
58
59
  if (matchingRelation && !nestedProps.includes('id')) nestedProps.push('id');
59
- if (hasLink && (!!matchingRelation || !!matchingDynamicProp)) nestedProps.push('url');
60
+ if (hasLink && (!!matchingProperty || !!matchingRelation || !!matchingDynamicProp))
61
+ nestedProps.push('url');
60
62
  const jointNestedProps = nestedProps.join(',');
61
63
  if (base === 'category' && shouldAddCategoryProps)
62
64
  return `${base}{${jointNestedProps}, ${categoryProps}}`;
@@ -31,8 +31,9 @@ const buildSetFilters = ({
31
31
  }
32
32
 
33
33
  const shouldApplyFilterValues = filterBy.length && filterByProperty.length;
34
- const listFilterValues = shouldApplyFilterValues ? getFilterValues(filterBy) : {};
34
+ if (!shouldApplyFilterValues) return { checkboxFilters, listFilterValues: {} };
35
35
 
36
+ const listFilterValues = getFilterValues(filterBy);
36
37
  return { checkboxFilters, listFilterValues };
37
38
  };
38
39
 
@@ -2,10 +2,11 @@ import isFilterEntitysId from './is-filter-entitys-id';
2
2
  import getFilterProps from './get-filter-props';
3
3
  import { ID } from '../constants';
4
4
 
5
- const getQueryProps = (inheritedFilters, currentSchema, filterEntitySchema) => {
5
+ const getQueryProps = (inheritedFilters, currentSchema, filterEntitySchema = {}) => {
6
6
  if (!currentSchema || !inheritedFilters.length) return ID;
7
7
 
8
- const { identifier: currentEntityId } = currentSchema;
8
+ const { identifier: currentEntityId, properties } = currentSchema;
9
+ const { identifier: filterEntityId } = filterEntitySchema;
9
10
 
10
11
  return inheritedFilters.reduce((acc, filter) => {
11
12
  const {
@@ -17,12 +18,19 @@ const getQueryProps = (inheritedFilters, currentSchema, filterEntitySchema) => {
17
18
  relationForeignKeys,
18
19
  shouldIgnoreFilter
19
20
  } = getFilterProps(filter, currentSchema, filterEntitySchema);
20
-
21
21
  if (shouldIgnoreFilter) return acc;
22
22
  if (relationForeignKeys && relationForeignKeys.length) {
23
23
  return `${acc} ${relationForeignKeys.join(' ')}`;
24
24
  }
25
-
25
+ if (filterName === ID) {
26
+ const queryValue = Object.keys(properties).find(
27
+ propKey =>
28
+ properties[propKey] &&
29
+ properties[propKey].relation &&
30
+ properties[propKey].relation.entityIdentifier === filterEntityId
31
+ );
32
+ if (queryValue) return `${acc} ${queryValue} `;
33
+ }
26
34
  const queryProp = relationEntityName ? `${relationName} { ${relationProp} }` : filterName;
27
35
  const queryPropFinalValue =
28
36
  isEntityItself && isFilterEntitysId(filterName, currentEntityId) ? ID : queryProp;
@@ -0,0 +1,72 @@
1
+ import '@testing-library/jest-dom/extend-expect';
2
+ import getUpdatedItemsToDisplay from '../../../../../../src/components/Card/helpers/get-updated-items-to-display';
3
+
4
+ const mockedProps = {
5
+ itemsToDisplay: [
6
+ {
7
+ displayItems: ['54321']
8
+ }
9
+ ],
10
+ parentEntityData: {
11
+ authorIds: ['12345']
12
+ },
13
+ parentSchema: {
14
+ properties: {
15
+ authorIds: {
16
+ relation: {
17
+ entityIdentifier: 'author'
18
+ }
19
+ }
20
+ }
21
+ },
22
+ inheritedFilters: ['id/author']
23
+ };
24
+
25
+ describe('getUpdatedItemsToDisplay helper function', () => {
26
+ it('should return empty array if no props passed', () => {
27
+ const emptyArray = getUpdatedItemsToDisplay({});
28
+ expect(emptyArray).toEqual([]);
29
+ });
30
+
31
+ it('should return old itemsToDisplay itemsToDisplay if no idProp match, no parentSchema or no parentEntityData', () => {
32
+ const onlyItemsToDisplayPassed = getUpdatedItemsToDisplay({
33
+ itemsToDisplay: mockedProps.itemsToDisplay
34
+ });
35
+ const noIdPropMatch = getUpdatedItemsToDisplay({
36
+ ...mockedProps,
37
+ inheritedFilters: ['notid/author']
38
+ });
39
+ const noParentSchema = getUpdatedItemsToDisplay({
40
+ ...mockedProps,
41
+ parentSchema: null
42
+ });
43
+ const noParentEntityData = getUpdatedItemsToDisplay({
44
+ ...mockedProps,
45
+ parentEntityData: null
46
+ });
47
+ expect(onlyItemsToDisplayPassed).toEqual(mockedProps.itemsToDisplay);
48
+ expect(noIdPropMatch).toEqual(mockedProps.itemsToDisplay);
49
+ expect(noParentSchema).toEqual(mockedProps.itemsToDisplay);
50
+ expect(noParentEntityData).toEqual(mockedProps.itemsToDisplay);
51
+ });
52
+
53
+ it('should return old itemsToDisplay if parentSchema has no propMatch with idProp entity', () => {
54
+ const sameItemsToDisplay = getUpdatedItemsToDisplay({
55
+ ...mockedProps,
56
+ inheritedFilters: ['id/noentitymatch']
57
+ });
58
+ expect(sameItemsToDisplay).toEqual(mockedProps.itemsToDisplay);
59
+ });
60
+
61
+ it('should return updated itemsToDisplay otherwise', () => {
62
+ const sameItemsToDisplay = getUpdatedItemsToDisplay({
63
+ ...mockedProps
64
+ });
65
+ expect(sameItemsToDisplay).toEqual([
66
+ ...mockedProps.itemsToDisplay,
67
+ {
68
+ displayItems: ['12345']
69
+ }
70
+ ]);
71
+ });
72
+ });
@@ -182,6 +182,31 @@ describe('get card render props', () => {
182
182
  'id,name,url,sponsored,featured,category{name,listingPageId,listingPageEntity, id publishedListingPage{id, url}},address{country,id}'
183
183
  );
184
184
  });
185
+
186
+ it('should url props where enableLink is set', () => {
187
+ const _data = {
188
+ getEntitySchema: {
189
+ interfaces: [CONTENT_INTERFACE],
190
+ properties: {
191
+ id: 'id',
192
+ nestedProperty: {
193
+ type: 'object'
194
+ }
195
+ },
196
+ relations: [{ localField: 'address' }],
197
+ dynamicProperties: {
198
+ nestedDynamicProperty: {
199
+ type: 'object'
200
+ }
201
+ }
202
+ }
203
+ };
204
+ const linkProps = ['nestedProperty.title', 'nestedDynamicProperty.title', 'address.title'];
205
+ const query = buildPropsQuery(_data, linkProps, {}, linkProps);
206
+ expect(query).toEqual(
207
+ 'id,name,url,sponsored,featured,nestedProperty{title,url},nestedDynamicProperty{title,url},address{title,id,url}'
208
+ );
209
+ });
185
210
  });
186
211
 
187
212
  function testUrlProperty({ extraProperties = {}, dynamicProperties = {}, cardProps }) {