Skip to content

Commit

Permalink
Replaces filterControlPanelsSchema setting by
Browse files Browse the repository at this point in the history
unwantedControlPanelsFields

filterControlPanelsSchema has been migrated to Controlpanel.jsx and uses
the unwantedControlPanelsFields setting. So, if any portal wants to add
fields in the Control Panel, it will be necessary to customize only the
unwantedControlPanelsFields configuration, instead of customizing the
entire filterControlPanelsSchema function.
  • Loading branch information
wesleybl committed Apr 16, 2024
1 parent 72bc909 commit 26c4c02
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 70 deletions.
4 changes: 2 additions & 2 deletions docs/source/configuration/settings-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ 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.
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.
errorHandlers
A list of error handlers that will be called when there is an unhandled exception. Each error handler is a function that
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/4819.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replaces ``filterControlPanelsSchema`` setting by ``unwantedControlPanelsFields`. @wesleybl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,39 @@ 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
Expand Down Expand Up @@ -149,8 +182,6 @@ class Controlpanel extends Component {
* @returns {string} Markup for the component.
*/
render() {
const { filterControlPanelsSchema } = config.settings;

if (this.props.controlpanel) {
return (
<div id="page-controlpanel">
Expand Down
95 changes: 33 additions & 62 deletions packages/volto/src/config/ControlPanels.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,66 +53,37 @@ export const filterControlPanels = (controlpanels) => {
);
};

// Filters props.controlpanel.schema to only valid/relevant fields
export const filterControlPanelsSchema = (controlpanel) => {
const panelType = controlpanel['@id'].split('/').pop();

const unwantedSettings = {
language: ['display_flags', 'always_show_selector'],
search: ['enable_livesearch'],
site: [
'display_publication_date_in_byline',
'icon_visibility',
'thumb_visibility',
'no_thumbs_portlet',
'no_thumbs_lists',
'no_thumbs_summary',
'no_thumbs_tables',
'thumb_scale_portlet',
'thumb_scale_listing',
'thumb_scale_table',
'thumb_scale_summary',
'toolbar_position',
'toolbar_logo',
'default_page',
'site_favicon',
'site_favicon_mimetype',
'exposeDCMetaTags',
'enable_sitemap',
'robots_txt',
'webstats_js',
],
editing: ['available_editors', 'default_editor', 'ext_editor'],
imaging: [
'highpixeldensity_scales',
'quality_2x',
'quality_3x',
'picture_variants',
'image_captioning',
],
};

// Creates modified version of properties object
const newPropertiesObj = Object.fromEntries(
Object.entries(controlpanel.schema.properties).filter(
([key, val]) => !(unwantedSettings[panelType] || []).includes(key),
),
);
// Filters props.controlpanel.schema.fieldsets.fields to only valid/relevant fields
const filterFields = (fields) => {
return fields.filter(
(field) => !(unwantedSettings[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,
};
export const unwantedControlPanelsFields = {
language: ['display_flags', 'always_show_selector'],
search: ['enable_livesearch'],
site: [
'display_publication_date_in_byline',
'icon_visibility',
'thumb_visibility',
'no_thumbs_portlet',
'no_thumbs_lists',
'no_thumbs_summary',
'no_thumbs_tables',
'thumb_scale_portlet',
'thumb_scale_listing',
'thumb_scale_table',
'thumb_scale_summary',
'toolbar_position',
'toolbar_logo',
'default_page',
'site_favicon',
'site_favicon_mimetype',
'exposeDCMetaTags',
'enable_sitemap',
'robots_txt',
'webstats_js',
],
editing: ['available_editors', 'default_editor', 'ext_editor'],
imaging: [
'highpixeldensity_scales',
'quality_2x',
'quality_3x',
'picture_variants',
'image_captioning',
],
};
4 changes: 2 additions & 2 deletions packages/volto/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { styleClassNameConverters, styleClassNameExtenders } from './Style';
import {
controlPanelsIcons,
filterControlPanels,
filterControlPanelsSchema,
unwantedControlPanelsFields,
} from './ControlPanels';

import applyAddonConfiguration, { addonsInfo } from 'load-volto-addons';
Expand Down Expand Up @@ -151,7 +151,7 @@ let config = {
controlpanels: [],
controlPanelsIcons,
filterControlPanels,
filterControlPanelsSchema,
unwantedControlPanelsFields,
externalRoutes: [
// URL to be considered as external
// {
Expand Down
4 changes: 2 additions & 2 deletions packages/volto/test-setup-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import {
controlPanelsIcons,
filterControlPanels,
filterControlPanelsSchema,
unwantedControlPanelsFields,
} from '@plone/volto/config/ControlPanels';

import ListingBlockSchema from '@plone/volto/components/manage/Blocks/Listing/schema';
Expand Down Expand Up @@ -47,7 +47,7 @@ config.set('settings', {
},
controlPanelsIcons,
filterControlPanels,
filterControlPanelsSchema,
unwantedControlPanelsFields,
apiExpanders: [],
downloadableObjects: ['File'],
viewableInBrowserObjects: [],
Expand Down

0 comments on commit 26c4c02

Please sign in to comment.