From faccd129f5e71330df6de85156dd44f43c524258 Mon Sep 17 00:00:00 2001 From: Josh <37798644+joshuaellis@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:09:32 +0000 Subject: [PATCH 1/2] fix: filter path because a dynamic zone component is a component but it should be classified as a dynamic zone --- .../DynamicZone/components/DynamicComponent.js | 2 +- .../utils/recursivelyFindPathsBasedOnCondition.js | 9 ++++++++- .../RelationInputDataManager/RelationInputDataManager.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/admin/admin/src/content-manager/components/DynamicZone/components/DynamicComponent.js b/packages/core/admin/admin/src/content-manager/components/DynamicZone/components/DynamicComponent.js index 5eea846d45..cccefa2ce5 100644 --- a/packages/core/admin/admin/src/content-manager/components/DynamicZone/components/DynamicComponent.js +++ b/packages/core/admin/admin/src/content-manager/components/DynamicZone/components/DynamicComponent.js @@ -111,7 +111,7 @@ const DynamicZoneComponent = ({ } + startIcon={icon && } action={ {showDownIcon && ( diff --git a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/recursivelyFindPathsBasedOnCondition.js b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/recursivelyFindPathsBasedOnCondition.js index f1ee85ccbf..4a3fe11017 100644 --- a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/recursivelyFindPathsBasedOnCondition.js +++ b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/recursivelyFindPathsBasedOnCondition.js @@ -55,8 +55,15 @@ const recursivelyFindPathsBasedOnConditionSetup = (components, predicate = () => * * NOTE: we don't need to know the path to the `array` because it's about data shape not about the actual data */ - }).map((path) => path.split(`${componentName}.`)[1]); + }).map((path) => { + return path.split(`${componentName}.`)[1]; + }); }) + /** + * We filter because this will give you `dynamiczone.undefined` because the dynamic_zone component + * is not required to be returned in this circumstance. + */ + .filter((path) => Boolean(path)) .map((path) => `${key}.${path}`); acc = [...acc, attributesInDynamicComponents]; diff --git a/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js b/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js index 91004b657a..63ac4098af 100644 --- a/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js +++ b/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js @@ -40,7 +40,7 @@ export const RelationInputDataManager = ({ const { connectRelation, disconnectRelation, loadRelation, modifiedData, slug, initialData } = useCMEditViewDataManager(); - const relationsFromModifiedData = get(modifiedData, name) ?? []; + const relationsFromModifiedData = get(modifiedData, name, []); const currentLastPage = Math.ceil(get(initialData, name, []).length / RELATIONS_TO_DISPLAY); From d5ef35ed03dbe997dad3ee7e9ffb60aaf242d3f4 Mon Sep 17 00:00:00 2001 From: Josh <37798644+joshuaellis@users.noreply.github.com> Date: Fri, 9 Dec 2022 16:29:37 +0000 Subject: [PATCH 2/2] chore: add tests --- ...cursivelyFindPathsBasedOnCondition.test.js | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js index 5d2bb7a886..bd3f4a1fea 100644 --- a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js +++ b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/utils/tests/recursivelyFindPathsBasedOnCondition.test.js @@ -611,4 +611,79 @@ describe('recursivelyFindPathsBasedOnCondition', () => { expect(actual).toEqual(['dynamic_relations', 'dynamic_relations.simple']); }); }); + + describe('components', () => { + test('given that a component exits, it should be returned', () => { + const components = { + 'basic.simple': { + attributes: { + id: { + type: 'integer', + }, + categories: { + type: 'relation', + relation: 'oneToMany', + target: 'api::category.category', + targetModel: 'api::category.category', + relationType: 'oneToMany', + }, + my_name: { + type: 'string', + }, + }, + }, + }; + + const attributes = { + relation: { + type: 'component', + component: 'basic.simple', + repeatable: false, + }, + }; + + const actual = recursivelyFindPathsBasedOnCondition( + components, + (value) => value.type === 'component' && !value.repeatable + )(attributes); + + expect(actual).toEqual(['relation']); + }); + + test('given that a component is in a dynamic zone it should not return the name of the dynamic zone', () => { + const components = { + 'basic.simple': { + attributes: { + id: { + type: 'integer', + }, + categories: { + type: 'relation', + relation: 'oneToMany', + target: 'api::category.category', + targetModel: 'api::category.category', + relationType: 'oneToMany', + }, + my_name: { + type: 'string', + }, + }, + }, + }; + + const attributes = { + dynamic_relations: { + type: 'dynamiczone', + components: ['basic.simple'], + }, + }; + + const actual = recursivelyFindPathsBasedOnCondition( + components, + (value) => value.type === 'component' && value.repeatable === false + )(attributes); + + expect(actual).toEqual([]); + }); + }); });