Skip to content

Commit

Permalink
fix(cb2-10211): fix duplicate error messages + global error service n…
Browse files Browse the repository at this point in the history
…ot focusing elements (#1331)
  • Loading branch information
pbardy2000 authored Dec 15, 2023
1 parent a4d818b commit da337a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/app/core/components/global-error/global-error.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,26 @@ export class GlobalErrorComponent {

goto(error: GlobalError) {
if (error.anchorLink) {
const el = document.getElementById(error.anchorLink);
if (el) {
el.focus({ preventScroll: false });
}
let focusCount = 0;

document.querySelectorAll(`
#${error.anchorLink},
#${error.anchorLink} a[href]:not([tabindex='-1']),
#${error.anchorLink} area[href]:not([tabindex='-1']),
#${error.anchorLink} input:not([disabled]):not([tabindex='-1']),
#${error.anchorLink} select:not([disabled]):not([tabindex='-1']),
#${error.anchorLink} textarea:not([disabled]):not([tabindex='-1']),
#${error.anchorLink} button:not([disabled]):not([tabindex='-1']),
#${error.anchorLink} iframe:not([tabindex='-1']),
#${error.anchorLink} [tabindex]:not([tabindex='-1']),
#${error.anchorLink} [contentEditable=true]:not([tabindex='-1'])
`)
.forEach((el) => {
if (el instanceof HTMLElement && focusCount < 2) {
focusCount++;
el.focus({ preventScroll: false });
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { fetchSearchResult, fetchSearchResultFailed } from '@store/tech-record-search/actions/tech-record-search.actions';
// eslint-disable-next-line import/no-cycle
import * as TestResultActions from '@store/test-records';
import _ from 'lodash';
import * as ReferenceDataActions from '../../reference-data/actions/reference-data.actions';
import * as TechnicalRecordServiceActions from '../../technical-records/actions/technical-record-service.actions';
import { createVehicleRecordFailure } from '../../technical-records/actions/technical-record-service.actions';
Expand Down Expand Up @@ -57,7 +58,7 @@ export const globalErrorReducer = createReducer(
),
on(GlobalErrorActions.setErrors, TestResultActions.updateTestResultFailed, TestResultActions.createTestResultFailed, (state, { errors }) => ({
...state,
errors: [...errors],
errors: [...(_.uniqWith(errors, (a, b) => _.isEqual(a.error, b.error)))],
})),
on(GlobalErrorActions.patchErrors, (state, { errors }) => ({ ...state, errors: [...state.errors, ...errors] })),
on(createVehicleRecordFailure, (state, action) => ({ errors: [...state.errors, { error: action.error }] })),
Expand Down

0 comments on commit da337a7

Please sign in to comment.