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

Connect state of save/revert buttons to something sensible #310

Merged
merged 2 commits into from
May 1, 2024

Conversation

mwcraig
Copy link
Contributor

@mwcraig mwcraig commented Apr 30, 2024

I think the save and revert buttons should only be enabled when the value of the widget is valid (in the pydantic model sense) and there are unsaved changes.

This PR does that, and adds a test for it.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.80%. Comparing base (ae22f87) to head (e0155c0).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #310      +/-   ##
==========================================
+ Coverage   73.71%   73.80%   +0.09%     
==========================================
  Files          27       27              
  Lines        3390     3402      +12     
==========================================
+ Hits         2499     2511      +12     
  Misses        891      891              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"""
A handler must take an argument but we don't use it here.
"""
needs_to_save = widget.is_valid and widget.savebuttonbar.unsaved_changes
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever bit of logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to break it into steps because I was confusing myself when I tried to make it a single line 😬

# Which means we don't need the button to show/hide them
assert ui.bn_shownull.layout.display == "none"

# For now we do not show the validaation output because it is painfully
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo of "validation", somewhat ironic since it passed initial review by the author....


# So it turns out that the validation stuff only updates when changes are made
# in the UI rather than programmatically. Since we know we've set a valid value,
# and that we've made changes we just manually set the relevant values.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is rather sad, forcing the test to work, but I suppose it checks that changing ui.savebuttonbar.unsaved_changes and ui.is_valid.value have the intended effects on the save button.

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, this was not my first choice. I tried calling the handlers that I thought ipyautoui was invoking, but i) they were private (started with _) and ii) didn't do anything.

@JuanCab JuanCab self-requested a review April 30, 2024 22:13
Copy link
Contributor

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

Might want to fix the typo, otherwise all good.

@mwcraig mwcraig merged commit d49279b into feder-observatory:main May 1, 2024
8 of 9 checks passed
@mwcraig mwcraig deleted the update-ui-generator branch May 1, 2024 13:27
mwcraig added a commit that referenced this pull request May 1, 2024
Remove save button code made unnecessary by #310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants