user_group_pill: Accept setting_type as parameter in typeahead_source.

We currently use the pills UI only for can_manage_group setting so
it is fine to pass setting type as "group" directly to
get_realm_user_groups_for_setting, but it would be better to just
accept setting_type as parameter in typeahead_source and pass that
to get_realm_user_groups_for_setting as other settings will also
use the pills UI in future.
This commit is contained in:
Sahil Batra 2024-09-24 14:30:15 +05:30 committed by Tim Abbott
parent b2e1c5aec4
commit c4026615ae
7 changed files with 14 additions and 2 deletions

View File

@ -114,6 +114,7 @@ export function set_up_pill_typeahead({
$pill_container: JQuery;
opts: {
setting_name: string;
setting_type: "realm" | "stream" | "group";
group: UserGroup | undefined;
};
}): void {

View File

@ -134,6 +134,7 @@ export function set_up_group_setting_typeahead(
pills: GroupSettingPillContainer,
opts: {
setting_name: string;
setting_type: "realm" | "stream" | "group";
group: UserGroup | undefined;
},
): void {
@ -146,7 +147,7 @@ export function set_up_group_setting_typeahead(
source(_query: string): GroupSettingTypeaheadItem[] {
let source: GroupSettingTypeaheadItem[] = [];
source = user_group_pill.typeahead_source(pills, opts.setting_name);
source = user_group_pill.typeahead_source(pills, opts.setting_name, opts.setting_type);
source = [...source, ...user_pill.typeahead_source(pills, true)];
return source;

View File

@ -1444,15 +1444,18 @@ type group_setting_name = "can_manage_group";
export function create_group_setting_widget({
$pill_container,
setting_name,
setting_type,
group,
}: {
$pill_container: JQuery;
setting_name: group_setting_name;
setting_type: "realm" | "stream" | "group";
group?: UserGroup;
}): void {
const pill_widget = group_setting_pill.create_pills($pill_container, setting_name);
const opts = {
setting_name,
setting_type,
group,
};
group_setting_pill.set_up_pill_typeahead({pill_widget, $pill_container, opts});

View File

@ -243,6 +243,7 @@ export function set_up_handlers(): void {
settings_components.create_group_setting_widget({
$pill_container,
setting_name: "can_manage_group",
setting_type: "group",
});
user_group_components.setup_permissions_dropdown("can_mention_group", undefined, true);

View File

@ -172,6 +172,7 @@ function show_general_settings(group) {
settings_components.create_group_setting_widget({
$pill_container,
setting_name: "can_manage_group",
setting_type: "group",
group,
});
update_general_panel_ui(group);

View File

@ -1,3 +1,5 @@
import assert from "minimalistic-assert";
import {$t_html} from "./i18n";
import type {InputPillContainer} from "./input_pill";
import * as people from "./people";
@ -110,10 +112,12 @@ export function filter_taken_groups(
export function typeahead_source(
pill_widget: CombinedPillContainer | GroupSettingPillContainer,
setting_name?: string,
setting_type?: "realm" | "stream" | "group",
): UserGroupPillData[] {
let groups;
if (setting_name !== undefined) {
groups = user_groups.get_realm_user_groups_for_setting(setting_name, "group", true);
assert(setting_type !== undefined);
groups = user_groups.get_realm_user_groups_for_setting(setting_name, setting_type, true);
} else {
groups = user_groups.get_realm_user_groups();
}

View File

@ -708,6 +708,7 @@ run_test("set_up_group_setting_typeahead", ({mock_template, override, override_r
const opts = {
setting_name: "can_manage_group",
setting_type: "group",
group: testers,
};
pill_typeahead.set_up_group_setting_typeahead($fake_input, $pill_widget, opts);