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 setGutenbergExperiments
to requestUtils
#56663
Conversation
Size Change: 0 B Total Size: 1.69 MB ℹ️ View Unchanged
|
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.
Maybe we should expose this setting via REST API, and then we can use requestUtils.getSiteSettings
and requestUtils.updateSiteSettings
utils.
Do you know what it takes to expose a new REST API 😅 (I genuinely have no idea)? I wonder if it's worth the effort for a fully experimental feature. It's also probably only going to be used inside this project 🤔. Do you think we should give it some more thought before introducing this new API or should we just yolo ship it? |
We'll need to update the option registration, set |
I tried to see if we could expose the experimental settings as a REST API. I added In the end, I was able to achieve this by hooking Codefunction gutenberg_register_experiments_settings() {
// Moved from gutenberg_initialize_experiments_settings() function
register_setting(
'gutenberg-experiments',
'gutenberg-experiments',
array(
'type' => 'object',
'show_in_rest' => array(
'schema' => array(
'type' => 'object',
'properties' => array(
'gutenberg-dataviews' => array(
'type' => 'boolean',
),
'gutenberg-pattern-partial-syncing' => array(
'type' => 'boolean',
),
'gutenberg-sync-collaboration' => array(
'type' => 'boolean',
),
'gutenberg-zoomed-out-view' => array(
'type' => 'boolean',
),
'gutenberg-dataviews' => array(
'type' => 'boolean',
),
'gutenberg-color-randomizer' => array(
'type' => 'boolean',
),
'gutenberg-form-blocks' => array(
'type' => 'boolean',
),
'gutenberg-group-grid-variation' => array(
'type' => 'boolean',
),
'gutenberg-no-tinymce' => array(
'type' => 'boolean',
),
'gutenberg-custom-fields' => array(
'type' => 'boolean',
),
'gutenberg-pattern-partial-syncing' => array(
'type' => 'boolean',
),
),
),
),
)
);
}
add_action( 'admin_init', 'gutenberg_register_experiments_settings' );
add_action( 'rest_api_init', 'gutenberg_register_experiments_settings' ); At least, I was able to confirm that the expected data was obtained by entering the following code into the console with the block editor open. wp.apiFetch( { path: '/wp/v2/settings' } ).then( ( response ) => {
console.log( response );
} ); However, I have not tested whether this setting can be referenced or updated using |
I guess now the question is should we expose them in the public API? 🤔 |
@kevin940726, the user needs to have the |
Oh I mean that if we want to expose it to the developers using the settings API, since it's only a gutenberg-specific thing. I guess that means if we consider this as a "site setting"? |
Good question. I think the plugin should be able to expose internal/experimental settings that never make it into the core without worrying about backward compatibility.
It would be the Gutenberg plugin setting, but since there's only one Settings API, we must expose it as a "site setting". |
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.
The approach here looks good to me.
I'm personally not sure about the need to expose the settings via the REST API, that feels like the test and experiment code starts leaking into production to me.
The setGutenbergExperiments
function signature is very clean and minimal, so if a better way is found it should be possible to change the implementation later on without issue, I don't see any reason to hold back merging this PR.
551bb62
to
55cac6f
Compare
8b87757
to
aab3385
Compare
Thanks for all your inputs! I think I lean more towards keeping it simple for now. We can always circle back if we find exposing it to REST API helpful though! |
What?
A request util to programmatically set gutenberg experiments in e2e tests.
Why?
It's faster and easier to use a request util rather than visiting the page or creating dedicated test plugins.
How?
The util mimics the request sent in the gutenberg experiments page.
Testing Instructions
CI should pass.
Testing Instructions for Keyboard
N/A
Screenshots or screencast
N/A