mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-07 09:35:41 -05:00
SQL Bindings - Adds Views support for Create Azure Function with SQL Binding (#19894)
* add views logic * add views tests * address PR and Figma comments * add ObjectType Enum to be used as a parameter * add comment
This commit is contained in:
@@ -11,7 +11,7 @@ import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
||||
import * as constants from '../common/constants';
|
||||
import * as azureFunctionsContracts from '../contracts/azureFunctions/azureFunctionsContracts';
|
||||
import { CreateAzureFunctionStep, TelemetryActions, TelemetryReporter, TelemetryViews, ExitReason } from '../common/telemetry';
|
||||
import { AddSqlBindingParams, BindingType, GetAzureFunctionsParams, GetAzureFunctionsResult, IConnectionStringInfo, ResultStatus } from 'sql-bindings';
|
||||
import { AddSqlBindingParams, BindingType, GetAzureFunctionsParams, GetAzureFunctionsResult, IConnectionStringInfo, ObjectType, ResultStatus } from 'sql-bindings';
|
||||
import { IConnectionInfo, ITreeNodeInfo } from 'vscode-mssql';
|
||||
import { createAddConnectionStringStep } from '../createNewProject/addConnectionStringStep';
|
||||
|
||||
@@ -99,23 +99,32 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
// create a system file watcher for the project folder
|
||||
newFunctionFileObject = azureFunctionsUtils.waitForNewFunctionFile(projectFolder);
|
||||
|
||||
// Prompt user for binding type
|
||||
telemetryStep = CreateAzureFunctionStep.getBindingType;
|
||||
let selectedBindingType: BindingType | undefined;
|
||||
let selectedBinding = await azureFunctionsUtils.promptForBindingType();
|
||||
if (!selectedBinding) {
|
||||
return;
|
||||
}
|
||||
selectedBindingType = selectedBinding;
|
||||
propertyBag.bindingType = selectedBindingType;
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag).send();
|
||||
|
||||
// Get connection string parameters and construct object name from prompt or connectionInfo given
|
||||
let objectName: string | undefined;
|
||||
let selectedBindingType: BindingType | undefined;
|
||||
if (!node) {
|
||||
// if user selects command in command palette we prompt user for information
|
||||
// user selects command in command palette we prompt user for information
|
||||
telemetryStep = CreateAzureFunctionStep.launchFromCommandPalette;
|
||||
|
||||
let chosenObjectType = await azureFunctionsUtils.promptForObjectType();
|
||||
if (!chosenObjectType) {
|
||||
// User cancelled
|
||||
return;
|
||||
}
|
||||
|
||||
// Prompt user for binding type
|
||||
telemetryStep = CreateAzureFunctionStep.getBindingType;
|
||||
selectedBindingType = await azureFunctionsUtils.promptForBindingType(chosenObjectType);
|
||||
if (!selectedBindingType) {
|
||||
return;
|
||||
}
|
||||
|
||||
// send telemetry for chosen object type and binding type
|
||||
propertyBag.objectType = chosenObjectType;
|
||||
propertyBag.bindingType = selectedBindingType;
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag).send();
|
||||
|
||||
// prompt user for connection profile to get connection info
|
||||
while (true) {
|
||||
try {
|
||||
@@ -135,7 +144,7 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
telemetryStep = CreateAzureFunctionStep.getObjectName;
|
||||
|
||||
// prompt user for object name to create function from
|
||||
objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding, connectionInfo);
|
||||
objectName = await azureFunctionsUtils.promptForObjectName(selectedBindingType, connectionInfo, chosenObjectType);
|
||||
if (!objectName) {
|
||||
// user cancelled
|
||||
continue;
|
||||
@@ -143,12 +152,12 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// if user selects table in tree view we use connection info from Object Explorer node
|
||||
telemetryStep = CreateAzureFunctionStep.launchFromTable;
|
||||
// user selects table in tree view we use connection info from Object Explorer node
|
||||
telemetryStep = CreateAzureFunctionStep.launchFromObjectExplorer;
|
||||
connectionInfo = node.connectionInfo;
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag).withConnectionInfo(connectionInfo).send();
|
||||
// set the database containing the selected table so it can be used
|
||||
// set the database containing the selected table or view so it can be used
|
||||
// for the initial catalog property of the connection string
|
||||
let newNode: ITreeNodeInfo = node;
|
||||
while (newNode) {
|
||||
@@ -159,6 +168,21 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
newNode = newNode.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
// Prompt user for binding type
|
||||
telemetryStep = CreateAzureFunctionStep.getBindingType;
|
||||
let nodeType = ObjectType.Table === node.nodeType ? ObjectType.Table : ObjectType.View;
|
||||
selectedBindingType = await azureFunctionsUtils.promptForBindingType(nodeType);
|
||||
if (!selectedBindingType) {
|
||||
return;
|
||||
}
|
||||
|
||||
// send telemetry for object type and binding type
|
||||
propertyBag.objectType = node.nodeType;
|
||||
propertyBag.bindingType = selectedBindingType;
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag).send();
|
||||
|
||||
objectName = utils.generateQuotedFullName(node.metadata.schema, node.metadata.name);
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag).withConnectionInfo(connectionInfo).send();
|
||||
|
||||
Reference in New Issue
Block a user