mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add setFilter to DeclarativeTableComponent (#14143)
* Add setFilter to DeclarativeTableComponent * fix tests * Update param name
This commit is contained in:
@@ -367,16 +367,20 @@ export class PostgresParametersPage extends DashboardPage {
|
|||||||
@debounce(500)
|
@debounce(500)
|
||||||
private onSearchFilter(): void {
|
private onSearchFilter(): void {
|
||||||
if (!this.searchBox!.value) {
|
if (!this.searchBox!.value) {
|
||||||
this.parametersTable.data = this._parameters.map(p => [p.parameterName, p.valueContainer, p.description, p.resetButton]);
|
this.parametersTable.setFilter(undefined);
|
||||||
} else {
|
} else {
|
||||||
this.filterParameters(this.searchBox!.value);
|
this.filterParameters(this.searchBox!.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private filterParameters(search: string): void {
|
private filterParameters(search: string): void {
|
||||||
this.parametersTable.data = this._parameters
|
const filteredRowIndexes: number[] = [];
|
||||||
.filter(p => p.parameterName?.search(search) !== -1 || p.description?.search(search) !== -1)
|
this.parametersTable.data?.forEach((row, index) => {
|
||||||
.map(p => [p.parameterName, p.valueContainer, p.description, p.resetButton]);
|
if (row[0]?.search(search) !== -1 || row[2]?.search(search) !== -1) {
|
||||||
|
filteredRowIndexes.push(index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.parametersTable.setFilter(filteredRowIndexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleOnTextChanged(component: azdata.InputBoxComponent, currentValue: string | undefined): boolean {
|
private handleOnTextChanged(component: azdata.InputBoxComponent, currentValue: string | undefined): boolean {
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ export function createViewContext(): ViewTestContext {
|
|||||||
let declarativeTable: () => azdata.DeclarativeTableComponent = () => Object.assign({}, componentBase, {
|
let declarativeTable: () => azdata.DeclarativeTableComponent = () => Object.assign({}, componentBase, {
|
||||||
onDataChanged: undefined!,
|
onDataChanged: undefined!,
|
||||||
onRowSelected: undefined!,
|
onRowSelected: undefined!,
|
||||||
|
setFilter: undefined!,
|
||||||
data: [],
|
data: [],
|
||||||
columns: []
|
columns: []
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -347,6 +347,7 @@ class TestDeclarativeTableComponent extends TestComponentBase implements azdata.
|
|||||||
}
|
}
|
||||||
onDataChanged: vscode.Event<any> = this.onClick.event;
|
onDataChanged: vscode.Event<any> = this.onClick.event;
|
||||||
onRowSelected: vscode.Event<any> = this.onClick.event;
|
onRowSelected: vscode.Event<any> = this.onClick.event;
|
||||||
|
setFilter: undefined;
|
||||||
data: any[][];
|
data: any[][];
|
||||||
columns: azdata.DeclarativeTableColumn[];
|
columns: azdata.DeclarativeTableColumn[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ describe('Manage Package Dialog', () => {
|
|||||||
let declarativeTable: () => azdata.DeclarativeTableComponent = () => Object.assign({}, componentBase, {
|
let declarativeTable: () => azdata.DeclarativeTableComponent = () => Object.assign({}, componentBase, {
|
||||||
onDataChanged: undefined!,
|
onDataChanged: undefined!,
|
||||||
onRowSelected: undefined!,
|
onRowSelected: undefined!,
|
||||||
|
setFilter: undefined!,
|
||||||
data: [],
|
data: [],
|
||||||
columns: []
|
columns: []
|
||||||
});
|
});
|
||||||
|
|||||||
5
src/sql/azdata.proposed.d.ts
vendored
5
src/sql/azdata.proposed.d.ts
vendored
@@ -300,6 +300,11 @@ declare module 'azdata' {
|
|||||||
|
|
||||||
export interface DeclarativeTableComponent extends Component, DeclarativeTableProperties {
|
export interface DeclarativeTableComponent extends Component, DeclarativeTableProperties {
|
||||||
onRowSelected: vscode.Event<DeclarativeTableRowSelectedEvent>;
|
onRowSelected: vscode.Event<DeclarativeTableRowSelectedEvent>;
|
||||||
|
/**
|
||||||
|
* Sets the filter currently applied to this table - only rows with index in the given array will be visible. undefined
|
||||||
|
* will clear the filter
|
||||||
|
*/
|
||||||
|
setFilter(rowIndexes: number[] | undefined): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ export enum ComponentEventType {
|
|||||||
*/
|
*/
|
||||||
export enum ModelViewAction {
|
export enum ModelViewAction {
|
||||||
SelectTab = 'selectTab',
|
SelectTab = 'selectTab',
|
||||||
AppendData = 'appendData'
|
AppendData = 'appendData',
|
||||||
|
Filter = 'filter'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1585,6 +1585,10 @@ class DeclarativeTableWrapper extends ComponentWrapper implements azdata.Declara
|
|||||||
this.setProperty('selectEffect', v);
|
this.setProperty('selectEffect', v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setFilter(rowIndexes: number[]): void {
|
||||||
|
this._proxy.$doAction(this._handle, this._id, ModelViewAction.Filter, rowIndexes);
|
||||||
|
}
|
||||||
|
|
||||||
public toComponentShape(): IComponentShape {
|
public toComponentShape(): IComponentShape {
|
||||||
// Overridden to ensure we send the correct properties mapping.
|
// Overridden to ensure we send the correct properties mapping.
|
||||||
return <IComponentShape>{
|
return <IComponentShape>{
|
||||||
|
|||||||
@@ -183,7 +183,8 @@ export enum ModelComponentTypes {
|
|||||||
|
|
||||||
export enum ModelViewAction {
|
export enum ModelViewAction {
|
||||||
SelectTab = 'selectTab',
|
SelectTab = 'selectTab',
|
||||||
AppendData = 'appendData'
|
AppendData = 'appendData',
|
||||||
|
Filter = 'filter'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ColumnSizingMode {
|
export enum ColumnSizingMode {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<tbody role="rowgroup">
|
<tbody role="rowgroup">
|
||||||
<ng-container *ngIf="data.length > 0">
|
<ng-container *ngIf="data.length > 0">
|
||||||
<ng-container *ngFor="let row of data;let r = index;">
|
<ng-container *ngFor="let row of data;let r = index;">
|
||||||
<tr class="declarative-table-row" [class.selected]="isRowSelected(r)" role="row">
|
<tr [style.display]="isFiltered(r) ? 'none' : ''" class="declarative-table-row" [class.selected]="isRowSelected(r)" role="row">
|
||||||
<ng-container *ngFor="let cellData of row;let c = index;trackBy:trackByFnCols">
|
<ng-container *ngFor="let cellData of row;let c = index;trackBy:trackByFnCols">
|
||||||
<td class="declarative-table-cell" [style.width]="getColumnWidth(c)"
|
<td class="declarative-table-cell" [style.width]="getColumnWidth(c)"
|
||||||
[attr.aria-label]="getAriaLabel(r, c)"
|
[attr.aria-label]="getAriaLabel(r, c)"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { ContainerBase } from 'sql/workbench/browser/modelComponents/componentBa
|
|||||||
import { ISelectData } from 'vs/base/browser/ui/selectBox/selectBox';
|
import { ISelectData } from 'vs/base/browser/ui/selectBox/selectBox';
|
||||||
import { equals as arrayEquals } from 'vs/base/common/arrays';
|
import { equals as arrayEquals } from 'vs/base/common/arrays';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType, ModelViewAction } from 'sql/platform/dashboard/browser/interfaces';
|
||||||
import { convertSize } from 'sql/base/browser/dom';
|
import { convertSize } from 'sql/base/browser/dom';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
@@ -36,6 +36,7 @@ export default class DeclarativeTableComponent extends ContainerBase<any, azdata
|
|||||||
@Input() modelStore: IModelStore;
|
@Input() modelStore: IModelStore;
|
||||||
|
|
||||||
private _data: azdata.DeclarativeTableCellValue[][] = [];
|
private _data: azdata.DeclarativeTableCellValue[][] = [];
|
||||||
|
private _filteredRowIndexes: number[] | undefined = undefined;
|
||||||
private columns: azdata.DeclarativeTableColumn[] = [];
|
private columns: azdata.DeclarativeTableColumn[] = [];
|
||||||
private _selectedRow: number;
|
private _selectedRow: number;
|
||||||
|
|
||||||
@@ -311,10 +312,29 @@ export default class DeclarativeTableComponent extends ContainerBase<any, azdata
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public doAction(action: string, ...args: any[]): void {
|
||||||
|
if (action === ModelViewAction.Filter) {
|
||||||
|
this._filteredRowIndexes = args[0];
|
||||||
|
}
|
||||||
|
this._changeRef.detectChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a given row is filtered (not visible)
|
||||||
|
* @param rowIndex The row to check
|
||||||
|
*/
|
||||||
|
public isFiltered(rowIndex: number): boolean {
|
||||||
|
if (this._filteredRowIndexes === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this._filteredRowIndexes.includes(rowIndex) ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
public get CSSStyles(): azdata.CssStyles {
|
public get CSSStyles(): azdata.CssStyles {
|
||||||
return this.mergeCss(super.CSSStyles, {
|
return this.mergeCss(super.CSSStyles, {
|
||||||
'width': this.getWidth(),
|
'width': this.getWidth(),
|
||||||
'height': this.getHeight()
|
'height': this.getHeight()
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user