-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Connectors: Support non-AI provider types and add JS extensibility e2e test #76722
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
+187
−20
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e789535
Connectors: Support non-AI provider types and add JS extensibility e2…
gziolo a3ac192
Tests: Add e2e coverage for server-only connector without JS render
gziolo 85c8cc0
Update plugin header to document both test connectors
gziolo c20277f
Fix comments to accurately describe server+client merging behavior
gziolo c8444e7
Disable import/no-extraneous-dependencies for test plugin module
gziolo 5156dd8
Address PR feedback: hyphen support, type widening, and empty state fix
gziolo 6d48b73
Fix test plugin to use renamed connector props (name/logo)
gziolo 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
68 changes: 68 additions & 0 deletions
68
packages/e2e-tests/plugins/connectors-js-extensibility.php
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,68 @@ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Gutenberg Test Connectors JS Extensibility | ||
| * Plugin URI: https://github.com/WordPress/gutenberg | ||
| * Author: Gutenberg Team | ||
| * | ||
| * Registers two custom-type connectors on the server: | ||
| * | ||
| * 1. test_custom_service — also registered client-side via a script module using | ||
| * the merging strategy (two registerConnector calls with the same slug: one | ||
| * providing the render function, the other metadata). | ||
| * 2. test_server_only_service — server-only, with no client-side render function, | ||
| * so it should not display a card in the UI. | ||
| * | ||
| * @package gutenberg-test-connectors-js-extensibility | ||
| */ | ||
|
|
||
| // Register two custom-type connectors for E2E testing. | ||
| add_action( | ||
| 'wp_connectors_init', | ||
| static function ( WP_Connector_Registry $registry ) { | ||
| $registry->register( | ||
| 'test_custom_service', | ||
| array( | ||
| 'name' => 'Test Custom Service', | ||
| 'description' => 'A custom service for E2E testing.', | ||
| 'type' => 'custom_service', | ||
| 'authentication' => array( | ||
| 'method' => 'none', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $registry->register( | ||
| 'test_server_only_service', | ||
| array( | ||
| 'name' => 'Test Server Only Service', | ||
| 'description' => 'A server-only service with no JS render.', | ||
| 'type' => 'custom_service', | ||
| 'authentication' => array( | ||
| 'method' => 'none', | ||
| ), | ||
| ) | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| // Enqueue the script module on the connectors page. | ||
| add_action( | ||
| 'admin_enqueue_scripts', | ||
| static function () { | ||
| if ( ! isset( $_GET['page'] ) || 'options-connectors-wp-admin' !== $_GET['page'] ) { | ||
| return; | ||
| } | ||
|
|
||
| wp_register_script_module( | ||
| 'gutenberg-test-connectors-js-extensibility', | ||
| plugins_url( 'connectors-js-extensibility/index.mjs', __FILE__ ), | ||
| array( | ||
| array( | ||
| 'id' => '@wordpress/connectors', | ||
| 'import' => 'static', | ||
| ), | ||
| ) | ||
| ); | ||
| wp_enqueue_script_module( 'gutenberg-test-connectors-js-extensibility' ); | ||
| } | ||
| ); |
35 changes: 35 additions & 0 deletions
35
packages/e2e-tests/plugins/connectors-js-extensibility/index.mjs
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,35 @@ | ||
| /** | ||
| * Script module that demonstrates client-side connector registration. | ||
| * | ||
| * The server registers test_custom_service with its name and description. | ||
| * This module calls registerConnector() with the same slug to add a render | ||
| * function. The store merges both registrations, so the final connector | ||
| * combines the render function from JS with the metadata from PHP. | ||
| */ | ||
|
|
||
| // eslint-disable-next-line import/no-extraneous-dependencies | ||
| import { | ||
| __experimentalRegisterConnector as registerConnector, | ||
| __experimentalConnectorItem as ConnectorItem, | ||
| } from '@wordpress/connectors'; | ||
|
|
||
| const h = window.React.createElement; | ||
|
|
||
| // Register the render function for the connector. | ||
| registerConnector( 'test_custom_service', { | ||
| render: ( props ) => | ||
| h( | ||
| ConnectorItem, | ||
| { | ||
| className: 'connector-item--test_custom_service', | ||
| name: props.name, | ||
| description: props.description, | ||
| logo: props.logo, | ||
| }, | ||
| h( | ||
| 'p', | ||
| { className: 'test-custom-service-content' }, | ||
| 'Custom rendered content for testing.' | ||
| ) | ||
| ), | ||
| } ); |
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
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.