Skip to content

Commit

Permalink
[NIFI-13589] improve loading and error handling for jolt UI (#9155)
Browse files Browse the repository at this point in the history
* [NIFI-13589] improve loading and error handling for jolt UI

* remove unused state

* cleanup more state

* show errors in center of page

This closes #9155
  • Loading branch information
scottyaslan authored Aug 15, 2024
1 parent e46c7db commit 30e8df6
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h3 class="primary-color">Advanced</h3>
(codeMirrorLoaded)="initSpecEditor($event)"></ngx-codemirror>
</div>
<div class="w-full overflow-ellipsis overflow-hidden whitespace-nowrap">
@if (joltState.validate().saving) {
@if (joltState.validate().loading) {
<i
class="fa fa-refresh fa-spin mr-2"
nifiTooltip
Expand Down Expand Up @@ -293,7 +293,7 @@ <h3 class="primary-color">Advanced</h3>
</div>
<div class="flex flex-1 mt-2 justify-start">
<div class="w-full overflow-ellipsis overflow-hidden whitespace-nowrap">
@if (joltState.transform().saving) {
@if (joltState.transform().loading) {
<i
class="fa fa-refresh fa-spin mr-2"
nifiTooltip
Expand Down Expand Up @@ -381,9 +381,15 @@ <h3 class="primary-color">Advanced</h3>
</div>
</form>
} @else {
<div class="flex flex-1 justify-center items-center">
<i class="fa fa-warning caution-color mr-2"></i>An error has occurred loading the editor.
</div>
@if (processorDetailsLoading$ | async) {
<div class="h-full flex items-center justify-center">
<mat-spinner color="primary"></mat-spinner>
</div>
} @else if (processorDetailsError()) {
<div class="flex flex-1 justify-center items-center">
<i class="fa fa-warning caution-color mr-2"></i>{{ processorDetailsError() }}
</div>
}
}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
selectEditableFromRoute,
selectJoltTransformJsonProcessorDetailsState,
selectProcessorDetails,
selectProcessorDetailsError,
selectProcessorDetailsLoading,
selectProcessorIdFromRoute,
selectRevisionFromRoute
} from '../state/jolt-transform-json-processor-details/jolt-transform-json-processor-details.selectors';
Expand Down Expand Up @@ -84,6 +86,8 @@ export class JoltTransformJsonUi implements OnDestroy {
transform: this.store.selectSignal(selectJoltTransformJsonTransformState)
};
processorDetails$ = this.store.select(selectProcessorDetails);
processorDetailsLoading$ = this.store.select(selectProcessorDetailsLoading);
processorDetailsError = this.store.selectSignal(selectProcessorDetailsError);
editable: boolean = false;
createNew: (existingEntries: string[]) => Observable<MapTableEntry> =
this.mapTableHelperService.createNewEntry('Attribute');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { MatExpansionModule } from '@angular/material/expansion';
import { JoltTransformJsonTransformEffects } from '../state/jolt-transform-json-transform/jolt-transform-json-transform.effects';
import { JoltTransformJsonValidateEffects } from '../state/jolt-transform-json-validate/jolt-transform-json-validate.effects';
import { JoltTransformJsonPropertyEffects } from '../state/jolt-transform-json-property/jolt-transform-json-property.effects';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';

@NgModule({
declarations: [JoltTransformJsonUi],
Expand Down Expand Up @@ -70,7 +71,8 @@ import { JoltTransformJsonPropertyEffects } from '../state/jolt-transform-json-p
ComponentContext,
MatExpansionModule,
FormsModule,
MapTable
MapTable,
MatProgressSpinnerModule
]
})
export class JoltTransformJsonUiModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/

export interface JoltTransformJsonProcessorDetailsState {
saving: boolean;
loading: boolean;
error: string | null;
processorDetails: ProcessorDetails | null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ export const loadProcessorDetailsSuccess = createAction(

export const loadProcessorDetailsFailure = createAction(
`${JOLT_TRANSFORM_JSON_PROCESSOR_DETAILS_PREFIX} Load Processor Details Failure`,
props<{ response: HttpErrorResponse }>()
props<{ response: string }>()
);
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ export class JoltTransformJsonProcessorDetailsEffects {
})
),
catchError((errorResponse: HttpErrorResponse) => {
let errorMessage = 'An unspecified error occurred.';

if (errorResponse.status !== 0) {
if (typeof errorResponse.error === 'string') {
errorMessage = errorResponse.error;
} else {
errorMessage = errorResponse.message || `${errorResponse.status}`;
}
}

return of(
loadProcessorDetailsFailure({
response: errorResponse
response: errorMessage
})
);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import { JoltTransformJsonProcessorDetailsState } from './index';
import { createReducer, on } from '@ngrx/store';
import {
loadProcessorDetails,
loadProcessorDetailsFailure,
loadProcessorDetailsSuccess,
resetJoltTransformJsonProcessorDetailsState
} from './jolt-transform-json-processor-details.actions';

export const initialState: JoltTransformJsonProcessorDetailsState = {
saving: false,
loading: false,
error: null,
processorDetails: null
};

Expand All @@ -33,12 +35,20 @@ export const joltTransformJsonProcessorDetailsReducer = createReducer(
on(resetJoltTransformJsonProcessorDetailsState, () => ({
...initialState
})),
on(loadProcessorDetails, (state) => ({
...state,
error: null,
loading: true
})),
on(loadProcessorDetailsSuccess, (state, { response }) => ({
...state,
processorDetails: response
processorDetails: response,
loading: false
})),
on(loadProcessorDetailsFailure, (state) => ({
on(loadProcessorDetailsFailure, (state, { response }) => ({
...state,
processorDetails: null
processorDetails: null,
error: response,
loading: false
}))
);
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ export const selectProcessorDetails = createSelector(
(state: JoltTransformJsonProcessorDetailsState) => state.processorDetails
);

export const selectSaving = createSelector(
export const selectProcessorDetailsLoading = createSelector(
selectJoltTransformJsonProcessorDetailsState,
(state: JoltTransformJsonProcessorDetailsState) => state.saving
(state: JoltTransformJsonProcessorDetailsState) => state.loading
);

export const selectProcessorDetailsError = createSelector(
selectJoltTransformJsonProcessorDetailsState,
(state: JoltTransformJsonProcessorDetailsState) => state.error
);

export const selectProcessorIdFromRoute = createSelector(selectCurrentRoute, (route) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { HttpErrorResponse } from '@angular/common/http';

export interface JoltTransformJsonTransformState {
saving: boolean;
loading: boolean;
transformationResponse?: TransformJoltSpecSuccess | null;
transformationFailureResponse?: HttpErrorResponse | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from './jolt-transform-json-transform.actions';

export const initialState: JoltTransformJsonTransformState = {
saving: false,
loading: false,
transformationResponse: null,
transformationFailureResponse: null
};
Expand All @@ -37,16 +37,16 @@ export const joltTransformJsonTransformReducer = createReducer(
})),
on(transformJoltSpec, (state) => ({
...state,
saving: true
loading: true
})),
on(transformJoltSpecSuccess, (state, { response }) => ({
...state,
saving: false,
loading: false,
transformationResponse: response
})),
on(transformJoltSpecFailure, (state, { response }) => ({
...state,
saving: false,
loading: false,
transformationResponse: null,
transformationFailureResponse: response
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,3 @@ export const selectJoltTransformJsonTransformState = createSelector(
selectJoltTransformJsonUiState,
(state: JoltTransformJsonUiState) => state[joltTransformJsonTransformFeatureKey]
);

export const selectSaving = createSelector(
selectJoltTransformJsonTransformState,
(state: JoltTransformJsonTransformState) => state.saving
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { HttpErrorResponse } from '@angular/common/http';

export interface JoltTransformJsonValidateState {
saving: boolean | null;
loading: boolean | null;
validationResponse?: ValidateJoltSpecSuccess | null;
validationFailureResponse?: HttpErrorResponse | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from './jolt-transform-json-validate.actions';

export const initialState: JoltTransformJsonValidateState = {
saving: false,
loading: false,
validationResponse: null,
validationFailureResponse: null
};
Expand All @@ -38,21 +38,21 @@ export const joltTransformJsonValidateReducer = createReducer(
})),
on(validateJoltSpec, (state) => ({
...state,
saving: true
loading: true
})),
on(validateJoltSpecSuccess, (state, { response }) => ({
...state,
saving: false,
loading: false,
validationResponse: response
})),
on(validateJoltSpecFailure, (state, { response }) => ({
...state,
saving: false,
loading: false,
validationFailureResponse: response
})),
on(resetValidateJoltSpecState, (state) => ({
...state,
saving: null,
loading: null,
validationResponse: null,
validationFailureResponse: null
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,3 @@ export const selectJoltTransformJsonValidateState = createSelector(
selectJoltTransformJsonUiState,
(state: JoltTransformJsonUiState) => state[joltTransformJsonValidateFeatureKey]
);

export const selectSaving = createSelector(
selectJoltTransformJsonValidateState,
(state: JoltTransformJsonValidateState) => state.saving
);

0 comments on commit 30e8df6

Please sign in to comment.