🔄 refactor: Principal Type Handling in Search Principals to use Array

This commit is contained in:
Danny Avila 2025-08-12 16:49:19 -04:00
parent dcd96c29c5
commit 803ade8601
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
9 changed files with 68 additions and 151 deletions

View file

@ -24,21 +24,28 @@ export const usePeoplePickerPermissions = () => {
const hasPeoplePickerAccess = canViewUsers || canViewGroups || canViewRoles;
const peoplePickerTypeFilter:
| PrincipalType.USER
| PrincipalType.GROUP
| PrincipalType.ROLE
| null = useMemo(() => {
if (canViewUsers && canViewGroups && canViewRoles) {
return null; // All types allowed
} else if (canViewUsers) {
return PrincipalType.USER;
} else if (canViewGroups) {
return PrincipalType.GROUP;
} else if (canViewRoles) {
return PrincipalType.ROLE;
const peoplePickerTypeFilter: Array<
PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE
> | null = useMemo(() => {
const allowedTypes: Array<PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE> = [];
if (canViewUsers) {
allowedTypes.push(PrincipalType.USER);
}
return null;
if (canViewGroups) {
allowedTypes.push(PrincipalType.GROUP);
}
if (canViewRoles) {
allowedTypes.push(PrincipalType.ROLE);
}
// Return null if no types are allowed (will show no results)
// or if all types are allowed (no filtering needed)
if (allowedTypes.length === 0 || allowedTypes.length === 3) {
return null;
}
return allowedTypes;
}, [canViewUsers, canViewGroups, canViewRoles]);
return {