Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
dropdown_widget: Pass current value to get_options to avoid hacky this.
evykassirer9366d42f14eb
diff --git a/web/src/dropdown_widget.ts b/web/src/dropdown_widget.tsindex adfa0e361a0..a2dfd172341 100644--- a/web/src/dropdown_widget.ts+++ b/web/src/dropdown_widget.ts@@ -73,7 +73,7 @@ export class DropdownWidget {widget_selector: string;widget_wrapper_id: string;widget_value_selector: string;- get_options: () => Option[];+ get_options: (current_value: string | number | undefined) => Option[];item_click_callback: (event: JQuery.ClickEvent,instance: tippy.Instance,@@ -200,20 +200,24 @@ export class DropdownWidget {"input.dropdown-list-search-input",);- this.list_widget = ListWidget.create($dropdown_list_body, this.get_options(), {- name: `${CSS.escape(this.widget_name)}-list-widget`,- get_item: ListWidget.default_get_item,- modifier_html(item) {- return render_dropdown_list({item});- },- filter: {- $element: $search_input,- predicate(item, value) {- return item.name.toLowerCase().includes(value);+ this.list_widget = ListWidget.create(+ $dropdown_list_body,+ this.get_options(this.current_value),+ {+ name: `${CSS.escape(this.widget_name)}-list-widget`,+ get_item: ListWidget.default_get_item,+ modifier_html(item) {+ return render_dropdown_list({item});+ },+ filter: {+ $element: $search_input,+ predicate(item, value) {+ return item.name.toLowerCase().includes(value);+ },},+ $simplebar_container: $popper.find(".dropdown-list-wrapper"),},- $simplebar_container: $popper.find(".dropdown-list-wrapper"),- });+ );$search_input.on("input.list_widget_filter", () => {this.show_empty_if_no_items($popper);@@ -371,7 +375,7 @@ export class DropdownWidget {this.current_value = value;}- const all_options = this.get_options();+ const all_options = this.get_options(this.current_value);const option = all_options.find((option) => option.unique_id === this.current_value);// If provided, show custom text if cannot find current option.diff --git a/web/src/views_util.js b/web/src/views_util.jsindex da57874d2d3..9582471bdce 100644--- a/web/src/views_util.js+++ b/web/src/views_util.js@@ -33,19 +33,19 @@ export const COMMON_DROPDOWN_WIDGET_PARAMS = {disable_for_spectators: true,};-export function filters_dropdown_options() {+export function filters_dropdown_options(current_value) {return [{unique_id: FILTERS.FOLLOWED_TOPICS,name: $t({defaultMessage: "Followed topics"}),description: $t({defaultMessage: "Only topics you follow"}),- bold_current_selection: this.current_value === FILTERS.FOLLOWED_TOPICS,+ bold_current_selection: current_value === FILTERS.FOLLOWED_TOPICS,},{unique_id: FILTERS.UNMUTED_TOPICS,name: $t({defaultMessage: "Standard view"}),description: $t({defaultMessage: "All unmuted topics"}),- bold_current_selection: this.current_value === FILTERS.UNMUTED_TOPICS,+ bold_current_selection: current_value === FILTERS.UNMUTED_TOPICS,},{unique_id: FILTERS.ALL_TOPICS,@@ -53,7 +53,7 @@ export function filters_dropdown_options() {description: $t({defaultMessage: "Includes muted streams and topics",}),- bold_current_selection: this.current_value === FILTERS.ALL_TOPICS,+ bold_current_selection: current_value === FILTERS.ALL_TOPICS,},];}