soupette f50f89f0a8 Update eslint configuration
Signed-off-by: soupette <cyril.lpz@gmail.com>
2020-01-21 16:03:31 +01:00

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;