Skip to content

Commit

Permalink
SHIBUI-770 Implemented validation for duplicate entity id entries on …
Browse files Browse the repository at this point in the history
…filters
  • Loading branch information
rmathis committed Aug 16, 2018
1 parent 9449d07 commit 4b05e15
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
9 changes: 9 additions & 0 deletions ui/src/app/metadata/filter/effect/collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MetadataFilter } from '../../domain/model';
import { removeNulls } from '../../../shared/util';
import { EntityAttributesFilterEntity } from '../../domain/entity/filter/entity-attributes-filter';
import { MetadataFilterService } from '../../domain/service/filter.service';
import { SelectProviderRequest } from '../../provider/action/collection.action';

/* istanbul ignore next */
@Injectable()
Expand Down Expand Up @@ -96,6 +97,14 @@ export class FilterCollectionEffects {
);
})
);
@Effect()
updateFilterSuccessReloadProvider$ = this.actions$.pipe(
ofType<actions.UpdateFilterSuccess>(FilterCollectionActionTypes.UPDATE_FILTER_SUCCESS),
map(action => action.payload),
withLatestFrom(this.store.select(fromProvider.getSelectedProviderId).pipe(skipWhile(id => !id))),
map(([filter, providerId]) => new SelectProviderRequest(providerId))
);

@Effect({ dispatch: false })
updateFilterSuccessRedirect$ = this.actions$.pipe(
ofType<actions.UpdateFilterSuccess>(FilterCollectionActionTypes.UPDATE_FILTER_SUCCESS),
Expand Down
33 changes: 27 additions & 6 deletions ui/src/app/metadata/provider/effect/collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Router } from '@angular/router';
import { of } from 'rxjs';
import { map, catchError, switchMap, tap, withLatestFrom, debounceTime } from 'rxjs/operators';
import {
ProviderCollectionActionsUnion,
ProviderCollectionActionTypes,
AddProviderRequest,
AddProviderSuccess,
Expand All @@ -32,14 +31,32 @@ import {
import { MetadataProviderService } from '../../domain/service/provider.service';
import * as fromProvider from '../reducer';
import * as fromRoot from '../../../app.reducer';
import { AddFilterSuccess, FilterCollectionActionTypes } from '../../filter/action/collection.action';
import { debounce } from '../../../../../node_modules/rxjs-compat/operator/debounce';
import { ClearProvider, ResetChanges } from '../action/entity.action';
import { ShowContentionAction } from '../../../contention/action/contention.action';
import { ContentionService } from '../../../contention/service/contention.service';
import { MetadataProvider } from '../../domain/model';


/* istanbul ignore next */
@Injectable()
export class CollectionEffects {

@Effect()
openContention$ = this.actions$.pipe(
ofType<UpdateProviderFail>(ProviderCollectionActionTypes.UPDATE_PROVIDER_FAIL),
map(action => action.payload),
withLatestFrom(this.store.select(fromProvider.getSelectedProvider)),
switchMap(([changes, current]) =>
this.providerService.find(current.resourceId).pipe(
map(data => new ShowContentionAction(this.contentionService.getContention(current, changes, data, {
resolve: (obj) => this.store.dispatch(new UpdateProviderRequest(<MetadataProvider>{ ...obj })),
reject: (obj) => this.store.dispatch(new ResetChanges())
})))
)
)
);


@Effect()
loadProviders$ = this.actions$.pipe(
ofType<LoadProviderRequest>(ProviderCollectionActionTypes.LOAD_PROVIDER_REQUEST),
Expand Down Expand Up @@ -100,7 +117,7 @@ export class CollectionEffects {
.update(provider)
.pipe(
map(p => new UpdateProviderSuccess({id: p.id, changes: p})),
catchError((e) => of(new UpdateProviderFail(e)))
catchError((e) => of(new UpdateProviderFail(provider)))
)
)
);
Expand All @@ -116,7 +133,10 @@ export class CollectionEffects {
updateProviderSuccessRedirect$ = this.actions$.pipe(
ofType<UpdateProviderSuccess>(ProviderCollectionActionTypes.UPDATE_PROVIDER_SUCCESS),
map(action => action.payload),
tap(provider => this.router.navigate(['metadata', 'manager', 'providers']))
tap(provider => {
this.store.dispatch(new ClearProvider());
this.router.navigate(['metadata', 'manager', 'providers']);
})
);

@Effect()
Expand Down Expand Up @@ -210,6 +230,7 @@ export class CollectionEffects {
private actions$: Actions,
private router: Router,
private store: Store<fromRoot.State>,
private providerService: MetadataProviderService
private providerService: MetadataProviderService,
private contentionService: ContentionService
) { }
}
2 changes: 2 additions & 0 deletions ui/src/app/metadata/provider/provider.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ProviderFilterListComponent } from './container/provider-filter-list.co

import { ProviderEditorNavComponent } from './component/provider-editor-nav.component';
import { UnsavedProviderComponent } from './component/unsaved-provider.dialog';
import { ContentionModule } from '../../contention/contention.module';

@NgModule({
declarations: [
Expand All @@ -55,6 +56,7 @@ import { UnsavedProviderComponent } from './component/unsaved-provider.dialog';
SharedModule,
FormModule,
RouterModule,
ContentionModule,
NgbDropdownModule
],
exports: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
[matches]="ids$ | async"
(keydown.enter)="onSelectValue(search.value)">
</auto-complete>
<small>You must add at least one entity id target.</small>
<small [class.text-danger]="search.invalid && search.touched">
You must add at least one entity id target and they must each be unique.
</small>
</ng-container>
<ng-container *ngSwitchCase="'CONDITION_SCRIPT'">
<p class="codearea form-control" rows="8" contenteditable [formControl]="script" name="script"></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnDestroy, AfterViewInit } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { FormControl, Validators, AbstractControl, ValidatorFn } from '@angular/forms';
import { ObjectWidget } from 'ngx-schema-form';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
Expand All @@ -25,7 +25,9 @@ export class FilterTargetComponent extends ObjectWidget implements OnDestroy, Af
search: FormControl = new FormControl(
'',
[],
[EntityValidators.existsInCollection(this.store.select(fromFilters.getEntityCollection))]
[
EntityValidators.existsInCollection(this.store.select(fromFilters.getEntityCollection))
]
);

script: FormControl = new FormControl(
Expand Down Expand Up @@ -59,6 +61,14 @@ export class FilterTargetComponent extends ObjectWidget implements OnDestroy, Af
ngAfterViewInit(): void {
super.ngAfterViewInit();
this.script.setValue(this.targets[0]);

this.search.setValidators(this.unique());
}

unique(): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => {
return this.targets.indexOf(control.value) > -1 ? { unique: true } : null;
};
}

searchEntityIds(term: string): void {
Expand Down

0 comments on commit 4b05e15

Please sign in to comment.