Skip to content

Commit

Permalink
Add setting unwantedControlPanelsFields and use it in the function fi…
Browse files Browse the repository at this point in the history
…lterControlPanelsSchema (#4819)

Co-authored-by: Steve Piercy <[email protected]>
  • Loading branch information
wesleybl and stevepiercy authored Aug 24, 2024
1 parent 73ebaca commit a79ebb4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 44 deletions.
8 changes: 7 additions & 1 deletion docs/source/configuration/settings-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ 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.
A schema factory for a control panel.
It is used internally, to tweak the schemas provided by the `@controlpanels` endpoint, making them fit for Volto.
It uses the `unwantedControlPanelsFields` setting.
unwantedControlPanelsFields
Control panels' fields that are not used in Volto.
It is used internally by the `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
1 change: 1 addition & 0 deletions packages/volto/news/4819.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add setting `unwantedControlPanelsFields` and use it in the function `filterControlPanelsSchema`. @wesleybl
91 changes: 48 additions & 43 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 @@ -53,62 +54,66 @@ export const filterControlPanels = (controlpanels = []) => {
);
};

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',
],
navigation: [
'generate_tabs',
'navigation_depth',
'sort_tabs_on',
'sort_tabs_reversed',
'sitemap_depth',
],
};

// 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',
],
navigation: [
'generate_tabs',
'navigation_depth',
'sort_tabs_on',
'sort_tabs_reversed',
'sitemap_depth',
],
};
const { unwantedControlPanelsFields } = config.settings;

// Creates modified version of properties object
const newPropertiesObj = Object.fromEntries(
Object.entries(controlpanel.schema.properties).filter(
([key, val]) => !(unwantedSettings[panelType] || []).includes(key),
([key, _val]) =>
!(unwantedControlPanelsFields[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),
(field) =>
!(unwantedControlPanelsFields[panelType] || []).includes(field),
);
};
// Creates modified version of fieldsets array
Expand Down
2 changes: 2 additions & 0 deletions packages/volto/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
controlPanelsIcons,
filterControlPanels,
filterControlPanelsSchema,
unwantedControlPanelsFields,
} from './ControlPanels';

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

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

0 comments on commit a79ebb4

Please sign in to comment.