From a3d42a0e9f3151929b04333443a1b1b195a1e838 Mon Sep 17 00:00:00 2001 From: wesleybl Date: Tue, 16 Apr 2024 17:39:57 -0300 Subject: [PATCH] Keep configuration filterControlPanelsSchema --- .../configuration/settings-reference.md | 5 ++- packages/volto/news/4819.feature | 2 +- .../manage/Controlpanels/Controlpanel.jsx | 35 ++----------------- packages/volto/src/config/ControlPanels.js | 34 ++++++++++++++++++ packages/volto/src/config/index.js | 2 ++ packages/volto/test-setup-config.js | 2 ++ 6 files changed, 45 insertions(+), 35 deletions(-) diff --git a/docs/source/configuration/settings-reference.md b/docs/source/configuration/settings-reference.md index 7c578e7748..28219d4552 100644 --- a/docs/source/configuration/settings-reference.md +++ b/docs/source/configuration/settings-reference.md @@ -205,8 +205,11 @@ controlpanels The group can be one of the default groups 'General', 'Content', 'Security', 'Add-on Configuration', 'Users and Groups' or a custom group. +filterControlPanelsSchema + A schema factory for a control panel. It is used internally, to tweak the schemas provided by the controlpanel endpoint, to make them fit for Volto. Uses the ``unwantedControlPanelsFields`` setting. + unwantedControlPanelsFields - Control panels fields that are not used on the Volto. It is used internally, to tweak the schemas provided by the controlpanel endpoint, to make them fit for Volto. + Control panels fields that are not used on the Volto. It is used internally by ``filterControlPanelsSchema`` function. errorHandlers A list of error handlers that will be called when there is an unhandled exception. Each error handler is a function that diff --git a/packages/volto/news/4819.feature b/packages/volto/news/4819.feature index 292c2386f2..afb35392f3 100644 --- a/packages/volto/news/4819.feature +++ b/packages/volto/news/4819.feature @@ -1 +1 @@ -Replaces ``filterControlPanelsSchema`` setting by ``unwantedControlPanelsFields`. @wesleybl +Add setting ``unwantedControlPanelsFields`` and use it in the function ``filterControlPanelsSchema``. @wesleybl diff --git a/packages/volto/src/components/manage/Controlpanels/Controlpanel.jsx b/packages/volto/src/components/manage/Controlpanels/Controlpanel.jsx index 5193ac004f..a55477d787 100644 --- a/packages/volto/src/components/manage/Controlpanels/Controlpanel.jsx +++ b/packages/volto/src/components/manage/Controlpanels/Controlpanel.jsx @@ -45,39 +45,6 @@ const messages = defineMessages({ }, }); -// Filters props.controlpanel.schema to only valid/relevant fields -const filterControlPanelsSchema = (controlpanel) => { - const panelType = controlpanel['@id'].split('/').pop(); - - const { unwantedControlPanelsFields } = config.settings; - - // Creates modified version of properties object - const newPropertiesObj = Object.fromEntries( - Object.entries(controlpanel.schema.properties).filter( - ([key, _val]) => - !(unwantedControlPanelsFields[panelType] || []).includes(key), - ), - ); - // Filters props.controlpanel.schema.fieldsets.fields to only valid/relevant fields - const filterFields = (fields) => { - return fields.filter( - (field) => - !(unwantedControlPanelsFields[panelType] || []).includes(field), - ); - }; - // Creates modified version of fieldsets array - const newFieldsets = controlpanel.schema.fieldsets.map((fieldset) => { - return { ...fieldset, fields: filterFields(fieldset.fields) }; - }); - - // Returns clone of props.controlpanel.schema, with updated properties/fieldsets - return { - ...controlpanel.schema, - properties: newPropertiesObj, - fieldsets: newFieldsets, - }; -}; - /** * Controlpanel class. * @class Controlpanel @@ -182,6 +149,8 @@ class Controlpanel extends Component { * @returns {string} Markup for the component. */ render() { + const { filterControlPanelsSchema } = config.settings; + if (this.props.controlpanel) { return (
diff --git a/packages/volto/src/config/ControlPanels.js b/packages/volto/src/config/ControlPanels.js index a066ffc6f8..c1ff4e20cd 100644 --- a/packages/volto/src/config/ControlPanels.js +++ b/packages/volto/src/config/ControlPanels.js @@ -19,6 +19,7 @@ import rulesSVG from '@plone/volto/icons/content-existing.svg'; import undoControlPanelSVG from '@plone/volto/icons/undo-control-panel.svg'; import linkSVG from '@plone/volto/icons/link.svg'; import relationsSVG from '@plone/volto/icons/ahead.svg'; +import config from '@plone/volto/registry'; export const controlPanelsIcons = { default: settingsSVG, @@ -87,3 +88,36 @@ export const unwantedControlPanelsFields = { 'image_captioning', ], }; + +// Filters props.controlpanel.schema to only valid/relevant fields +export const filterControlPanelsSchema = (controlpanel) => { + const panelType = controlpanel['@id'].split('/').pop(); + + const { unwantedControlPanelsFields } = config.settings; + + // Creates modified version of properties object + const newPropertiesObj = Object.fromEntries( + Object.entries(controlpanel.schema.properties).filter( + ([key, _val]) => + !(unwantedControlPanelsFields[panelType] || []).includes(key), + ), + ); + // Filters props.controlpanel.schema.fieldsets.fields to only valid/relevant fields + const filterFields = (fields) => { + return fields.filter( + (field) => + !(unwantedControlPanelsFields[panelType] || []).includes(field), + ); + }; + // Creates modified version of fieldsets array + const newFieldsets = controlpanel.schema.fieldsets.map((fieldset) => { + return { ...fieldset, fields: filterFields(fieldset.fields) }; + }); + + // Returns clone of props.controlpanel.schema, with updated properties/fieldsets + return { + ...controlpanel.schema, + properties: newPropertiesObj, + fieldsets: newFieldsets, + }; +}; diff --git a/packages/volto/src/config/index.js b/packages/volto/src/config/index.js index 32fb6bb910..ff7447fb08 100644 --- a/packages/volto/src/config/index.js +++ b/packages/volto/src/config/index.js @@ -24,6 +24,7 @@ import { styleClassNameConverters, styleClassNameExtenders } from './Style'; import { controlPanelsIcons, filterControlPanels, + filterControlPanelsSchema, unwantedControlPanelsFields, } from './ControlPanels'; @@ -151,6 +152,7 @@ let config = { controlpanels: [], controlPanelsIcons, filterControlPanels, + filterControlPanelsSchema, unwantedControlPanelsFields, externalRoutes: [ // URL to be considered as external diff --git a/packages/volto/test-setup-config.js b/packages/volto/test-setup-config.js index 40e85349e4..d6211f6ce1 100644 --- a/packages/volto/test-setup-config.js +++ b/packages/volto/test-setup-config.js @@ -19,6 +19,7 @@ import { import { controlPanelsIcons, filterControlPanels, + filterControlPanelsSchema, unwantedControlPanelsFields, } from '@plone/volto/config/ControlPanels'; @@ -47,6 +48,7 @@ config.set('settings', { }, controlPanelsIcons, filterControlPanels, + filterControlPanelsSchema, unwantedControlPanelsFields, apiExpanders: [], downloadableObjects: ['File'],