Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@

import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Client } from '../../../service/client.service';
import { LoadBulletinBoardRequest } from '../state/bulletin-board';

@Injectable({ providedIn: 'root' })
export class BulletinBoardService {
private static readonly API: string = '../nifi-api';

constructor(
private httpClient: HttpClient,
private client: Client
) {}
constructor(private httpClient: HttpClient) {}

getBulletins(request: LoadBulletinBoardRequest) {
const params: HttpParams = request as HttpParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ export const resetBulletinBoardState = createAction(`${BULLETIN_BOARD_PREFIX} Re

export const clearBulletinBoard = createAction(`${BULLETIN_BOARD_PREFIX} Clear Bulletin Board`);

export const bulletinBoardApiError = createAction(
`${BULLETIN_BOARD_PREFIX} Load Bulletin Board Errors`,
props<{ error: string }>()
);

export const setBulletinBoardFilter = createAction(
`${BULLETIN_BOARD_PREFIX} Set Bulletin Board Filter`,
props<{ filter: BulletinBoardFilterArgs }>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,29 @@ import { Injectable } from '@angular/core';
import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { NiFiState } from '../../../../state';
import { Router } from '@angular/router';
import * as BulletinBoardActions from './bulletin-board.actions';
import { asyncScheduler, from, interval, map, of, switchMap, takeUntil } from 'rxjs';
import { asyncScheduler, catchError, from, interval, map, of, switchMap, takeUntil } from 'rxjs';
import { BulletinBoardService } from '../../service/bulletin-board.service';
import { selectBulletinBoardFilter, selectLastBulletinId } from './bulletin-board.selectors';
import { selectBulletinBoardFilter, selectLastBulletinId, selectStatus } from './bulletin-board.selectors';
import { LoadBulletinBoardRequest } from './index';
import { ErrorHelper } from '../../../../service/error-helper.service';
import { HttpErrorResponse } from '@angular/common/http';

@Injectable()
export class BulletinBoardEffects {
constructor(
private actions$: Actions,
private store: Store<NiFiState>,
private router: Router,
private bulletinBoardService: BulletinBoardService
private bulletinBoardService: BulletinBoardService,
private errorHelper: ErrorHelper
) {}

loadBulletinBoard$ = createEffect(() =>
this.actions$.pipe(
ofType(BulletinBoardActions.loadBulletinBoard),
map((action) => action.request),
switchMap((request) =>
concatLatestFrom(() => this.store.select(selectStatus)),
switchMap(([request, status]) =>
from(
this.bulletinBoardService.getBulletins(request).pipe(
map((response: any) =>
Expand All @@ -49,6 +51,9 @@ export class BulletinBoardEffects {
loadedTimestamp: response.bulletinBoard.generated
}
})
),
catchError((errorResponse: HttpErrorResponse) =>
of(this.errorHelper.handleLoadingError(status, errorResponse))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { BulletinBoardEvent, BulletinBoardItem, BulletinBoardState } from './index';
import { createReducer, on } from '@ngrx/store';
import {
bulletinBoardApiError,
clearBulletinBoard,
loadBulletinBoard,
loadBulletinBoardSuccess,
Expand All @@ -36,7 +35,6 @@ export const initialBulletinBoardState: BulletinBoardState = {
autoRefresh: true,
lastBulletinId: 0,
status: 'pending',
error: null,
loadedTimestamp: ''
};

Expand Down Expand Up @@ -67,17 +65,10 @@ export const bulletinBoardReducer = createReducer(
bulletinBoardItems: [...state.bulletinBoardItems, ...items],
lastBulletinId: lastId,
status: 'success' as const,
error: null,
loadedTimestamp: response.loadedTimestamp
};
}),

on(bulletinBoardApiError, (state, { error }) => ({
...state,
error,
status: 'error' as const
})),

on(resetBulletinBoardState, () => ({ ...initialBulletinBoardState })),

on(clearBulletinBoard, (state) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ export const selectBulletinBoardFilter = createSelector(
selectBulletinBoardState,
(state: BulletinBoardState) => state.filter
);

export const selectStatus = createSelector(selectBulletinBoardState, (state: BulletinBoardState) => state.status);
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export interface BulletinBoardState {
autoRefresh: boolean;
lastBulletinId: number;
loadedTimestamp: string;
error: string | null;
status: 'pending' | 'loading' | 'error' | 'success';
status: 'pending' | 'loading' | 'success';
}

export interface LoadBulletinBoardResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const loadCountersSuccess = createAction(
);

export const counterListingApiError = createAction(
`${COUNTER_PREFIX} Load Counter Listing Errors`,
`${COUNTER_PREFIX} Load Counter Listing Error`,
props<{ error: string }>()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,34 @@
*/

import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects';
import { NiFiState } from '../../../../state';
import { Store } from '@ngrx/store';
import { Router } from '@angular/router';
import * as CounterListingActions from './counter-listing.actions';
import { catchError, from, map, of, switchMap, take, tap } from 'rxjs';
import { CountersService } from '../../service/counters.service';
import { MatDialog } from '@angular/material/dialog';
import { YesNoDialog } from '../../../../ui/common/yes-no-dialog/yes-no-dialog.component';
import * as ErrorActions from '../../../../state/error/error.actions';
import { ErrorHelper } from '../../../../service/error-helper.service';
import { HttpErrorResponse } from '@angular/common/http';
import { selectStatus } from './counter-listing.selectors';

@Injectable()
export class CounterListingEffects {
constructor(
private actions$: Actions,
private store: Store<NiFiState>,
private router: Router,
private countersService: CountersService,
private errorHelper: ErrorHelper,
private dialog: MatDialog
) {}

loadCounters$ = createEffect(() =>
this.actions$.pipe(
ofType(CounterListingActions.loadCounters),
switchMap(() =>
concatLatestFrom(() => this.store.select(selectStatus)),
switchMap(([, status]) =>
from(this.countersService.getCounters()).pipe(
map((response) =>
CounterListingActions.loadCountersSuccess({
Expand All @@ -49,12 +53,8 @@ export class CounterListingEffects {
}
})
),
catchError((error) =>
of(
CounterListingActions.counterListingApiError({
error: error.error
})
)
catchError((errorResponse: HttpErrorResponse) =>
of(this.errorHelper.handleLoadingError(status, errorResponse))
)
)
)
Expand Down Expand Up @@ -98,9 +98,19 @@ export class CounterListingEffects {
response
})
),
catchError((error) => of(CounterListingActions.counterListingApiError({ error: error.error })))
catchError((errorResponse: HttpErrorResponse) =>
of(CounterListingActions.counterListingApiError({ error: errorResponse.error }))
)
)
)
)
);

counterListingApiError$ = createEffect(() =>
this.actions$.pipe(
ofType(CounterListingActions.counterListingApiError),
map((action) => action.error),
switchMap((error) => of(ErrorActions.snackBarError({ error })))
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const initialState: CounterListingState = {
counters: [],
saving: false,
loadedTimestamp: '',
error: null,
status: 'pending'
};

Expand All @@ -44,14 +43,11 @@ export const counterListingReducer = createReducer(
...state,
counters: response.counters,
loadedTimestamp: response.loadedTimestamp,
error: null,
status: 'success' as const
})),
on(counterListingApiError, (state, { error }) => ({
on(counterListingApiError, (state) => ({
...state,
saving: false,
error,
status: 'error' as const
saving: false
})),
on(resetCounterSuccess, (state, { response }) => {
return produce(state, (draftState) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ export const selectCounterListingState = createSelector(
);

export const selectCounters = createSelector(selectCounterListingState, (state: CounterListingState) => state.counters);

export const selectStatus = createSelector(selectCounterListingState, (state: CounterListingState) => state.status);
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export interface CounterListingState {
counters: CounterEntity[];
saving: boolean;
loadedTimestamp: string;
error: string | null;
status: 'pending' | 'loading' | 'error' | 'success';
status: 'pending' | 'loading' | 'success';
}

export interface LoadCounterListingResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,9 @@ export class ControllerServicesEffects {
}
})
),
catchError((errorResponse: HttpErrorResponse) => {
if (status === 'success') {
if (this.errorHelper.showErrorInContext(errorResponse.status)) {
return of(ErrorActions.snackBarError({ error: errorResponse.error }));
} else {
return of(this.errorHelper.fullScreenError(errorResponse));
}
} else {
return of(this.errorHelper.fullScreenError(errorResponse));
}
})
catchError((errorResponse: HttpErrorResponse) =>
of(this.errorHelper.handleLoadingError(status, errorResponse))
)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ export const disableFlowAnalysisRuleSuccess = createAction(
props<{ response: DisableFlowAnalysisRuleSuccess }>()
);

export const flowAnalysisRuleApiError = createAction(
'[Flow Analysis Rules] Load Flow Analysis Rules Error',
export const flowAnalysisRuleBannerApiError = createAction(
'[Flow Analysis Rules] Load Flow Analysis Rule Banner Error',
props<{ error: string }>()
);

export const flowAnalysisRuleSnackbarApiError = createAction(
'[Flow Analysis Rules] Load Flow Analysis Rule Snackbar Error',
props<{ error: string }>()
);

Expand Down
Loading