mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 17:23:02 -05:00
Remove typings and replace missing methods with vscodes (#8217)
* remove typings and replace missing methods with vscodes * fix strict-null-checks * fix tests
This commit is contained in:
@@ -18,6 +18,7 @@ import * as types from 'vs/base/common/types';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
|
||||
import { firstIndex } from 'vs/base/common/arrays';
|
||||
|
||||
export interface IPanelOptions {
|
||||
/**
|
||||
@@ -202,7 +203,7 @@ export class PanelComponent extends Disposable {
|
||||
* Select on the next tab
|
||||
*/
|
||||
public selectOnNextTab(): void {
|
||||
let activeIndex = this._tabs.toArray().findIndex(i => i === this._activeTab);
|
||||
let activeIndex = firstIndex(this._tabs.toArray(), i => i === this._activeTab);
|
||||
let nextTabIndex = activeIndex + 1;
|
||||
if (nextTabIndex === this._tabs.length) {
|
||||
nextTabIndex = 0;
|
||||
@@ -211,7 +212,7 @@ export class PanelComponent extends Disposable {
|
||||
}
|
||||
|
||||
private findAndRemoveTabFromMRU(tab: TabComponent): void {
|
||||
let mruIndex = this._mru.findIndex(i => i === tab);
|
||||
let mruIndex = firstIndex(this._mru, i => i === tab);
|
||||
|
||||
if (mruIndex !== -1) {
|
||||
// Remove old index
|
||||
|
||||
@@ -15,6 +15,7 @@ import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import * as map from 'vs/base/common/map';
|
||||
import { firstIndex } from 'vs/base/common/arrays';
|
||||
|
||||
export interface ITabbedPanelStyles {
|
||||
titleActiveForeground?: Color;
|
||||
@@ -171,11 +172,11 @@ export class TabbedPanel extends Disposable {
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
if (event.equals(KeyCode.RightArrow)) {
|
||||
let currentIndex = this._tabOrder.findIndex(x => x === tab.tab.identifier);
|
||||
let currentIndex = firstIndex(this._tabOrder, x => x === tab.tab.identifier);
|
||||
this.focusNextTab(currentIndex + 1);
|
||||
}
|
||||
if (event.equals(KeyCode.LeftArrow)) {
|
||||
let currentIndex = this._tabOrder.findIndex(x => x === tab.tab.identifier);
|
||||
let currentIndex = firstIndex(this._tabOrder, x => x === tab.tab.identifier);
|
||||
this.focusNextTab(currentIndex - 1);
|
||||
}
|
||||
if (event.equals(KeyCode.Tab)) {
|
||||
@@ -191,8 +192,7 @@ export class TabbedPanel extends Disposable {
|
||||
|
||||
const insertBefore = !isUndefinedOrNull(index) ? this.tabList.children.item(index) : undefined;
|
||||
if (insertBefore) {
|
||||
this._tabOrder.copyWithin(index! + 1, index!);
|
||||
this._tabOrder[index!] = tab.tab.identifier;
|
||||
this._tabOrder.splice(index!, 0, tab.tab.identifier);
|
||||
this.tabList.insertBefore(tabHeaderElement, insertBefore);
|
||||
} else {
|
||||
this.tabList.append(tabHeaderElement);
|
||||
@@ -267,7 +267,7 @@ export class TabbedPanel extends Disposable {
|
||||
}
|
||||
actualTab.disposables.dispose();
|
||||
this._tabMap.delete(tab);
|
||||
let index = this._tabOrder.findIndex(t => t === tab);
|
||||
let index = firstIndex(this._tabOrder, t => t === tab);
|
||||
this._tabOrder.splice(index, 1);
|
||||
if (this._shownTabId === tab) {
|
||||
this._shownTabId = undefined;
|
||||
|
||||
@@ -136,7 +136,7 @@ export class HeaderFilter<T extends Slick.SlickData> {
|
||||
this.workingFilters = columnDef.filterValues.slice(0);
|
||||
|
||||
for (let i = 0; i < filterItems.length; i++) {
|
||||
const filtered = _.contains(this.workingFilters, filterItems[i]);
|
||||
const filtered = this.workingFilters.some(x => x === filterItems[i]);
|
||||
|
||||
filterOptions += '<label><input type="checkbox" value="' + i + '"'
|
||||
+ (filtered ? ' checked="checked"' : '')
|
||||
@@ -184,7 +184,7 @@ export class HeaderFilter<T extends Slick.SlickData> {
|
||||
let filterOptions = '<label><input type="checkbox" value="-1" />(Select All)</label>';
|
||||
|
||||
for (let i = 0; i < filterItems.length; i++) {
|
||||
const filtered = _.contains(this.workingFilters, filterItems[i]);
|
||||
const filtered = this.workingFilters.some(x => x === filterItems[i]);
|
||||
if (filterItems[i] && filterItems[i].indexOf('Error:') < 0) {
|
||||
filterOptions += '<label><input type="checkbox" value="' + i + '"'
|
||||
+ (filtered ? ' checked="checked"' : '')
|
||||
@@ -282,7 +282,7 @@ export class HeaderFilter<T extends Slick.SlickData> {
|
||||
workingFilters.length = 0;
|
||||
}
|
||||
} else {
|
||||
const index = _.indexOf(workingFilters, filterItems[value]);
|
||||
const index = workingFilters.indexOf(filterItems[value]);
|
||||
|
||||
if ($checkbox.prop('checked') && index < 0) {
|
||||
workingFilters.push(filterItems[value]);
|
||||
@@ -326,7 +326,7 @@ export class HeaderFilter<T extends Slick.SlickData> {
|
||||
for (let i = 0; i < dataView.getLength(); i++) {
|
||||
const value = dataView.getItem(i)[column.field!];
|
||||
|
||||
if (!_.contains(seen, value)) {
|
||||
if (!seen.some(x => x === value)) {
|
||||
seen.push(value);
|
||||
}
|
||||
}
|
||||
@@ -346,18 +346,18 @@ export class HeaderFilter<T extends Slick.SlickData> {
|
||||
const itemValue = !value ? '' : value;
|
||||
const lowercaseFilter = filter.toString().toLowerCase();
|
||||
const lowercaseVal = itemValue.toString().toLowerCase();
|
||||
if (!_.contains(seen, value) && lowercaseVal.indexOf(lowercaseFilter) > -1) {
|
||||
if (!seen.some(x => x === value) && lowercaseVal.indexOf(lowercaseFilter) > -1) {
|
||||
seen.push(value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!_.contains(seen, value)) {
|
||||
if (!seen.some(x => x === value)) {
|
||||
seen.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _.sortBy(seen, (v) => { return v; });
|
||||
return seen.sort((v) => { return v; });
|
||||
}
|
||||
|
||||
private getAllFilterValues(data: Array<Slick.SlickData>, column: Slick.Column<T>) {
|
||||
@@ -365,12 +365,12 @@ export class HeaderFilter<T extends Slick.SlickData> {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const value = data[i][column.field!];
|
||||
|
||||
if (!_.contains(seen, value)) {
|
||||
if (!seen.some(x => x === value)) {
|
||||
seen.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
return _.sortBy(seen, (v) => { return v; });
|
||||
return seen.sort((v) => { return v; });
|
||||
}
|
||||
|
||||
private handleMenuItemClick(e: JQuery.Event<HTMLElement, null>, command: string, columnDef: Slick.Column<T>) {
|
||||
|
||||
8
src/sql/base/common/collections.ts
Normal file
8
src/sql/base/common/collections.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export function entries<K>(o: Record<string, K>): [string, K][] {
|
||||
return Object.keys(o).map(k => [k, o[k]]);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Alterable version of the vs memorize function; to unmemoize use unmemoize
|
||||
*/
|
||||
export function memoize(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;
|
||||
|
||||
if (fn!.length !== 0) {
|
||||
console.warn('Memoize should only be used in functions with zero parameters');
|
||||
}
|
||||
} else if (typeof descriptor.get === 'function') {
|
||||
fnKey = 'get';
|
||||
fn = descriptor.get;
|
||||
}
|
||||
|
||||
if (!fn) {
|
||||
throw new Error('not supported');
|
||||
}
|
||||
|
||||
const memoizeKey = `$memoize$${key}`;
|
||||
|
||||
descriptor[fnKey!] = function (...args: any[]) {
|
||||
if (!this.hasOwnProperty(memoizeKey)) {
|
||||
Object.defineProperty(this, memoizeKey, {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: fn!.apply(this, args)
|
||||
});
|
||||
}
|
||||
|
||||
return this[memoizeKey];
|
||||
};
|
||||
}
|
||||
|
||||
export function unmemoize(target: Object, key: string) {
|
||||
const memoizeKey = `$memoize$${key}`;
|
||||
if (target.hasOwnProperty(memoizeKey)) {
|
||||
delete target[memoizeKey];
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,3 @@ export function mixin(destination: any, source: any, overwrite: boolean = true,
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
export function entries<T>(o: { [key: string]: T }): [string, T][] {
|
||||
return Object.keys(o).map(k => [k, o[k]] as [string, T]);
|
||||
}
|
||||
|
||||
export function values<T>(o: { [key: string]: T }): T[] {
|
||||
return Object.keys(o).map(k => o[k]);
|
||||
}
|
||||
|
||||
@@ -19,3 +19,20 @@ export function escape(html: string): string {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// gotten from https://github.com/59naga/string-raw/blob/master/src/index.js
|
||||
export function raw(callSite: any, ...substitutions: any[]): string {
|
||||
let template;
|
||||
try {
|
||||
template = Array.from(callSite.raw);
|
||||
} catch (e) {
|
||||
throw new TypeError('Cannot convert undefined or null to object');
|
||||
}
|
||||
|
||||
return template.map((chunk, i) => {
|
||||
if (callSite.raw.length <= i) {
|
||||
return chunk;
|
||||
}
|
||||
return substitutions[i - 1] ? substitutions[i - 1] + chunk : chunk;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ export class Dropdown extends Disposable {
|
||||
}
|
||||
|
||||
private _inputValidator(value: string): IMessage | null {
|
||||
if (!this._input.hasFocus() && !this._tree.isDOMFocused() && this._dataSource.options && !this._dataSource.options.find(i => i.value === value)) {
|
||||
if (!this._input.hasFocus() && !this._tree.isDOMFocused() && this._dataSource.options && !this._dataSource.options.some(i => i.value === value)) {
|
||||
if (this._options.strictSelection && this._options.errorMessage) {
|
||||
return {
|
||||
content: this._options.errorMessage,
|
||||
|
||||
@@ -96,7 +96,7 @@ export class DropdownFilter extends TreeDefaults.DefaultFilter {
|
||||
public filterString: string;
|
||||
|
||||
public isVisible(tree: tree.ITree | undefined, element: Resource): boolean {
|
||||
return element.value.toLowerCase().includes(this.filterString.toLowerCase());
|
||||
return element.value.toLowerCase().indexOf(this.filterString.toLowerCase()) !== -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ suite('TableDataView', () => {
|
||||
const ret = new Array<number>();
|
||||
for (let i = 0; i < columnCount; i++) {
|
||||
const colVal = val[getColumnName(i)];
|
||||
if (colVal && colVal.toLocaleLowerCase().includes(exp.toLocaleLowerCase())) {
|
||||
if (colVal && colVal.toLocaleLowerCase().indexOf(exp.toLocaleLowerCase()) > -1) {
|
||||
ret.push(i);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ suite('TableDataView', () => {
|
||||
const ret = new Array<number>();
|
||||
for (let i = 0; i < columnCount; i++) {
|
||||
const colVal = val[getColumnName(i)];
|
||||
if (colVal && colVal.toLocaleLowerCase().includes(exp.toLocaleLowerCase())) {
|
||||
if (colVal && colVal.toLocaleLowerCase().indexOf(exp.toLocaleLowerCase()) > -1) {
|
||||
ret.push(i);
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ suite('TableDataView', () => {
|
||||
const ret = new Array<number>();
|
||||
for (let i = 0; i < columnCount; i++) {
|
||||
const colVal = val[getColumnName(i)];
|
||||
if (colVal && colVal.toLocaleLowerCase().includes(exp.toLocaleLowerCase())) {
|
||||
if (colVal && colVal.toLocaleLowerCase().indexOf(exp.toLocaleLowerCase()) > -1) {
|
||||
ret.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export class EventVerifierSingle<T> {
|
||||
private _eventArgument: T;
|
||||
@@ -64,13 +65,13 @@ export class EventVerifierMultiple<T> {
|
||||
public assertFired(expectedArgument?: T) {
|
||||
assert.ok(this.eventFired);
|
||||
if (expectedArgument) {
|
||||
assert.ok(this._eventArguments.includes(expectedArgument));
|
||||
assert.ok(this._eventArguments.some(x => x === expectedArgument));
|
||||
}
|
||||
}
|
||||
|
||||
public assertNotFired(expectedArgument?: T) {
|
||||
if (expectedArgument) {
|
||||
assert.ok(!this._eventArguments.includes(expectedArgument));
|
||||
assert.ok(!this._eventArguments.some(x => x === expectedArgument));
|
||||
} else {
|
||||
assert.ok(!this.eventFired);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user