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

Social: Refactor feature option storing #34113

Merged
merged 26 commits into from
Dec 7, 2023

Conversation

gmjuhasz
Copy link
Contributor

@gmjuhasz gmjuhasz commented Nov 14, 2023

This change refactors how we store our options for SIG and auto conversion. We moved to use the register_setting function, this way we need no Rest controllers.
It's easier to review this following the commits.

FEATURE BRANCH OTHER PRs:

Proposed changes:

  • f37dd1a - Added the new settings file and tests for it.
  • d00d07e - Updated the initial state, so it uses the new object. Also changed every usage where SIG needed the default template
  • 012eb2c - This commit updates the UI parts to match the new data structure, and also updates the store so it calls the core wp/v2 endpoint to retrieve and update the settings.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

https://github.com/orgs/Automattic/projects/733/views/2?pane=issue&itemId=44049666

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

This probably needs a lot of testing to see that everything is working. You can run the tests on the backend with composer run test-php from the publicize folder.

To test the flow you can do the following:

  • Have both Jetpack and Jetpack Social enabled. Open up The Jetpack Settings, and go to the sharing section. On another tab open up the Social admin page.

    • Toggle on/off SIG and the conversion in one of the pages, then refreshing the other page should reflect the changes. Try to change the template too.
    • Make sure that turning the main module off, refreshing, then turning it on shows the correct values.
  • Have the conversion on, then create a new post. The default state of SIG in the editor should match the state of the toggle in the admin page.

  • Clear the dismissed notices with jetpack docker wp option delete jetpack_social_dismissed_notices

  • Open up a new post with the conversion on, then upload an invalid image that can be converted. You should see the notice that the image will be converted.

    • Click on change settings, then turn the conversion off
    • Switch back to the other tab, the page should reflect the changes without needing to refresh it

@github-actions github-actions bot added [JS Package] Publicize Components [Package] Publicize [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Social Issues about the Jetpack Social plugin [Status] In Progress [Tests] Includes Tests RNA labels Nov 14, 2023
Copy link
Contributor

github-actions bot commented Nov 14, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for January 9, 2024 (scheduled code freeze on January 8, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Backup plugin:

  • Next scheduled release: January 2, 2024.
  • Scheduled code freeze: December 25, 2023.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Search plugin:

  • Next scheduled release: January 2, 2024.
  • Scheduled code freeze: December 25, 2023.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Social plugin:

  • Next scheduled release: January 2, 2024.
  • Scheduled code freeze: December 25, 2023.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Starter Plugin plugin:

  • Next scheduled release: January 2, 2024.
  • Scheduled code freeze: December 25, 2023.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Protect plugin:

  • Next scheduled release: January 2, 2024.
  • Scheduled code freeze: December 25, 2023.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Videopress plugin:

  • Next scheduled release: January 2, 2024.
  • Scheduled code freeze: December 25, 2023.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Migration plugin:

  • Next scheduled release: January 2, 2024.
  • Scheduled code freeze: December 25, 2023.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Contributor

github-actions bot commented Nov 14, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the refactor/social-register-feature-settings branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack refactor/social-register-feature-settings
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@gmjuhasz gmjuhasz self-assigned this Nov 14, 2023
@gmjuhasz gmjuhasz requested a review from a team November 14, 2023 14:58
@gmjuhasz gmjuhasz marked this pull request as ready for review November 14, 2023 15:25
Comment on lines 100 to -111
return apiFetch( {
path: '/jetpack/v4/social-image-generator/settings',
path: '/wp/v2/settings',
method: 'POST',
data: action.settings,
data: {
jetpack_social_image_generator_settings: action.settings,
},
} );
},
[ FETCH_AUTO_CONVERSION_SETTINGS ]: function () {
return apiFetch( { path: '/jetpack/v4/auto-conversion/settings' } );
return apiFetch( {
path: '/wp/v2/settings?_fields=jetpack_social_autoconvert_images',
} );
},
[ UPDATE_AUTO_CONVERSION_SETTINGS ]: function ( action ) {
return apiFetch( {
path: '/jetpack/v4/auto-conversion/settings',
path: '/wp/v2/settings',
method: 'POST',
data: action.settings,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need multiple API calls? Can we make a single API call to get all the settings at once?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add the settings fields separated by comma

/wp/v2/settings?_fields=jetpack_social_image_generator_settings,jetpack_social_autoconvert_images

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, to fetch the settings we can just have one call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll do that.

Copy link
Contributor Author

@gmjuhasz gmjuhasz Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turned out to be a bigger change as I had to remove the old refreshes introduced in #33969, so I added the store functions in b6952a2 and created another PR on this branch for the others #34142

* Remove unneeded files

* changelog
* Remove previous refresh functionality

* Add wrapper to refresh settings in class component on Jetpack Settings

* Refresh on social admin page on module toggle change

* Remove useEffect

* Run useEffect only once on module update

* Show toggles instantly on change + only refresh ones on page lifetime

* Update ref logic
@github-actions github-actions bot added the Admin Page React-powered dashboard under the Jetpack menu label Nov 20, 2023
manzoorwanijk
manzoorwanijk previously approved these changes Nov 21, 2023
Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well now

@github-actions github-actions bot added [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. labels Dec 7, 2023
@gmjuhasz gmjuhasz force-pushed the refactor/social-register-feature-settings branch from def6ef2 to b7c2568 Compare December 7, 2023 09:51
@gmjuhasz gmjuhasz removed [Package] Sync [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Starter Plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Migration labels Dec 7, 2023
@github-actions github-actions bot added [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Migration [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. labels Dec 7, 2023
Comment on lines +26 to +34
updatedSettings.jetpack_social_image_generator_settings
);
return true;
} catch ( e ) {
return false;
} finally {
yield setUpdatingAutoConversionSettingsDone();
yield setUpdatingSocialImageGeneratorSettingsDone();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that finally block is executed before the return statement inside try/catch.

Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with and without Jetpack plugin and it works fine and the code also looks good.

@gmjuhasz gmjuhasz merged commit 1039bd3 into trunk Dec 7, 2023
60 checks passed
@gmjuhasz gmjuhasz deleted the refactor/social-register-feature-settings branch December 7, 2023 12:54
),
),
),
'type' => 'boolean',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something might be wrong here, this type should be object. Do you think that's how it ended up being the empty string? I think maybe something has been cast as a boolean and it's evaluated to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu [JS Package] Publicize Components [Package] Publicize [Package] Sync [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Migration [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. RNA [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants