-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for search filter on executions list page
- Loading branch information
1 parent
535f32a
commit a49c73c
Showing
9 changed files
with
188 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 12 additions & 10 deletions
22
src/app/executions/executions-list/executions-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
<div class="bg-white d-flex search-header header-shadow"> | ||
<div class="container d-flex flex-column justify-content-around"> | ||
<div class="pt-2"> | ||
<p><input type="text" class="form-control" placeholder="Search workflows"></p> | ||
<p><strong>Showing {{executions.length}} Executions</strong></p> | ||
<p><input type="text" class="form-control" placeholder="Search workflows" [(ngModel)]="search"></p> | ||
<!--<p><strong>Showing {{executions.length}} Executions</strong></p>--> | ||
</div> | ||
|
||
<div class="row pb-1 m-0 text-muted"> | ||
<div class="col-sm-1 col-3">State</div> | ||
<div class="col-sm-8 col-4">Workflow</div> | ||
<div class="col-sm-3 col-5">Created At</div> | ||
<div class="col-sm-3 col-5"><i class="fa fa-caret-down"></i> Created At</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
|
||
<div class="container search-results"> | ||
<div class="" id="executions-list"> | ||
<div class="row py-3 m-0 execution-list-item pointer" *ngFor="let execution of executions; trackBy: execTrackBy" [routerLink]="[execution.id]"> | ||
<div class="col-sm-1 col-3"> | ||
<span class="badge font-weight-normal" [ngClass]="execution.state">{{execution.state}}</span> | ||
<div id="executions-list"> | ||
<ng-container *ngFor="let execution of executions | search : search ; trackBy: execTrackBy"> | ||
<div [routerLink]="[execution.id]" class="row py-3 m-0 execution-list-item pointer"> | ||
<div class="col-sm-1 col-3"> | ||
<span class="badge font-weight-normal" [ngClass]="execution.state">{{execution.state}}</span> | ||
</div> | ||
<div class="col-sm-8 col-4 word-break-all">{{execution.workflow_name}}</div> | ||
<div class="col-sm-3 col-5">{{execution.created_at}}</div> | ||
</div> | ||
<div class="col-sm-8 col-4 word-break-all">{{execution.workflow_name}}</div> | ||
<div class="col-sm-3 col-5">{{execution.created_at}}</div> | ||
</div> | ||
</ng-container> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (C) 2017 Nokia | ||
|
||
import {SearchPipe} from './search.pipe'; | ||
|
||
describe('SearchPipe', () => { | ||
let pipe: SearchPipe; | ||
const input = [{animal: "Cat", age: 6}, {animal: "Dog", age: 12}]; | ||
|
||
beforeEach(() => { | ||
pipe = new SearchPipe(); | ||
}); | ||
|
||
it('return the whole array when search value is empty', () => { | ||
expect(pipe.transform(input, "")).toEqual(input); | ||
}); | ||
|
||
describe('Test empty arrays', () => { | ||
it('return empty array on null', () => { | ||
expect(pipe.transform(null, "")).toEqual([]); | ||
}); | ||
|
||
it('return empty array on undefined', () => { | ||
expect(pipe.transform(undefined, "")).toEqual([]); | ||
}); | ||
|
||
it('return empty array on empty array', () => { | ||
expect(pipe.transform([], "")).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('Array filter with field name', () => { | ||
it('should find an item', () => { | ||
const result = pipe.transform(input, "cat", "animal"); | ||
expect(result.length).toEqual(1); | ||
expect(result[0].age).toEqual(6); | ||
}); | ||
|
||
it("shouldn't find an item", () => { | ||
const result = pipe.transform(input, "jaguar", "animal"); | ||
expect(result.length).toEqual(0); | ||
}); | ||
}); | ||
|
||
describe('Array filter on any field', () => { | ||
it('should find an item', () => { | ||
const result = pipe.transform(input, "12"); | ||
expect(result.length).toEqual(1); | ||
expect(result[0].animal).toEqual("Dog"); | ||
}); | ||
|
||
it("Shouldn't find any items", () => { | ||
const result = pipe.transform(input, "14"); | ||
expect(result.length).toEqual(0); | ||
}); | ||
}); | ||
|
||
describe('Ignore case', () => { | ||
it('should find an item', () => { | ||
const result = pipe.transform(input, "cat"); | ||
expect(result.length).toEqual(1); | ||
expect(result[0].animal).toEqual("Cat"); | ||
}); | ||
|
||
it("shouldn't find an item", () => { | ||
const result = pipe.transform(input, "jaguar"); | ||
expect(result.length).toEqual(0); | ||
}); | ||
}); | ||
|
||
describe('Partial input', () => { | ||
it('should find 2 items', () => { | ||
const input2 = [{name: "ABCD"}, {name: "FABCE"}, {name: "DCBA"}]; | ||
const result = pipe.transform(input2, "ab"); | ||
expect(result.length).toEqual(2); | ||
}); | ||
|
||
it("shouldn't find any items", () => { | ||
const input2 = [{name: "ABCD"}, {name: "FABCE"}, {name: "DCBA"}]; | ||
const result = pipe.transform(input2, "abe"); | ||
expect(result.length).toEqual(0); | ||
}); | ||
}); | ||
|
||
describe("Don't fail on null values of fields", () => { | ||
it("Shouldn't fail on null value", () => { | ||
expect(() => pipe.transform([{name: null}], "val")).not.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2017 Nokia | ||
|
||
import {Pipe, PipeTransform} from '@angular/core'; | ||
|
||
@Pipe({ | ||
name: 'search' | ||
}) | ||
export class SearchPipe implements PipeTransform { | ||
|
||
private static fieldMatch(item: any, fieldName: string, searchValue: string): boolean { | ||
return item[fieldName] != null && | ||
item[fieldName].toString().toLocaleLowerCase().includes(searchValue); | ||
} | ||
|
||
private static anywhere(item: any, searchValue: string): boolean { | ||
return Object.keys(item).some(key => SearchPipe.fieldMatch(item, key, searchValue)); | ||
} | ||
|
||
private static matches(item: any, searchValue: string, fieldName?: string): boolean { | ||
return fieldName ? SearchPipe.fieldMatch(item, fieldName, searchValue) : SearchPipe.anywhere(item, searchValue); | ||
} | ||
|
||
transform(items: any[], searchValue: string, fieldName?: string): any { | ||
if (!items) { | ||
return []; | ||
} | ||
if (!searchValue) { | ||
return items; | ||
} | ||
return items.filter(it => SearchPipe.matches(it, searchValue.toLocaleLowerCase(), fieldName)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.