-
Notifications
You must be signed in to change notification settings - Fork 0
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
[BBT-83] Reset/Save button functionality enhancements #30
Conversation
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.
From the ticket description, it looks like fields not updating when reset is pressed has been resolved in recent work, but we do also want to update the reset button to revert to the previously saved state (not the original theme.json setting) when clicked. Can you look into adding this?
Expectation:
- theme.json has background-color: red
- update background-color to green via UI
- save
- update background-color to blue via UI
- click "reset"
- background-color should revert to green, not red
We will likely move the "reset to theme.json" functionality to the settings dropdown alongside "export" but not expecting that to be done here.
@g-elwell Sorry I've misunderstood the ticket requirements there. I've now implemented this logic by adding a new state variable, |
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.
I think we can simplify this a lot by using getEntityRecord to retrieve the original user config.
eg:
const { globalStylesId, baseConfig, userConfig, savedUserConfig } =
useSelect( ( select ) => {
const {
__experimentalGetCurrentGlobalStylesId,
__experimentalGetCurrentThemeBaseGlobalStyles,
getEditedEntityRecord,
getEntityRecord,
} = select( 'core' );
const currentGlobalStylesId =
__experimentalGetCurrentGlobalStylesId();
return {
globalStylesId: currentGlobalStylesId,
baseConfig: __experimentalGetCurrentThemeBaseGlobalStyles(),
userConfig: getEditedEntityRecord(
'root',
'globalStyles',
currentGlobalStylesId
),
savedUserConfig: getEntityRecord(
'root',
'globalStyles',
currentGlobalStylesId
),
};
} );
We are currently using getEditedEntityRecord
for userConfig
, and editEntityRecord
to update this value whenever the UI is interacted with. This keeps the theme settings in state but won't update the entity until we call saveEditedEntityRecord
when the save button is pressed.
So, we should be able to compare the original/saved entity with our "live"/edited entity to determine if things are dirty.
If this works, it should remove the need for any additional state or manipulating objects to compare them.
The behaviour now is spot on though, both the reset/save and warning when leaving the page 👍
@g-elwell Thanks, I've got a better understanding of where this data is being saved now. I've made those changes so there's no need for the extra state I was creating before. |
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.
Works great, thanks @Joe-Rouse !
Description
Completes BBT-83 - This PR makes some improvements to the functionality of the current save & reset buttons. The ticket outlines issues with the reset button not resetting the components, but I can't recreate this issue. However, this ticket was made nearly 4 months ago so I understand it could be a little outdated. I've completed all other suggestions in the main ticket description & comments.
Change Log
isEqual
for this comparison).Steps to test
Screenshots/Videos
Alert
Screen.Recording.2023-10-11.at.15.11.51.mov
Button disabled status
Screen.Recording.2023-10-11.at.15.13.38.mov
Checklist: