Skip to content

Commit

Permalink
Merged in bugfix/SHIBUI-1091 (pull request #267)
Browse files Browse the repository at this point in the history
SHIBUI-1091 Implemented fix for state not clearing on update

Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Jan 8, 2019
2 parents f946884 + fc19023 commit b88cdc1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
25 changes: 19 additions & 6 deletions ui/src/app/metadata/filter/container/edit-filter.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { Component, OnDestroy } from '@angular/core';
import { Store } from '@ngrx/store';
import { Subject, Observable } from 'rxjs';
import { Subject, Observable, Subscription } from 'rxjs';

import * as fromFilter from '../reducer';
import { MetadataFilterTypes } from '../model';
Expand All @@ -11,13 +11,15 @@ import { UpdateFilterRequest } from '../action/collection.action';
import { CancelCreateFilter, UpdateFilterChanges } from '../action/filter.action';
import { PreviewEntity } from '../../domain/action/entity.action';
import { EntityAttributesFilterEntity } from '../../domain/entity';
import { shareReplay, map, withLatestFrom, filter, switchMap, startWith, defaultIfEmpty } from 'rxjs/operators';
import { shareReplay, map, withLatestFrom, filter, switchMap, startWith, defaultIfEmpty, takeUntil } from 'rxjs/operators';

@Component({
selector: 'edit-filter-page',
templateUrl: './edit-filter.component.html'
})
export class EditFilterComponent {
export class EditFilterComponent implements OnDestroy {

private ngUnsubscribe: Subject<void> = new Subject<void>();

valueChangeSubject = new Subject<Partial<any>>();
private valueChangeEmitted$ = this.valueChangeSubject.asObservable();
Expand All @@ -39,21 +41,25 @@ export class EditFilterComponent {

actions: any;

defSub: Subscription;

constructor(
private store: Store<fromFilter.State>,
private schemaService: SchemaService
) {
this.definition$ = this.store.select(fromFilter.getFilterType).pipe(
takeUntil(this.ngUnsubscribe),
filter(t => !!t),
map(t => MetadataFilterTypes[t])
);

this.definition$.subscribe(d => this.definition = d);
this.defSub = this.definition$.subscribe(d => this.definition = d);

this.schema$ = this.definition$.pipe(
takeUntil(this.ngUnsubscribe),
filter(d => !!d),
switchMap(d => {
return this.schemaService.get(d.schema);
return this.schemaService.get(d.schema).pipe(takeUntil(this.ngUnsubscribe));
}),
shareReplay()
);
Expand All @@ -67,6 +73,7 @@ export class EditFilterComponent {
});

this.validators$ = this.store.select(fromFilter.getFilterNames).pipe(
takeUntil(this.ngUnsubscribe),
withLatestFrom(
this.store.select(fromFilter.getSelectedFilter),
this.definition$
Expand All @@ -87,6 +94,12 @@ export class EditFilterComponent {
};
}

ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
this.defSub.unsubscribe();
}

save(): void {
this.store.dispatch(new UpdateFilterRequest(this.filter));
}
Expand Down
6 changes: 5 additions & 1 deletion ui/src/app/metadata/filter/container/new-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class NewFilterComponent implements OnDestroy, OnInit {
filter(t => !!t),
map(t => MetadataFilterTypes[t])
);

this.schema$ = this.definition$.pipe(
takeUntil(this.ngUnsubscribe),
filter(d => !!d),
Expand All @@ -80,7 +81,10 @@ export class NewFilterComponent implements OnDestroy, OnInit {
this.options$ = of(Object.values(MetadataFilterTypes));

this.form.get('type').valueChanges
.pipe(distinctUntilChanged())
.pipe(
takeUntil(this.ngUnsubscribe),
distinctUntilChanged()
)
.subscribe(type => this.store.dispatch(new SelectFilterType(type)));
}

Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/metadata/filter/effect/collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ export class FilterCollectionEffects {
tap(([filter, provider]) => this.router.navigate(['/', 'metadata', 'provider', provider, 'filters']))
);

@Effect()
updateFilterSuccessResetState$ = this.actions$.pipe(
ofType<UpdateFilterSuccess>(FilterCollectionActionTypes.UPDATE_FILTER_SUCCESS),
map(() => new ClearFilter())
);

@Effect()
getOrderWithLoad$ = this.actions$.pipe(
ofType<LoadFilterSuccess>(FilterCollectionActionTypes.LOAD_FILTER_SUCCESS),
Expand Down

0 comments on commit b88cdc1

Please sign in to comment.