mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 01:25:39 -05:00
Layering of everything else but query (#5085)
* layer profiler and edit data * relayering everything but query * fix css import * readd qp * fix script src * fix hygiene
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput';
|
||||
import { ProfilerInput } from 'sql/workbench/parts/profiler/browser/profilerInput';
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import * as azdata from 'azdata';
|
||||
import { INewProfilerState } from 'sql/parts/profiler/editor/profilerState';
|
||||
import { INewProfilerState } from 'sql/workbench/parts/profiler/common/profilerState';
|
||||
|
||||
const PROFILER_SERVICE_ID = 'profilerService';
|
||||
export const IProfilerService = createDecorator<IProfilerService>(PROFILER_SERVICE_ID);
|
||||
|
||||
103
src/sql/workbench/services/profiler/common/profilerFilter.ts
Normal file
103
src/sql/workbench/services/profiler/common/profilerFilter.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ProfilerFilterClause, ProfilerFilter, ProfilerFilterClauseOperator } from 'sql/workbench/services/profiler/common/interfaces';
|
||||
|
||||
|
||||
export function FilterData(filter: ProfilerFilter, data: any[]): any[] {
|
||||
if (!data || !filter) {
|
||||
return data;
|
||||
}
|
||||
return data.filter(item => matches(item, filter.clauses));
|
||||
}
|
||||
|
||||
function matches(item: any, clauses: ProfilerFilterClause[]): boolean {
|
||||
let match = true;
|
||||
if (!item) {
|
||||
match = false;
|
||||
} else if (clauses) {
|
||||
for (let i = 0; i < clauses.length; i++) {
|
||||
let clause = clauses[i];
|
||||
if (!!clause && !!clause.field) {
|
||||
let actualValue: any = item[clause.field];
|
||||
let expectedValue: any = clause.value;
|
||||
let actualValueString: string = actualValue === undefined ? undefined : actualValue.toLocaleLowerCase();
|
||||
let expectedValueString: string = expectedValue === undefined ? undefined : expectedValue.toLocaleLowerCase();
|
||||
let actualValueDate = new Date(actualValue).valueOf();
|
||||
let expectedValueDate = new Date(expectedValue).valueOf();
|
||||
let actualValueNumber = Number(actualValue).valueOf();
|
||||
let expectedValueNumber = Number(expectedValue).valueOf();
|
||||
|
||||
if (isValidNumber(actualValue) && isValidNumber(expectedValue)) {
|
||||
actualValue = actualValueNumber;
|
||||
expectedValue = expectedValueNumber;
|
||||
} else if (isValidDate(actualValue) && isValidDate(expectedValue)) {
|
||||
actualValue = actualValueDate;
|
||||
expectedValue = expectedValueDate;
|
||||
} else {
|
||||
actualValue = actualValueString;
|
||||
expectedValue = expectedValueString;
|
||||
}
|
||||
|
||||
switch (clause.operator) {
|
||||
case ProfilerFilterClauseOperator.Equals:
|
||||
match = actualValue === expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotEquals:
|
||||
match = actualValue !== expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.LessThan:
|
||||
match = actualValue < expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.LessThanOrEquals:
|
||||
match = actualValue <= expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.GreaterThan:
|
||||
match = actualValue > expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.GreaterThanOrEquals:
|
||||
match = actualValue >= expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.IsNull:
|
||||
match = actualValue === undefined || actualValue === null || actualValue === '';
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.IsNotNull:
|
||||
match = actualValue !== undefined && actualValue !== null && actualValue !== '';
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.Contains:
|
||||
match = actualValueString && actualValueString.includes(expectedValueString);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotContains:
|
||||
match = !actualValueString || !actualValueString.includes(expectedValueString);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.StartsWith:
|
||||
match = actualValueString.startsWith(expectedValueString);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotStartsWith:
|
||||
match = !actualValueString || !actualValueString.startsWith(expectedValueString);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Not a valid operator: ${clause.operator}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
function isValidNumber(value: string): boolean {
|
||||
let num = Number(value);
|
||||
return value !== undefined && !isNaN(num.valueOf()) && value.replace(' ', '') !== '';
|
||||
}
|
||||
|
||||
function isValidDate(value: string): boolean {
|
||||
let date = new Date(value);
|
||||
return value !== undefined && !isNaN(date.valueOf());
|
||||
}
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
PROFILER_SETTINGS, IProfilerSettings
|
||||
} from './interfaces';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput';
|
||||
import { ProfilerColumnEditorDialog } from 'sql/parts/profiler/dialog/profilerColumnEditorDialog';
|
||||
import { ProfilerInput } from 'sql/workbench/parts/profiler/browser/profilerInput';
|
||||
import { ProfilerColumnEditorDialog } from 'sql/workbench/parts/profiler/browser/profilerColumnEditorDialog';
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
@@ -20,7 +20,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { Memento } from 'vs/workbench/common/memento';
|
||||
import { ProfilerFilterDialog } from 'sql/parts/profiler/dialog/profilerFilterDialog';
|
||||
import { ProfilerFilterDialog } from 'sql/workbench/parts/profiler/browser/profilerFilterDialog';
|
||||
|
||||
class TwoWayMap<T, K> {
|
||||
private forwardMap: Map<T, K>;
|
||||
|
||||
Reference in New Issue
Block a user