mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 23:44:08 +00:00
40 lines
956 B
JavaScript
40 lines
956 B
JavaScript
import { get, isEmpty } from 'lodash';
|
|
|
|
/* eslint-disable no-restricted-syntax */
|
|
|
|
const createAttributesLayout = (currentLayout, attributes) => {
|
|
const getType = name => get(attributes, [name, 'type'], '');
|
|
let currentRowIndex = 0;
|
|
const newLayout = [];
|
|
|
|
for (let row of currentLayout) {
|
|
const hasDynamicZone = row.some(
|
|
({ name }) => getType(name) === 'dynamiczone'
|
|
);
|
|
|
|
if (!newLayout[currentRowIndex]) {
|
|
newLayout[currentRowIndex] = [];
|
|
}
|
|
|
|
if (hasDynamicZone) {
|
|
currentRowIndex =
|
|
currentRowIndex === 0 && isEmpty(newLayout[0])
|
|
? 0
|
|
: currentRowIndex + 1;
|
|
|
|
if (!newLayout[currentRowIndex]) {
|
|
newLayout[currentRowIndex] = [];
|
|
}
|
|
newLayout[currentRowIndex].push(row);
|
|
|
|
currentRowIndex += 1;
|
|
} else {
|
|
newLayout[currentRowIndex].push(row);
|
|
}
|
|
}
|
|
|
|
return newLayout.filter(arr => arr.length > 0);
|
|
};
|
|
|
|
export default createAttributesLayout;
|