mirror of
https://github.com/coder/coder.git
synced 2026-11-04 15:15:19 +08:00
<img width="339" height="330" alt="Screenshot 2025-12-13 at 18 39 30" src="https://github.com/user-attachments/assets/41bade09-1e2e-4ff4-9b27-a3bdc9cb07f2" />
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import type { Group, ReducedUser, User } from "api/typesGenerated";
|
|
|
|
type UserOrGroupAutocompleteValue = User | ReducedUser | Group | null;
|
|
|
|
/**
|
|
* Type guard to check if the value is a Group.
|
|
* Groups have a "members" property that users don't have.
|
|
*/
|
|
export const isGroup = (
|
|
value: UserOrGroupAutocompleteValue,
|
|
): value is Group => {
|
|
return value !== null && typeof value === "object" && "members" in value;
|
|
};
|
|
|
|
/**
|
|
* Returns true if the provided group is the 'Everyone' group.
|
|
* The everyone group represents all the users in an organization
|
|
* for which every organization member is implicitly a member of.
|
|
*
|
|
* @param {Group} group - The group to evaluate.
|
|
* @returns {boolean} - Returns true if the group's ID matches its
|
|
* organization ID.
|
|
*/
|
|
export const isEveryoneGroup = (group: Group): boolean =>
|
|
group.id === group.organization_id;
|
|
|
|
export const getGroupSubtitle = (group: Group): string => {
|
|
// It is the everyone group when a group id is the same of the org id
|
|
if (group.id === group.organization_id) {
|
|
return "All users";
|
|
}
|
|
|
|
if (!group.members) {
|
|
return "0 members";
|
|
}
|
|
|
|
if (group.members.length === 1) {
|
|
return "1 member";
|
|
}
|
|
|
|
return `${group.members.length} members`;
|
|
};
|