mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
fix strict null issues (#22430)
This commit is contained in:
@@ -69,7 +69,7 @@ async function handleNewUserDialogCommand(context: azdata.ObjectExplorerContext,
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const dialog = new UserDialog(service, connectionUri, context.connectionProfile.databaseName, true, undefined, context);
|
||||
const dialog = new UserDialog(service, connectionUri, context.connectionProfile!.databaseName!, true, undefined, context);
|
||||
await dialog.open();
|
||||
}
|
||||
catch (err) {
|
||||
@@ -85,15 +85,15 @@ async function handleObjectPropertiesDialogCommand(context: azdata.ObjectExplore
|
||||
if (!connectionUri) {
|
||||
return;
|
||||
}
|
||||
const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo.nodeType);
|
||||
const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo!.nodeType);
|
||||
try {
|
||||
let dialog;
|
||||
switch (context.nodeInfo.nodeType) {
|
||||
switch (context.nodeInfo!.nodeType) {
|
||||
case NodeType.Login:
|
||||
dialog = new LoginDialog(service, connectionUri, false, context.nodeInfo.label);
|
||||
dialog = new LoginDialog(service, connectionUri, false, context.nodeInfo!.label);
|
||||
break;
|
||||
case NodeType.User:
|
||||
dialog = new UserDialog(service, connectionUri, context.connectionProfile.databaseName, false, context.nodeInfo.label);
|
||||
dialog = new UserDialog(service, connectionUri, context.connectionProfile!.databaseName!, false, context.nodeInfo!.label);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -104,9 +104,9 @@ async function handleObjectPropertiesDialogCommand(context: azdata.ObjectExplore
|
||||
}
|
||||
catch (err) {
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.OpenPropertiesDialog, err).withAdditionalProperties({
|
||||
objectType: context.nodeInfo.nodeType
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}).send();
|
||||
await vscode.window.showErrorMessage(localizedConstants.OpenObjectPropertiesDialogError(nodeTypeDisplayName, context.nodeInfo.label, getErrorMessage(err)));
|
||||
await vscode.window.showErrorMessage(localizedConstants.OpenObjectPropertiesDialogError(nodeTypeDisplayName, context.nodeInfo!.label, getErrorMessage(err)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,16 +115,16 @@ async function handleDeleteObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
if (!connectionUri) {
|
||||
return;
|
||||
}
|
||||
let additionalConfirmationMessage: string;
|
||||
switch (context.nodeInfo.nodeType) {
|
||||
let additionalConfirmationMessage: string | undefined = undefined;
|
||||
switch (context.nodeInfo!.nodeType) {
|
||||
case NodeType.Login:
|
||||
additionalConfirmationMessage = localizedConstants.DeleteLoginConfirmationText;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo.nodeType);
|
||||
let confirmMessage = localizedConstants.DeleteObjectConfirmationText(nodeTypeDisplayName, context.nodeInfo.label);
|
||||
const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo!.nodeType);
|
||||
let confirmMessage = localizedConstants.DeleteObjectConfirmationText(nodeTypeDisplayName, context.nodeInfo!.label);
|
||||
if (additionalConfirmationMessage) {
|
||||
confirmMessage = `${additionalConfirmationMessage} ${confirmMessage}`;
|
||||
}
|
||||
@@ -133,23 +133,23 @@ async function handleDeleteObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
return;
|
||||
}
|
||||
azdata.tasks.startBackgroundOperation({
|
||||
displayName: localizedConstants.DeleteObjectOperationDisplayName(nodeTypeDisplayName, context.nodeInfo.label),
|
||||
displayName: localizedConstants.DeleteObjectOperationDisplayName(nodeTypeDisplayName, context.nodeInfo!.label),
|
||||
description: '',
|
||||
isCancelable: false,
|
||||
operation: async (operation) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
await service.drop(connectionUri, context.nodeInfo.metadata.urn);
|
||||
await service.drop(connectionUri, context.nodeInfo!.metadata!.urn);
|
||||
TelemetryReporter.sendTelemetryEvent(TelemetryActions.DeleteObject, {
|
||||
objectType: context.nodeInfo.nodeType
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}, {
|
||||
elapsedTimeMs: Date.now() - startTime
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, localizedConstants.DeleteObjectError(nodeTypeDisplayName, context.nodeInfo.label, getErrorMessage(err)));
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, localizedConstants.DeleteObjectError(nodeTypeDisplayName, context.nodeInfo!.label, getErrorMessage(err)));
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.DeleteObject, err).withAdditionalProperties({
|
||||
objectType: context.nodeInfo.nodeType
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}).send();
|
||||
return;
|
||||
}
|
||||
@@ -164,8 +164,8 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
if (!connectionUri) {
|
||||
return;
|
||||
}
|
||||
const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo.nodeType);
|
||||
const originalName = context.nodeInfo.metadata.name;
|
||||
const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo!.nodeType);
|
||||
const originalName = context.nodeInfo!.metadata!.name;
|
||||
const newName = await vscode.window.showInputBox({
|
||||
title: localizedConstants.RenameObjectDialogTitle,
|
||||
value: originalName,
|
||||
@@ -191,9 +191,9 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
operation: async (operation) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
await service.rename(connectionUri, context.nodeInfo.metadata.urn, newName);
|
||||
await service.rename(connectionUri, context.nodeInfo!.metadata!.urn, newName);
|
||||
TelemetryReporter.sendTelemetryEvent(TelemetryActions.RenameObject, {
|
||||
objectType: context.nodeInfo.nodeType
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}, {
|
||||
elapsedTimeMs: Date.now() - startTime
|
||||
});
|
||||
@@ -201,7 +201,7 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
catch (err) {
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, localizedConstants.RenameObjectError(nodeTypeDisplayName, originalName, newName, getErrorMessage(err)));
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.RenameObject, err).withAdditionalProperties({
|
||||
objectType: context.nodeInfo.nodeType
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}).send();
|
||||
return;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
}
|
||||
|
||||
async function getConnectionUri(context: azdata.ObjectExplorerContext): Promise<string> {
|
||||
const connectionUri = await azdata.connection.getUriForConnection(context.connectionProfile.id);
|
||||
const connectionUri = await azdata.connection.getUriForConnection(context.connectionProfile!.id);
|
||||
if (!connectionUri) {
|
||||
await vscode.window.showErrorMessage(localizedConstants.FailedToRetrieveConnectionInfoErrorMessage, { modal: true });
|
||||
}
|
||||
|
||||
@@ -236,7 +236,8 @@ export class TestObjectManagementService implements IObjectManagementService {
|
||||
authenticationType: AuthenticationType.Sql,
|
||||
loginName: 'sa',
|
||||
ownedSchemas: [],
|
||||
databaseRoles: []
|
||||
databaseRoles: [],
|
||||
password: ''
|
||||
},
|
||||
languages: languages,
|
||||
schemas: schemas,
|
||||
|
||||
@@ -122,7 +122,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
width: DefaultInputWidth
|
||||
}).component();
|
||||
this.disposables.push(this.nameInput.onTextChanged(async () => {
|
||||
this.objectInfo.name = this.nameInput.value;
|
||||
this.objectInfo.name = this.nameInput.value!;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
@@ -149,7 +149,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
|
||||
this.enabledCheckbox = this.createCheckbox(localizedConstants.EnabledText, this.objectInfo.isEnabled);
|
||||
this.disposables.push(this.enabledCheckbox.onChanged(() => {
|
||||
this.objectInfo.isEnabled = this.enabledCheckbox.checked;
|
||||
this.objectInfo.isEnabled = this.enabledCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.generalSection = this.createGroup(localizedConstants.GeneralSectionHeader, [nameContainer, authTypeContainer, this.enabledCheckbox], false);
|
||||
@@ -222,7 +222,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
this.lockedOutCheckbox = this.createCheckbox(localizedConstants.LoginLockedOutText, this.objectInfo.isLockedOut, this.viewInfo.canEditLockedOutState);
|
||||
items.push(this.lockedOutCheckbox);
|
||||
this.disposables.push(this.lockedOutCheckbox.onChanged(() => {
|
||||
this.objectInfo.isLockedOut = this.lockedOutCheckbox.checked;
|
||||
this.objectInfo.isLockedOut = this.lockedOutCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
}
|
||||
@@ -250,7 +250,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
|
||||
this.connectPermissionCheckbox = this.createCheckbox(localizedConstants.PermissionToConnectText, this.objectInfo.connectPermission);
|
||||
this.disposables.push(this.connectPermissionCheckbox.onChanged(() => {
|
||||
this.objectInfo.connectPermission = this.connectPermissionCheckbox.checked;
|
||||
this.objectInfo.connectPermission = this.connectPermissionCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
items.push(defaultDatabaseContainer, defaultLanguageContainer, this.connectPermissionCheckbox);
|
||||
|
||||
@@ -53,7 +53,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
protected readonly objectManagementService: IObjectManagementService,
|
||||
protected readonly connectionUri: string,
|
||||
protected isNewObject: boolean,
|
||||
protected readonly objectName: string | undefined = undefined,
|
||||
protected readonly objectName: string = '',
|
||||
protected readonly objectExplorerContext?: azdata.ObjectExplorerContext,
|
||||
dialogWidth: azdata.window.DialogWidth = 'narrow') {
|
||||
const objectTypeDisplayName = getNodeTypeDisplayName(objectType, true);
|
||||
@@ -204,7 +204,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
} else {
|
||||
this.dialogObject.message = undefined;
|
||||
this.dialogObject.message = { text: '' };
|
||||
}
|
||||
return errors.length === 0;
|
||||
}
|
||||
@@ -270,7 +270,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
height: getTableHeight(tableData.length)
|
||||
}
|
||||
).component();
|
||||
this.disposables.push(table.onCellAction((arg: azdata.ICheckboxCellActionEventArgs) => {
|
||||
this.disposables.push(table.onCellAction!((arg: azdata.ICheckboxCellActionEventArgs) => {
|
||||
const name = listValues[arg.row];
|
||||
const idx = selectedValues.indexOf(name);
|
||||
if (arg.checked && idx === -1) {
|
||||
@@ -283,7 +283,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
return table;
|
||||
}
|
||||
|
||||
protected createDropdown(ariaLabel: string, values: string[], value: string, enabled: boolean = true, width: number = DefaultInputWidth): azdata.DropDownComponent {
|
||||
protected createDropdown(ariaLabel: string, values: string[], value: string | undefined, enabled: boolean = true, width: number = DefaultInputWidth): azdata.DropDownComponent {
|
||||
// Automatically add an empty item to the beginning of the list if the current value is not specified.
|
||||
// This is needed when no meaningful default value can be provided.
|
||||
if (!value) {
|
||||
|
||||
@@ -53,7 +53,7 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
if (this.objectInfo.password !== this.confirmPasswordInput.value) {
|
||||
errors.push(localizedConstants.PasswordsNotMatchError);
|
||||
}
|
||||
if (!isValidSQLPassword(this.objectInfo.password, this.objectInfo.name)
|
||||
if (!isValidSQLPassword(this.objectInfo.password!, this.objectInfo.name)
|
||||
&& (this.isNewObject || this.objectInfo.password !== this.originalObjectInfo.password)) {
|
||||
errors.push(localizedConstants.InvalidPasswordError);
|
||||
}
|
||||
@@ -96,12 +96,12 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
width: DefaultInputWidth
|
||||
}).component();
|
||||
this.disposables.push(this.nameInput.onTextChanged(async () => {
|
||||
this.objectInfo.name = this.nameInput.value;
|
||||
this.objectInfo.name = this.nameInput.value!;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
const nameContainer = this.createLabelInputContainer(localizedConstants.NameText, this.nameInput);
|
||||
this.defaultSchemaDropdown = this.createDropdown(localizedConstants.DefaultSchemaText, this.viewInfo.schemas, this.objectInfo.defaultSchema);
|
||||
this.defaultSchemaDropdown = this.createDropdown(localizedConstants.DefaultSchemaText, this.viewInfo.schemas, this.objectInfo.defaultSchema!);
|
||||
this.defaultSchemaContainer = this.createLabelInputContainer(localizedConstants.DefaultSchemaText, this.defaultSchemaDropdown);
|
||||
this.disposables.push(this.defaultSchemaDropdown.onValueChanged(() => {
|
||||
this.objectInfo.defaultSchema = <string>this.defaultSchemaDropdown.value;
|
||||
|
||||
@@ -31,7 +31,7 @@ export function deepClone<T>(obj: T): T {
|
||||
export async function refreshParentNode(context: azdata.ObjectExplorerContext): Promise<void> {
|
||||
if (context) {
|
||||
try {
|
||||
const node = await azdata.objectexplorer.getNode(context.connectionProfile.id, context.nodeInfo.nodePath);
|
||||
const node = await azdata.objectexplorer.getNode(context.connectionProfile!.id, context.nodeInfo!.nodePath);
|
||||
const parentNode = await node?.getParent();
|
||||
await parentNode?.refresh();
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export async function refreshParentNode(context: azdata.ObjectExplorerContext):
|
||||
export async function refreshNode(context: azdata.ObjectExplorerContext): Promise<void> {
|
||||
if (context) {
|
||||
try {
|
||||
const node = await azdata.objectexplorer.getNode(context.connectionProfile.id, context.nodeInfo.nodePath);
|
||||
const node = await azdata.objectexplorer.getNode(context.connectionProfile!.id, context.nodeInfo!.nodePath);
|
||||
await node?.refresh();
|
||||
}
|
||||
catch (err) {
|
||||
@@ -72,7 +72,9 @@ export function getNodeTypeDisplayName(type: string, inTitle: boolean = false):
|
||||
}
|
||||
}
|
||||
|
||||
export function getAuthenticationTypeDisplayName(authType: AuthenticationType): string {
|
||||
export function getAuthenticationTypeDisplayName(authType: AuthenticationType | undefined): string | undefined {
|
||||
if (authType === undefined) { return undefined; }
|
||||
|
||||
switch (authType) {
|
||||
case AuthenticationType.Windows:
|
||||
return WindowsAuthenticationTypeDisplayText;
|
||||
|
||||
Reference in New Issue
Block a user