-
Notifications
You must be signed in to change notification settings - Fork 22
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
EXUI-2058: Add error message on staffUI #3778
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b31eda
Add ngrx store for staff ui, Add error handling when staff user selec…
Josh-HMCTS 9bafb74
add Unit tests
Josh-HMCTS 02e29f4
Merge branch 'master' into fix/exui-2058
Josh-HMCTS c920315
Merge branch 'master' into fix/exui-2058
Josh-HMCTS 63f0454
Code review comments resolved
Josh-HMCTS 0eb3749
Merge branch 'master' into fix/exui-2058
Josh-HMCTS 2b884fa
Merge branch 'master' into fix/exui-2058
RiteshHMCTS 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
1 change: 1 addition & 0 deletions
1
src/staff-administrator/containers/staff-users/staff-users.component.html
This file contains 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 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 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 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,5 @@ | ||
import { StaffUserResponseError } from './staff-user-response-error.model'; | ||
|
||
export interface StaffState { | ||
staffGetError: null | StaffUserResponseError; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/staff-administrator/models/staff-user-response-error.model.ts
This file contains 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,7 @@ | ||
export interface StaffUserResponseError { | ||
errorCode: number; | ||
errorDescription: string; | ||
errorMessage: string; | ||
status: string; | ||
timeStamp: string; | ||
} |
19 changes: 15 additions & 4 deletions
19
src/staff-administrator/resolvers/staff-user-details-resolver.service.ts
This file contains 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 |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot } from '@angular/router'; | ||
import { map } from 'rxjs/operators'; | ||
import { Store } from '@ngrx/store'; | ||
import { catchError, map, tap } from 'rxjs/operators'; | ||
import { of } from 'rxjs'; | ||
import { StaffUser } from '../models/staff-user.model'; | ||
import { StaffDataAccessService } from '../services/staff-data-access/staff-data-access.service'; | ||
import { SetError, ResetStaffSelect } from '../store/actions/staff-select.action'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class StaffUserDetailsResolverService { | ||
constructor(private staffDataAccessService: StaffDataAccessService) { | ||
} | ||
constructor( | ||
private staffDataAccessService: StaffDataAccessService, | ||
private store: Store | ||
) {} | ||
|
||
public resolve(route?: ActivatedRouteSnapshot) { | ||
this.store.dispatch(new ResetStaffSelect()); | ||
return this.staffDataAccessService.fetchSingleUserById(route.params.id).pipe( | ||
map((user) => StaffUser.from(user)) | ||
tap((user:StaffUser) => console.log('User:', user)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you should commit this console.log There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, will remove |
||
map((user) => StaffUser.from(user)), | ||
catchError((error) => { | ||
this.store.dispatch(new SetError(error.error)); | ||
return of(); | ||
}) | ||
); | ||
} | ||
} |
This file contains 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
32 changes: 32 additions & 0 deletions
32
src/staff-administrator/store/actions/staff-select.action.spec.ts
This file contains 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,32 @@ | ||
import { StaffUserResponseError } from '../../models/staff-user-response-error.model'; | ||
import { SetError, ResetStaffSelect, SET_STAFF_SELECT_ERROR, RESET_STAFF_SELECT_ERROR } from './staff-select.action'; | ||
|
||
describe('StaffSelect Actions', () => { | ||
describe('SetError', () => { | ||
it('should create an action', () => { | ||
const error: StaffUserResponseError = { | ||
errorMessage: 'An error occurred.', | ||
errorCode: 404, | ||
errorDescription: 'A description of the error.', | ||
status: 'Failed', | ||
timeStamp: new Date().toISOString() | ||
}; | ||
const action = new SetError(error); | ||
|
||
expect({ ...action }).toEqual({ | ||
type: SET_STAFF_SELECT_ERROR, | ||
payload: error | ||
}); | ||
}); | ||
}); | ||
|
||
describe('ResetStaffSelect', () => { | ||
it('should create an action', () => { | ||
const action = new ResetStaffSelect(); | ||
|
||
expect({ ...action }).toEqual({ | ||
type: RESET_STAFF_SELECT_ERROR | ||
}); | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/staff-administrator/store/actions/staff-select.action.ts
This file contains 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 { Action } from '@ngrx/store'; | ||
import { StaffUserResponseError } from '../../models/staff-user-response-error.model'; | ||
|
||
export const SET_STAFF_SELECT_ERROR = '[Staff Select] Set Select Staff Error'; | ||
export const RESET_STAFF_SELECT_ERROR = '[Staff Select] Reset Staff Select Error'; | ||
|
||
export class SetError implements Action { | ||
public readonly type = SET_STAFF_SELECT_ERROR; | ||
constructor(public payload: StaffUserResponseError) { } | ||
} | ||
|
||
export class ResetStaffSelect implements Action { | ||
public readonly type = RESET_STAFF_SELECT_ERROR; | ||
} | ||
|
||
export type StaffSelectAction = | ||
| SetError | ||
| ResetStaffSelect; |
44 changes: 44 additions & 0 deletions
44
src/staff-administrator/store/reducers/staff-select.reducer.spec.ts
This file contains 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,44 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockStore } from '@ngrx/store/testing'; | ||
import { staffSelectReducer, initialState } from './staff-select.reducer'; | ||
import * as ErrorActions from '../actions/staff-select.action'; | ||
import { StaffUserResponseError } from '../../models/staff-user-response-error.model'; | ||
|
||
describe('staffSelectReducer', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [provideMockStore({ initialState })] | ||
}); | ||
}); | ||
|
||
it('should return the initial state', () => { | ||
const action = { type: 'NOOP' } as any; | ||
const result = staffSelectReducer(initialState, action); | ||
|
||
expect(result).toEqual(initialState); | ||
}); | ||
|
||
it('should handle RESET_STAFF_SELECT_ERROR', () => { | ||
const action = new ErrorActions.ResetStaffSelect(); | ||
const result = staffSelectReducer(initialState, action); | ||
|
||
expect(result).toEqual(initialState); | ||
}); | ||
|
||
it('should handle SET_STAFF_SELECT_ERROR', () => { | ||
const error: StaffUserResponseError = { | ||
errorMessage: 'Test error', | ||
errorCode: 123, | ||
errorDescription: 'Test error description', | ||
status: 'Error', | ||
timeStamp: '2022-01-01T00:00:00Z' | ||
}; | ||
const action = new ErrorActions.SetError(error); | ||
const result = staffSelectReducer(initialState, action); | ||
|
||
expect(result).toEqual({ | ||
...initialState, | ||
staffGetError: error | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/staff-administrator/store/reducers/staff-select.reducer.ts
This file contains 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,31 @@ | ||
import { StaffState } from '../../models/staff-state.model'; | ||
import * as ErrorActions from '../actions/staff-select.action'; | ||
|
||
export const initialState: StaffState = { | ||
staffGetError: null | ||
}; | ||
|
||
export function staffSelectReducer( | ||
currentState = initialState, | ||
action: ErrorActions.StaffSelectAction | ||
) { | ||
switch (action.type) { | ||
case ErrorActions.RESET_STAFF_SELECT_ERROR: { | ||
return { | ||
...initialState | ||
}; | ||
} | ||
case ErrorActions.SET_STAFF_SELECT_ERROR: { | ||
return { | ||
...currentState, | ||
staffGetError: action.payload | ||
}; | ||
} | ||
default: { | ||
return { | ||
...currentState | ||
}; | ||
} | ||
} | ||
} | ||
|
29 changes: 29 additions & 0 deletions
29
src/staff-administrator/store/selectors/staff-select.selector.spec.ts
This file contains 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,29 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { StoreModule, Store, select } from '@ngrx/store'; | ||
import { selectStaffError } from './staff-select.selector'; | ||
import { staffSelectReducer } from '../reducers/staff-select.reducer'; | ||
|
||
describe('Staff Selectors', () => { | ||
let store: Store; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
StoreModule.forRoot({}), | ||
StoreModule.forFeature('staffUI', staffSelectReducer) | ||
] | ||
}); | ||
store = TestBed.inject(Store); | ||
spyOn(store, 'dispatch').and.callThrough(); | ||
}); | ||
|
||
describe('getHearingConditions', () => { | ||
it('should return hearings navigation state', () => { | ||
let result = null; | ||
store.pipe(select(selectStaffError)).subscribe((value) => { | ||
result = value; | ||
}); | ||
expect(result).toBeNull(); | ||
}); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
src/staff-administrator/store/selectors/staff-select.selector.ts
This file contains 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,9 @@ | ||
import { createFeatureSelector, createSelector } from '@ngrx/store'; | ||
import { StaffState } from '../../models/staff-state.model'; | ||
|
||
export const selectStaffFeature = createFeatureSelector<any>('staffUI'); | ||
|
||
export const selectStaffError = createSelector( | ||
selectStaffFeature, | ||
(state: StaffState) => state.staffGetError | ||
); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use optional chaining on error?.errorDescription, or possibly a ternary:
error ? { title: 'Staff error', description: error.errorDescription ? error.errorDescription : "unknown error" } : null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added optional chaining and ternary