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

Add a button to the "Editor Toolbar" #113

Closed
10 tasks done
Tracked by #109
josephfusco opened this issue Apr 16, 2024 · 1 comment
Closed
10 tasks done
Tracked by #109

Add a button to the "Editor Toolbar" #113

josephfusco opened this issue Apr 16, 2024 · 1 comment
Assignees
Labels
type: enhancement Improvements to existing functionality

Comments

@josephfusco
Copy link
Member

josephfusco commented Apr 16, 2024

Acceptance Criteria

  • registerDocumentEditorToolbarButton() exists and is callable by 3rd party plugins
  • Function handles edge cases & invalid input
  • Existing toolbar buttons are using registerDocumentEditorToolbarButton()
  • Create e2e tests:
    • assert that private data is returned when toggle authentication button is enabled (color)
    • assert that private data is not returned when toggle authentication button disabled (grayscale)
    • assert that clipboard contains query when copy button is clicked
    • assert that malformatted query is formatted as expected when prettify button is clicked
    • assert that a valid share URL is copied to clipboard when share query button is clicked
    • assert that fragments are merged into the query as expected when the merge fragments button is clicked

Technical Details

const { registerDocumentEditorToolbarButton } = WPGRAPHQL_IDE;

registerDocumentEditorToolbarButton( 'my-editor-toolbar-button', {
  title: 'My Editor Toolbar Button',
  label: () => {},
  icon: () => {}, // name of icon from supported icon library or custom Icon component
  onClick: () => {} // callback for the button click event
} );

If we were to use this API for the auth button, it might look like this:

const { registerDocumentEditorToolbarButton } = WPGRAPHQL_IDE;

registerDocumentEditorToolbarButton( 'toggle-auth-button', {
  title: 'Toggle Authentication',
  label: () => {
    const isAuthenticated = useSelect( ( select ) => select( 'whatever-store-maintains-auth-state' ).isAuthenticated() );

    return isAuthenticated
	? 'Switch to execute as a public user'
	: 'Switch to execute as the logged-in user';
  },
  icon: () => <DynamicAvatar />,
  onClick: () => {
    useSelect( ( select ) => select( 'whatever-store-maintains-auth-state' ).toggleAuthentication() );
  }
} );

Image

The list of editor toolbar buttons should be maintained in the Redux store, so registering an editor toolbar button should modify the list of editor toolbar buttons in the Redux store. Similar when you call registerBlockType in Gutenberg.

Reference

Related

@josephfusco josephfusco mentioned this issue Apr 16, 2024
14 tasks
@josephfusco josephfusco added the type: enhancement Improvements to existing functionality label May 2, 2024
@josephfusco josephfusco self-assigned this May 2, 2024
@josephfusco
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvements to existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant