Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
dropdown_widget: Allow showing custom text if value is not in options.
Aman Agrawal2acf3cbfa4cc
diff --git a/web/src/dropdown_widget.js b/web/src/dropdown_widget.jsindex 5c1c28f9961..39e565916b9 100644--- a/web/src/dropdown_widget.js+++ b/web/src/dropdown_widget.js@@ -44,8 +44,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,+ // Text to show if the current value is not in `get_options()`.+ text_if_current_value_not_in_options = null,hide_search_box = false,// Disable the widget for spectators.disable_for_spectators = false,@@ -70,8 +70,7 @@ 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;+ this.text_if_current_value_not_in_options = text_if_current_value_not_in_options;this.hide_search_box = hide_search_box;this.disable_for_spectators = disable_for_spectators;}@@ -308,11 +307,12 @@ export class DropdownWidget {}const all_options = this.get_options();- let option = all_options.find((option) => option.unique_id === this.current_value);+ const 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 provided, show custom text if cannot find current option.+ if (!option && this.text_if_current_value_not_in_options) {+ $(this.widget_value_selector).text(this.text_if_current_value_not_in_options);+ return;}if (!option) {diff --git a/web/src/settings_org.js b/web/src/settings_org.jsindex 9f2997f11d7..7cd029c6804 100644--- a/web/src/settings_org.js+++ b/web/src/settings_org.js@@ -626,7 +626,7 @@ export function init_dropdown_widgets() {const disabled_option = {is_setting_disabled: true,unique_id: DISABLED_STATE_ID,- name: $t({defaultMessage: "Cannot view stream"}),+ name: $t({defaultMessage: "Disabled"}),};options.unshift(disabled_option);@@ -649,7 +649,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,+ text_if_current_value_not_in_options: $t({defaultMessage: "Cannot view stream"}),});settings_components.set_notifications_stream_widget(notifications_stream_widget);notifications_stream_widget.setup();@@ -670,7 +670,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,+ text_if_current_value_not_in_options: $t({defaultMessage: "Cannot view stream"}),});settings_components.set_signup_notifications_stream_widget(signup_notifications_stream_widget);signup_notifications_stream_widget.setup();