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

settings_components: Split functions to improve type checking. #30090

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

afeefuddin
Copy link
Collaborator

Refactor get_property_value and check_property_changed to improve type checking and code readability.

Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

property_value = settings_components.get_stream_settings_property_value(property_name, sub);
} else {
property_value = settings_components.get_realm_settings_property_value(property_name);
}
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

We should also split this function, like the others it's mainly a bunch of switch statements for individual settings and thus will do nicely being split up.

@afeefuddin afeefuddin marked this pull request as draft May 15, 2024 20:59
@afeefuddin afeefuddin force-pushed the settings_components_refactor branch from 006a7d6 to bb83d80 Compare May 21, 2024 15:17
@afeefuddin afeefuddin force-pushed the settings_components_refactor branch 3 times, most recently from 3a6790c to 96b4987 Compare May 22, 2024 11:17
@afeefuddin afeefuddin marked this pull request as ready for review May 22, 2024 11:27
@afeefuddin afeefuddin force-pushed the settings_components_refactor branch from 96b4987 to 49cce92 Compare May 22, 2024 11:32
@afeefuddin
Copy link
Collaborator Author

Ready for review! Naming might be a concern because the names of the functions aren't very concise.

update_dependent_subsettings(property_name);
}

export function discard_stream_proprty_element_changes(elem, sub) {
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

property has a typo here.

@timabbott
Copy link
Sponsor Member

I think this version does achieve our type-checking goals; @sahil839 should probably do a round of review and testing to make sure it doesn't regress anything. @afeefuddin how have you tested this?

@sahil839
Copy link
Collaborator

sahil839 commented May 29, 2024

@afeefuddin can you also rebase this? Some reafactoring changes in the settings code have been merged recently.

@afeefuddin
Copy link
Collaborator Author

Done with rebasing @sahil839. One test is cancelled for some reason. I have tested a few functions manually, but I don't know how I should test this otherwise.

Copy link
Collaborator

@sahil839 sahil839 left a comment

Choose a reason for hiding this comment

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

Posted a couple of comments. I did some testing and it works fine.

if (property_name === "can_mention_group") {
proposed_val = get_dropdown_list_widget_setting_value($elem);
} else if (current_val !== undefined) {
proposed_val = get_input_element_value(elem, typeof current_val);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we update this to use switch like other functions do? We would soon add new settings so would be good to just write the code considering that.

if (property_name === "can_mention_group") {
data[property_name] = JSON.stringify({
new: input_value,
old: group!.can_mention_group,
old: group.can_mention_group,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code will only be called for can_mention_group and we expect all future group settings to follow the same format, so maybe we can just remove the if condition and call this directly.
And then if we have some other fields which are not group settings using the save discard widget, then we can update this later.

@sahil839
Copy link
Collaborator

A good way of testing would to test all the sections where save-discard widget is used by verifying that the setting is changed, setting is discarded on clicking "Discard" and also by resetting the setting by selecting the same value after changing it once and check that the save-discard widget disappears as expected.

@sahil839
Copy link
Collaborator

Also, would it be worth moving functions for streams and groups to respective files like user_group_components, etc. as a follow-up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants