mirror of
https://github.com/strapi/strapi.git
synced 2025-11-16 10:07:55 +00:00
migrate editRelations to edit during configurationSync
This commit is contained in:
parent
68fa694345
commit
db1bf34f2a
@ -139,11 +139,6 @@ const hasEditableAttribute = (schema, name) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRelation(schema.attributes[name])) {
|
|
||||||
if (schema.modelType === 'component') return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -42,9 +42,8 @@ const getDefaultFieldSize = type => {
|
|||||||
async function createDefaultLayouts(schema) {
|
async function createDefaultLayouts(schema) {
|
||||||
return {
|
return {
|
||||||
list: createDefaultListLayout(schema),
|
list: createDefaultListLayout(schema),
|
||||||
editRelations: createDefaultEditRelationsLayout(schema),
|
|
||||||
edit: createDefaultEditLayout(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);
|
.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);
|
const rowSize = els => els.reduce((sum, el) => sum + el.size, 0);
|
||||||
|
|
||||||
function createDefaultEditLayout(schema) {
|
function createDefaultEditLayout(schema) {
|
||||||
@ -77,9 +70,12 @@ function syncLayouts(configuration, schema) {
|
|||||||
|
|
||||||
let cleanList = list.filter(attr => isListable(schema, attr));
|
let cleanList = list.filter(attr => isListable(schema, attr));
|
||||||
|
|
||||||
|
// TODO V5: remove editRelations
|
||||||
let cleanEditRelations = editRelations.filter(attr => hasRelationAttribute(schema, attr));
|
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 = [];
|
let cleanEdit = [];
|
||||||
for (let row of edit) {
|
for (let row of edit) {
|
||||||
let newRow = [];
|
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
|
// add new attributes to edit view
|
||||||
const newEditAttributes = newAttributes.filter(key => hasEditableAttribute(schema, key));
|
const newEditAttributes = newAttributes.filter(key => hasEditableAttribute(schema, key));
|
||||||
|
|
||||||
@ -137,10 +126,6 @@ function syncLayouts(configuration, schema) {
|
|||||||
return {
|
return {
|
||||||
list: cleanList.length > 0 ? cleanList : createDefaultListLayout(schema),
|
list: cleanList.length > 0 ? cleanList : createDefaultListLayout(schema),
|
||||||
edit: cleanEdit.length > 0 ? cleanEdit : createDefaultEditLayout(schema),
|
edit: cleanEdit.length > 0 ? cleanEdit : createDefaultEditLayout(schema),
|
||||||
editRelations:
|
|
||||||
editRelations.length === 0 || cleanEditRelations.length > 0
|
|
||||||
? cleanEditRelations
|
|
||||||
: createDefaultEditRelationsLayout(schema),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user