Skip to content

Commit

Permalink
Added a new filter-side-drawer component for filtering reports (#390)
Browse files Browse the repository at this point in the history
* initial commit with first version of the side panel for filters. old filter has been commented out

* added animation for the filter-side-drawer

* made the first input fields for the metadatanames in the filter view. needs to be aligned correctly including other elements in the filter-side-drawer

* made the filter side drawer look better with the input fields and made the basic method calls for updating the filter. it just needs to call the updatefilters method in table component now

* put the filter fields next to each other for readability of code

* added functionality to filter side drawer with the help of filter.service.ts
table component functionality has barely been changed. only difference is that the api request now accepts string arrays so the parameters for the api call have also been changed.

* Title change of filter side drawer

* Update src/app/debug/filter-side-drawer/filter-side-drawer.component.html

Co-authored-by: Sergi Philipsen <philipsen.sergi@gmail.com>

* Update src/app/debug/filter-side-drawer/filter-side-drawer.component.ts

Co-authored-by: Sergi Philipsen <philipsen.sergi@gmail.com>

* Removed unnecessary line of code from filter-side-drawer.component.ts

* changed name and order of observables and subjects of the filter.service.ts

* refactor for code review.
removed resetFilter from filter-side-drawer.component.ts as the trigger might as well call the resetFitler directly in the filterService.
updateFilter parameter type added.
Added autocomplete feature for filter options. Fixes a known ladybug-frontend issue
Fixed filter side drawer size option. now possible to scroll if screen is too small

* added unit tests for the mat autocomplete element

* ngModelChange is now used to detect changes to user input. for filterContext a debounceTime was added to not overload the API. added cleardebugStorage() to afterEach() cypress e2e test for the filter table

* filter is closed at the end of test

* changed some api request issues.
api was called multiple times when trying to refresh, filter reset has been removed from refresh method.
moved creation of subscription in table component to ngInit to avoid multiple instances of a subscription being formed
added refresh method to cypress tests

* minor fixes to the structure of the code.
subscriptions moved to dedicated subscribe and unsubscribe methods.
Records have been changed to Maps for consistency.
small css changes.
Added a type to one of the subscribers where I forgot to add one.
made filter-side-drawer.component.ts standalone
Changed ngIf to an @if in filter-side-drawer.component.html
Replaced the empty mat-option with a clear button that shows next to the metadata input element.
updated the cypress e2e test accordingly with the new clear button

* added word-break because correlationId would clip outside of container in firefox

* added imports to spec file

* FilterSideDrawerComponent removed from declaration and added to imports

* Update src/app/debug/filter-side-drawer/filter-side-drawer.component.css

Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>

* chore: change some styling in the filter side drawer

* chore: added missing unsubscribe calls to table component

* chore: removed console.logs and changed foreach loop to for loop in filter component

* chore: removed unnecessary foreach and added more types to methods where it was missing.

* chore: fixed some styling issues

* chore: removed an unnecessary casting to string array

* Update src/app/debug/filter-side-drawer/filter-side-drawer.component.html

Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>

* Update src/app/debug/filter-side-drawer/filter-side-drawer.component.html

Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>

---------

Co-authored-by: Sergi Philipsen <philipsen.sergi@gmail.com>
Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>
Co-authored-by: MatthijsSmets <s1122126@student.hsleiden.nl>
  • Loading branch information
4 people authored May 7, 2024
1 parent 8182b2b commit 5a64ad7
Show file tree
Hide file tree
Showing 13 changed files with 403 additions and 75 deletions.
4 changes: 1 addition & 3 deletions cypress/e2e/copying.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ describe('Tests about copying', function() {
cy.get('[data-cy-test="selectAll"]').click();
cy.get('[data-cy-test="deleteSelected"]').click();
cy.get('[data-cy-delete-modal="confirm"]').click();
cy.get('[data-cy-nav-tab="debugTab"]').click();
});

it('Copy report to test tab', () => {
cy.visit('');
cy.get('[data-cy-nav-tab="testTab"]').click();
cy.checkTestTableNumRows(0);
cy.get('[data-cy-nav-tab="debugTab"]').click();
cy.checkTableNumRows(0);
cy.createReport();
cy.get('[data-cy-debug="refresh"]').click();
cy.refreshApp();
cy.checkTableNumRows(1);
cy.get('[data-cy-debug="selectAll"]').click();
cy.get('[data-cy-debug="openSelected"]').click();
Expand Down
41 changes: 35 additions & 6 deletions cypress/e2e/debug_filterTable.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ describe('Table size and toggle filter', () => {
cy.initializeApp();
});

afterEach(() => {
cy.clearDebugStore();
})

it('Typing in a table size and retyping it', () => {
// We only assume here that the default is two or more.
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 2);
Expand All @@ -25,20 +29,45 @@ describe('Table size and toggle filter', () => {
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 2)
})

it('After clicking filter button, the filters should appear', () => {
cy.get('[data-cy-debug="tableFilterRow"]').should('not.exist')
it('After clicking filter button, the filter side drawer should appear', () => {
cy.get('[data-cy-debug="filter-side-drawer"]').should('not.exist')
cy.get('[data-cy-debug="filter"]').click()
cy.get('[data-cy-debug="tableFilterRow"]').should('be.visible')

cy.get('[data-cy-debug="filter-side-drawer"]').should('be.visible')
cy.get('[data-cy-debug="filter"]').click()
cy.get('[data-cy-debug="filter-side-drawer"]').should('not.exist')
cy.get('[data-cy-debug="filter"]').click()
cy.get('[data-cy-debug="tableFilterRow"]').should('not.exist')
cy.get('[data-cy-debug="filter-side-drawer"]').should('be.visible')
cy.get('[data-cy-debug="close-filter-btn"]').click()
cy.get('[data-cy-debug="filter-side-drawer"]').should('not.exist')
})

it('Type in a filter parameter', () => {
it('Type in a filter parameter should limit the records viewed in the record table', () => {
cy.get('[data-cy-debug="filter"]').click()
cy.get('[data-cy-debug="tableFilter"]').eq(3).type('(Simple report){enter}')
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 1)
cy.get('[data-cy-debug="tableFilter"]').eq(3).clear().type('{enter}')
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 2)
cy.get('[data-cy-debug="tableFilter"]').eq(3).type('(Simple report){enter}')
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 1)
cy.get('[data-cy-debug="clear-filter-btn"').click()
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 2)
})

it('After clicking or typing in the filter text field, an autocomplete menu should show that displays the options of the current filter', () => {
cy.get('[data-cy-debug="filter"]').click()
cy.get('[data-cy-debug="tableFilter"]').eq(3).type('test')
cy.get('[data-cy-debug="matAutocompleteOption"]').should('be.visible')
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 2);
})

it('Selecting an option should update the table and selecting the empty option should reset the text field of the selected filter', () => {
cy.get('[data-cy-debug="filter"]').click()
cy.get('[data-cy-debug="tableFilter"]').eq(3).type('test')
cy.get('[data-cy-debug="matAutocompleteOption"]').first().click()
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 1);
cy.get('[data-cy-debug="tableFilter"]').eq(3).type('test')
cy.get('[data-cy-debug="filterClearButton"]').eq(3).click()
cy.get('[data-cy-debug="tableBody"]').find('tr').should('have.length', 2);
cy.get('[data-cy-debug="filter"]').click()
})
})
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { ActiveFiltersComponent } from './debug/active-filters/active-filters.component';
import { DictionaryPipe } from './shared/pipes/dictionary.pipe';
import { ReportDisplayComponent } from './report-display/report-display.component';
import { FilterSideDrawerComponent } from './debug/filter-side-drawer/filter-side-drawer.component';
import { NgSimpleFileTreeModule } from 'ng-simple-file-tree';
import { TestFolderTreeComponent } from './test/test-folder-tree/test-folder-tree.component';

Expand Down Expand Up @@ -83,6 +84,7 @@ import { TestFolderTreeComponent } from './test/test-folder-tree/test-folder-tre
CheckpointTypePipe,
ClipboardModule,
NgSimpleFileTreeModule,
FilterSideDrawerComponent,
TestFolderTreeComponent,
],
providers: [],
Expand Down
65 changes: 65 additions & 0 deletions src/app/debug/filter-side-drawer/filter-side-drawer.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.filter-vertical-panel {
position: fixed;
top: 0;
right: 0;
height: 100%;
width: 300px;
background-color: #f0f0f0;
box-shadow: 0 0 8px 1px gray;
z-index: 1000;
display: flex;
flex-direction: column;
}

.panel-container {
position: relative;
height: 100%;
}

.filter-input-container {
margin: 1rem 1rem;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 4;
overflow-y: auto;
max-height: 800px;
height: 80%;
}

.input-container {
display: flex;
flex-direction: column;
margin: 0.6rem;
}

.btn-container {
display: flex;
width: calc(100% - 2rem);
justify-content: space-between;
margin: 1rem;
position: absolute;
bottom: 0;
z-index: 5;
}

.filter-label {
margin-left: 1rem;
margin-top: 1rem;
font-size: 1.5rem;
text-decoration: underline;
}

.metadata-input-label {
font-weight: bold;
font-size: .9rem;
}

.metadata-input-container {
display: flex;
}

.filter-option {
font-size: .9rem;
word-break: break-all;
}
55 changes: 55 additions & 0 deletions src/app/debug/filter-side-drawer/filter-side-drawer.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@if (shouldShowFilter) {
<div @removeTrigger class="filter-vertical-panel" data-cy-debug="filter-side-drawer">
<div class="panel-container">
<h1 class="h1 filter-label">Filter</h1>
<div class="filter-input-container">
@for (metadataName of metadataNames; track metadataName) {
<div class="input-container">
<label class="metadata-input-label">{{ metadataName | titlecase }}</label>
<div class="metadata-input-container input-group">
<input
class="form-control"
type="text"
[title]="metadataName"
[ngModel]="filterService.getCurrentFilterContext().get(metadataName)"
[matAutocomplete]="auto"
[placeholder]="'Filter for ' + metadataName"
(ngModelChange)="updateFilter($event, metadataName)"
data-cy-debug="tableFilter">
<div class="input-group-append input-group-append">
<button
class="btn btn-sm btn-danger button-clear-text input-group-text"
(click)="removeFilter(metadataName)"
data-cy-debug="filterClearButton">
Clear
</button>
</div>
</div>
<mat-autocomplete
#auto="matAutocomplete"
(optionSelected)="updateFilter($event.option.value, metadataName)">
@for (option of currentRecords.get(metadataName.toLocaleLowerCase()); track option) {
<mat-option
[value]="option"
class="filter-option"
data-cy-debug="matAutocompleteOption">
{{ option }}
</mat-option>
}
</mat-autocomplete>
</div>
}
</div>
<div class="btn-container">
<button class="close-filter-btn btn btn-info" (click)="closeFilter()" data-cy-debug="close-filter-btn">Close
</button>
<button
class="clear-filter-btn btn btn-info"
(click)="filterService.resetFilter()"
data-cy-debug="clear-filter-btn">
Clear
</button>
</div>
</div>
</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FilterSideDrawerComponent } from './filter-side-drawer.component';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { FormsModule } from '@angular/forms';

describe('FilterSideDrawerComponent', () => {
let component: FilterSideDrawerComponent;
let fixture: ComponentFixture<FilterSideDrawerComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatAutocompleteModule, FormsModule, FilterSideDrawerComponent],
}).compileComponents();

fixture = TestBed.createComponent(FilterSideDrawerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
81 changes: 81 additions & 0 deletions src/app/debug/filter-side-drawer/filter-side-drawer.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FilterService } from './filter.service';
import { Subscription } from 'rxjs';
import { animate, style, transition, trigger } from '@angular/animations';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { FormsModule } from '@angular/forms';
import { TitleCasePipe } from '@angular/common';

@Component({
standalone: true,
selector: 'app-filter-side-drawer',
templateUrl: './filter-side-drawer.component.html',
styleUrl: './filter-side-drawer.component.css',
animations: [
trigger('removeTrigger', [
transition(':enter', [
style({ transform: 'translateX(100%)' }),
animate('300ms ease-in', style({ transform: 'translateX(0)' })),
]),
transition(':leave', animate('300ms ease-out', style({ transform: 'translateX(100%)' }))),
]),
],
imports: [MatAutocompleteModule, FormsModule, TitleCasePipe],
})
export class FilterSideDrawerComponent implements OnDestroy, OnInit {
protected shouldShowFilter!: boolean;
protected metadataNames!: string[];
protected filters: Map<string, string> = new Map<string, string>();
protected currentRecords: Map<string, Array<string>> = new Map<string, Array<string>>();

shouldShowFilterSubscriber!: Subscription;
metadataNamesSubscriber!: Subscription;
filterSubscriber!: Subscription;
currentRecordsSubscriber!: Subscription;

constructor(protected filterService: FilterService) {}

ngOnInit(): void {
this.setSubscriptions();
}

ngOnDestroy(): void {
this.unsubscribeAll();
}

setSubscriptions(): void {
this.shouldShowFilterSubscriber = this.filterService.showFilter$.subscribe((show: boolean): void => {
this.shouldShowFilter = show;
});
this.metadataNamesSubscriber = this.filterService.metadataNames$.subscribe((metadataNames: string[]): void => {
this.metadataNames = metadataNames;
});
this.filterSubscriber = this.filterService.filterContext$.subscribe((filterContext: Map<string, string>): void => {
this.filters = filterContext;
});
this.currentRecordsSubscriber = this.filterService.currentRecords$.subscribe(
(records: Map<string, Array<string>>): void => {
this.currentRecords = records;
},
);
}

unsubscribeAll(): void {
this.shouldShowFilterSubscriber.unsubscribe();
this.metadataNamesSubscriber.unsubscribe();
this.filterSubscriber.unsubscribe();
this.currentRecordsSubscriber.unsubscribe();
}

closeFilter() {
this.filterService.setShowFilter(false);
}

updateFilter(filter: string, metadataName: string): void {
this.filterService.updateFilterContext(metadataName, filter);
}

removeFilter(metadataName: string): void {
this.filterService.updateFilterContext(metadataName, '');
}
}
16 changes: 16 additions & 0 deletions src/app/debug/filter-side-drawer/filter.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { FilterService } from './filter.service';

describe('FilterService', () => {
let service: FilterService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(FilterService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
45 changes: 45 additions & 0 deletions src/app/debug/filter-side-drawer/filter.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Injectable } from '@angular/core';
import { debounceTime, Observable, Subject } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class FilterService {
private showFilterSubject: Subject<boolean> = new Subject();
private metadataNamesSubject: Subject<string[]> = new Subject();
private filterContextSubject: Subject<Map<string, string>> = new Subject();
private currentRecordsSubject: Subject<Map<string, Array<string>>> = new Subject();
private filters: Map<string, string> = new Map<string, string>();

showFilter$: Observable<boolean> = this.showFilterSubject.asObservable();
metadataNames$: Observable<string[]> = this.metadataNamesSubject.asObservable();
filterContext$: Observable<Map<string, string>> = this.filterContextSubject.pipe(debounceTime(300));
currentRecords$: Observable<Map<string, Array<string>>> = this.currentRecordsSubject.asObservable();

setShowFilter(show: boolean): void {
this.showFilterSubject.next(show);
}

setMetadataNames(metadataNames: string[]): void {
this.metadataNamesSubject.next(metadataNames);
}

updateFilterContext(filterName: string, filterContext: string): void {
if (filterContext.length > 0) this.filters.set(filterName, filterContext);
else this.filters.delete(filterName);
this.filterContextSubject.next(this.filters);
}

getCurrentFilterContext(): Map<string, string> {
return this.filters;
}

resetFilter(): void {
this.filters = new Map<string, string>();
this.filterContextSubject.next(this.filters);
}

setCurrentRecords(records: Map<string, Array<string>>): void {
this.currentRecordsSubject.next(records);
}
}
Loading

0 comments on commit 5a64ad7

Please sign in to comment.