From cf7f2197a644803ef80de480f038f34897748245 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Tue, 14 Aug 2018 17:48:03 +0000 Subject: [PATCH] Merged in feature/SHIBUI-599 (pull request #156) SHIBUI-599 Implemented saving loader on provider/source Approved-by: Shibui Jenkins Approved-by: Ryan Mathis --- .../container/provider-edit.component.html | 8 +++- .../container/provider-edit.component.ts | 2 + .../container/provider-wizard.component.ts | 1 + .../provider/reducer/entity.reducer.spec.ts | 45 +++++++++++++++++++ .../provider/reducer/entity.reducer.ts | 20 ++++++++- .../component/wizard-nav.component.html | 13 +++++- .../component/wizard-nav.component.ts | 2 + .../wizard/component/wizard.component.html | 17 +++++-- 8 files changed, 100 insertions(+), 8 deletions(-) diff --git a/ui/src/app/metadata/provider/container/provider-edit.component.html b/ui/src/app/metadata/provider/container/provider-edit.component.html index 6f15638b7..85fc2bfc9 100644 --- a/ui/src/app/metadata/provider/container/provider-edit.component.html +++ b/ui/src/app/metadata/provider/container/provider-edit.component.html @@ -18,10 +18,14 @@
  diff --git a/ui/src/app/metadata/provider/container/provider-edit.component.ts b/ui/src/app/metadata/provider/container/provider-edit.component.ts index a29949bb5..a2c2e0b86 100644 --- a/ui/src/app/metadata/provider/container/provider-edit.component.ts +++ b/ui/src/app/metadata/provider/container/provider-edit.component.ts @@ -33,6 +33,7 @@ export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate valid$: Observable; isInvalid$: Observable; status$: Observable; + isSaving$: Observable; latest: MetadataProvider; provider: MetadataProvider; @@ -52,6 +53,7 @@ export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate this.valid$ = this.store.select(fromProvider.getEditorIsValid); this.isInvalid$ = this.valid$.pipe(map(v => !v)); this.status$ = this.store.select(fromProvider.getInvalidEditorForms); + this.isSaving$ = this.store.select(fromProvider.getEntityIsSaving); let startIndex$ = this.route.firstChild ? this.route.firstChild.params.pipe(map(p => p.form || 'filters')) : diff --git a/ui/src/app/metadata/provider/container/provider-wizard.component.ts b/ui/src/app/metadata/provider/container/provider-wizard.component.ts index f7f958db8..8a4e481f5 100644 --- a/ui/src/app/metadata/provider/container/provider-wizard.component.ts +++ b/ui/src/app/metadata/provider/container/provider-wizard.component.ts @@ -86,6 +86,7 @@ export class ProviderWizardComponent implements OnDestroy { } save(): void { + this.store.dispatch(new SetDisabled(true)); this.store.dispatch(new AddProviderRequest(this.provider)); } diff --git a/ui/src/app/metadata/provider/reducer/entity.reducer.spec.ts b/ui/src/app/metadata/provider/reducer/entity.reducer.spec.ts index a37687766..2f1bcff62 100644 --- a/ui/src/app/metadata/provider/reducer/entity.reducer.spec.ts +++ b/ui/src/app/metadata/provider/reducer/entity.reducer.spec.ts @@ -1,6 +1,15 @@ import { reducer, initialState as snapshot, isEntitySaved } from './entity.reducer'; import { EntityActionTypes, ClearProvider } from '../action/entity.action'; import { MetadataProvider } from '../../domain/model'; +import { + ProviderCollectionActionTypes, + UpdateProviderRequest, + AddProviderRequest, + UpdateProviderSuccess, + UpdateProviderFail, + AddProviderFail, + AddProviderSuccess +} from '../action/collection.action'; describe('Provider Editor Reducer', () => { describe('undefined action', () => { @@ -17,6 +26,42 @@ describe('Provider Editor Reducer', () => { }); }); + describe(`${ProviderCollectionActionTypes.UPDATE_PROVIDER_REQUEST}`, () => { + it('should set to `saving`', () => { + expect(reducer(snapshot, new UpdateProviderRequest({})).saving).toBe(true); + }); + }); + + describe(`${ProviderCollectionActionTypes.ADD_PROVIDER_REQUEST}`, () => { + it('should set to `saving`', () => { + expect(reducer(snapshot, new AddProviderRequest({})).saving).toBe(true); + }); + }); + + describe(`${ProviderCollectionActionTypes.UPDATE_PROVIDER_SUCCESS}`, () => { + it('should set to not `saving`', () => { + expect(reducer(snapshot, new UpdateProviderSuccess({id: 'foo', changes: {} })).saving).toBe(false); + }); + }); + + describe(`${ProviderCollectionActionTypes.ADD_PROVIDER_FAIL}`, () => { + it('should set to not `saving`', () => { + expect(reducer(snapshot, new AddProviderFail({})).saving).toBe(false); + }); + }); + + describe(`${ProviderCollectionActionTypes.ADD_PROVIDER_SUCCESS}`, () => { + it('should set to not `saving`', () => { + expect(reducer(snapshot, new AddProviderSuccess({})).saving).toBe(false); + }); + }); + + describe(`${ProviderCollectionActionTypes.UPDATE_PROVIDER_FAIL}`, () => { + it('should set to not `saving`', () => { + expect(reducer(snapshot, new UpdateProviderFail({})).saving).toBe(false); + }); + }); + describe(`isEntitySaved method`, () => { it('should return false if there are changes', () => { expect(isEntitySaved({ diff --git a/ui/src/app/metadata/provider/reducer/entity.reducer.ts b/ui/src/app/metadata/provider/reducer/entity.reducer.ts index 175c769d8..faa90afd5 100644 --- a/ui/src/app/metadata/provider/reducer/entity.reducer.ts +++ b/ui/src/app/metadata/provider/reducer/entity.reducer.ts @@ -1,5 +1,6 @@ import { MetadataProvider } from '../../domain/model'; import { EntityActionTypes, EntityActionUnion } from '../action/entity.action'; +import { ProviderCollectionActionsUnion, ProviderCollectionActionTypes } from '../action/collection.action'; export interface EntityState { saving: boolean; @@ -11,8 +12,25 @@ export const initialState: EntityState = { changes: null }; -export function reducer(state = initialState, action: EntityActionUnion): EntityState { +export function reducer(state = initialState, action: EntityActionUnion | ProviderCollectionActionsUnion): EntityState { switch (action.type) { + case ProviderCollectionActionTypes.ADD_PROVIDER_REQUEST: + case ProviderCollectionActionTypes.UPDATE_PROVIDER_REQUEST: { + return { + ...state, + saving: true + }; + } + + case ProviderCollectionActionTypes.UPDATE_PROVIDER_FAIL: + case ProviderCollectionActionTypes.UPDATE_PROVIDER_SUCCESS: + case ProviderCollectionActionTypes.ADD_PROVIDER_FAIL: + case ProviderCollectionActionTypes.ADD_PROVIDER_SUCCESS: { + return { + ...state, + saving: false + }; + } case EntityActionTypes.CLEAR_PROVIDER: { return { ...initialState diff --git a/ui/src/app/metadata/resolver/component/wizard-nav.component.html b/ui/src/app/metadata/resolver/component/wizard-nav.component.html index 02ff3865f..ca6c3cccc 100644 --- a/ui/src/app/metadata/resolver/component/wizard-nav.component.html +++ b/ui/src/app/metadata/resolver/component/wizard-nav.component.html @@ -35,10 +35,19 @@