@@ -25,6 +25,7 @@ import {
2525 i18n ,
2626 showProNoticesOption ,
2727 isPro ,
28+ v2disabledBlocks ,
2829} from 'stackable'
2930import classnames from 'classnames'
3031import { importBlocks } from '~stackable/util/admin'
@@ -35,6 +36,8 @@ import AdminTextSetting from '~stackable/components/admin-text-setting'
3536import AdminToolbarSetting from '~stackable/components/admin-toolbar-setting'
3637import { GettingStarted } from './getting-started'
3738import { BLOCK_STATE } from '~stackable/util/blocks'
39+ import { BlockToggler , OptimizationSettings } from '~stackable/deprecated/v2/welcome/admin'
40+ import blockData from '~stackable/deprecated/v2/welcome/blocks'
3841
3942const FREE_BLOCKS = importBlocks ( require . context ( '../block' , true , / b l o c k \. j s o n $ / ) )
4043
@@ -222,6 +225,22 @@ const SEARCH_TREE = [
222225 } ,
223226 ] ,
224227 } ,
228+ {
229+ id : 'v2-settings' ,
230+ label : __ ( 'V2 Settings' , i18n ) ,
231+ groups : [
232+ {
233+ id : 'optimizations' ,
234+ children : [
235+ __ ( 'Frontend JS & CSS Files' ) ,
236+ ] ,
237+ } ,
238+ {
239+ id : 'blocks' ,
240+ children : Object . values ( blockData ) . map ( block => block . title ) ,
241+ } ,
242+ ] ,
243+ } ,
225244]
226245
227246const BLOCK_DEPENDENCIES = {
@@ -402,6 +421,7 @@ const Sidenav = ( {
402421 currentSearch,
403422 filteredSearchTree,
404423 isSaving,
424+ hasV2Tab,
405425} ) => {
406426 const saveButtonClasses = classnames ( [
407427 's-save-changes' ,
@@ -424,6 +444,11 @@ const Sidenav = ( {
424444 { 's-sidenav-item-highlight' : isSearched } ,
425445 { 's-active' : currentTab === id } ,
426446 ] )
447+
448+ if ( id === 'v2-settings' && ! hasV2Tab ) {
449+ return null
450+ }
451+
427452 return ( < button
428453 key = { id }
429454 className = { tabClasses }
@@ -437,12 +462,14 @@ const Sidenav = ( {
437462 )
438463 } ) }
439464 < div className = "s-save-changes-wrapper" >
440- < button
441- className = { saveButtonClasses }
442- onClick = { handleSettingsSave }
443- >
444- { isSaving ? < Spinner /> : __ ( 'Save Changes' , i18n ) }
445- </ button >
465+ { currentTab !== 'v2-settings' &&
466+ < button
467+ className = { saveButtonClasses }
468+ onClick = { handleSettingsSave }
469+ >
470+ { isSaving ? < Spinner /> : __ ( 'Save Changes' , i18n ) }
471+ </ button >
472+ }
446473 </ div >
447474 </ div >
448475 </ nav >
@@ -474,6 +501,13 @@ const Settings = () => {
474501 const [ currentTab , setCurrentTab ] = useState ( 'editor-settings' )
475502 const [ currentSearch , setCurrentSearch ] = useState ( '' )
476503 const [ isSaving , setIsSaving ] = useState ( false )
504+ const [ hasV2Tab , setHasV2Tab ] = useState ( false )
505+
506+ const hasV2Compatibility = currentSettings => {
507+ return currentSettings . stackable_v2_frontend_compatibility === '1' ||
508+ currentSettings . stackable_v2_editor_compatibility === '1' ||
509+ currentSettings . stackable_v2_editor_compatibility_usage === '1'
510+ }
477511
478512 const handleSettingsChange = useCallback ( newSettings => {
479513 setSettings ( prev => ( { ...prev , ...newSettings } ) )
@@ -500,10 +534,19 @@ const Settings = () => {
500534 const settings = new models . Settings ( )
501535 settings . fetch ( ) . then ( response => {
502536 setSettings ( response )
537+ // Should only be set initially since we have to reload after setting for it to work with the backend
538+ setHasV2Tab ( hasV2Compatibility ( response ) )
503539 } )
504540 } )
505541 } , [ ] )
506542
543+ // However, when disabling V2 blocks, update the settings page to disallow further configuration
544+ useEffect ( ( ) => {
545+ if ( ! hasV2Compatibility ( settings ) ) {
546+ setHasV2Tab ( false )
547+ }
548+ } , [ settings ] )
549+
507550 const hasUnsavedChanges = useMemo ( ( ) => Object . keys ( unsavedChanges ) . length > 0 , [ unsavedChanges ] )
508551 const filteredSearchTree = useMemo ( ( ) => {
509552 if ( ! currentSearch ) {
@@ -526,6 +569,7 @@ const Settings = () => {
526569 settings,
527570 handleSettingsChange,
528571 filteredSearchTree,
572+ currentTab,
529573 }
530574
531575 return < >
@@ -537,6 +581,7 @@ const Settings = () => {
537581 currentSearch = { currentSearch }
538582 filteredSearchTree = { filteredSearchTree }
539583 isSaving = { isSaving }
584+ hasV2Tab = { hasV2Tab }
540585 />
541586 < article className = "s-box" id = { currentTab } >
542587 < Searchbar currentSearch = { currentSearch } handleSearchChange = { setCurrentSearch } />
@@ -549,6 +594,8 @@ const Settings = () => {
549594 { currentTab === 'custom-fields-settings' && < CustomFields { ...props } /> }
550595 { currentTab === 'integrations' && < Integrations { ...props } /> }
551596 { currentTab === 'other-settings' && < AdditionalOptions { ...props } /> }
597+ { /* Render the V2 settings and show/hide via CSS */ }
598+ < V2Settings { ...props } />
552599 </ article >
553600 </ >
554601}
@@ -1262,6 +1309,7 @@ const AdditionalOptions = props => {
12621309 { migrationSettings . children . length > 0 &&
12631310 < div className = "s-setting-group" >
12641311 < h3 > { __ ( 'Migration Settings' , i18n ) } </ h3 >
1312+ < p > { __ ( 'After enabling the version 2 blocks, please refresh the page to re-fetch the blocks from the server.' , i18n ) } </ p >
12651313 < p >
12661314 { __ ( 'Migrating from version 2 to version 3?' , i18n ) }
12671315
@@ -1308,8 +1356,39 @@ const AdditionalOptions = props => {
13081356 )
13091357}
13101358
1311- AdditionalOptions . defaultProps = {
1312- showProNoticesOption : false ,
1359+ const V2Settings = props => {
1360+ const groups = props . filteredSearchTree . find ( tab => tab . id === 'v2-settings' ) . groups
1361+ const optimizations = groups . find ( group => group . id === 'optimizations' )
1362+ const blocks = groups . find ( group => group . id === 'blocks' )
1363+
1364+ const classes = classnames ( [
1365+ 's-v2-settings' ,
1366+ { 's-settings-hide' : props . currentTab !== 'v2-settings' } ,
1367+ ] )
1368+
1369+ return (
1370+ < div className = { classes } >
1371+ { optimizations . children . length > 0 &&
1372+ < div className = "s-setting-group" >
1373+ < h2 > { __ ( '🏃♂️ Optimization Settings' , i18n ) } (V2)</ h2 >
1374+ < p className = "s-settings-subtitle" >
1375+ { __ ( 'Here are some settings that you can tweak to optimize Stackable.' , i18n ) }
1376+ < a href = "https://docs.wpstackable.com/article/460-how-to-use-optimization-settings?utm_source=wp-settings-global-settings& utm_campaign = learnmore & utm_medium = wp - dashboard " target = "_docs" > { __ ( 'Learn more.' , i18n ) } </ a >
1377+ < br />
1378+ < strong > { __ ( 'This only works for version 2 blocks.' , i18n ) } </ strong >
1379+ </ p >
1380+ < OptimizationSettings searchedSettings = { optimizations . children } />
1381+ </ div >
1382+ }
1383+ { blocks . children . length > 0 &&
1384+ < div className = "s-setting-group" >
1385+ < h2 > { __ ( 'Enable & Disable Blocks' , i18n ) } (V2)</ h2 >
1386+ < strong > { __ ( 'This only works for version 2 blocks.' , i18n ) } </ strong >
1387+ < BlockToggler blocks = { blockData } disabledBlocks = { v2disabledBlocks } searchedSettings = { blocks . children } />
1388+ </ div >
1389+ }
1390+ </ div >
1391+ )
13131392}
13141393
13151394// Load all the options into the UI.
0 commit comments