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

Add setting to automatically show submit button #200

Merged
merged 8 commits into from
Feb 6, 2025

Conversation

glolichen
Copy link
Contributor

Copy link

codecov bot commented Jan 19, 2025

Codecov Report

Attention: Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 75.97%. Comparing base (d3205fb) to head (104f8eb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/pages/dashboard_page.dart 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #200   +/-   ##
=======================================
  Coverage   75.96%   75.97%           
=======================================
  Files          79       79           
  Lines        8618     8633   +15     
=======================================
+ Hits         6547     6559   +12     
- Misses       2071     2074    +3     

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

Comment on lines 41 to 48

if (preferences.getBool(PrefKeys.autoSubmitButton) ?? false) {
showSubmitButton = true;
}
else {
showSubmitButton ??= ntConnection.getTopicFromName(topic)?.isPersistent;
showSubmitButton ??= false;
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think these lines are necessary, what was there previously should be fine

Copy link
Owner

Choose a reason for hiding this comment

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

One issue I found with this is that if showSubmitButton is explicity set to false, it will be flipped back to true. Instead, it should be initialized to true only if there was no value present initially:

showSubmitButton ??= preferences.getBool(PrefKeys.autoSubmitButton);
showSubmitButton ??= ntConnection.getTopicFromName(topic)?.isPersistent;
showSubmitButton ??= false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But now, if the preferences.getBool(PrefKeys.autoSubmitButton) setting is false, but the topic is persistent, showSubmitButton is set to false but it really should be true.

I think these work (I could be wrong):

    if (preferences.getBool(PrefKeys.autoSubmitButton) ?? false) {
      showSubmitButton ??= true;
    }
    else {
      showSubmitButton ??= ntConnection.getTopicFromName(topic)?.isPersistent;
      showSubmitButton ??= false;
    }

so if it has been explicitly set nothing changes, or (very ugly):

    showSubmitButton ??= (
      (preferences.getBool(PrefKeys.autoSubmitButton) ?? false) ||
      (ntConnection.getTopicFromName(topic)?.isPersistent ?? false)
    );

@Gold872
Copy link
Owner

Gold872 commented Jan 22, 2025

Thanks for making this PR!

Could you add unit tests for these features? There should be one for the settings dialog (in test/widgets/settings_dialog_test.dart), and one for the text display (you'll have to set a mock initial value in shared preferences)

I also think this button could be moved out of developer settings since I wouldn't say it's a very advanced feature, the appearance settings should work just fine for this

@glolichen
Copy link
Contributor Author

Moved the setting under appearance settings; added unit tests for text display dialog and settings page. I tried to follow what the other tests did but I am not sure these are the kind you wanted. I also tested the new setting on a real robot and it works.

I think the changes made earlier in text_display.dart are necessary to automatically show the submit button based on the SharedPreferences. Deleting it breaks the new unit tests.

Copy link
Owner

@Gold872 Gold872 left a comment

Choose a reason for hiding this comment

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

Amazing work on this! There's just a few issues with the unit tests, variable naming, and some minor async things, but the UI to this look good.

Also, the CI is failing since the formatting is incorrect, to fix this, run these 3 commands:
dart format .
dart run import_sorter:main
dart fix --apply

lib/pages/dashboard_page.dart Outdated Show resolved Hide resolved
lib/services/settings.dart Outdated Show resolved Hide resolved
lib/widgets/settings_dialog.dart Outdated Show resolved Hide resolved
lib/widgets/settings_dialog.dart Outdated Show resolved Hide resolved
lib/widgets/settings_dialog.dart Outdated Show resolved Hide resolved
test/widgets/settings_dialog_test.dart Outdated Show resolved Hide resolved
Comment on lines 41 to 48

if (preferences.getBool(PrefKeys.autoSubmitButton) ?? false) {
showSubmitButton = true;
}
else {
showSubmitButton ??= ntConnection.getTopicFromName(topic)?.isPersistent;
showSubmitButton ??= false;
}
Copy link
Owner

Choose a reason for hiding this comment

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

One issue I found with this is that if showSubmitButton is explicity set to false, it will be flipped back to true. Instead, it should be initialized to true only if there was no value present initially:

showSubmitButton ??= preferences.getBool(PrefKeys.autoSubmitButton);
showSubmitButton ??= ntConnection.getTopicFromName(topic)?.isPersistent;
showSubmitButton ??= false;

@glolichen
Copy link
Contributor Author

Thanks for reviewing!

I reverted to the old "true if topic is persistent" test without setting the preference, and added two tests for preference is true and preference is false.

I do still have a question on what text_display.dart should actually be, I put my proposed new code in the commit but please see if there is anything wrong.

@github-actions github-actions bot added the GUI Changes to Elastic's UI label Feb 2, 2025
@glolichen glolichen requested a review from Gold872 February 2, 2025 05:39
@Gold872
Copy link
Owner

Gold872 commented Feb 6, 2025

I do still have a question on what text_display.dart should actually be, I put my proposed new code in the commit but please see if there is anything wrong.

I think the way it is now is good, I realize now the reason for it, which is the situation where the topic is persistent but the preference is set to false.

Copy link
Owner

@Gold872 Gold872 left a comment

Choose a reason for hiding this comment

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

This looks great!

What I'd like to add for 2026 is the ability to set default settings for any widget. I'll have to think more about the implementation of it, but for the time being this will be a useful addition.

@Gold872 Gold872 merged commit 864513f into Gold872:main Feb 6, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI Changes to Elastic's UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants