Skip to content

Commit

Permalink
Turn off DFM for style book and style editing (#52117)
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu authored Jul 3, 2023
1 parent eee507a commit afa9979
Showing 1 changed file with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,27 @@ export function SidebarNavigationItemGlobalStyles( props ) {
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const { createNotice } = useDispatch( noticesStore );
const { set: setPreference } = useDispatch( preferencesStore );
const { hasGlobalStyleVariations, isDistractionFree } = useSelect(
( select ) => ( {
hasGlobalStyleVariations:
!! select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
isDistractionFree: select( preferencesStore ).get(
editSiteStore.name,
'distractionFree'
),
} ),
const { get: getPrefference } = useSelect( preferencesStore );

const turnOffDistractionFreeMode = useCallback( () => {
const isDistractionFree = getPrefference(
editSiteStore.name,
'distractionFree'
);
if ( ! isDistractionFree ) {
return;
}
setPreference( editSiteStore.name, 'distractionFree', false );
createNotice( 'info', __( 'Distraction free mode turned off' ), {
isDismissible: true,
type: 'snackbar',
} );
}, [ createNotice, setPreference, getPrefference ] );
const hasGlobalStyleVariations = useSelect(
( select ) =>
!! select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
[]
);
if ( hasGlobalStyleVariations ) {
Expand All @@ -63,19 +73,7 @@ export function SidebarNavigationItemGlobalStyles( props ) {
<SidebarNavigationItem
{ ...props }
onClick={ () => {
// Disable distraction free mode.
if ( isDistractionFree ) {
setPreference(
editSiteStore.name,
'distractionFree',
false
);
createNotice(
'info',
__( 'Distraction free mode turned off.' ),
{ type: 'snackbar' }
);
}
turnOffDistractionFreeMode();
// Switch to edit mode.
setCanvasMode( 'edit' );
// Open global styles sidebar.
Expand Down Expand Up @@ -170,6 +168,9 @@ export default function SidebarNavigationScreenGlobalStyles() {
const { setCanvasMode, setEditorCanvasContainerView } = unlock(
useDispatch( editSiteStore )
);
const { createNotice } = useDispatch( noticesStore );
const { set: setPreference } = useDispatch( preferencesStore );
const { get: getPrefference } = useSelect( preferencesStore );

const isStyleBookOpened = useSelect(
( select ) =>
Expand All @@ -178,14 +179,28 @@ export default function SidebarNavigationScreenGlobalStyles() {
[]
);

const openGlobalStyles = useCallback(
async () =>
Promise.all( [
setCanvasMode( 'edit' ),
openGeneralSidebar( 'edit-site/global-styles' ),
] ),
[ setCanvasMode, openGeneralSidebar ]
);
const turnOffDistractionFreeMode = useCallback( () => {
const isDistractionFree = getPrefference(
editSiteStore.name,
'distractionFree'
);
if ( ! isDistractionFree ) {
return;
}
setPreference( editSiteStore.name, 'distractionFree', false );
createNotice( 'info', __( 'Distraction free mode turned off' ), {
isDismissible: true,
type: 'snackbar',
} );
}, [ createNotice, setPreference, getPrefference ] );

const openGlobalStyles = useCallback( async () => {
turnOffDistractionFreeMode();
return Promise.all( [
setCanvasMode( 'edit' ),
openGeneralSidebar( 'edit-site/global-styles' ),
] );
}, [ setCanvasMode, openGeneralSidebar, turnOffDistractionFreeMode ] );

const openStyleBook = useCallback( async () => {
await openGlobalStyles();
Expand Down

1 comment on commit afa9979

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in afa9979.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5444392422
📝 Reported issues:

Please sign in to comment.