mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Add debounce to pg parameters search filter (#14140)
* Add debounce to pg parameters search filter * Update tsconfig
This commit is contained in:
@@ -295,3 +295,35 @@ export async function tryExecuteAction<T>(action: () => T | PromiseLike<T>): Pro
|
|||||||
}
|
}
|
||||||
return { result, error };
|
return { result, error };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decorate(decorator: (fn: Function, key: string) => Function): Function {
|
||||||
|
return (_target: any, key: string, descriptor: any) => {
|
||||||
|
let fnKey: string | null = null;
|
||||||
|
let fn: Function | null = null;
|
||||||
|
|
||||||
|
if (typeof descriptor.value === 'function') {
|
||||||
|
fnKey = 'value';
|
||||||
|
fn = descriptor.value;
|
||||||
|
} else if (typeof descriptor.get === 'function') {
|
||||||
|
fnKey = 'get';
|
||||||
|
fn = descriptor.get;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fn || !fnKey) {
|
||||||
|
throw new Error('not supported');
|
||||||
|
}
|
||||||
|
|
||||||
|
descriptor[fnKey] = decorator(fn, key);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function debounce(delay: number): Function {
|
||||||
|
return decorate((fn, key) => {
|
||||||
|
const timerKey = `$debounce$${key}`;
|
||||||
|
|
||||||
|
return function (this: any, ...args: any[]) {
|
||||||
|
clearTimeout(this[timerKey]);
|
||||||
|
this[timerKey] = setTimeout(() => fn.apply(this, args), delay);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { UserCancelledError } from '../../../common/api';
|
|||||||
import { IconPathHelper, cssStyles } from '../../../constants';
|
import { IconPathHelper, cssStyles } from '../../../constants';
|
||||||
import { DashboardPage } from '../../components/dashboardPage';
|
import { DashboardPage } from '../../components/dashboardPage';
|
||||||
import { EngineSettingsModel, PostgresModel } from '../../../models/postgresModel';
|
import { EngineSettingsModel, PostgresModel } from '../../../models/postgresModel';
|
||||||
|
import { debounce } from '../../../common/utils';
|
||||||
|
|
||||||
export type ParametersModel = {
|
export type ParametersModel = {
|
||||||
parameterName: string,
|
parameterName: string,
|
||||||
@@ -358,13 +359,18 @@ export class PostgresParametersPage extends DashboardPage {
|
|||||||
|
|
||||||
this.disposables.push(
|
this.disposables.push(
|
||||||
this.searchBox.onTextChanged(() => {
|
this.searchBox.onTextChanged(() => {
|
||||||
|
this.onSearchFilter();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@debounce(500)
|
||||||
|
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.data = this._parameters.map(p => [p.parameterName, p.valueContainer, p.description, p.resetButton]);
|
||||||
} else {
|
} else {
|
||||||
this.filterParameters(this.searchBox!.value);
|
this.filterParameters(this.searchBox!.value);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private filterParameters(search: string): void {
|
private filterParameters(search: string): void {
|
||||||
@@ -375,7 +381,7 @@ export class PostgresParametersPage extends DashboardPage {
|
|||||||
|
|
||||||
private handleOnTextChanged(component: azdata.InputBoxComponent, currentValue: string | undefined): boolean {
|
private handleOnTextChanged(component: azdata.InputBoxComponent, currentValue: string | undefined): boolean {
|
||||||
if (!component.valid) {
|
if (!component.valid) {
|
||||||
// If invalid value retun false and enable discard button
|
// If invalid value return false and enable discard button
|
||||||
this.discardButton!.enabled = true;
|
this.discardButton!.enabled = true;
|
||||||
return false;
|
return false;
|
||||||
} else if (component.value === currentValue) {
|
} else if (component.value === currentValue) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"extends": "../shared.tsconfig.json",
|
"extends": "../shared.tsconfig.json",
|
||||||
"compileOnSave": true,
|
"compileOnSave": true,
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
"outDir": "./out",
|
"outDir": "./out",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es6",
|
"es6",
|
||||||
|
|||||||
Reference in New Issue
Block a user