-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SHIBUI-669
- Loading branch information
Showing
42 changed files
with
1,440 additions
and
140 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
ui/src/app/metadata/domain/model/providers/base-metadata-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { MetadataProvider } from '../metadata-provider'; | ||
|
||
export interface BaseMetadataProvider extends MetadataProvider { | ||
metadataFilters: any[]; | ||
} |
8 changes: 5 additions & 3 deletions
8
ui/src/app/metadata/domain/model/providers/file-backed-http-metadata-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { MetadataProvider } from '../metadata-provider'; | ||
import { BaseMetadataProvider } from './base-metadata-provider'; | ||
|
||
export interface FileBackedHttpMetadataProvider extends MetadataProvider { | ||
metadataFilters: any[]; | ||
export interface FileBackedHttpMetadataProvider extends BaseMetadataProvider { | ||
id: string; | ||
metadataURL: string; | ||
reloadableMetadataResolverAttributes: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './file-backed-http-metadata-provider'; | ||
export * from './file-backed-http-metadata-provider'; | ||
export * from './base-metadata-provider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
ui/src/app/metadata/provider/container/provider-edit-step.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ng-container *ngIf="definition$ | async"> | ||
<sf-form | ||
[schema]="schema$ | async" | ||
[model]="model$ | async" | ||
[validators]="validators$ | async" | ||
(onChange)="valueChangeSubject.next($event)" | ||
(onErrorChange)="statusChangeSubject.next($event)"></sf-form> | ||
</ng-container> |
90 changes: 90 additions & 0 deletions
90
ui/src/app/metadata/provider/container/provider-edit-step.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture, fakeAsync, tick } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { StoreModule, Store, combineReducers } from '@ngrx/store'; | ||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { ProviderEditStepComponent } from './provider-edit-step.component'; | ||
import * as fromRoot from '../reducer'; | ||
import * as fromWizard from '../../../wizard/reducer'; | ||
import { SchemaFormModule, WidgetRegistry, DefaultWidgetRegistry } from 'ngx-schema-form'; | ||
import { SharedModule } from '../../../shared/shared.module'; | ||
import { SetDefinition } from '../../../wizard/action/wizard.action'; | ||
import { FileBackedHttpMetadataProviderEditor } from '../model'; | ||
|
||
@Component({ | ||
template: ` | ||
<provider-edit-step></provider-edit-step> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(ProviderEditStepComponent) | ||
public componentUnderTest: ProviderEditStepComponent; | ||
} | ||
|
||
describe('Provider Edit Step Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: ProviderEditStepComponent; | ||
let store: Store<fromRoot.State>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbDropdownModule.forRoot(), | ||
RouterTestingModule, | ||
SchemaFormModule.forRoot(), | ||
SharedModule, | ||
StoreModule.forRoot({ | ||
provider: combineReducers(fromRoot.reducers), | ||
wizard: combineReducers(fromWizard.reducers, { | ||
wizard: { | ||
index: 'common', | ||
disabled: false, | ||
definition: FileBackedHttpMetadataProviderEditor, | ||
schemaCollection: [] | ||
} | ||
}) | ||
}) | ||
], | ||
declarations: [ | ||
ProviderEditStepComponent, | ||
TestHostComponent | ||
], | ||
providers: [ | ||
{ provide: WidgetRegistry, useClass: DefaultWidgetRegistry } | ||
] | ||
}).compileComponents(); | ||
|
||
store = TestBed.get(Store); | ||
spyOn(store, 'dispatch'); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
app = instance.componentUnderTest; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should instantiate the component', async(() => { | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
describe('updateStatus method', () => { | ||
it('should update the status with provided errors', () => { | ||
app.currentPage = 'common'; | ||
app.updateStatus({value: 'common'}); | ||
app.updateStatus({value: 'foo'}); | ||
expect(store.dispatch).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
|
||
describe('valueChangeEmitted$ subject', () => { | ||
it('should update the provider', fakeAsync(() => { | ||
app.valueChangeSubject.next({value: { name: 'foo' } }); | ||
fixture.detectChanges(); | ||
tick(); | ||
fixture.detectChanges(); | ||
expect(store.dispatch).toHaveBeenCalled(); | ||
})); | ||
}); | ||
}); |
93 changes: 93 additions & 0 deletions
93
ui/src/app/metadata/provider/container/provider-edit-step.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Component, OnDestroy } from '@angular/core'; | ||
import { Observable, Subject } from 'rxjs'; | ||
import { Store } from '@ngrx/store'; | ||
|
||
import * as fromProvider from '../reducer'; | ||
import { UpdateStatus } from '../action/editor.action'; | ||
import { Wizard } from '../../../wizard/model'; | ||
import { MetadataProvider } from '../../domain/model'; | ||
|
||
import * as fromWizard from '../../../wizard/reducer'; | ||
import { withLatestFrom, map, skipWhile, distinctUntilChanged } from 'rxjs/operators'; | ||
import { UpdateProvider } from '../action/entity.action'; | ||
|
||
@Component({ | ||
selector: 'provider-edit-step', | ||
templateUrl: './provider-edit-step.component.html', | ||
styleUrls: [] | ||
}) | ||
|
||
export class ProviderEditStepComponent implements OnDestroy { | ||
valueChangeSubject = new Subject<Partial<any>>(); | ||
private valueChangeEmitted$ = this.valueChangeSubject.asObservable(); | ||
|
||
statusChangeSubject = new Subject<Partial<any>>(); | ||
private statusChangeEmitted$ = this.statusChangeSubject.asObservable(); | ||
|
||
currentPage: string; | ||
|
||
namesList: string[] = []; | ||
|
||
schema$: Observable<any>; | ||
provider$: Observable<MetadataProvider>; | ||
model$: Observable<any>; | ||
definition$: Observable<Wizard<MetadataProvider>>; | ||
changes$: Observable<MetadataProvider>; | ||
|
||
validators$: Observable<{ [key: string]: any }>; | ||
|
||
constructor( | ||
private store: Store<fromProvider.ProviderState> | ||
) { | ||
this.schema$ = this.store.select(fromProvider.getSchema); | ||
this.definition$ = this.store.select(fromWizard.getWizardDefinition); | ||
this.changes$ = this.store.select(fromProvider.getEntityChanges); | ||
this.provider$ = this.store.select(fromProvider.getSelectedProvider); | ||
|
||
this.validators$ = this.store.select(fromProvider.getProviderNames).pipe( | ||
withLatestFrom(this.definition$, this.provider$), | ||
map(([names, def, provider]) => def.getValidators(names.filter(n => n !== provider.name))) | ||
); | ||
|
||
this.model$ = this.schema$.pipe( | ||
withLatestFrom( | ||
this.store.select(fromProvider.getSelectedProvider), | ||
this.store.select(fromWizard.getModel), | ||
this.changes$, | ||
this.definition$ | ||
), | ||
map(([schema, provider, model, changes, definition]) => ({ | ||
model: { | ||
...model, | ||
...provider, | ||
...changes | ||
}, | ||
definition | ||
})), | ||
skipWhile(({ model, definition }) => !definition || !model), | ||
map(({ model, definition }) => definition.translate.formatter(model)) | ||
); | ||
|
||
this.valueChangeEmitted$.pipe( | ||
map(changes => changes.value), | ||
withLatestFrom(this.definition$), | ||
skipWhile(([ changes, definition ]) => !definition || !changes), | ||
map(([ changes, definition ]) => definition.translate.parser(changes)) | ||
) | ||
.subscribe(changes => this.store.dispatch(new UpdateProvider(changes))); | ||
|
||
this.statusChangeEmitted$.pipe(distinctUntilChanged()).subscribe(errors => this.updateStatus(errors)); | ||
|
||
this.store.select(fromWizard.getWizardIndex).subscribe(i => this.currentPage = i); | ||
} | ||
|
||
updateStatus(errors: any): void { | ||
const status = { [this.currentPage]: !(errors.value) ? 'VALID' : 'INVALID' }; | ||
this.store.dispatch(new UpdateStatus(status)); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.valueChangeSubject.complete(); | ||
} | ||
} | ||
|
Oops, something went wrong.