Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of Concept: Config Enable/Disable API #47535

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 14 additions & 0 deletions client/lib/create-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
31 changes: 31 additions & 0 deletions client/my-sites/sidebar-unified/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
import React from 'react';
import { useSelector } from 'react-redux';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -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 );
Expand Down Expand Up @@ -75,6 +78,34 @@ export const MySitesSidebarUnified = ( { path } ) => {
return <MySitesSidebarUnifiedItem key={ item.slug } selected={ isSelected } { ...item } />;
} ) }
<CollapseSidebar key="collapse" title="Collapse menu" icon="dashicons-admin-collapse" />
<li>
Feature "foo" is: { config.isEnabled( 'foo' ) ? 'ON' : 'OFF' }
<br />
<span
role="link"
tabIndex={ -10 }
onKeyDown={ () => setRenderCount( renderCount + 1 ) /* Pass accessibility lint */ }
onClick={ () => {
config.enable( 'foo' );
setRenderCount( renderCount + 1 ); // Force Rerender, since config changes don't
} }
>
Click to Enable
</span>
<br />
<span
role="link"
tabIndex={ -11 }
onKeyDown={ () => setRenderCount( renderCount + 1 ) }
onClick={ () => {
config.disable( 'foo' );
setRenderCount( renderCount + 1 ); // Force Rerender, since config changes don't
} }
>
Click to Disable
</span>
<br />
</li>
</Sidebar>
);
};
Expand Down