migrate editRelations to edit during configurationSync

This commit is contained in:
Pierre Noël 2022-08-04 12:11:57 +02:00
parent 68fa694345
commit db1bf34f2a
2 changed files with 5 additions and 25 deletions

View File

@ -139,11 +139,6 @@ const hasEditableAttribute = (schema, name) => {
return false;
}
if (isRelation(schema.attributes[name])) {
if (schema.modelType === 'component') return true;
return false;
}
return true;
};

View File

@ -42,9 +42,8 @@ const getDefaultFieldSize = type => {
async function createDefaultLayouts(schema) {
return {
list: createDefaultListLayout(schema),
editRelations: createDefaultEditRelationsLayout(schema),
edit: createDefaultEditLayout(schema),
..._.pick(_.get(schema, ['config', 'layouts'], {}), ['list', 'edit', 'editRelations']),
..._.pick(_.get(schema, ['config', 'layouts'], {}), ['list', 'edit']),
};
}
@ -54,12 +53,6 @@ function createDefaultListLayout(schema) {
.slice(0, DEFAULT_LIST_LENGTH);
}
function createDefaultEditRelationsLayout(schema) {
if (schema.modelType === 'component') return [];
return Object.keys(schema.attributes).filter(name => hasRelationAttribute(schema, name));
}
const rowSize = els => els.reduce((sum, el) => sum + el.size, 0);
function createDefaultEditLayout(schema) {
@ -77,9 +70,12 @@ function syncLayouts(configuration, schema) {
let cleanList = list.filter(attr => isListable(schema, attr));
// TODO V5: remove editRelations
let cleanEditRelations = editRelations.filter(attr => hasRelationAttribute(schema, attr));
let elementsToReAppend = [];
// backward compatibility with when relations were on the side of the layout
// it migrates the displayed relations to the main edit layout
let elementsToReAppend = [...cleanEditRelations];
let cleanEdit = [];
for (let row of edit) {
let newRow = [];
@ -122,13 +118,6 @@ function syncLayouts(configuration, schema) {
);
}
// add new relations to layout
if (schema.modelType !== 'component') {
const newRelations = newAttributes.filter(key => hasRelationAttribute(schema, key));
cleanEditRelations = _.uniq(cleanEditRelations.concat(newRelations));
}
// add new attributes to edit view
const newEditAttributes = newAttributes.filter(key => hasEditableAttribute(schema, key));
@ -137,10 +126,6 @@ function syncLayouts(configuration, schema) {
return {
list: cleanList.length > 0 ? cleanList : createDefaultListLayout(schema),
edit: cleanEdit.length > 0 ? cleanEdit : createDefaultEditLayout(schema),
editRelations:
editRelations.length === 0 || cleanEditRelations.length > 0
? cleanEditRelations
: createDefaultEditRelationsLayout(schema),
};
}