diff --git a/src/welcome/admin.js b/src/welcome/admin.js index 63ee636319..6a8a079b06 100644 --- a/src/welcome/admin.js +++ b/src/welcome/admin.js @@ -29,6 +29,7 @@ import { isPro, v2disabledBlocks, defaultBreakpoints, + editorRoles, } from 'stackable' import classnames from 'classnames' import { fetchSettings, importBlocks } from '~stackable/util/admin' @@ -166,14 +167,7 @@ const SEARCH_TREE = [ groups: [ { id: 'role-manager', - children: [ - __( 'Role Manager', i18n ), - __( 'Administrator', i18n ), - __( 'Editor', i18n ), - __( 'Author', i18n ), - __( 'Contributor', i18n ), - __( 'Subscriber', i18n ), - ], + children: Object.values( editorRoles || {} ), }, ], }, @@ -185,11 +179,7 @@ const SEARCH_TREE = [ id: 'custom-fields-settings', children: [ __( 'Custom Fields', i18n ), - __( 'Administrator', i18n ), - __( 'Editor', i18n ), - __( 'Author', i18n ), - __( 'Contributor', i18n ), - __( 'Subscriber', i18n ), + ...Object.values( editorRoles || {} ), ], }, ], @@ -578,13 +568,13 @@ const Settings = () => { }, [ hasUnsavedChanges ] ) const filteredSearchTree = useMemo( () => { - if ( ! currentSearch ) { - return SEARCH_TREE - } const loweredSearch = currentSearch.toLowerCase() return SEARCH_TREE.map( tabs => { const filtedGroups = tabs.groups.map( group => { + if ( ! currentSearch ) { + return { ...group, children: null } + } const filteredChildren = group.children.filter( child => { return child.toLowerCase().includes( loweredSearch.toLowerCase() ) } ) @@ -597,6 +587,7 @@ const Settings = () => { const props = { settings, handleSettingsChange, + currentSearch, filteredSearchTree, currentTab, isFetching, @@ -643,15 +634,15 @@ const EditorSettings = props => { const editor = groups.find( group => group.id === 'editor' ) const toolbar = groups.find( group => group.id === 'toolbar' ) const inspector = groups.find( group => group.id === 'inspector' ) - const groupLength = groups.reduce( ( acc, curr ) => acc + curr.children.length, 0 ) + const hasGroupMatch = groups.some( group => group.children === null || group.children.length > 0 ) return (
{ __( 'Adjust the width of Stackable blocks here.', i18n ) }
@@ -677,7 +668,7 @@ const EditorSettings = props => { />{ __( 'You can customize some of the features and behavior of Stackable in the editor here.', i18n ) }
@@ -736,7 +727,7 @@ const EditorSettings = props => { />{ __( 'You can disable some toolbar features here.', i18n ) }
@@ -787,7 +778,7 @@ const EditorSettings = props => { /> }{ __( 'You can customize some of the features and behavior of Stackable in the inspector here.', i18n ) }
@@ -826,15 +817,15 @@ const Responsiveness = props => { const groups = filteredSearchTree.find( tab => tab.id === 'responsiveness' ).groups const dynamicBreakpoints = groups.find( group => group.id === 'dynamic-breakpoints' ) - const groupLength = groups.reduce( ( acc, curr ) => acc + curr.children.length, 0 ) + const hasGroupMatch = groups.some( group => group.children === null || group.children.length > 0 ) return (@@ -898,7 +889,7 @@ const Blocks = props => { } ) const DERIVED_BLOCKS = getAllBlocks() const groups = filteredSearchTree.find( tab => tab.id === 'blocks' ).groups - const groupLength = groups.reduce( ( acc, curr ) => acc + curr.children.length, 0 ) + const hasGroupMatch = groups.some( group => group.children === null || group.children.length > 0 ) const disabledBlocks = settings.stackable_block_states ?? {} // eslint-disable-line camelcase const [ isDisabledDialogOpen, setIsDisabledDialogOpen ] = useState( false ) @@ -1079,7 +1070,7 @@ const Blocks = props => { ) }
{ __( 'Here you can adjust some optimization settings that are performed by Stackable.', i18n ) }
@@ -1206,15 +1197,15 @@ const Optimizations = props => { const GlobalSettings = props => { const groups = props.filteredSearchTree.find( tab => tab.id === 'global-settings' ).groups const globalSettings = groups.find( group => group.id === 'global-settings' ) - const groupLength = groups.reduce( ( acc, curr ) => acc + curr.children.length, 0 ) + const hasGroupMatch = groups.some( group => group.children === null || group.children.length > 0 ) return ({ __( 'Here you can tweak Global Settings that affect the styles across your entire site.', i18n ) }
@@ -1238,7 +1229,7 @@ const GlobalSettings = props => { const RoleManager = props => { const groups = props.filteredSearchTree.find( tab => tab.id === 'role-manager' ).groups - const groupLength = groups.reduce( ( acc, curr ) => acc + curr.children.length, 0 ) + const hasGroupMatch = groups.some( group => group.children === null || group.children.length > 0 ) const propsToPass = { ...props, roleManager: groups.find( group => group.id === 'role-manager' ), @@ -1248,11 +1239,11 @@ const RoleManager = props => { return (@@ -1290,7 +1281,7 @@ const RoleManager = props => { const CustomFields = props => { const groups = props.filteredSearchTree.find( tab => tab.id === 'custom-fields-settings' ).groups - const groupLength = groups.reduce( ( acc, curr ) => acc + curr.children.length, 0 ) + const hasGroupMatch = groups.some( group => group.children === null || group.children.length > 0 ) const propsToPass = { ...props, customFields: groups.find( group => group.id === 'custom-fields-settings' ), @@ -1301,11 +1292,11 @@ const CustomFields = props => { return (
{ __( 'Here are settings for the different integrations available in Stackable.', i18n ) }
@@ -1459,19 +1450,21 @@ const AdditionalOptions = props => { const groups = filteredSearchTree.find( tab => tab.id === 'other-settings' ).groups const miscellaneous = groups.find( group => group.id === 'miscellaneous' ) const migrationSettings = groups.find( group => group.id === 'migration-settings' ) - const groupLength = groups.reduce( ( acc, curr ) => acc + curr.children.length, 0 ) + const hasGroupMatch = groups.some( group => group.children === null || group.children.length > 0 ) const searchClassname = ( label, searchedSettings ) => { - return searchedSettings.children.includes( label ) ? '' : 'ugb-admin-setting--not-highlight' + return searchedSettings.children === null || searchedSettings.children.includes( label ) + ? '' + : 'ugb-admin-setting--not-highlight' } return ({ __( 'Below are other minor settings. Some may be useful when upgrading from older versions of Stackable.', i18n ) }
@@ -1528,7 +1521,7 @@ const AdditionalOptions = props => { />{ __( 'After enabling the version 2 blocks, please refresh the page to re-fetch the blocks from the server.', i18n ) }
@@ -1592,7 +1585,7 @@ const V2Settings = props => { return (
@@ -1604,7 +1597,7 @@ const V2Settings = props => {