Skip to content

Commit

Permalink
feat: Filter users by beta status
Browse files Browse the repository at this point in the history
  • Loading branch information
zusorio committed Dec 13, 2024
1 parent ebe2c33 commit 19a187d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
35 changes: 24 additions & 11 deletions frontend/src/app/users/user-settings/user-settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,29 @@ <h2 class="text-xl font-medium">Manage Users</h2>
<span class="text-sm">{{ users.length }} registered users</span>
}
</div>
<form [formGroup]="form">
<mat-form-field class="mb-[-20px] mt-[10px] w-full" appearance="outline">
<mat-label>Search</mat-label>
<input
formControlName="search"
matInput
placeholder="Username"
class="mr-2"
/>
<mat-icon matSuffix>search</mat-icon>
</mat-form-field>

<mat-form-field class="mb-[-20px] mt-[10px] w-full" appearance="outline">
<mat-label>Search</mat-label>
<input
[(ngModel)]="search"
matInput
placeholder="Username"
class="mr-2"
/>
<mat-icon matSuffix>search</mat-icon>
</mat-form-field>
<div>
<mat-chip-listbox formControlName="userType">
<mat-chip-option value="general">Normal</mat-chip-option>
<mat-chip-option value="beta">
<div class="flex items-center gap-1">
<mat-icon inline>science</mat-icon><span>Beta Tester</span>
</div>
</mat-chip-option>
</mat-chip-listbox>
</div>
</form>

<div class="max-h-[50vh] overflow-y-scroll">
@for (role of userRoles; track role) {
Expand All @@ -43,7 +55,8 @@ <h2 class="text-xl font-medium">Manage Users</h2>
<div>
<div class="break-all text-[17.5px]">{{ user.name }}</div>
<div class="text-[14px] text-gray-500">
{{ roleMapping[user.role] }}
{{ roleMapping[user.role] }} |
{{ user.beta_tester ? "Beta Tester" : "" }}
</div>
</div>
</a>
Expand Down
20 changes: 14 additions & 6 deletions frontend/src/app/users/user-settings/user-settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AsyncValidatorFn,
} from '@angular/forms';
import { MatIconButton, MatButton } from '@angular/material/button';
import { MatChipListbox, MatChipOption } from '@angular/material/chips';
import { MatDialog } from '@angular/material/dialog';
import {
MatFormField,
Expand Down Expand Up @@ -59,11 +60,11 @@ import { UserWrapperService } from 'src/app/users/user-wrapper/user-wrapper.serv
MatButton,
AsyncPipe,
NgxSkeletonLoaderModule,
MatChipListbox,
MatChipOption,
],
})
export class UserSettingsComponent implements OnInit {
search = '';

public readonly roleMapping = {
user: 'Global User',
administrator: 'Global Administrator',
Expand All @@ -80,6 +81,11 @@ export class UserSettingsComponent implements OnInit {
}),
});

form = new FormGroup({
search: new FormControl<string>(''),
userType: new FormControl<string | null>(null),
});

constructor(
public ownUserService: OwnUserWrapperService,
public userWrapperService: UserWrapperService,
Expand Down Expand Up @@ -252,10 +258,12 @@ export class UserSettingsComponent implements OnInit {
users: User[] | null | undefined,
role: UserRole,
): User[] | undefined {
return users?.filter(
(user) =>
user.role == role &&
user.name.toLowerCase().includes(this.search.toLowerCase()),
return users?.filter((user) =>
user.role == role &&
user.name.toLowerCase().includes(this.form.value.search.toLowerCase()) &&

Check failure on line 263 in frontend/src/app/users/user-settings/user-settings.component.ts

View workflow job for this annotation

GitHub Actions / pre-commit

Object is possibly 'null' or 'undefined'.
this.form.value.userType
? user.beta_tester == (this.form.value.userType == 'beta')
: true,
);
}
}

0 comments on commit 19a187d

Please sign in to comment.