Skip to content

Commit

Permalink
Add check for edit CSS capability to overflow menu (#47714)
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz authored Feb 3, 2023
1 parent c6d80e2 commit 127e3d3
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { experiments as blockEditorExperiments } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import { moreVertical } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -45,6 +46,20 @@ const { Slot: GlobalStylesMenuSlot, Fill: GlobalStylesMenuFill } =

function GlobalStylesActionMenu() {
const { toggle } = useDispatch( preferencesStore );
const { canEditCSS } = useSelect( ( select ) => {
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
select( coreStore );

const globalStylesId = __experimentalGetCurrentGlobalStylesId();
const globalStyles = globalStylesId
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
: undefined;

return {
canEditCSS:
!! globalStyles?._links?.[ 'wp:action-edit-css' ] ?? false,
};
}, [] );
const { useGlobalStylesReset } = unlock( blockEditorExperiments );
const [ canReset, onReset ] = useGlobalStylesReset();
const { goTo } = useNavigator();
Expand All @@ -65,10 +80,14 @@ function GlobalStylesActionMenu() {
onClick: () =>
toggle( 'core/edit-site', 'welcomeGuideStyles' ),
},
{
title: __( 'Additional CSS' ),
onClick: loadCustomCSS,
},
...( canEditCSS
? [
{
title: __( 'Additional CSS' ),
onClick: loadCustomCSS,
},
]
: [] ),
] }
/>
</GlobalStylesMenuFill>
Expand Down

1 comment on commit 127e3d3

@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 127e3d3.
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/4080267326
📝 Reported issues:

Please sign in to comment.