From 72400ffa0b7f5a04adaf0896a4df82997cd16a90 Mon Sep 17 00:00:00 2001 From: Tobias Messner Date: Fri, 13 Dec 2024 11:35:58 +0100 Subject: [PATCH] feat: Filter users by beta status --- .../user-settings.component.html | 136 ++++++++++-------- .../user-settings/user-settings.component.ts | 25 +++- .../user-settings/user-settings.stories.ts | 6 + 3 files changed, 99 insertions(+), 68 deletions(-) diff --git a/frontend/src/app/users/user-settings/user-settings.component.html b/frontend/src/app/users/user-settings/user-settings.component.html index 10e82e5a5..2398ec752 100644 --- a/frontend/src/app/users/user-settings/user-settings.component.html +++ b/frontend/src/app/users/user-settings/user-settings.component.html @@ -11,80 +11,94 @@

Manage Users

{{ users.length }} registered users } +
+ + Search + + search + - - Search - - search - +
+ + Regular User + +
+ scienceBeta Tester +
+
+
+
+
@for (role of userRoles; track role) { -
- {{ getUsersByRole(userWrapperService.users$ | async, role)?.length }} - {{ roleMapping[role] + "(s)" }} -
- @for ( - user of getUsersByRole(userWrapperService.users$ | async, role); - track user.id - ) { -
- -
- account_circle -
-
-
{{ user.name }}
-
- {{ roleMapping[user.role] }} + @let users = getUsersByRole(userWrapperService.users$ | async, role); + @if (users) { +
+ {{ users.length }} + {{ roleMapping[role] }}{{ users.length !== 1 ? "s" : "" }} +
+ @for (user of users; track user.id) { +
- -
- @if (user.role === "administrator") { - @if (user.id !== ownUserService.user?.id) { +
+
{{ user.name }}
+
+ {{ roleMapping[user.role] + }}{{ user.beta_tester ? ", Beta Tester" : "" }} +
+
+ +
+ @if (user.role === "administrator") { + @if (user.id !== ownUserService.user?.id) { + + } + } @else { } - } @else { - - } - @if (user.id !== ownUserService.user?.id) { - - } + @if (user.id !== ownUserService.user?.id) { + + } +
-
+ } } + @if ((userWrapperService.users$ | async) === undefined) { (''), + userType: new FormControl(null), + }); + constructor( public ownUserService: OwnUserWrapperService, public userWrapperService: UserWrapperService, @@ -252,10 +258,15 @@ 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) => { + const roleMatches = user.role == role; + const searchMatches = user.name + .toLowerCase() + .includes(this.form.value.search?.toLowerCase() || ''); + const userTypeMatches = + this.form.value.userType == null || + user.beta_tester == (this.form.value.userType == 'beta'); + return roleMatches && searchMatches && userTypeMatches; + }); } } diff --git a/frontend/src/app/users/user-settings/user-settings.stories.ts b/frontend/src/app/users/user-settings/user-settings.stories.ts index 6e65480b0..9595f1943 100644 --- a/frontend/src/app/users/user-settings/user-settings.stories.ts +++ b/frontend/src/app/users/user-settings/user-settings.stories.ts @@ -45,6 +45,7 @@ export const Overview: Story = { ...mockUser, role: 'administrator', name: 'globalAdministrator2', + beta_tester: true, }, loggedInUser, mockUser, @@ -52,6 +53,11 @@ export const Overview: Story = { ...mockUser, name: 'userWithReallyLongNameThatHasToBeWrapped', }, + { + ...mockUser, + name: 'userThatsAlsoABetaTester', + beta_tester: true, + }, ]), mockOwnUserWrapperServiceProvider(loggedInUser), ],