fix: dynamic zone component data (#16969)

This commit is contained in:
Josh 2023-06-09 15:45:06 +01:00 committed by GitHub
parent 80258ecc38
commit ce0cc74e94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 14 deletions

View File

@ -43,7 +43,7 @@ const DynamicZone = ({ name, labelAction, fieldSchema, metadatas }) => {
[modifiedData, name]
);
const { getComponentLayout } = useContentTypeLayout();
const { getComponentLayout, components: allComponents } = useContentTypeLayout();
/**
* @type {Record<string, Array<{category: string; info: unknown, attributes: Record<string, unknown>}>>}
@ -94,19 +94,11 @@ const DynamicZone = ({ name, labelAction, fieldSchema, metadatas }) => {
const componentLayoutData = getComponentLayout(componentUid);
const allComponents = Object.values(dynamicComponentsByCategory).reduce((acc, components) => {
const componentObjects = components.reduce((acc, { componentUid, attributes }) => {
acc[componentUid] = {
attributes,
uid: componentUid,
};
return acc;
}, {});
return { ...acc, ...componentObjects };
}, {});
/**
* You have to pass _every component_ because the EditViewDataManager is not part of redux
* and you could have a dynamic component option that contains a component that is not part
* of the former list. Therefore it's schema is inaccessible leading to a crash.
*/
addComponentToDynamicZone(name, componentLayoutData, allComponents, hasError, position);
};

View File

@ -39,6 +39,7 @@ jest.mock('@strapi/helper-plugin', () => ({
jest.mock('../../../hooks', () => ({
...jest.requireActual('../../../hooks'),
useContentTypeLayout: jest.fn().mockReturnValue({
components: {},
getComponentLayout: jest.fn().mockImplementation((componentUid) => layoutData[componentUid]),
}),
}));