mirror of
https://github.com/strapi/strapi.git
synced 2025-09-01 04:42:58 +00:00
Created util that creates an header object from an array
This commit is contained in:
parent
7131187c5e
commit
6be5bfaa8b
@ -182,7 +182,6 @@ function List({
|
|||||||
dzName={dzName}
|
dzName={dzName}
|
||||||
isNestedInDZComponent={isNestedInDZComponent}
|
isNestedInDZComponent={isNestedInDZComponent}
|
||||||
targetUid={targetUid}
|
targetUid={targetUid}
|
||||||
// NEW props
|
|
||||||
mainTypeName={mainTypeName}
|
mainTypeName={mainTypeName}
|
||||||
editTarget={editTarget}
|
editTarget={editTarget}
|
||||||
firstLoopComponentName={firstLoopComponentName}
|
firstLoopComponentName={firstLoopComponentName}
|
||||||
@ -197,7 +196,6 @@ function List({
|
|||||||
{...item}
|
{...item}
|
||||||
customRowComponent={customRowComponent}
|
customRowComponent={customRowComponent}
|
||||||
targetUid={targetUid}
|
targetUid={targetUid}
|
||||||
// NEW PROPS
|
|
||||||
dzName={dzName}
|
dzName={dzName}
|
||||||
isNestedInDZComponent={isFromDynamicZone}
|
isNestedInDZComponent={isFromDynamicZone}
|
||||||
mainTypeName={mainTypeName}
|
mainTypeName={mainTypeName}
|
||||||
|
@ -11,6 +11,7 @@ import IconWrapper from './IconWrapper';
|
|||||||
import UpperFirst from '../UpperFirst';
|
import UpperFirst from '../UpperFirst';
|
||||||
|
|
||||||
const ModalHeader = ({ headerId, headers }) => {
|
const ModalHeader = ({ headerId, headers }) => {
|
||||||
|
console.log({ headers });
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<HeaderModalTitle style={{ textTransform: 'none' }}>
|
<HeaderModalTitle style={{ textTransform: 'none' }}>
|
||||||
|
@ -564,6 +564,7 @@ const FormModal = () => {
|
|||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (e, shouldContinue = isCreating) => {
|
const handleSubmit = async (e, shouldContinue = isCreating) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -603,7 +604,9 @@ const FormModal = () => {
|
|||||||
modalType: 'chooseAttribute',
|
modalType: 'chooseAttribute',
|
||||||
forTarget: state.forTarget,
|
forTarget: state.forTarget,
|
||||||
targetUid,
|
targetUid,
|
||||||
headerDisplayName: modifiedData.name,
|
header_label_1: modifiedData.name,
|
||||||
|
header_icon_name_1: 'contentType',
|
||||||
|
header_icon_isCustom_1: null,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} else if (isCreatingComponent) {
|
} else if (isCreatingComponent) {
|
||||||
@ -622,7 +625,9 @@ const FormModal = () => {
|
|||||||
modalType: 'chooseAttribute',
|
modalType: 'chooseAttribute',
|
||||||
forTarget: state.forTarget,
|
forTarget: state.forTarget,
|
||||||
targetUid: componentUid,
|
targetUid: componentUid,
|
||||||
headerDisplayName: modifiedData.name,
|
header_label_1: modifiedData.name,
|
||||||
|
header_icon_name_1: 'contentType',
|
||||||
|
header_icon_isCustom_1: null,
|
||||||
}),
|
}),
|
||||||
pathname: `/plugins/${pluginId}/component-categories/${category}/${componentUid}`,
|
pathname: `/plugins/${pluginId}/component-categories/${category}/${componentUid}`,
|
||||||
});
|
});
|
||||||
@ -636,6 +641,7 @@ const FormModal = () => {
|
|||||||
}
|
}
|
||||||
} else if (isEditingCategory) {
|
} else if (isEditingCategory) {
|
||||||
if (toLower(initialData.name) === toLower(modifiedData.name)) {
|
if (toLower(initialData.name) === toLower(modifiedData.name)) {
|
||||||
|
// Close the modal
|
||||||
push({ search: '' });
|
push({ search: '' });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
import { isObject } from 'lodash';
|
||||||
|
|
||||||
|
const createHeadersObjectFromArray = array => {
|
||||||
|
return array.reduce((acc, current, index) => {
|
||||||
|
const createHeaderObject = (obj, i, middle = '') =>
|
||||||
|
Object.keys(obj).reduce((acc1, current1) => {
|
||||||
|
if (isObject(obj[current1])) {
|
||||||
|
return {
|
||||||
|
...acc1,
|
||||||
|
...createHeaderObject(obj[current1], i, `_${current1}`),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = `header${middle}_${current1}_${i}`;
|
||||||
|
|
||||||
|
acc1[name] = obj[current1];
|
||||||
|
|
||||||
|
return acc1;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const headerObject = createHeaderObject(current, index + 1);
|
||||||
|
|
||||||
|
return { ...acc, ...headerObject };
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default createHeadersObjectFromArray;
|
@ -0,0 +1,45 @@
|
|||||||
|
import createHeadersObjectFromArray from '../createHeadersObjectFromArray';
|
||||||
|
|
||||||
|
describe('FormModal | utils | createHeadersArray', () => {
|
||||||
|
it('should return an headers object', () => {
|
||||||
|
const data = [
|
||||||
|
{
|
||||||
|
label: 'test',
|
||||||
|
icon: {
|
||||||
|
name: 'contentType',
|
||||||
|
isCustom: false,
|
||||||
|
},
|
||||||
|
info: {
|
||||||
|
name: null,
|
||||||
|
category: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'test2',
|
||||||
|
icon: {
|
||||||
|
name: 'book',
|
||||||
|
isCustom: true,
|
||||||
|
},
|
||||||
|
info: {
|
||||||
|
name: 'something',
|
||||||
|
category: 'default',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
header_label_1: 'test',
|
||||||
|
header_icon_name_1: 'contentType',
|
||||||
|
header_icon_isCustom_1: false,
|
||||||
|
header_info_name_1: null,
|
||||||
|
header_info_category_1: null,
|
||||||
|
header_label_2: 'test2',
|
||||||
|
header_icon_name_2: 'book',
|
||||||
|
header_icon_isCustom_2: true,
|
||||||
|
header_info_name_2: 'something',
|
||||||
|
header_info_category_2: 'default',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(createHeadersObjectFromArray(data)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user