Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

714 list view grid highlighting #1944

Merged
merged 10 commits into from
Aug 29, 2018
11 changes: 9 additions & 2 deletions skyux-spa-visual-tests/src/app/grid/grid-visual.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<div id="screenshot-grid">
<sky-grid fit="scroll" [data]="items">
<sky-grid fit="scroll" [data]="items" [highlightText]="highlightText">
<sky-grid-column field="column1" heading="Column1"></sky-grid-column>
<sky-grid-column field="column2" heading="Column2"></sky-grid-column>
<sky-grid-column field="column3" heading="Column3"></sky-grid-column>
<sky-grid-column field="column3" heading="Column3" [excludeFromHighlighting]="true"></sky-grid-column>
</sky-grid>
</div>
<button
id="highlight-button"
class="sky-btn sky-btn-primary"
(click)="triggerHighlight()"
>
Trigger Highlight
</button>
6 changes: 6 additions & 0 deletions skyux-spa-visual-tests/src/app/grid/grid-visual.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ListItemModel } from '@blackbaud/skyux/dist/core';
})
export class GridVisualComponent {

public highlightText: string;

public items = [
new ListItemModel('1', { column1: '1', column2: 'Apple', column3: 'aa' }),
new ListItemModel('2', { column1: '01', column2: 'Banana', column3: 'bb' }),
Expand All @@ -19,4 +21,8 @@ export class GridVisualComponent {
new ListItemModel('6', { column1: '20', column2: 'Fig', column3: 'ff' }),
new ListItemModel('7', { column1: '21', column2: 'Grape', column3: 'gg' })
];

public triggerHighlight() {
this.highlightText = 'e';
}
}
12 changes: 12 additions & 0 deletions skyux-spa-visual-tests/src/app/grid/grid.visual-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ describe('grid component', () => {
});

});

it('should highlight cells correctly', () => {
return SkyVisualTest.setupTest('grid')
.then(() => {
element(by.css('#highlight-button')).click();
return SkyVisualTest.compareScreenshot({
screenshotName: 'grid-highlight',
selector: '#screenshot-grid'
});
});

});
});
3 changes: 3 additions & 0 deletions src/modules/grid/grid-column.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export class SkyGridColumnComponent implements OnChanges {
@Input()
public isSortable: boolean = true;

@Input()
public excludeFromHighlighting: boolean;

/* tslint:disable:no-input-rename */
@Input('search')
public searchFunction: (value: any, searchText: string) => boolean = this.search;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/grid/grid-column.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class SkyGridColumnModel {
public locked: boolean;
public description: string;
public isSortable: boolean = true;
public excludeFromHighlighting: boolean;
public searchFunction: (data: any, searchText: string) => boolean;

constructor(template: TemplateRef<any>, data?: any) {
Expand All @@ -27,6 +28,7 @@ export class SkyGridColumnModel {
this.description = data.description;
this.searchFunction = data.searchFunction;
this.isSortable = data.isSortable;
this.excludeFromHighlighting = data.excludeFromHighlighting;
}
}
}
1 change: 1 addition & 0 deletions src/modules/grid/grid.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class="sky-grid-cell"
*ngFor="let column of displayedColumns; let last = last; let i = index">
<sky-grid-cell
[skyHighlight]="!column.excludeFromHighlighting ? highlightText : undefined"
[template]="column.template || defaultCellTemplate"
[fieldSelector]="column.field"
[item]="item"
Expand Down
3 changes: 3 additions & 0 deletions src/modules/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export class SkyGridComponent implements AfterContentInit, OnChanges, OnDestroy
@Input()
public sortField: ListSortFieldSelectorModel;

@Input()
public highlightText: string;

@Output()
public selectedColumnIdsChange = new EventEmitter<Array<string>>();

Expand Down
2 changes: 2 additions & 0 deletions src/modules/grid/grid.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SkyGridComponent } from './grid.component';
import { SkyGridColumnComponent } from './grid-column.component';
import { SkyGridCellComponent } from './grid-cell.component';
import { DragulaModule } from 'ng2-dragula/ng2-dragula';
import { SkyTextHighlightModule } from '../text-highlight';

@NgModule({
declarations: [
Expand All @@ -13,6 +14,7 @@ import { DragulaModule } from 'ng2-dragula/ng2-dragula';
],
imports: [
CommonModule,
SkyTextHighlightModule,
DragulaModule
],
exports: [
Expand Down
1 change: 1 addition & 0 deletions src/modules/list-view-grid/list-view-grid.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[selectedColumnIds]="selectedColumnIds | async"
[columns]="columns | async"
[hasToolbar]="hasToolbar | async"
[highlightText]="highlightSearchText ? (currentSearchText | async) : undefined"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can highlightSearchText be a getter so that this logic could be handled in the ts file and included in coverage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. The logic will be much worse, since currentSearchText is an observable. We will leave this as it is

(selectedColumnIdsChange)="columnIdsChanged($event)"
[sortField]="sortField | async"
(sortFieldChange)="sortFieldChanged($event)"
Expand Down
18 changes: 18 additions & 0 deletions src/modules/list-view-grid/list-view-grid.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ describe('List View Grid Component', () => {
expect(firstHeading.textContent.trim()).toEqual('Column1');
}));

it('should handle a search being applied', fakeAsync(() => {
setupTest();

flush();
tick();

state.take(1).subscribe((current) => {
dispatcher.searchSetText('searchText');
tick();
flush();
component.grid.currentSearchText.subscribe(currentText => {
expect(currentText).toBe('searchText');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a done() call or something to ensure the expect is always being hit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't mix fakeAsync and done as done makes the test async. I did some manual testing and see that it is getting hit and based the test off others in this spec. I don't mind changing it to async but know that in another PR I was asked to look into making a test fakeAsync instead of async.

Thoughts @blackbaud-conorwright?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, done will not be usable here. As long is this catches when the logic is removed it's fine :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked and if the logic to updated currentSearchText is removed then the test fails


tick();
}));

describe('Models and State', () => {
it('should run ListViewGridColumnsLoadAction action', async(() => {
setupTest();
Expand Down
8 changes: 8 additions & 0 deletions src/modules/list-view-grid/list-view-grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export class SkyListViewGridComponent
@Input()
public height: number | Observable<number>;

@Input()
public highlightSearchText: boolean = true;

@Output()
public selectedColumnIdsChange = new EventEmitter<Array<string>>();

Expand All @@ -109,6 +112,8 @@ export class SkyListViewGridComponent

public sortField: Observable<ListSortFieldSelectorModel>;

public currentSearchText: Observable<string>;

/* tslint:disable */
@Input('search')
private searchFunction: (data: any, searchText: string) => boolean;
Expand Down Expand Up @@ -203,6 +208,9 @@ export class SkyListViewGridComponent
}
});

this.currentSearchText = this.state.map(s => s.search.searchText)
.distinctUntilChanged();

this.gridDispatcher.next(new ListViewGridColumnsLoadAction(columnModels, true));

this.handleColumnChange();
Expand Down