Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TT-97 fix: refactor code
  • Loading branch information
PaulRC-ioet committed Jan 18, 2021
commit 2a0472e20a83ce2998d7ba21d5130ca00965fedc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
<td class="col">{{ user.name }}</td>
<td class="col text-center" *ngIf="isFlagOn">
<div>
<ui-switch size="small" (change)="revokeOrGrantRole(user.id, user.role)" [checked]="isAdmin(user.role)"></ui-switch>
Admin
</div>
<div>
<ui-switch size="small"></ui-switch>
Test
<ui-switch
size="small"
(change)="switchRole(user.id, user.roles, 'admin', 'time-tracker-admin')"
[checked]="user.roles.includes('time-tracker-admin')"
></ui-switch>
admin
<ui-switch
size="small"
(change)="switchRole(user.id, user.roles, 'test', 'time-tracker-tester')"
[checked]="user.roles.includes('time-tracker-tester')"
></ui-switch>
test
</div>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('UsersListComponent', () => {
expect(component.users).toEqual(state.data);
});
/*
TODO: blocke commented on purpose so that when the tests pass and the Feature toggle is removed,
TODO: block commented on purpose so that when the tests pass and the Feature toggle is removed,
the table will be rendered again with dtInstance and not with dtOptions

it('on success load users, the data of roles should be an array and role null', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
this.isLoading$ = store.pipe(delay(0), select(getIsLoading));
this.isFeatureToggleAactivated().subscribe((flag) => {
this.isFlagOn = flag;
console.log(this.isFlagOn);
});
}

Expand Down Expand Up @@ -78,14 +77,10 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
}
}

isAdmin(role) {
return role ? true : false;
}

revokeOrGrantRole(userId: string, userRole: string) {
userRole
? this.store.dispatch(new RevokeRoleUser(userId, 'admin'))
: this.store.dispatch(new GrantRoleUser(userId, 'admin'));
switchRole(userId: string, userRoles: string[], roleId: string, roleValue: string) {
userRoles.includes(roleValue)
? this.store.dispatch(new RevokeRoleUser(userId, roleId))
: this.store.dispatch(new GrantRoleUser(userId, roleId));
}

isFeatureToggleAactivated() {
Expand Down