Check if the loaded filter definition has the valid format
Fixes an issue where malformated or old filter-definition where considered to be valid filters which could cause some issues
This commit is contained in:
parent
d2b81e2a28
commit
bd4da53255
@ -122,7 +122,7 @@ export abstract class BaseFilterListService<V extends BaseViewModel> {
|
|||||||
public async initFilters(inputData: Observable<V[]>): Promise<void> {
|
public async initFilters(inputData: Observable<V[]>): Promise<void> {
|
||||||
const storedFilter = await this.store.get<OsFilter[]>('filter_' + this.name);
|
const storedFilter = await this.store.get<OsFilter[]>('filter_' + this.name);
|
||||||
|
|
||||||
if (storedFilter) {
|
if (storedFilter && this.isOsFilter(storedFilter)) {
|
||||||
this.filterDefinitions = storedFilter;
|
this.filterDefinitions = storedFilter;
|
||||||
} else {
|
} else {
|
||||||
this.filterDefinitions = this.getFilterDefinitions();
|
this.filterDefinitions = this.getFilterDefinitions();
|
||||||
@ -139,6 +139,29 @@ export abstract class BaseFilterListService<V extends BaseViewModel> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the (stored) filter list matches the current definition of OsFilter
|
||||||
|
*
|
||||||
|
* @param storedFilter
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
private isOsFilter(storedFilter: OsFilter[]): boolean {
|
||||||
|
if (Array.isArray(storedFilter) && storedFilter.length) {
|
||||||
|
return storedFilter.every(filter => {
|
||||||
|
// Interfaces do not exist at runtime. Manually check if the
|
||||||
|
// Required information of the interface are present
|
||||||
|
return (
|
||||||
|
filter.hasOwnProperty('options') &&
|
||||||
|
filter.hasOwnProperty('property') &&
|
||||||
|
filter.options.length &&
|
||||||
|
!!filter.property
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enforce children implement a method that returns actual filter definitions
|
* Enforce children implement a method that returns actual filter definitions
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user