Skip to content

Commit 321d812

Browse files
wobravoLEON12699
authored andcommitted
fix: TT-190 use add remove groups
1 parent dc4ebbc commit 321d812

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
<div>
2323
<ui-switch
2424
size="small"
25-
(change)="switchRole(user.id, user.roles, 'admin', 'time-tracker-admin')"
26-
[checked]="user.roles.includes('time-tracker-admin')"
25+
(change)="switchGroups(user.id, user.groups, 'admin', 'time-tracker-admin')"
26+
[checked]="user.groups.includes('time-tracker-admin')"
2727
></ui-switch>
2828
admin
2929
<ui-switch
3030
size="small"
31-
(change)="switchRole(user.id, user.roles, 'test', 'time-tracker-tester')"
32-
[checked]="user.roles.includes('time-tracker-tester')"
31+
(change)="switchGroups(user.id, user.groups, 'test', 'time-tracker-tester')"
32+
[checked]="user.groups.includes('time-tracker-tester')"
3333
></ui-switch>
3434
test
3535
</div>

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

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
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';
5-
import { delay, filter } from 'rxjs/operators';
4+
import { Observable, Subject, Subscription} from 'rxjs';
5+
import { delay, filter, map } from 'rxjs/operators';
6+
import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service';
67
import { User } from '../../models/users';
7-
import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes } from '../../store/user.actions';
8+
import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes, AddUserToGroup, RemoveUserToGroup} from '../../store/user.actions';
89
import { getIsLoading } from '../../store/user.selectors';
910

1011
@Component({
@@ -21,8 +22,16 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
2122
@ViewChild(DataTableDirective, { static: false })
2223
dtElement: DataTableDirective;
2324
dtOptions: any = {};
25+
switchGroupsSubscription: Subscription;
26+
isEnableToggleSubscription: Subscription;
27+
isUserRoleToggleOn;
28+
flakyToggle: true;
2429

25-
constructor(private store: Store<User>, private actionsSubject$: ActionsSubject) {
30+
constructor(
31+
private store: Store<User>,
32+
private actionsSubject$: ActionsSubject,
33+
private featureManagerService: FeatureManagerService
34+
) {
2635
this.isLoading$ = store.pipe(delay(0), select(getIsLoading));
2736
}
2837

@@ -35,6 +44,24 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
3544
this.rerenderDataTable();
3645
});
3746

47+
this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
48+
this.isUserRoleToggleOn = flag;
49+
console.log('in subscription', this.isUserRoleToggleOn);
50+
});
51+
52+
this.switchGroupsSubscription = this.actionsSubject$
53+
.pipe(
54+
filter(
55+
(action: any) =>
56+
action.type === UserActionTypes.ADD_USER_TO_GROUP_SUCCESS ||
57+
action.type === UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS
58+
)
59+
)
60+
.subscribe((action) => {
61+
this.store.dispatch(new LoadUsers());
62+
this.rerenderDataTable();
63+
});
64+
3865
this.switchRoleSubscription = this.actionsSubject$
3966
.pipe(
4067
filter(
@@ -55,6 +82,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
5582
ngOnDestroy() {
5683
this.loadUsersSubscription.unsubscribe();
5784
this.dtTrigger.unsubscribe();
85+
this.isEnableToggleSubscription.unsubscribe();
5886
}
5987

6088
private rerenderDataTable(): void {
@@ -73,4 +101,18 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
73101
? this.store.dispatch(new RevokeRoleUser(userId, roleId))
74102
: this.store.dispatch(new GrantRoleUser(userId, roleId));
75103
}
104+
105+
isFeatureToggleActivated() {
106+
return this.featureManagerService.isToggleEnabledForUser('ui-list-technologies').pipe(
107+
map((enabled) => {
108+
return enabled === true ? true : false;
109+
})
110+
);
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+
}
76118
}

0 commit comments

Comments
 (0)