Skip to content

Commit

Permalink
refactor: simplify type check for filter keys
Browse files Browse the repository at this point in the history
  • Loading branch information
infacc committed Jul 18, 2023
1 parent 9622400 commit ec041cf
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges } from '@angular/core';

type FilterType = 'and' | 'or' | 'name' | 'tag' | 'version';
// Define filter types ('not' excluded)
// The PluginFilterNodeComponent component is designed to encapsulate a filter object and the information wether the filter is inverted ('not').
// When the filter is inverted, the filter object is wrapped in a 'not' object and the 'inverted' property is set to true.
const filterTypes = ['and', 'or', 'name', 'tag', 'version'] as const;
type FilterType = (typeof filterTypes)[number];
const isFilterType = (x: any): x is FilterType => filterTypes.includes(x);

@Component({
selector: 'qhana-plugin-filter-node',
Expand Down Expand Up @@ -46,11 +51,11 @@ export class PluginFilterNodeComponent implements OnInit {
}
const filterKeys = Object.keys(filter)
if (filterKeys.length != 1) {
console.error("Filters with more than one attribute are not supported!");
console.error("Filters with more than one attribute are not supported! ", filterKeys);
}
const type = filterKeys[0];
if (type !== 'and' && type !== 'or' && type !== 'name' && type !== 'tag' && type !== 'version') {
console.warn("Invalid filter type provided to plugin filter node component");
if (!isFilterType(type)) {
console.warn("Invalid filter type provided to plugin filter node component: ", type);
return;
}
this.type = type as FilterType;
Expand Down

0 comments on commit ec041cf

Please sign in to comment.