-
Notifications
You must be signed in to change notification settings - Fork 158
Add better support for the block editor's fullscreen mode #750
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b0fe17a
Move distributor information from the post status panel to it's own p…
38f8940
Only show the Distributor panel if we are on a supported post type
5b0d6e7
Replace inline SVG with an import. Add a webpack loader to handle SVG…
95c351b
Ensure we have a supported post status instead of just hardcoding to …
c7867ff
Change our toggle button to not only showing the admin bar (if needed…
5fae6d9
Add more robust checking of user permissions
c775660
Merge branch 'develop' into feature/gutenberg-fullscreen-support
70edf29
Move click event to the actual butto and not the container around it.…
bfc80da
Change how we add the overlay when the distributor menu is open. Inst…
4828970
Hide Distributor panel on smaller screens
48490eb
Add a slight delay around showing the overlay when triggered from a h…
8d64062
Simplify our useSelect functions and ensure we aren't passing in a st…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| import { wp, dtGutenberg } from 'window'; | ||
| import PluginIcon from '../img/icon.svg'; // eslint-disable-line no-unused-vars | ||
|
|
||
| const { Icon } = wp.components; // eslint-disable-line no-unused-vars | ||
| const { select, useSelect } = wp.data; | ||
| const { PluginDocumentSettingPanel } = wp.editPost; // eslint-disable-line no-unused-vars | ||
| const { __, sprintf } = wp.i18n; | ||
| const { registerPlugin } = wp.plugins; | ||
|
|
||
| /** | ||
| * Add ability to show the admin bar, if needed | ||
| */ | ||
| const RenderShowAdminBar = () => { // eslint-disable-line no-unused-vars | ||
| const bodyClasses = document.body.classList; | ||
| const isFullScreenMode = select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' ); | ||
| const distributorTopMenu = document.querySelector( '#wp-admin-bar-distributor' ); | ||
| const distributorAdminItem = document.querySelector( '#wp-admin-bar-distributor > a' ); | ||
|
|
||
| // Don't show anything if this is a distributed item | ||
| if ( 0 !== parseInt( dtGutenberg.syndicationTime ) ) { | ||
| return null; | ||
| } | ||
|
|
||
| if ( ! distributorTopMenu || ! distributorAdminItem ) { | ||
| return ( | ||
| <div className="distributor-toggle"> | ||
| <span>{ __( 'Refresh page to see distribution options', 'distributor' ) }</span> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="distributor-toggle"> | ||
| <button | ||
| className="components-button is-secondary" | ||
| type="button" | ||
| onClick={ () => { | ||
| const mouseEvent = new MouseEvent( 'mouseenter' ); | ||
|
|
||
| if ( isFullScreenMode ) { | ||
| bodyClasses.add( 'is-showing-distributor' ); | ||
| } else { | ||
| bodyClasses.remove( 'is-showing-distributor' ); | ||
| } | ||
|
|
||
| distributorTopMenu.classList.toggle( 'hover' ); | ||
| distributorAdminItem.dispatchEvent( mouseEvent ); | ||
| } } | ||
| > | ||
| { sprintf( __( 'Distribute %1$s', 'distributor' ), dtGutenberg.postTypeSingular || 'Content' ) } | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Render the draft message | ||
| */ | ||
| const RenderDraftMessage = () => { // eslint-disable-line no-unused-vars | ||
| if ( 0 !== parseInt( dtGutenberg.syndicationTime ) ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <p> | ||
| { __( 'Distribution options available once published', 'distributor' ) } | ||
| </p> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Render the distribution information, if needed | ||
| */ | ||
| const RenderDistributionInfo = () => { // eslint-disable-line no-unused-vars | ||
| if ( 0 < parseInt( dtGutenberg.syndicationCount ) ) { | ||
| return <RenderDistributedTo />; | ||
| } else if ( 0 !== parseInt( dtGutenberg.syndicationTime ) ) { | ||
| return <RenderDistributedFrom />; | ||
| } | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| /** | ||
| * Render the distributed to component | ||
| */ | ||
| const RenderDistributedTo = () => { // eslint-disable-line no-unused-vars | ||
| return( | ||
| <span id='distributed-to'> | ||
| { sprintf( __( 'Distributed to %1$s connection%2$s.', 'distributor' ), | ||
| dtGutenberg.syndicationCount, | ||
| '1' === dtGutenberg.syndicationCount ? '' : 's' ) } | ||
| </span> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Render the distributed from component | ||
| */ | ||
| const RenderDistributedFrom = () => { // eslint-disable-line no-unused-vars | ||
| return( | ||
| <span id='distributed-from'> | ||
| { __( 'Distributed on: ', 'distributor' ) } | ||
| <strong> { dtGutenberg.syndicationTime } </strong> | ||
| </span> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Create the Distributor icon | ||
| */ | ||
| const DistributorIcon = () => ( | ||
| <Icon | ||
| className="components-panel__icon" | ||
| icon={ <PluginIcon /> } | ||
| size={ 20 } | ||
| /> | ||
| ); | ||
|
|
||
| /** | ||
| * Add the Distributor panel to Gutenberg | ||
| */ | ||
| const DistributorPlugin = () => { | ||
| // Ensure the user has proper permissions | ||
| if ( dtGutenberg.noPermissions && 1 === parseInt( dtGutenberg.noPermissions ) ) { | ||
| return null; | ||
| } | ||
|
|
||
| const postType = useSelect( select => select( 'core/editor' ).getCurrentPostType() ); | ||
| const postStatus = useSelect( select => select( 'core/editor' ).getCurrentPostAttribute( 'status' ) ); | ||
|
|
||
| // Ensure we are on a supported post type | ||
| if ( dtGutenberg.supportedPostTypes && dtGutenberg.supportedPostTypes[ postType ] === undefined ) { | ||
| return null; | ||
| } | ||
|
|
||
| // If we are on a non-supported post status, change what we show | ||
| if ( dtGutenberg.supportedPostStati && ! dtGutenberg.supportedPostStati.includes( postStatus ) ) { | ||
| return ( | ||
| <PluginDocumentSettingPanel | ||
| title={ __( 'Distributor', 'distributor' ) } | ||
| icon={ DistributorIcon } | ||
| className="distributor-panel" | ||
| > | ||
| <RenderDraftMessage /> | ||
| <RenderDistributionInfo /> | ||
| </PluginDocumentSettingPanel> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <PluginDocumentSettingPanel | ||
| title={ __( 'Distributor', 'distributor' ) } | ||
| icon={ DistributorIcon } | ||
| className="distributor-panel" | ||
| > | ||
| <RenderShowAdminBar /> | ||
| <RenderDistributionInfo /> | ||
| </PluginDocumentSettingPanel> | ||
| ); | ||
| }; | ||
|
|
||
| registerPlugin( 'distributor-plugin', { render: DistributorPlugin } ); | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look like we haven't added Eslint rules for react yet. I think it's better to do it in this PR so we don't have to add these comments to disable Eslint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dinhtungdu Any recommendations on the best way to add these rules without impacting other things? We currently use an older version of the
@10up/eslint-configand I updated that to the latest version (following instructions here), but I find that brings over a lot of pretty strict rules, some of which I don't agree with (which is fine, that's just my opinion).But what this does mean is all the JS files will need a bunch of minor formatting changes applied in order to pass these new rules. Not sure we want all of that cleanup work on this PR, so wondering if there's either a simpler solution for now to add better React eslint rules or if we tackle this in a separate PR, one built around updating our entire build/lint process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with (1) resolving those eslint failures in a separate PR and (2) not worrying about those until the next release (aka let's not block this issue/release by those eslint issues).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think about this. Let's fix the eslint in other PR.