-
Notifications
You must be signed in to change notification settings - Fork 1
569 create option users #575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d34f7c0
feat: #569 create users and users-list components
PaulRC-ioet e2caaea
feat: #569 create a user store and consume the service of users
PaulRC-ioet e998883
feat: #569 add test for user effects and selectors
PaulRC-ioet 6ad20d6
fix: #569 fix PR comments
PaulRC-ioet 5cc3346
fix: #569 fix PR comments by Rene
PaulRC-ioet f529b3e
fix: #569 remove column switch to admin
PaulRC-ioet 7b637c9
fix: #569 remove container from table
PaulRC-ioet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
15 changes: 15 additions & 0 deletions
15
src/app/modules/users/components/users-list/users-list.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <table *ngIf="users" class="table table-sm table-bordered table-striped mb-0" datatable [dtTrigger]="dtTrigger"> | ||
| <thead class="thead-blue"> | ||
| <tr class="d-flex"> | ||
| <th class="col-6">User Email</th> | ||
| <th class="col-6">Names</th> | ||
| </tr> | ||
| </thead> | ||
| <app-loading-bar *ngIf="isLoading$ | async"></app-loading-bar> | ||
| <tbody *ngIf="(isLoading$ | async) === false"> | ||
| <tr class="d-flex" *ngFor="let user of users"> | ||
| <td class="col-sm-6">{{ user.email }}</td> | ||
| <td class="col-sm-6">{{ user.name }}</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> |
80 changes: 80 additions & 0 deletions
80
src/app/modules/users/components/users-list/users-list.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { MockStore, provideMockStore } from '@ngrx/store/testing'; | ||
|
|
||
| import { NgxPaginationModule } from 'ngx-pagination'; | ||
| import { UsersListComponent } from './users-list.component'; | ||
| import { UserActionTypes, UserState, LoadUsers } from '../../store'; | ||
| import { ActionsSubject } from '@ngrx/store'; | ||
| import { DataTablesModule } from 'angular-datatables'; | ||
|
|
||
| describe('UsersListComponent', () => { | ||
| let component: UsersListComponent; | ||
| let fixture: ComponentFixture<UsersListComponent>; | ||
| let store: MockStore<UserState>; | ||
| const actionSub: ActionsSubject = new ActionsSubject(); | ||
|
|
||
| const state: UserState = { | ||
| data: [{ name: 'name', email: 'email', role: 'role', id: 'id', tenant_id: 'tenant id', deleted: 'delete' }], | ||
| isLoading: false, | ||
| message: '', | ||
| }; | ||
|
|
||
| beforeEach(async(() => { | ||
| TestBed.configureTestingModule({ | ||
| imports: [NgxPaginationModule, DataTablesModule], | ||
| declarations: [UsersListComponent], | ||
| providers: [provideMockStore({ initialState: state }), { provide: ActionsSubject, useValue: actionSub }], | ||
| }).compileComponents(); | ||
| })); | ||
|
|
||
| beforeEach(() => { | ||
| fixture = TestBed.createComponent(UsersListComponent); | ||
| component = fixture.componentInstance; | ||
| store = TestBed.inject(MockStore); | ||
| store.setState(state); | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('when the component is initialized the load User action is triggered', () => { | ||
| spyOn(store, 'dispatch'); | ||
|
|
||
| component.ngOnInit(); | ||
|
|
||
| expect(store.dispatch).toHaveBeenCalledWith(new LoadUsers()); | ||
| }); | ||
|
|
||
| it('on success load users, the user list should be populated', () => { | ||
| const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; | ||
| const action = { | ||
| type: UserActionTypes.LOAD_USERS_SUCCESS, | ||
| payload: state.data, | ||
| }; | ||
|
|
||
| actionSubject.next(action); | ||
|
|
||
| expect(component.users).toEqual(state.data); | ||
| }); | ||
|
|
||
| it('on success load users, the datatable should be reloaded', async () => { | ||
| const actionSubject = TestBed.inject(ActionsSubject); | ||
| const action = { | ||
| type: UserActionTypes.LOAD_USERS_SUCCESS, | ||
| payload: state.data, | ||
| }; | ||
| spyOn(component.dtElement.dtInstance, 'then'); | ||
|
|
||
| actionSubject.next(action); | ||
|
|
||
| expect(component.dtElement.dtInstance.then).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| component.dtTrigger.unsubscribe(); | ||
| component.loadUsersSubscription.unsubscribe(); | ||
| fixture.destroy(); | ||
| }); | ||
| }); | ||
55 changes: 55 additions & 0 deletions
55
src/app/modules/users/components/users-list/users-list.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; | ||
| import { ActionsSubject, select, Store } from '@ngrx/store'; | ||
| import { DataTableDirective } from 'angular-datatables'; | ||
| import { Observable, Subject, Subscription } from 'rxjs'; | ||
| import { delay, filter } from 'rxjs/operators'; | ||
| import { User } from '../../models/users'; | ||
| import { LoadUsers, UserActionTypes } from '../../store/user.actions'; | ||
| import { getIsLoading } from '../../store/user.selectors'; | ||
| @Component({ | ||
| selector: 'app-users-list', | ||
| templateUrl: './users-list.component.html', | ||
| styleUrls: ['./users-list.component.css'], | ||
| }) | ||
| export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { | ||
| users: User[] = []; | ||
| isLoading$: Observable<boolean>; | ||
| loadUsersSubscription: Subscription; | ||
| dtTrigger: Subject<any> = new Subject(); | ||
| @ViewChild(DataTableDirective, { static: false }) | ||
| dtElement: DataTableDirective; | ||
|
|
||
| constructor(private store: Store<User>, private actionsSubject$: ActionsSubject) { | ||
| this.isLoading$ = store.pipe(delay(0), select(getIsLoading)); | ||
| } | ||
|
|
||
| ngOnInit(): void { | ||
| this.loadUsersSubscription = this.actionsSubject$ | ||
| .pipe(filter((action: any) => action.type === UserActionTypes.LOAD_USERS_SUCCESS)) | ||
| .subscribe((action) => { | ||
| this.users = action.payload; | ||
| this.rerenderDataTable(); | ||
| }); | ||
| this.store.dispatch(new LoadUsers()); | ||
| } | ||
|
|
||
| ngAfterViewInit(): void { | ||
| this.rerenderDataTable(); | ||
PaulRC-ioet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| ngOnDestroy() { | ||
| this.loadUsersSubscription.unsubscribe(); | ||
| this.dtTrigger.unsubscribe(); | ||
| } | ||
|
|
||
| private rerenderDataTable(): void { | ||
| if (this.dtElement && this.dtElement.dtInstance) { | ||
| this.dtElement.dtInstance.then((dtInstances: DataTables.Api) => { | ||
| dtInstances.destroy(); | ||
| this.dtTrigger.next(); | ||
| }); | ||
| } else { | ||
| this.dtTrigger.next(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export interface User { | ||
| name: string; | ||
| email: string; | ||
| role?: string; | ||
| id: string; | ||
| tenant_id?: string; | ||
| deleted?: string; | ||
| } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <app-users-list></app-users-list> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { UsersComponent } from './users.component'; | ||
|
|
||
| describe('UsersComponent', () => { | ||
| let component: UsersComponent; | ||
| let fixture: ComponentFixture<UsersComponent>; | ||
|
|
||
| beforeEach(async(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [ UsersComponent ] | ||
| }) | ||
| .compileComponents(); | ||
| })); | ||
|
|
||
| beforeEach(() => { | ||
| fixture = TestBed.createComponent(UsersComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
PaulRC-ioet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-users', | ||
| templateUrl: './users.component.html', | ||
| styleUrls: ['./users.component.css'], | ||
| }) | ||
| export class UsersComponent { | ||
| constructor() {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { inject, TestBed } from '@angular/core/testing'; | ||
| import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
| import { UsersService } from './users.service'; | ||
|
|
||
| describe('UsersService', () => { | ||
| let service: UsersService; | ||
| let httpMock: HttpTestingController; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ imports: [HttpClientTestingModule] }); | ||
| service = TestBed.inject(UsersService); | ||
| httpMock = TestBed.inject(HttpTestingController); | ||
| service.baseUrl = 'users'; | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(service).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('services are ready to used', inject( | ||
| [HttpClientTestingModule, UsersService], | ||
| (httpClient: HttpClientTestingModule, userService: UsersService) => { | ||
| expect(httpClient).toBeTruthy(); | ||
| expect(userService).toBeTruthy(); | ||
| } | ||
| )); | ||
|
|
||
| it('load all users', () => { | ||
| service.loadUsers().subscribe(); | ||
|
|
||
| const loadUserRequest = httpMock.expectOne(service.baseUrl); | ||
| expect(loadUserRequest.request.method).toBe('GET'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { HttpClient } from '@angular/common/http'; | ||
| import { Injectable } from '@angular/core'; | ||
| import { Observable } from 'rxjs'; | ||
| import { environment } from './../../../../environments/environment'; | ||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class UsersService { | ||
| constructor(private http: HttpClient) {} | ||
|
|
||
| baseUrl = `${environment.timeTrackerApiUrl}/users`; | ||
|
|
||
| loadUsers(): Observable<any> { | ||
| return this.http.get(this.baseUrl); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './user.actions'; | ||
| export * from './user.reducers'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as actions from './user.actions'; | ||
|
|
||
| describe('UserActions', () => { | ||
| it('LoadUsers type is UserActionTypes.LOAD_USERS', () => { | ||
| const action = new actions.LoadUsers(); | ||
| expect(action.type).toEqual(actions.UserActionTypes.LOAD_USERS); | ||
| }); | ||
|
|
||
| it('LoadUsersSuccess type is UserActionTypes.LOAD_USERS_SUCCESS', () => { | ||
| const action = new actions.LoadUsersSuccess([]); | ||
| expect(action.type).toEqual(actions.UserActionTypes.LOAD_USERS_SUCCESS); | ||
| }); | ||
|
|
||
| it('LoadUsersFail type is UserActionTypes.LOAD_USERS_FAIL', () => { | ||
| const action = new actions.LoadUsersFail('error'); | ||
| expect(action.type).toEqual(actions.UserActionTypes.LOAD_USERS_FAIL); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Action } from '@ngrx/store'; | ||
| import { User } from '../models/users'; | ||
|
|
||
| export enum UserActionTypes { | ||
| LOAD_USERS = '[User] LOAD_USERS', | ||
| LOAD_USERS_SUCCESS = '[User] LOAD_USERS_SUCCESS', | ||
| LOAD_USERS_FAIL = '[User] LOAD_USERS_FAIL', | ||
| } | ||
|
|
||
| export class LoadUsers implements Action { | ||
| public readonly type = UserActionTypes.LOAD_USERS; | ||
| } | ||
|
|
||
| export class LoadUsersSuccess implements Action { | ||
| readonly type = UserActionTypes.LOAD_USERS_SUCCESS; | ||
| constructor(readonly payload: User[]) {} | ||
| } | ||
|
|
||
| export class LoadUsersFail implements Action { | ||
| public readonly type = UserActionTypes.LOAD_USERS_FAIL; | ||
| constructor(public error: string) {} | ||
| } | ||
|
|
||
| export type UserActions = LoadUsers | LoadUsersSuccess | LoadUsersFail; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.