Skip to content

Commit

Permalink
Keep configuration filterControlPanelsSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleybl committed Apr 16, 2024
1 parent 26c4c02 commit 04f2756
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
5 changes: 4 additions & 1 deletion docs/source/configuration/settings-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -182,6 +149,8 @@ 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
34 changes: 34 additions & 0 deletions packages/volto/src/config/ControlPanels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};
};
2 changes: 2 additions & 0 deletions packages/volto/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { styleClassNameConverters, styleClassNameExtenders } from './Style';
import {
controlPanelsIcons,
filterControlPanels,
filterControlPanelsSchema,
unwantedControlPanelsFields,
} from './ControlPanels';

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

Expand Down Expand Up @@ -47,6 +48,7 @@ config.set('settings', {
},
controlPanelsIcons,
filterControlPanels,
filterControlPanelsSchema,
unwantedControlPanelsFields,
apiExpanders: [],
downloadableObjects: ['File'],
Expand Down

0 comments on commit 04f2756

Please sign in to comment.