diff --git a/client/config/index.js b/client/config/index.js index 66bcd9a57b0255..6323406e6eda09 100644 --- a/client/config/index.js +++ b/client/config/index.js @@ -73,3 +73,5 @@ const configApi = createConfig( configData ); export default configApi; export const isEnabled = configApi.isEnabled; +export const enable = configApi.enable; +export const disable = configApi.disable; diff --git a/client/lib/create-config/index.js b/client/lib/create-config/index.js index 37422582e2e524..a7add4cb429fa4 100644 --- a/client/lib/create-config/index.js +++ b/client/lib/create-config/index.js @@ -66,9 +66,23 @@ const config = ( data ) => ( key ) => { const isEnabled = ( data ) => ( feature ) => ( data.features && !! data.features[ feature ] ) || false; +const enable = ( data ) => ( feature ) => { + if ( data.features ) { + data.features[ feature ] = true; + } +}; + +const disable = ( data ) => ( feature ) => { + if ( data.features ) { + data.features[ feature ] = false; + } +}; + module.exports = ( data ) => { const configApi = config( data ); configApi.isEnabled = isEnabled( data ); + configApi.enable = enable( data ); + configApi.disable = disable( data ); return configApi; }; diff --git a/client/my-sites/sidebar-unified/index.jsx b/client/my-sites/sidebar-unified/index.jsx index 1ec51b739e1982..94f6dc4d35d563 100644 --- a/client/my-sites/sidebar-unified/index.jsx +++ b/client/my-sites/sidebar-unified/index.jsx @@ -12,6 +12,7 @@ */ import React from 'react'; import { useSelector } from 'react-redux'; +import { useState } from '@wordpress/element'; /** * Internal dependencies @@ -30,8 +31,10 @@ import Spinner from 'calypso/components/spinner'; import { itemLinkMatches } from '../sidebar/utils'; import { getSidebarIsCollapsed } from 'calypso/state/ui/selectors'; import './style.scss'; +import config from 'calypso/config'; export const MySitesSidebarUnified = ( { path } ) => { + const [ renderCount, setRenderCount ] = useState( 0 ); const menuItems = useSiteMenuItems(); const isAllDomainsView = useDomainsViewStatus(); const isRequestingMenu = useSelector( getIsRequestingAdminMenu ); @@ -75,6 +78,34 @@ export const MySitesSidebarUnified = ( { path } ) => { return ; } ) } +
  • + Feature "foo" is: { config.isEnabled( 'foo' ) ? 'ON' : 'OFF' } +
    + setRenderCount( renderCount + 1 ) /* Pass accessibility lint */ } + onClick={ () => { + config.enable( 'foo' ); + setRenderCount( renderCount + 1 ); // Force Rerender, since config changes don't + } } + > + Click to Enable + +
    + setRenderCount( renderCount + 1 ) } + onClick={ () => { + config.disable( 'foo' ); + setRenderCount( renderCount + 1 ); // Force Rerender, since config changes don't + } } + > + Click to Disable + +
    +
  • ); };