mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 01:25:36 -05:00
Strict nulls for contrib/restore and contrib/views (#12044)
* strict nulls for contrib/restore and contrib/views * remove unnecessary function * compile error
This commit is contained in:
@@ -19,7 +19,6 @@ import { CommonServiceInterface } from 'sql/workbench/services/bootstrap/browser
|
||||
import { alert } from 'vs/base/browser/ui/aria/aria';
|
||||
import { IInputOptions, InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
|
||||
import { Delayer } from 'vs/base/common/async';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { isStringArray } from 'vs/base/common/types';
|
||||
import 'vs/css!./media/explorerWidget';
|
||||
import * as nls from 'vs/nls';
|
||||
@@ -104,7 +103,7 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
|
||||
this._register(subscriptionToDisposable(this._bootstrap.metadataService.metadata.subscribe(
|
||||
data => {
|
||||
if (data) {
|
||||
const objectData = ObjectMetadataWrapper.createFromObjectMetadata(data.objectMetadata);
|
||||
const objectData = data.objectMetadata.map(o => new ObjectMetadataWrapper(o));
|
||||
objectData.sort(ObjectMetadataWrapper.sort);
|
||||
this.updateTable(objectData);
|
||||
}
|
||||
@@ -155,7 +154,7 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
|
||||
|
||||
const currentProfile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile;
|
||||
this.updateTable(data.map(d => {
|
||||
const item = assign({}, d.options);
|
||||
const item = Object.assign({}, d.options);
|
||||
const profile = new ConnectionProfile(this.capabilitiesService, currentProfile);
|
||||
profile.databaseName = d.options[NameProperty];
|
||||
item[ConnectionProfilePropertyName] = profile;
|
||||
|
||||
@@ -17,14 +17,12 @@ export class ObjectMetadataWrapper implements ObjectMetadata {
|
||||
return `${this.schema}.${this.name}`;
|
||||
}
|
||||
|
||||
constructor(from?: ObjectMetadata) {
|
||||
if (from) {
|
||||
this.metadataType = from.metadataType;
|
||||
this.metadataTypeName = from.metadataTypeName;
|
||||
this.urn = from.urn;
|
||||
this.name = from.name;
|
||||
this.schema = from.schema;
|
||||
}
|
||||
constructor(from: ObjectMetadata) {
|
||||
this.metadataType = from.metadataType;
|
||||
this.metadataTypeName = from.metadataTypeName;
|
||||
this.urn = from.urn;
|
||||
this.name = from.name;
|
||||
this.schema = from.schema;
|
||||
}
|
||||
|
||||
public matches(other: ObjectMetadataWrapper): boolean {
|
||||
@@ -37,14 +35,6 @@ export class ObjectMetadataWrapper implements ObjectMetadata {
|
||||
&& this.name === other.name;
|
||||
}
|
||||
|
||||
public static createFromObjectMetadata(objectMetadata: ObjectMetadata[]): ObjectMetadataWrapper[] {
|
||||
if (!objectMetadata) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return objectMetadata.map(m => new ObjectMetadataWrapper(m));
|
||||
}
|
||||
|
||||
// custom sort : Table > View > Stored Procedures > Function
|
||||
public static sort(metadata1: ObjectMetadataWrapper, metadata2: ObjectMetadataWrapper): number {
|
||||
// compare the object type
|
||||
|
||||
@@ -13,44 +13,43 @@ import { FlavorProperties } from 'sql/workbench/contrib/dashboard/browser/dashbo
|
||||
|
||||
suite('Explorer Widget Tests', () => {
|
||||
test('Sorting dashboard search objects works correctly', () => {
|
||||
let testMetadata = ObjectMetadataWrapper.createFromObjectMetadata(
|
||||
[
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testView',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Table,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testTable',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.SProc,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testSProc',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Function,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testFunction',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'firstView',
|
||||
schema: undefined
|
||||
}
|
||||
]);
|
||||
let testMetadata = [
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testView',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Table,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testTable',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.SProc,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testSProc',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Function,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testFunction',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'firstView',
|
||||
schema: undefined
|
||||
}
|
||||
].map(m => new ObjectMetadataWrapper(m));
|
||||
|
||||
// If I sort the object metadata wrapper list using ExplorerWidget's sort function
|
||||
let sortedMetadata = testMetadata.slice().sort(ObjectMetadataWrapper.sort);
|
||||
@@ -79,44 +78,43 @@ suite('Explorer Widget Tests', () => {
|
||||
});
|
||||
|
||||
test('object type filter', () => {
|
||||
const testMetadata = ObjectMetadataWrapper.createFromObjectMetadata(
|
||||
[
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testView',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Table,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testTable',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.SProc,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testSProc',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Function,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testFunction',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'firstView',
|
||||
schema: undefined
|
||||
}
|
||||
]);
|
||||
const testMetadata = [
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testView',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Table,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testTable',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.SProc,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testSProc',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.Function,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'testFunction',
|
||||
schema: undefined
|
||||
},
|
||||
{
|
||||
metadataType: MetadataType.View,
|
||||
metadataTypeName: undefined,
|
||||
urn: undefined,
|
||||
name: 'firstView',
|
||||
schema: undefined
|
||||
}
|
||||
].map(o => new ObjectMetadataWrapper(o));
|
||||
const filter = new ExplorerFilter('database', ['name']);
|
||||
let result = filter.filter('t:', testMetadata);
|
||||
assert.equal(result.length, 1, 'table type filter should return only 1 item');
|
||||
|
||||
@@ -26,9 +26,11 @@ const DE_RESTORE_COMMAND_ID = 'dataExplorer.restore';
|
||||
// Restore
|
||||
CommandsRegistry.registerCommand({
|
||||
id: DE_RESTORE_COMMAND_ID,
|
||||
handler: (accessor, args: TreeViewItemHandleArg) => {
|
||||
const commandService = accessor.get(ICommandService);
|
||||
return commandService.executeCommand(RestoreAction.ID, args.$treeItem.payload);
|
||||
handler: async (accessor, args: TreeViewItemHandleArg) => {
|
||||
if (args.$treeItem?.payload) {
|
||||
const commandService = accessor.get(ICommandService);
|
||||
return commandService.executeCommand(RestoreAction.ID, args.$treeItem.payload);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -39,9 +39,10 @@ export class RestoreAction extends Task {
|
||||
});
|
||||
}
|
||||
|
||||
runTask(accessor: ServicesAccessor, profile: IConnectionProfile): void | Promise<void> {
|
||||
runTask(accessor: ServicesAccessor, withProfile?: IConnectionProfile): void | Promise<void> {
|
||||
let profile = withProfile;
|
||||
const configurationService = accessor.get<IConfigurationService>(IConfigurationService);
|
||||
const previewFeaturesEnabled: boolean = configurationService.getValue('workbench')['enablePreviewFeatures'];
|
||||
const previewFeaturesEnabled: boolean = configurationService.getValue<{ enablePreviewFeatures: boolean }>('workbench').enablePreviewFeatures;
|
||||
if (!previewFeaturesEnabled) {
|
||||
return accessor.get<INotificationService>(INotificationService).info(localize('restore.isPreviewFeature', "You must enable preview features in order to use restore"));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export class NodeContextKey extends Disposable implements IContextKey<INodeConte
|
||||
private readonly _viewItemKey: IContextKey<string>;
|
||||
private readonly _nodeContextKey: IContextKey<INodeContextValue>;
|
||||
|
||||
private _nodeContextUtils: MssqlNodeContext;
|
||||
private _nodeContextUtils?: MssqlNodeContext;
|
||||
|
||||
constructor(
|
||||
@IContextKeyService private contextKeyService: IContextKeyService,
|
||||
@@ -47,7 +47,7 @@ export class NodeContextKey extends Disposable implements IContextKey<INodeConte
|
||||
}
|
||||
|
||||
set(value: INodeContextValue) {
|
||||
if (value.node && value.node.payload) {
|
||||
if (value.node?.payload) {
|
||||
this._connectableKey.set(true);
|
||||
this._connectedKey.set(this.oeService.isNodeConnected(value.viewId, value.node));
|
||||
this._connectionContextKey.set(value.node.payload);
|
||||
@@ -56,14 +56,14 @@ export class NodeContextKey extends Disposable implements IContextKey<INodeConte
|
||||
this._connectedKey.set(false);
|
||||
this._connectionContextKey.reset();
|
||||
}
|
||||
if (value.node) {
|
||||
if (value.node?.contextValue) {
|
||||
this._viewItemKey.set(value.node.contextValue);
|
||||
} else {
|
||||
this._viewItemKey.reset();
|
||||
}
|
||||
this._nodeContextKey.set(value);
|
||||
this._viewIdKey.set(value.viewId);
|
||||
this._nodeContextUtils = new MssqlNodeContext(this._nodeContextKey.get(), this.contextKeyService,
|
||||
this._nodeContextUtils = new MssqlNodeContext(this._nodeContextKey.get()!, this.contextKeyService,
|
||||
this.connectionManagementService, this.capabilitiesService);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export class NodeContextKey extends Disposable implements IContextKey<INodeConte
|
||||
this._connectedKey.reset();
|
||||
this._connectionContextKey.reset();
|
||||
this._nodeContextKey.reset();
|
||||
this._nodeContextUtils.dispose();
|
||||
this._nodeContextUtils?.dispose();
|
||||
}
|
||||
|
||||
get(): INodeContextValue | undefined {
|
||||
|
||||
@@ -665,7 +665,7 @@ class TreeDataSource implements IAsyncDataSource<ITreeItem, ITreeItem> {
|
||||
if (node.childProvider) {
|
||||
return this.objectExplorerService.providerExists(node.childProvider) && node.collapsibleState !== TreeItemCollapsibleState.None;
|
||||
}
|
||||
return this.treeView.dataProvider && node.collapsibleState !== TreeItemCollapsibleState.None;
|
||||
return !!this.treeView.dataProvider && node.collapsibleState !== TreeItemCollapsibleState.None;
|
||||
}
|
||||
|
||||
async getChildren(node: ITreeItem): Promise<any[]> {
|
||||
@@ -812,7 +812,7 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
|
||||
|
||||
if (iconUrl || sqlIcon) {
|
||||
templateData.icon.className = 'custom-view-tree-node-item-icon';
|
||||
DOM.toggleClass(templateData.icon, sqlIcon, !!sqlIcon); // tracked change
|
||||
DOM.toggleClass(templateData.icon, sqlIcon ?? '', !!sqlIcon); // tracked change
|
||||
DOM.toggleClass(templateData.icon, 'icon', !!sqlIcon);
|
||||
templateData.icon.style.backgroundImage = iconUrl ? DOM.asCSSUrl(iconUrl) : '';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user