Skip to content

Commit

Permalink
SHIBUI-1208 Fixed issue with filters
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Nov 1, 2019
1 parent cc8830c commit 4dcda6b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class ProviderEditStepComponent implements OnDestroy {
}),
filter(({ model, definition }) => definition && model),
map(({ model, definition }) => {
// console.log(model, definition.formatter(model));
return definition ? definition.formatter(model) : {};
})
);
Expand All @@ -104,14 +105,18 @@ export class ProviderEditStepComponent implements OnDestroy {
withLatestFrom(this.definition$, this.store.select(fromProvider.getSelectedProvider)),
filter(([ changes, definition, provider ]) => definition && changes && provider),
map(([ changes, definition, provider ]) => {
const parsed = definition.parser(changes);
return ({
...parsed,
metadataFilters: [
...provider.metadataFilters,
...(parsed.metadataFilters || [])
]
});
const appliedFilters = changes && changes.metadataFilters ? {
...changes,
metadataFilters: Object.keys(changes.metadataFilters).reduce((filters, filterType) => ({
...filters,
[filterType]: {
...provider.metadataFilters.find(f => f['@type'] === filterType) || {},
...changes.metadataFilters[filterType]
}
}), {})
} : changes;
const parsed = definition.parser(appliedFilters);
return parsed;
})
)
.subscribe(changes => this.store.dispatch(new UpdateProvider(changes)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate

formats = NAV_FORMATS;

latest$: Observable<MetadataProvider>;

constructor(
private store: Store<fromProvider.ProviderState>,
private router: Router,
Expand Down Expand Up @@ -70,7 +72,8 @@ export class ProviderEditComponent implements OnDestroy, CanComponentDeactivate
});

this.provider$.subscribe(p => this.provider = p);
this.store.select(fromProvider.getEntityChanges).subscribe(changes => this.latest = changes);
this.latest$ = this.store.select(fromProvider.getEntityChanges);
this.latest$.subscribe(changes => this.latest = changes);

this.canFilter$ = this.definition$.pipe(map(def => FilterableProviders.indexOf(def.type) > -1));
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/wizard/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getWizardDefinition = createSelector(getState, fromWizard.getDefini
export const getSchemaPath = (wizard: Wizard<any>) => wizard ? wizard.schema : null;

export const getSplitSchema = (schema: any, step: WizardStep) => {
if (!schema || !step.fields || !step.fields.length || !schema.properties) {
if (!schema || !step || !step.fields || !step.fields.length || !schema.properties) {
return schema;
}
const keys = Object.keys(schema.properties).filter(key => step.fields.indexOf(key) > -1);
Expand Down

0 comments on commit 4dcda6b

Please sign in to comment.