Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/plugin filter editor #48

Merged
merged 31 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
01bf1bb
add plugin filter editor
infacc Jun 19, 2023
e55a407
show plugin editor when no tab link is provided
infacc Jul 3, 2023
8b1fe43
hide mat-card if filter is empty
infacc Jul 4, 2023
5616886
refactor: improve filter editor usability
infacc Jul 11, 2023
76d7744
refactor: avoid ViewChild decorator in filter editor
infacc Jul 12, 2023
4e2edb3
simplify isLeaf check
infacc Jul 12, 2023
38879c2
rectify warning message
infacc Jul 12, 2023
e71700b
refactor: simplify filter setup
infacc Jul 12, 2023
d81143a
Merge branch 'feature/plugin-filter-editor' of github.com:UST-QuAntiL…
infacc Jul 12, 2023
fae56c0
handle filter deletion by parent
infacc Jul 13, 2023
4ceb6d4
catch JSON paring errors
infacc Jul 13, 2023
183ced2
separate ternary operator to improve readability
infacc Jul 13, 2023
a1fe552
add inverted indication for and/or filters
infacc Jul 13, 2023
05d026b
remove index property
infacc Jul 17, 2023
f62ff31
store info whether filter is empty in property
infacc Jul 17, 2023
334189a
refactor: separate input and output objects
infacc Jul 18, 2023
c0ee392
check for empty filter
infacc Jul 18, 2023
51171f8
fix bug: keep input focus when typing
infacc Jul 18, 2023
fff9496
fix bug: use JSON editor input on tab change
infacc Jul 18, 2023
be07ea4
add active warning for filters with multiple attributes
infacc Jul 18, 2023
9622400
set filter string via template expression
infacc Jul 18, 2023
ec041cf
refactor: simplify type check for filter keys
infacc Jul 18, 2023
62344c6
Merge branch 'main' into feature/plugin-filter-editor
infacc Jul 18, 2023
b8b6cf6
rename HTML class to avoid confusion
infacc Jul 18, 2023
16dd6a5
use deep copies to emit filters
infacc Jul 19, 2023
8ea5eea
remove filter string from template form
infacc Jul 20, 2023
af7ad6b
add reload filter button
infacc Jul 20, 2023
37526f4
remove unused location interface
infacc Jul 20, 2023
6a33202
add JSON validator to filter string textarea input
infacc Jul 20, 2023
f5423d5
rename revert filter button
infacc Jul 21, 2023
eb4ebca
hide button from screen readers
infacc Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h3 class="editor-description">Filter Editor</h3>
<mat-slide-toggle [(ngModel)]="showEditor">
Editor Mode {{ showEditor ? '(UI)' : '(JSON)' }}
</mat-slide-toggle>
<qhana-plugin-filter-node *ngIf="filterObject && showEditor" [filterObject]="filterObject" (childChange)="updateFilter($event)" (delete)="deleteFilter()"></qhana-plugin-filter-node>
<qhana-plugin-filter-node *ngIf="filterObject && showEditor" [filterIn]="filterObject" (filterOut)="updateFilter($event)" (delete)="deleteFilter()"></qhana-plugin-filter-node>
<ng-container *ngIf="!showEditor">
<mat-form-field class="form-field">
<mat-label>Filter String:</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class PluginFilterEditorComponent implements OnInit {
this.registry.getByApiLink<TemplateTabApiObject>(this.tabLink).then(response => {
this.filterString = response?.data?.filterString ?? this.filterString;
this.filterObject = JSON.parse(this.filterString);
this.updateFilter(this.filterObject);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<mat-card-content>
<ng-container *ngIf="children != null">
<span *ngIf="inverted" class="t-subheading">Not:</span>
<qhana-plugin-filter-node *ngFor="let child of children; let i = index" [filterObject]="children[i]"
[depth]="depth + 1" (childChange)="updateChild($event, i)" (delete)="deleteChild(i)"></qhana-plugin-filter-node>
<qhana-plugin-filter-node *ngFor="let child of children; let i = index" [filterIn]="children[i]"
[depth]="depth + 1" (filterOut)="updateChild($event, i)" (delete)="deleteChild(i)"></qhana-plugin-filter-node>
</ng-container>
<div class="config-filter" *ngIf="value != null">
<span *ngIf="inverted" class="t-subheading">Not:</span>
Expand All @@ -66,7 +66,7 @@
<mat-icon>delete</mat-icon>
</button>
</div>
<mat-checkbox [checked]="inverted" (change)="invertFilter()">Invert - <i>Negate this filter</i></mat-checkbox>
<mat-checkbox [checked]="inverted" (change)="invertFilter($event)">Invert - <i>Negate this filter</i></mat-checkbox>
</mat-card-content>
</mat-card>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ type FilterType = 'and' | 'or' | 'name' | 'tag' | 'version';
styleUrls: ['./plugin-filter-node.component.sass']
})
export class PluginFilterNodeComponent implements OnInit {
@Input() filterObject: any;
@Input() filterIn: any;
@Input() depth: number = 0;
@Output() childChange = new EventEmitter<any>();
@Output() filterOut = new EventEmitter<any>();
@Output() delete = new EventEmitter<void>();

filterObject: any = {};
type: FilterType | null = null;
children: any[] | null = null;
value: string | null = null;
Expand All @@ -26,25 +27,23 @@ export class PluginFilterNodeComponent implements OnInit {
}

ngOnChanges(changes: SimpleChanges) {
if (changes.filterObject != null) {
if (changes.filterIn.previousValue != null) {
this.setupFilter();
}
}

setupFilter() {
this.isEmpty = Object.keys(this.filterObject).length === 0;
if (this.isEmpty) {
return;
}
const currentValue = this.filterObject;
const filter = currentValue.not ?? this.filterObject;
this.inverted = currentValue.not != null;
this.isEmpty = Object.keys(this.filterIn).length === 0;
this.filterObject = { ...this.filterIn };
const filter = this.filterObject.not ?? this.filterObject;
infacc marked this conversation as resolved.
Show resolved Hide resolved
this.inverted = this.filterObject.not != null;
if (filter == null) {
console.warn("No filter object provided to plugin filter node component");
return;
}
// Should filters have multiple attributes at some point, this must be changed
const type = Object.keys(filter)[0];
// TODO: check for empty filter (currently prints warning)
if (type !== 'and' && type !== 'or' && type !== 'name' && type !== 'tag' && type !== 'version') {
infacc marked this conversation as resolved.
Show resolved Hide resolved
console.warn("Invalid filter type provided to plugin filter node component");
return;
Expand All @@ -56,8 +55,20 @@ export class PluginFilterNodeComponent implements OnInit {
} else {
this.children = filter[this.type];
}
this.filterObject = currentValue;
this.childChange.emit(this.filterObject);
}

updateFilterObject() {
if (this.type == null) {
console.warn("No type provided to plugin filter node component");
return;
}
const filter = { ...this.filterObject };
if (this.inverted) {
filter.not[this.type] = this.children ?? this.value;
} else {
filter[this.type] = this.children ?? this.value;
}
this.filterOut.emit(filter);
}

setFilter(type: FilterType) {
Expand Down Expand Up @@ -88,16 +99,6 @@ export class PluginFilterNodeComponent implements OnInit {
this.updateFilterObject();
}

updateFilterObject() {
if (this.type == null) {
console.warn("No type provided to plugin filter node component");
return;
}
const filter = this.filterObject.not ?? this.filterObject;
filter[this.type] = this.children ?? this.value;
this.childChange.emit(this.filterObject);
}

updateChild(value: any, index: number) {
if (this.children == null) {
console.warn("No children provided to plugin filter node component");
Expand All @@ -112,10 +113,10 @@ export class PluginFilterNodeComponent implements OnInit {
}

changeType(type: FilterType) {
if (type == null) {
if (type == null || this.type === type) {
return;
}
const filter = this.filterObject.not ?? this.filterObject;
const filter = { ...(this.filterObject.not ?? this.filterObject) };
const isLeaf = type !== 'and' && type !== 'or';
if (this.type != null) {
delete filter[this.type]
Expand All @@ -128,21 +129,21 @@ export class PluginFilterNodeComponent implements OnInit {
this.value = null;
filter[type] = this.children ?? [];
}
this.childChange.emit(this.filterObject);
this.filterOut.emit(filter);
infacc marked this conversation as resolved.
Show resolved Hide resolved
}

updateFilterString(event: any) {
this.value = event.target.value;
this.updateFilterObject();
}

invertFilter() {
this.inverted = !this.inverted;
invertFilter(event: any) {
this.inverted = event.checked;
if (this.inverted) {
this.filterObject = { not: this.filterObject };
} else {
this.filterObject = this.filterObject.not;
}
this.childChange.emit(this.filterObject);
this.filterOut.emit({ ...this.filterObject });
}
}