mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Return BindingType directly from promptForBindingType (#19200)
* Return BindingType directly from promptForBindingType * align * Fix tests * fix compile
This commit is contained in:
@@ -284,7 +284,7 @@ export async function isFunctionProject(folderPath: string): Promise<boolean> {
|
|||||||
/**
|
/**
|
||||||
* Prompts the user to select type of binding and returns result
|
* Prompts the user to select type of binding and returns result
|
||||||
*/
|
*/
|
||||||
export async function promptForBindingType(): Promise<(vscode.QuickPickItem & { type: BindingType }) | undefined> {
|
export async function promptForBindingType(): Promise<BindingType | undefined> {
|
||||||
const inputOutputItems: (vscode.QuickPickItem & { type: BindingType })[] = [
|
const inputOutputItems: (vscode.QuickPickItem & { type: BindingType })[] = [
|
||||||
{
|
{
|
||||||
label: constants.input,
|
label: constants.input,
|
||||||
@@ -302,7 +302,7 @@ export async function promptForBindingType(): Promise<(vscode.QuickPickItem & {
|
|||||||
ignoreFocusOut: true
|
ignoreFocusOut: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return selectedBinding;
|
return selectedBinding?.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -73,13 +73,13 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
|
|||||||
if (!selectedBinding) {
|
if (!selectedBinding) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
propertyBag.bindingType = selectedBinding.type;
|
propertyBag.bindingType = selectedBinding;
|
||||||
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.getBindingType)
|
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.getBindingType)
|
||||||
.withAdditionalProperties(propertyBag).send();
|
.withAdditionalProperties(propertyBag).send();
|
||||||
|
|
||||||
// 3. ask for object name for the binding
|
// 3. ask for object name for the binding
|
||||||
quickPickStep = 'getObjectName';
|
quickPickStep = 'getObjectName';
|
||||||
const objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding.type);
|
const objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding);
|
||||||
|
|
||||||
if (!objectName) {
|
if (!objectName) {
|
||||||
return;
|
return;
|
||||||
@@ -106,7 +106,7 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
|
|||||||
// 5. insert binding
|
// 5. insert binding
|
||||||
try {
|
try {
|
||||||
quickPickStep = 'insertBinding';
|
quickPickStep = 'insertBinding';
|
||||||
const result = await addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSettingName);
|
const result = await addSqlBinding(selectedBinding, uri.fsPath, azureFunctionName, objectName, connectionStringSettingName);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
void vscode.window.showErrorMessage(result.errorMessage);
|
void vscode.window.showErrorMessage(result.errorMessage);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
|
|||||||
addSqlBinding: async (bindingType: BindingType, filePath: string, functionName: string, objectName: string, connectionStringSetting: string): Promise<ResultStatus> => {
|
addSqlBinding: async (bindingType: BindingType, filePath: string, functionName: string, objectName: string, connectionStringSetting: string): Promise<ResultStatus> => {
|
||||||
return addSqlBinding(bindingType, filePath, functionName, objectName, connectionStringSetting);
|
return addSqlBinding(bindingType, filePath, functionName, objectName, connectionStringSetting);
|
||||||
},
|
},
|
||||||
promptForBindingType: async (): Promise<(vscode.QuickPickItem & { type: BindingType }) | undefined> => {
|
promptForBindingType: async (): Promise<BindingType | undefined> => {
|
||||||
return promptForBindingType();
|
return promptForBindingType();
|
||||||
},
|
},
|
||||||
promptForObjectName: async (bindingType: BindingType): Promise<string | undefined> => {
|
promptForObjectName: async (bindingType: BindingType): Promise<string | undefined> => {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
if (!selectedBinding) {
|
if (!selectedBinding) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectedBindingType = selectedBinding.type;
|
selectedBindingType = selectedBinding;
|
||||||
propertyBag.bindingType = selectedBindingType;
|
propertyBag.bindingType = selectedBindingType;
|
||||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.startCreateAzureFunctionWithSqlBinding)
|
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.startCreateAzureFunctionWithSqlBinding)
|
||||||
.withAdditionalProperties(propertyBag).send();
|
.withAdditionalProperties(propertyBag).send();
|
||||||
@@ -71,7 +71,7 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
connectionInfo.database = selectedDatabase;
|
connectionInfo.database = selectedDatabase;
|
||||||
|
|
||||||
// prompt user for object name to create function from
|
// prompt user for object name to create function from
|
||||||
objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding.type);
|
objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding);
|
||||||
if (!objectName) {
|
if (!objectName) {
|
||||||
// user cancelled
|
// user cancelled
|
||||||
return;
|
return;
|
||||||
@@ -106,8 +106,8 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
// User cancelled
|
// User cancelled
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectedBindingType = selectedBinding.type;
|
selectedBindingType = selectedBinding;
|
||||||
propertyBag.bindingType = selectedBinding.type;
|
propertyBag.bindingType = selectedBinding;
|
||||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.startCreateAzureFunctionWithSqlBinding)
|
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.startCreateAzureFunctionWithSqlBinding)
|
||||||
.withAdditionalProperties(propertyBag).withConnectionInfo(connectionInfo).send();
|
.withAdditionalProperties(propertyBag).withConnectionInfo(connectionInfo).send();
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ declare module 'sql-bindings' {
|
|||||||
addSqlBinding(bindingType: BindingType, filePath: string, functionName: string, objectName: string, connectionStringSetting: string): Promise<ResultStatus>;
|
addSqlBinding(bindingType: BindingType, filePath: string, functionName: string, objectName: string, connectionStringSetting: string): Promise<ResultStatus>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompts the user to select type of binding and returns result
|
* Prompts the user to select type of binding and returns result or undefined if the user cancelled out of the prompt
|
||||||
*/
|
*/
|
||||||
promptForBindingType(): Promise<(vscode.QuickPickItem & { type: BindingType }) | undefined>;
|
promptForBindingType(): Promise<BindingType | undefined>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompts the user to enter object name for the SQL query
|
* Prompts the user to enter object name for the SQL query
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import * as azureFunctionService from '../../services/azureFunctionsService';
|
|||||||
|
|
||||||
import { createTestUtils, TestUtils, createTestCredentials } from '../testUtils';
|
import { createTestUtils, TestUtils, createTestCredentials } from '../testUtils';
|
||||||
import { launchAddSqlBindingQuickpick } from '../../dialogs/addSqlBindingQuickpick';
|
import { launchAddSqlBindingQuickpick } from '../../dialogs/addSqlBindingQuickpick';
|
||||||
|
import { BindingType } from 'sql-bindings';
|
||||||
|
|
||||||
let testUtils: TestUtils;
|
let testUtils: TestUtils;
|
||||||
const fileUri = vscode.Uri.file('testUri');
|
const fileUri = vscode.Uri.file('testUri');
|
||||||
@@ -66,7 +67,7 @@ describe('Add SQL Binding quick pick', () => {
|
|||||||
// select Azure function
|
// select Azure function
|
||||||
let quickpickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().resolves({ label: 'af1' });
|
let quickpickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().resolves({ label: 'af1' });
|
||||||
// select input or output binding
|
// select input or output binding
|
||||||
quickpickStub.onSecondCall().resolves({ label: constants.input });
|
quickpickStub.onSecondCall().resolves(<any>{ label: constants.input, type: BindingType.input });
|
||||||
// give object name
|
// give object name
|
||||||
let inputBoxStub = sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves('dbo.table1');
|
let inputBoxStub = sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves('dbo.table1');
|
||||||
// give connection string setting name
|
// give connection string setting name
|
||||||
@@ -100,7 +101,7 @@ describe('Add SQL Binding quick pick', () => {
|
|||||||
// select Azure function
|
// select Azure function
|
||||||
quickpickStub.onFirstCall().resolves({ label: 'af1' });
|
quickpickStub.onFirstCall().resolves({ label: 'af1' });
|
||||||
// select input or output binding
|
// select input or output binding
|
||||||
quickpickStub.onSecondCall().resolves({ label: constants.input });
|
quickpickStub.onSecondCall().resolves(<any>{ label: constants.input, type: BindingType.input });
|
||||||
|
|
||||||
// give object name
|
// give object name
|
||||||
let inputBoxStub = sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves('dbo.table1');
|
let inputBoxStub = sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves('dbo.table1');
|
||||||
|
|||||||
Reference in New Issue
Block a user