settings: Refactor UserGroupPill to improve consistency.

Changed UserGroupPill's 'id' key to 'group_id' because
UserPill uses 'user_id' instead of only id.
This commit is contained in:
PieterCK 2024-05-09 14:24:02 +07:00 committed by Tim Abbott
parent ad177a8b48
commit 3b46d0e53c
2 changed files with 8 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import * as user_groups from "./user_groups";
export type UserGroupPill = {
type: "user_group";
id: number;
group_id: number;
group_name: string;
};
@ -30,14 +30,14 @@ export function create_item_from_group_name(
return undefined;
}
if (current_items.some((item) => item.type === "user_group" && item.id === group.id)) {
if (current_items.some((item) => item.type === "user_group" && item.group_id === group.id)) {
return undefined;
}
return {
type: "user_group",
display_value: display_pill(group),
id: group.id,
group_id: group.id,
group_name: group.name,
};
}
@ -51,7 +51,7 @@ export function get_user_ids(pill_widget: UserGroupPillWidget | CombinedPillCont
.items()
.flatMap((item) =>
item.type === "user_group"
? [...user_groups.get_user_group_from_id(item.id).members]
? [...user_groups.get_user_group_from_id(item.group_id).members]
: [],
);
user_ids = [...new Set(user_ids)];
@ -65,7 +65,7 @@ export function append_user_group(group: UserGroup, pill_widget: CombinedPillCon
pill_widget.appendValidatedData({
type: "user_group",
display_value: display_pill(group),
id: group.id,
group_id: group.id,
group_name: group.name,
});
pill_widget.clear_text();
@ -73,7 +73,7 @@ export function append_user_group(group: UserGroup, pill_widget: CombinedPillCon
export function get_group_ids(pill_widget: CombinedPillContainer): number[] {
const items = pill_widget.items();
return items.flatMap((item) => (item.type === "user_group" ? item.id : []));
return items.flatMap((item) => (item.type === "user_group" ? item.group_id : []));
}
export function filter_taken_groups(

View File

@ -22,13 +22,13 @@ const testers = {
};
const admins_pill = {
id: admins.id,
group_id: admins.id,
group_name: admins.name,
type: "user_group",
display_value: admins.name + ": " + admins.members.length + " users",
};
const testers_pill = {
id: testers.id,
group_id: testers.id,
group_name: testers.name,
type: "user_group",
display_value: testers.name + ": " + testers.members.length + " users",