From db1bf34f2a17265c1df6acd60d0e72dae173c554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 4 Aug 2022 12:11:57 +0200 Subject: [PATCH] migrate editRelations to edit during configurationSync --- .../utils/configuration/attributes.js | 5 ---- .../services/utils/configuration/layouts.js | 25 ++++--------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/packages/core/content-manager/server/services/utils/configuration/attributes.js b/packages/core/content-manager/server/services/utils/configuration/attributes.js index 2f15c3d758..c1f9c266b8 100644 --- a/packages/core/content-manager/server/services/utils/configuration/attributes.js +++ b/packages/core/content-manager/server/services/utils/configuration/attributes.js @@ -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; }; diff --git a/packages/core/content-manager/server/services/utils/configuration/layouts.js b/packages/core/content-manager/server/services/utils/configuration/layouts.js index 27188370a4..3fb88efa5c 100644 --- a/packages/core/content-manager/server/services/utils/configuration/layouts.js +++ b/packages/core/content-manager/server/services/utils/configuration/layouts.js @@ -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), }; }