mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add sample value provider (#17548)
This commit is contained in:
1
samples/sample-resource-deployment/.gitignore
vendored
Normal file
1
samples/sample-resource-deployment/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
out
|
||||
1
samples/sample-resource-deployment/.yarnrc
Normal file
1
samples/sample-resource-deployment/.yarnrc
Normal file
@@ -0,0 +1 @@
|
||||
--ignore-engines true
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3",
|
||||
"language": "python"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.8.10",
|
||||
"mimetype": "text/x-python",
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"pygments_lexer": "ipython3",
|
||||
"nbconvert_exporter": "python",
|
||||
"file_extension": ".py"
|
||||
}
|
||||
},
|
||||
"nbformat_minor": 2,
|
||||
"nbformat": 4,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"# Empty Notebook\n",
|
||||
"\n",
|
||||
"This is an empty Notebook to show what values are inserted into a Notebook by a deployment provider. The cell below is auto-generated by the provider and inserted into the Notebook that is opened for the user, so the Notebook templates can write logic that uses these values as input from the provider."
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "f415068b-89aa-437f-80ef-0a453d99df87"
|
||||
},
|
||||
"attachments": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -12,6 +12,12 @@
|
||||
"vscode": "*",
|
||||
"azdata": ">=1.19.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:azdata.resource.deploy"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Microsoft/azuredatastudio.git"
|
||||
@@ -21,6 +27,11 @@
|
||||
"microsoft.notebook",
|
||||
"microsoft.resource-deployment"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"scripts": {
|
||||
"compile": "node node_modules/typescript/bin/tsc -p ./tsconfig.json",
|
||||
"watch": "node node_modules/typescript/bin/tsc --watch -p ./tsconfig.json"
|
||||
},
|
||||
"contributes": {
|
||||
"resourceDeploymentTypes": [
|
||||
{
|
||||
@@ -120,20 +131,35 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "test-wizard",
|
||||
"displayName": "%resource.type.wizard.display.name%",
|
||||
"description": "%resource.type.wizard.description%",
|
||||
"name": "sample-deployment-type",
|
||||
"displayName": "%resource.type.sample.display.name%",
|
||||
"description": "%resource.type.sample.description%",
|
||||
"platforms": "*",
|
||||
"icon": {
|
||||
"light": "./images/book.svg",
|
||||
"dark": "./images/book_inverse.svg"
|
||||
},
|
||||
"options": [
|
||||
{
|
||||
"name": "sample-type",
|
||||
"displayName": "%option-sample-type%",
|
||||
"values": [
|
||||
{
|
||||
"name": "wizard",
|
||||
"displayName": "%option-wizard%"
|
||||
},
|
||||
{
|
||||
"name": "value-provider",
|
||||
"displayName": "%option-value-provider%"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"providers": [
|
||||
{
|
||||
"name": "test-wizard",
|
||||
"notebookWizard": {
|
||||
"notebook": "./notebooks/deploy-x-data-service-1.ipynb",
|
||||
"type": "new-arc-control-plane",
|
||||
"runNotebook": false,
|
||||
"codeCellInsertionPosition": 1,
|
||||
"actionText": "%deploy.wizard.action%",
|
||||
@@ -413,7 +439,94 @@
|
||||
"name": "kubectl"
|
||||
}
|
||||
],
|
||||
"when": true
|
||||
"when": "sample-type=wizard"
|
||||
},
|
||||
{
|
||||
"name": "sample-value-provider",
|
||||
"notebookWizard": {
|
||||
"notebook": "./notebooks/empty-notebook.ipynb",
|
||||
"codeCellInsertionPosition": 1,
|
||||
"actionText": "%deploy.wizard.action%",
|
||||
"title": "%sample.value-provider.title%",
|
||||
"name": "sample.value-provider",
|
||||
"labelPosition": "left",
|
||||
"generateSummaryPage": false,
|
||||
"pages": [
|
||||
{
|
||||
"title": "%sample.value-provider.single.title%",
|
||||
"sections": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"type": "readonly_text",
|
||||
"label": "%sample.value-provider.single.field.label%",
|
||||
"labelWidth": "600px",
|
||||
"isEvaluated": true,
|
||||
"defaultValue": "",
|
||||
"valueProvider": {
|
||||
"providerId": "sample-resource-deployment.sample-value-provider",
|
||||
"triggerFields": [
|
||||
"AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_SINGLE_NAME"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "%sample.value-provider.trigger-name.label%",
|
||||
"type": "text",
|
||||
"variableName": "AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_SINGLE_NAME",
|
||||
"defaultValue": "<Name>",
|
||||
"required": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "%sample.value-provider.multiple.title%",
|
||||
"sections": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"type": "readonly_text",
|
||||
"label": "%sample.value-provider.multiple.field.label%",
|
||||
"labelWidth": "600px",
|
||||
"defaultValue": "",
|
||||
"valueProvider": {
|
||||
"providerId": "sample-resource-deployment.sample-value-provider",
|
||||
"triggerFields": [
|
||||
"AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_NAME",
|
||||
"AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_PLACE"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "%sample.value-provider.trigger-name.label%",
|
||||
"type": "text",
|
||||
"variableName": "AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_NAME",
|
||||
"defaultValue": "<Name>",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "options",
|
||||
"label": "%sample.value-provider.trigger-place.label%",
|
||||
"required": true,
|
||||
"variableName": "AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_PLACE",
|
||||
"editable": true,
|
||||
"defaultValue": "Seattle",
|
||||
"options": [
|
||||
"Seattle",
|
||||
"Redmond",
|
||||
"Bellevue"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"requiredTools": [ ],
|
||||
"when": "sample-type=value-provider"
|
||||
}
|
||||
],
|
||||
"agreements": [
|
||||
@@ -592,5 +705,13 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/azdata": "^1.33.0",
|
||||
"@types/vscode": "^1.61.0",
|
||||
"@types/node": "14.x",
|
||||
"typescript": "^4.4.0-dev.20210607"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,24 @@
|
||||
"agreement": "I accept {0} and {1}.",
|
||||
"agreement-1-name": "Agreement 1",
|
||||
"agreement-2-name": "Agreement 2",
|
||||
"option-sample-type": "Sample Type",
|
||||
"option-wizard": "Wizard",
|
||||
"option-value-provider": "Value Provider",
|
||||
|
||||
"resource.type.wizard.display.name": "Test controller",
|
||||
"resource.type.wizard.description": "Creates a Test controller",
|
||||
"resource.type.sample.display.name": "Sample Deployment Types",
|
||||
"resource.type.sample.description": "Provides samples of various deployment types and their options",
|
||||
|
||||
"validation.wizard.display.name": "Validation Wizard",
|
||||
"validation.wizard.description": "A wizard to test out validations",
|
||||
|
||||
"sample.value-provider.title": "Value Provider Sample",
|
||||
"sample.value-provider.single.title": "Single Trigger Value Provider Sample",
|
||||
"sample.value-provider.single.field.label": "Field using single trigger field",
|
||||
"sample.value-provider.trigger-name.label": "Trigger field (name)",
|
||||
"sample.value-provider.trigger-place.label": "Trigger field (place)",
|
||||
"sample.value-provider.multiple.title": "Multiple Trigger Value Provider Sample",
|
||||
"sample.value-provider.multiple.field.label": "Field using multiple trigger fields",
|
||||
|
||||
"wizard.new.wizard.title": "Create Test controller",
|
||||
"wizard.cluster.environment.title": "What is your target existing Kubernetes cluster environment?",
|
||||
"wizard.select.cluster.title": "Select from installed existing Kubernetes clusters",
|
||||
|
||||
18
samples/sample-resource-deployment/src/extension.ts
Normal file
18
samples/sample-resource-deployment/src/extension.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as rd from 'resource-deployment';
|
||||
import * as vscode from 'vscode';
|
||||
import { SampleValueProvider } from './sampleValueProvider';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// Get the extension API for the resource deployment extension so we can register the value provider. Because the extension itself has a dependency
|
||||
// on the resource deployment extension we don't need to activate it here - we're guaranteed that it's already activated by the time activate is called here.
|
||||
const resourceDeploymentApi = vscode.extensions.getExtension(rd.extension.name)!.exports as rd.IExtension;
|
||||
// Always register value provider disposables so they're deregistered properly if the extension is deactivated
|
||||
context.subscriptions.push(resourceDeploymentApi.registerValueProvider(new SampleValueProvider()));
|
||||
}
|
||||
|
||||
export function deactivate() { }
|
||||
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as rd from 'resource-deployment';
|
||||
|
||||
/**
|
||||
* This is a sample value provider used to demonstrate how values are received and can be used to generate the return value.
|
||||
*/
|
||||
export class SampleValueProvider implements rd.IValueProvider {
|
||||
/**
|
||||
* This ID corresponds to the `providerId` property in the `valueProvider` properties of the package.json definitions.
|
||||
*/
|
||||
readonly id = 'sample-resource-deployment.sample-value-provider';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param triggerValues This is an object whose keys correspond to the `variableName` (or `label` if no `variableName` is given) property of the trigger fields.
|
||||
* This will contain an entry for every trigger field defined in the `valueProvider` property on the target field - even if those values are empty/undefined.
|
||||
* @returns The calculated input type to return. This is expected to match the type of the target field (so string for text, boolean for checkbox, etc)
|
||||
*/
|
||||
public async getValue(triggerValues: { [key: string]: rd.InputValueType; }): Promise<rd.InputValueType> {
|
||||
Object.values(triggerValues)
|
||||
// Because this example is used by two different fields we have logic here to handle determining which one it came from.
|
||||
// If you are making a generic provider that you don't want to have know about each field that uses it you can use
|
||||
// Object.values(triggerValues) to get the array of values and operate on those directly.
|
||||
if (triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_PLACE'] !== undefined) {
|
||||
return `Hello ${triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_NAME']} from ${triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_MULTIPLE_PLACE']}!`;
|
||||
} else {
|
||||
return `Hello ${triggerValues['AZDATA_NB_VAR_SAMPLE_VALUE_PROVIDER_SINGLE_NAME']}!`;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
samples/sample-resource-deployment/src/typings/refs.d.ts
vendored
Normal file
9
samples/sample-resource-deployment/src/typings/refs.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// This is used to get typing support for the resource-deployment extension API. For external extensions you will need to copy
|
||||
// https://github.com/microsoft/azuredatastudio/blob/main/extensions/resource-deployment/src/typings/resource-deployment.d.ts
|
||||
// to your extension repo and reference it there.
|
||||
/// <reference path='../../../../extensions/resource-deployment/src/typings/resource-deployment.d.ts'/>
|
||||
15
samples/sample-resource-deployment/tsconfig.json
Normal file
15
samples/sample-resource-deployment/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
25
samples/sample-resource-deployment/yarn.lock
Normal file
25
samples/sample-resource-deployment/yarn.lock
Normal file
@@ -0,0 +1,25 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/azdata@^1.33.0":
|
||||
version "1.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/azdata/-/azdata-1.33.0.tgz#0693e725ec676122d17b8d38bc1226549136b545"
|
||||
integrity sha512-Q3HnDTRtnqOsKOWwEC2QtU/7WVbWdPZyWSrcZOuLpP2HWGQISRnAYb8SmD7lg4Fe6Uk+Unt/4oipJmUX/tDx2A==
|
||||
dependencies:
|
||||
"@types/vscode" "*"
|
||||
|
||||
"@types/node@14.x":
|
||||
version "14.17.32"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.32.tgz#2ca61c9ef8c77f6fa1733be9e623ceb0d372ad96"
|
||||
integrity sha512-JcII3D5/OapPGx+eJ+Ik1SQGyt6WvuqdRfh9jUwL6/iHGjmyOriBDciBUu7lEIBTL2ijxwrR70WUnw5AEDmFvQ==
|
||||
|
||||
"@types/vscode@*", "@types/vscode@^1.61.0":
|
||||
version "1.61.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.61.0.tgz#c54335b6f84c19c69b1435b17cc0ce3b2cecfeec"
|
||||
integrity sha512-9k5Nwq45hkRwdfCFY+eKXeQQSbPoA114mF7U/4uJXRBJeGIO7MuJdhF1PnaDN+lllL9iKGQtd6FFXShBXMNaFg==
|
||||
|
||||
typescript@^4.4.0-dev.20210607:
|
||||
version "4.4.4"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
|
||||
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==
|
||||
Reference in New Issue
Block a user