Skip to content

Commit

Permalink
Merged in feature/SHIBUI-600 (pull request #98)
Browse files Browse the repository at this point in the history
SHIBUI-600 - Implemented navigation for wizard

Approved-by: Shibui Jenkins <shibui.jenkins@gmail.com>
Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Jun 29, 2018
2 parents 4949eba + 53f75e9 commit f141da5
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 27 deletions.
11 changes: 9 additions & 2 deletions ui/src/app/metadata/provider/action/entity.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export enum EntityActionTypes {
UPDATE_PROVIDER = '[Provider Entity] Update Provider',
SAVE_PROVIDER_REQUEST = '[Provider Entity] Save Provider Request',
SAVE_PROVIDER_SUCCESS = '[Provider Entity] Save Provider Success',
SAVE_PROVIDER_FAIL = '[Provider Entity] Save Provider Fail'
SAVE_PROVIDER_FAIL = '[Provider Entity] Save Provider Fail',

RESET_CHANGES = '[Provider Entity] Reset Provider Changes'
}

export class SelectProvider implements Action {
Expand Down Expand Up @@ -46,10 +48,15 @@ export class SaveProviderFail implements Action {
constructor(public payload: Error) { }
}

export class ResetChanges implements Action {
readonly type = EntityActionTypes.RESET_CHANGES;
}

export type EntityActionUnion =
| SelectProvider
| UpdateProvider
| SaveProviderRequest
| SaveProviderSuccess
| SaveProviderFail
| CreateProvider;
| CreateProvider
| ResetChanges;
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<sf-form
[schema]="schema$ | async"
[model]="formModel"
(onChange)="onValueChange($event)"
(onChange)="changeSubject.next($event)"
(isValid)="onStatusChange($event)"></sf-form>
</div>
<!--
<div class="col col-xl-6 col-lg-9 col-xs-12">
<code class="bg-light border rounded p-4 d-block"><pre>{{ changes$ | async | json }}</pre></code>
</div>
-->
-->
</div>
</div>
57 changes: 41 additions & 16 deletions ui/src/app/metadata/provider/container/provider-wizard.component.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@

import { Component, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription, Observable } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';
import { Subscription, Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, withLatestFrom } from 'rxjs/operators';
import { Store } from '@ngrx/store';

import * as fromProvider from '../reducer';
import * as fromWizard from '../../../wizard/reducer';

import { SetIndex, SetDisabled, UpdateDefinition, WizardActionTypes, Next } from '../../../wizard/action/wizard.action';
import { SetIndex, SetDisabled, UpdateDefinition, WizardActionTypes, Next, SetDefinition } from '../../../wizard/action/wizard.action';
import { LoadSchemaRequest, UpdateStatus } from '../action/editor.action';
import { startWith } from 'rxjs/operators';
import { Wizard, WizardStep } from '../../../wizard/model';
import { MetadataProvider } from '../../domain/model';
import { MetadataProviderTypes } from '../model';
import { MetadataProviderTypes, MetadataProviderWizard } from '../model';
import { UpdateProvider } from '../action/entity.action';
import { pick } from '../../../shared/util';

@Component({
selector: 'provider-wizard-page',
Expand All @@ -25,7 +26,11 @@ import { UpdateProvider } from '../action/entity.action';
export class ProviderWizardComponent implements OnDestroy {
actionsSubscription: Subscription;

changeSubject = new Subject<Partial<any>>();
private changeEmitted$ = this.changeSubject.asObservable();

schema$: Observable<any>;
schema: any;
definition$: Observable<Wizard<MetadataProvider>>;
changes$: Observable<MetadataProvider>;
currentPage: string;
Expand All @@ -37,9 +42,7 @@ export class ProviderWizardComponent implements OnDestroy {
previousStep: WizardStep;

constructor(
private store: Store<fromProvider.ProviderState>,
private route: ActivatedRoute,
private router: Router
private store: Store<fromProvider.ProviderState>
) {
this.store
.select(fromWizard.getCurrentWizardSchema)
Expand All @@ -59,14 +62,44 @@ export class ProviderWizardComponent implements OnDestroy {
.subscribe((valid) => {
this.store.dispatch(new SetDisabled(!valid));
});

this.schema$.subscribe(s => this.schema = s);

this.changeEmitted$
.pipe(
withLatestFrom(this.schema$, this.definition$),
)
.subscribe(
([changes, schema, definition]) => {
const type = changes.value['@type'];
if (type && type !== definition.type) {
const newDefinition = MetadataProviderTypes.find(def => def.type === type);
if (newDefinition) {
this.store.dispatch(new SetDefinition({
...MetadataProviderWizard,
...newDefinition,
steps: [
...MetadataProviderWizard.steps,
...newDefinition.steps
]
}));
changes = { value: pick(Object.keys(schema.properties))(changes.value) };
}
}
this.store.dispatch(new UpdateProvider(changes.value));
}
);
}

ngOnDestroy() {
this.actionsSubscription.unsubscribe();
this.changeSubject.complete();
}

next(): void {
this.store.dispatch(new SetIndex(this.nextStep.id));
if (this.nextStep) {
this.store.dispatch(new SetIndex(this.nextStep.id));
}
}

previous(): void {
Expand All @@ -77,14 +110,6 @@ export class ProviderWizardComponent implements OnDestroy {
console.log('Save!');
}

onValueChange(changes: any): void {
const type = changes.value['@type'];
if (type) {
this.store.dispatch(new UpdateDefinition(MetadataProviderTypes.find(def => def.type === type)));
}
this.store.dispatch(new UpdateProvider(changes.value));
}

onStatusChange(value): void {
const status = { [this.currentPage]: value ? 'VALID' : 'INVALID' };
this.store.dispatch(new UpdateStatus(status));
Expand Down
8 changes: 8 additions & 0 deletions ui/src/app/metadata/provider/effect/editor.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from '../action/editor.action';
import { map, switchMap, catchError } from 'rxjs/operators';
import { of } from 'rxjs';
import { SetDefinition, WizardActionTypes } from '../../../wizard/action/wizard.action';
import { ResetChanges } from '../action/entity.action';

@Injectable()
export class EditorEffects {
Expand All @@ -28,6 +30,12 @@ export class EditorEffects {
)
);

@Effect()
$resetChanges = this.actions$.pipe(
ofType<SetDefinition>(WizardActionTypes.SET_DEFINITION),
map(() => new ResetChanges())
);

constructor(
private schemaService: SchemaService,
private actions$: Actions
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/metadata/provider/reducer/entity.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const initialState: EntityState = {

export function reducer(state = initialState, action: EntityActionUnion): EntityState {
switch (action.type) {
case EntityActionTypes.RESET_CHANGES: {
return {
...state,
changes: initialState.changes
};
}
case EntityActionTypes.SELECT_PROVIDER:
case EntityActionTypes.CREATE_PROVIDER: {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
:host {
fieldset {
margin-bottom: 1rem;
legend {
font-size: 1em;
font-size: 1rem;
}
}
}
11 changes: 11 additions & 0 deletions ui/src/app/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ export function checkByType(value): boolean {
}
}
}

export function pick(approvedProperties: string[]): Function {
return (original) =>
Object.keys(original)
.filter((key) => approvedProperties.indexOf(key) > -1)
.reduce((newObj, key) => {
let value = original[key];
newObj[key] = value;
return newObj;
}, {});
}
13 changes: 13 additions & 0 deletions ui/src/app/wizard/component/wizard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ <h3 class="tag tag-primary">
</span>
</button>
</li>
<li class="nav-item" *ngIf="(last$ | async)">
<button class="nav-link next btn clearfix" (click)="onNext.emit(null)" [disabled]="disabled$ | async" role="button">
<span class="label pull-left">
Finish And Validate
</span>
<span class="direction pull-right">
<i class="fa fa-fw fa-arrow-circle-right d-block fa-2x"></i>
<ng-container i18n="@@action--next">Next</ng-container>
</span>
</button>
</li>
<!--
<li class="nav-item" *ngIf="(save$ | async) && !(next$ | async)">
<button class="nav-link save btn" aria-label="Save" role="button">
<span class="label pull-left" i18n="@@action--save">Save</span>
Expand All @@ -39,5 +51,6 @@ <h3 class="tag tag-primary">
</span>
</button>
</li>
-->
</ul>
</nav>
4 changes: 2 additions & 2 deletions ui/src/app/wizard/component/wizard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class WizardComponent implements OnChanges {
previous$: Observable<WizardStep>;
next$: Observable<WizardStep>;
current$: Observable<WizardStep>;
save$: Observable<boolean>;
last$: Observable<WizardStep>;

constructor(
private store: Store<fromWizard.WizardState>
Expand All @@ -37,7 +37,7 @@ export class WizardComponent implements OnChanges {
this.previous$ = this.store.select(fromWizard.getPrevious);
this.next$ = this.store.select(fromWizard.getNext);
this.current$ = this.store.select(fromWizard.getCurrent);
this.save$ = this.store.select(fromWizard.getSave);
this.last$ = this.store.select(fromWizard.getLast);
}

ngOnChanges(): void {
Expand Down
8 changes: 4 additions & 4 deletions ui/src/app/wizard/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export const getCurrentFn = (index: string, wizard: Wizard<any>) => {
return wizard.steps.find(s => s.id === index);
};

export const getSaveFn = (index: string, wizard: Wizard<any>) => {
export const getLastFn = (index: string, wizard: Wizard<any>) => {
if (!wizard) { return null; }
const step = wizard.steps[wizard.steps.length - 1] && wizard.steps.length > 1;
return step;
const step = wizard.steps.length > 1 && wizard.steps[wizard.steps.length - 1];
return index === step.id ? step : null;
};

export const getPrevious = createSelector(getWizardIndex, getWizardDefinition, getPreviousFn);
export const getCurrent = createSelector(getWizardIndex, getWizardDefinition, getCurrentFn);
export const getNext = createSelector(getWizardIndex, getWizardDefinition, getNextFn);
export const getSave = createSelector(getWizardIndex, getWizardDefinition, getSaveFn);
export const getLast = createSelector(getWizardIndex, getWizardDefinition, getLastFn);

0 comments on commit f141da5

Please sign in to comment.