Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
left sidebar: Hide search and filter when no groups exist.
sandeep9ffd142a95be
diff --git a/web/src/user_group_edit.ts b/web/src/user_group_edit.tsindex e628604af93..cca22f1201e 100644--- a/web/src/user_group_edit.ts+++ b/web/src/user_group_edit.ts@@ -1580,7 +1580,6 @@ export function update_group(event: UserGroupUpdateEvent, group: UserGroup): voi}if (event.data.deactivated !== undefined) {- update_filter_widget_visibility();if (event.data.deactivated) {handle_deleted_group(group.id);} else {@@ -1712,6 +1711,7 @@ function redraw_left_panel(tab_name: string): void {return;}group_list_widget.replace_list_data(groups_list_data);+ update_filter_widget_visibility(tab_name);update_empty_left_panel_message();}@@ -1728,7 +1728,6 @@ export function switch_group_tab(tab_name: string): void {use `group_list_toggler.goto`.*/- update_filter_widget_visibility(tab_name);redraw_left_panel(tab_name);setup_group_list_tab_hash(tab_name);}@@ -1795,6 +1794,10 @@ export function add_or_remove_from_group(}}+function is_group_search_active(): boolean {+ return $("#group_filter").css("display") !== "none" && $("#search_group_name").val() !== "";+}+export function update_empty_left_panel_message(): void {// Check if we have any groups in panel to decide whether to// display a notice.@@ -1830,8 +1833,7 @@ export function update_empty_left_panel_message(): void {// or has a filter applied, since the empty state is due to// filters, not the actual absence of groups.const is_filtered =- current_group_filter !== FILTERS.ACTIVE_AND_DEACTIVATED_GROUPS ||- $("#search_group_name").val() !== "";+ current_group_filter !== FILTERS.ACTIVE_AND_DEACTIVATED_GROUPS || is_group_search_active();const can_create_user_groups =settings_data.user_can_create_user_groups() && realm.zulip_plan_is_not_limited;@@ -1859,8 +1861,10 @@ function get_empty_user_group_list_message(current_group_filter: string,active_tab_key: string,): string {- const is_searching = $("#search_group_name").val() !== "";- if (is_searching || current_group_filter !== FILTERS.ACTIVE_AND_DEACTIVATED_GROUPS) {+ if (+ is_group_search_active() ||+ current_group_filter !== FILTERS.ACTIVE_AND_DEACTIVATED_GROUPS+ ) {if (active_tab_key === "roles") {return $t({defaultMessage: "There are no roles matching your filters."});}@@ -1968,21 +1972,53 @@ function setup_dropdown_filters_widget(): void {function update_filter_widget_visibility(tab_name?: string): void {const active_tab = tab_name ?? get_active_data().$tabs.first().attr("data-tab-key");++ // Roles tab is special: roles cannot be deactivated, so the+ // active/deactivated dropdown is not applicable. The search box is+ // always shown, and the filter value is ignored for this tab.if (active_tab === "roles") {- // Roles cannot be deactivated, so the active/deactivated filter- // dropdown is not applicable on the roles tab. We hide the dropdown- // and ignore the filter value completely for this tab.+ $("#group_filter").show();$("#user-group-edit-filter-options").hide();update_displayed_groups(FILTERS.ACTIVE_GROUPS);- } else if (!user_groups.realm_has_deactivated_user_groups()) {- $("#user-group-edit-filter-options").hide();- update_displayed_groups(FILTERS.ACTIVE_GROUPS);- if (filters_dropdown_widget) {+ return;+ }++ const groups =+ active_tab === "your-groups"+ ? user_groups.get_user_groups_of_user(people.my_current_user_id(), true)+ : user_groups.get_realm_user_groups(true);+ const has_active_groups = groups.some((group) => !group.deactivated);+ const has_deactivated_groups = groups.some((group) => group.deactivated);++ // Search box: shown when at least one group exists in this tab.+ // Dropdown filter: shown only when both active and deactivated groups+ // coexist, since otherwise there is nothing to switch between.+ $("#group_filter").toggle(has_active_groups || has_deactivated_groups);+ $("#user-group-edit-filter-options").toggle(has_active_groups && has_deactivated_groups);++ // If both kinds coexist (in this tab), honor the dropdown's current value;+ // otherwise show everything (the dropdown is hidden in that case anyway).+ let current_filter: string;+ if (has_active_groups && has_deactivated_groups) {+ current_filter =+ z.optional(z.string()).parse(filters_dropdown_widget?.value()) ?? FILTERS.ACTIVE_GROUPS;+ } else {+ current_filter = FILTERS.ACTIVE_AND_DEACTIVATED_GROUPS;++ // Reset the dropdown value only when the realm has only one kind+ // of group left. This way, if the user is on the "All groups" tab+ // with both kinds and switches to "Your groups" (where the dropdown+ // is hidden because they only joined active groups), their selection+ // is preserved when they switch back.+ const realm_groups = user_groups.get_realm_user_groups(true);+ const realm_has_both_kinds =+ realm_groups.some((group) => !group.deactivated) &&+ realm_groups.some((group) => group.deactivated);+ if (!realm_has_both_kinds && filters_dropdown_widget) {filters_dropdown_widget.render(FILTERS.ACTIVE_GROUPS);}- } else {- $("#user-group-edit-filter-options").show();}+ update_displayed_groups(current_filter);}export function setup_page(callback: () => void): void {diff --git a/web/src/user_groups.ts b/web/src/user_groups.tsindex e154f08dcea..2ca89fb8a71 100644--- a/web/src/user_groups.ts+++ b/web/src/user_groups.ts@@ -139,13 +139,6 @@ export function get_user_group_from_name(name: string): UserGroup | undefined {return user_group_name_dict.get(name);}-export function realm_has_deactivated_user_groups(): boolean {- const realm_user_groups = get_realm_user_groups(true);- const deactivated_group_count = realm_user_groups.filter((group) => group.deactivated).length;-- return deactivated_group_count > 0;-}-export function get_realm_user_groups(include_deactivated = false): UserGroup[] {const user_groups = [...user_group_by_id_dict.values()];user_groups.sort((a, b) => a.id - b.id);diff --git a/web/tests/user_groups.test.cjs b/web/tests/user_groups.test.cjsindex ca4ba52325f..bf89ab56070 100644--- a/web/tests/user_groups.test.cjs+++ b/web/tests/user_groups.test.cjs@@ -1342,31 +1342,6 @@ run_test("update_group_permission_settings", () => {assert.equal(user_groups.get_user_group_from_id(group.id).can_remove_members_group, 7);});-run_test("realm_has_deactivated_user_groups", () => {- user_groups.init();- const active = make_user_group({- name: "Active",- id: 1,- members: [1],- is_system_group: false,- direct_subgroup_ids: [],- deactivated: false,- });- user_groups.add(active);- assert.ok(!user_groups.realm_has_deactivated_user_groups());-- const deactivated = make_user_group({- name: "Deactivated",- id: 2,- members: [2],- is_system_group: false,- direct_subgroup_ids: [],- deactivated: true,- });- user_groups.add(deactivated);- assert.ok(user_groups.realm_has_deactivated_user_groups());-});-run_test("get_system_groups_list", ({override}) => {user_groups.init();const {nobody, owners, admins, moderators, members, everyone, full_members, internet} =