Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

dropdown_widget: Show disabled if value not in options.

Aman Agrawal3303b5ab726c
diff --git a/web/src/dropdown_widget.js b/web/src/dropdown_widget.js
index cf4a6847fde..b30862480fe 100644
--- a/web/src/dropdown_widget.js
+++ b/web/src/dropdown_widget.js
@@ -41,6 +41,8 @@ export class DropdownWidget {
// NOTE: Any value other than `null` will be rendered when class is initialized.
default_id = null,
unique_id_type = null,
+ // Show disabled state if the default_id is not in `get_options()`.
+ show_disabled_if_current_value_not_in_options = false,
}) {
this.widget_name = widget_name;
this.widget_id = `#${CSS.escape(widget_name)}_widget`;
@@ -62,6 +64,8 @@ export class DropdownWidget {
this.current_value = default_id;
this.unique_id_type = unique_id_type;
this.$events_container = $events_container;
+ this.show_disabled_if_current_value_not_in_options =
+ show_disabled_if_current_value_not_in_options;
}
init() {
@@ -254,7 +258,19 @@ export class DropdownWidget {
this.current_value = value;
}
- const option = this.get_options().find((option) => option.unique_id === this.current_value);
+ const all_options = this.get_options();
+ let option = all_options.find((option) => option.unique_id === this.current_value);
+
+ // Show disabled if cannot find current option.
+ if (!option && this.show_disabled_if_current_value_not_in_options) {
+ option = all_options.find((option) => option.is_setting_disabled === true);
+ }
+
+ if (!option) {
+ blueslip.error(`Cannot find current value: ${this.current_value} in provided options.`);
+ return;
+ }
+
if (option.is_setting_disabled) {
$(this.widget_value_selector).html(render_dropdown_disabled_state({name: option.name}));
} else if (option.stream) {
diff --git a/web/src/settings_org.js b/web/src/settings_org.js
index 68c8e159d07..230c6e2c70d 100644
--- a/web/src/settings_org.js
+++ b/web/src/settings_org.js
@@ -1043,6 +1043,7 @@ export function init_dropdown_widgets() {
},
default_id: page_params.realm_notifications_stream_id,
unique_id_type: dropdown_widget.DATA_TYPES.NUMBER,
+ show_disabled_if_current_value_not_in_options: true,
});
notifications_stream_widget.setup();
@@ -1062,6 +1063,7 @@ export function init_dropdown_widgets() {
},
default_id: page_params.realm_signup_notifications_stream_id,
unique_id_type: dropdown_widget.DATA_TYPES.NUMBER,
+ show_disabled_if_current_value_not_in_options: true,
});
signup_notifications_stream_widget.setup();