Skip to content

Commit 2bdeb20

Browse files
committed
feat: TT-190 Use add/remove groups endpoints in users section in UI
1 parent 321d812 commit 2bdeb20

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

src/app/modules/users/components/users-list/users-list.component.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,37 @@
1919
<td class="col-4 text-break">{{ user.email }}</td>
2020
<td class="col-5 text-break">{{ user.name }}</td>
2121
<td class="col-3 text-center">
22-
<div>
22+
<div *ngIf="flakyToggle; else elseBlock">
2323
<ui-switch
2424
size="small"
25-
(change)="switchGroups(user.id, user.groups, 'admin', 'time-tracker-admin')"
25+
(change)="switchGroup(user.id, user.groups, 'time-tracker-admin')"
2626
[checked]="user.groups.includes('time-tracker-admin')"
2727
></ui-switch>
2828
admin
2929
<ui-switch
3030
size="small"
31-
(change)="switchGroups(user.id, user.groups, 'test', 'time-tracker-tester')"
31+
(change)="switchGroup(user.id, user.groups, 'time-tracker-tester')"
3232
[checked]="user.groups.includes('time-tracker-tester')"
3333
></ui-switch>
3434
test
3535
</div>
36+
<ng-template #elseBlock>
37+
<div>
38+
<ui-switch
39+
size="small"
40+
(change)="switchRole(user.id, user.roles, 'admin','time-tracker-admin')"
41+
[checked]="user.roles.includes('time-tracker-admin')"
42+
></ui-switch>
43+
admin
44+
<ui-switch
45+
size="small"
46+
(change)="switchRole(user.id, user.roles,'tester','time-tracker-tester')"
47+
[checked]="user.roles.includes('time-tracker-tester')"
48+
></ui-switch>
49+
test
50+
</div>
51+
</ng-template>
52+
3653
</td>
3754
</tr>
3855
</tbody>

src/app/modules/users/components/users-list/users-list.component.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
22
import { ActionsSubject, select, Store } from '@ngrx/store';
33
import { DataTableDirective } from 'angular-datatables';
4-
import { Observable, Subject, Subscription} from 'rxjs';
4+
import { Observable, Subject, Subscription } from 'rxjs';
55
import { delay, filter, map } from 'rxjs/operators';
66
import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service';
77
import { User } from '../../models/users';
8-
import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes, AddUserToGroup, RemoveUserToGroup} from '../../store/user.actions';
8+
import {
9+
GrantRoleUser,
10+
LoadUsers,
11+
RevokeRoleUser,
12+
UserActionTypes,
13+
AddUserToGroup,
14+
RemoveUserToGroup,
15+
} from '../../store/user.actions';
916
import { getIsLoading } from '../../store/user.selectors';
1017

1118
@Component({
@@ -24,13 +31,13 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
2431
dtOptions: any = {};
2532
switchGroupsSubscription: Subscription;
2633
isEnableToggleSubscription: Subscription;
27-
isUserRoleToggleOn;
28-
flakyToggle: true;
34+
isUserGroupsToggleOn;
35+
flakyToggle: boolean = false; // borrar para implementar feature toggle
2936

3037
constructor(
3138
private store: Store<User>,
3239
private actionsSubject$: ActionsSubject,
33-
private featureManagerService: FeatureManagerService
40+
//private featureManagerService: FeatureManagerService
3441
) {
3542
this.isLoading$ = store.pipe(delay(0), select(getIsLoading));
3643
}
@@ -44,10 +51,10 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
4451
this.rerenderDataTable();
4552
});
4653

47-
this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
48-
this.isUserRoleToggleOn = flag;
49-
console.log('in subscription', this.isUserRoleToggleOn);
50-
});
54+
/* this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
55+
this.isUserGroupsToggleOn = flag;
56+
console.log('in subscription', this.isUserGroupsToggleOn);
57+
});*/
5158

5259
this.switchGroupsSubscription = this.actionsSubject$
5360
.pipe(
@@ -102,17 +109,17 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
102109
: this.store.dispatch(new GrantRoleUser(userId, roleId));
103110
}
104111

105-
isFeatureToggleActivated() {
112+
switchGroup(userId: string, userGroups: string[], groupName: string) {
113+
userGroups.includes(groupName)
114+
? this.store.dispatch(new RemoveUserToGroup(userId, groupName))
115+
: this.store.dispatch(new AddUserToGroup(userId, groupName));
116+
}
117+
118+
/* isFeatureToggleActivated() {
106119
return this.featureManagerService.isToggleEnabledForUser('ui-list-technologies').pipe(
107120
map((enabled) => {
108121
return enabled === true ? true : false;
109122
})
110123
);
111-
}
112-
113-
switchGroups(userId: string, userGroups: string[], groupname: string, groupValue: string) {
114-
userGroups.includes(groupValue)
115-
? this.store.dispatch(new RemoveUserToGroup(userId, groupname))
116-
: this.store.dispatch(new AddUserToGroup(userId, groupname));
117-
}
124+
}*/
118125
}

0 commit comments

Comments
 (0)