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

Feat: Add disable functionality to save settings button (#1531) #2259

Merged

Conversation

hbhalodia
Copy link
Contributor

@hbhalodia hbhalodia commented Jan 31, 2023

All Submissions:

Changes proposed in this Pull Request:

  • By adding this PR, we can ensure that save settings button is disabled until user changes any settings in a particular section. Before this commit save settings button was always enabled. This would only enable the save settings button for the section whose inner settings are changed, that would ensure all the sections on the page are async.
  • Also on this PR in file change index.js, we need to look upon the comment added on handleSectionUpdate function, because we have kept all sections save settings button async, hence user can change all settings at once and can try to update one by one which would override his settings because on update we are fetching the saved settings and adding it again on the response. We can remove this behavior by removing the setState again for saved settings instead use prev state only.

How to test the changes in this Pull Request:

  1. Checkout to the current branch.
  2. Head to Advertising --> Settings page.
  3. On first load you can see the button is disabled, Change any section settings you can see that section button is enabled, On save again button gets disabled.
  4. You can check with multiple section and each section works async.

Screencast for the current change

Untitled_.Jan.16.2023.5_28.PM.webm

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Closes - #1531

@hbhalodia hbhalodia marked this pull request as ready for review January 31, 2023 11:13
@hbhalodia hbhalodia requested a review from a team as a code owner January 31, 2023 11:13
@adekbadek adekbadek added the [Status] Needs Review The issue or pull request needs to be reviewed label Jan 31, 2023
Copy link
Contributor

@leogermani leogermani left a comment

Choose a reason for hiding this comment

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

Thank you for this!

It works as described but I left one comment about the button not being disabled while saving.

Also, it doesn't seem to apply to all SettingsSection components. If you go to Engagement > Social, you'll see that this will not work with the sections there. Apparently Ads settings are created in a very different way. cc @miguelpeixe

assets/components/src/plugin-settings/SettingsSection.js Outdated Show resolved Hide resolved
@leogermani leogermani added [Status] Needs changes or feedback The issue or pull request needs action from the original creator and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 24, 2023
@hbhalodia
Copy link
Contributor Author

hbhalodia commented Feb 28, 2023

Hi @leogermani, You need me to update for engagement > social settings also or we can keep this just for ads, as you said ads settings are created differently? Let me know on this. Thanks.

I think we can keep this for ads right now as this PR is created for the issue which has only advertisement issue. We can create another issue for that settings and should solve for all in that?

@hbhalodia
Copy link
Contributor Author

Hi @leogermani, I have added for engagement settings also. We need to apply this change where PluginSettings component is being used. Thanks.

@hbhalodia hbhalodia requested review from leogermani and removed request for leogermani February 28, 2023 05:13
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution, @hbhalodia!

May I suggest a different approach? The SettingsSection component is aware of the value changes and saves so we don't need to rely on another component to set this:

onChange: value => {
onChange( setting.key, value );
},

onClick={ () => {
onUpdate();
} }

With the current approach, every component that uses this will have to reimplement the same (or very similar) logic for a consistent experience. Case in point, the Ad Refresh Control is missing it, so that's how my Ads settings render currently:

image

assets/components/src/plugin-settings/SettingsSection.js Outdated Show resolved Hide resolved
@hbhalodia
Copy link
Contributor Author

Thanks! @miguelpeixe for the approach. I have worked on this approach and achieved the results for all settings. No need to reimplement the same logic again on each component. I have updated the PR with the new approach. You can review now.

Thanks!

@hbhalodia hbhalodia requested review from miguelpeixe and leogermani and removed request for leogermani and miguelpeixe March 2, 2023 05:07
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

Thank you for revising, @hbhalodia!

It's working well 👌

@miguelpeixe miguelpeixe merged commit e06d72f into Automattic:master Mar 2, 2023
matticbot pushed a commit that referenced this pull request Mar 3, 2023
# [1.106.0-alpha.1](v1.105.0...v1.106.0-alpha.1) (2023-03-03)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.106.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Mar 14, 2023
# [1.106.0](v1.105.1...v1.106.0) (2023-03-14)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))
* show handoff to finish Newspack setup only if setup is incomplete ([#2343](#2343)) ([1173b5b](1173b5b))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.106.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Needs changes or feedback The issue or pull request needs action from the original creator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants