wp-graphql / wpgraphql-ide

A next-gen query editor for WPGraphQL 🚀
GNU General Public License v3.0
10 stars 0 forks source link

Add a button to the "Activity Bar Utilities" #111

Open josephfusco opened 5 months ago

josephfusco commented 5 months ago

Acceptance Criteria

Technical Details

const { registerActivityBarUtility } = WPGRAPHQL_IDE;

registerActivityBarUtility( 'my-button', {
  title: 'My Button',
  label: 'My Button does x, y and z',
  icon: () => {}, // name of icon from supported icon library or custom Icon component
  onClick: () => {} // event callback for the button click
} );

If the GraphiQL schema refresh button was built as a plugin, it might look like this:

import { useSelect } from '@wordpress/data';

const { registerActivityBarUtility } = WPGRAPHQL_IDE;

registerActivityBarUtility( 'refresh-schema', {
  title: 'Refresh GraphQL Schema',
  label: 'Refresh the schema from the WPGraphQL endpoint and load it into the IDE',
  icon: () => <RefreshIcon />,
  onClick: () => {
    // access redux store and execute an action (pseudo code)
    useSelect( ( select ) => {
      return select( 'whatever-store-maintains-the-schema' ).fetchSchemaOrWhatever();
    });
  }
});

Image

The list of utilities should be maintained in the Redux store, so registering a utility should modify the list of utilities in the Redux store. Similar when you call registerBlockType in Gutenberg.

Reference