mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
fix option sources (#12387)
This commit is contained in:
@@ -11,15 +11,12 @@ import { apiService } from '../services/apiService';
|
|||||||
import { throwUnless } from '../utils';
|
import { throwUnless } from '../utils';
|
||||||
import { CacheManager } from './cacheManager';
|
import { CacheManager } from './cacheManager';
|
||||||
|
|
||||||
|
export enum OptionsSourceType {
|
||||||
|
ArcControllersOptionsSource = 'ArcControllersOptionsSource'
|
||||||
|
}
|
||||||
|
|
||||||
export type OptionsSourceType = 'ArcControllersOptionsSource';
|
|
||||||
|
|
||||||
const OptionsSources = new Map<OptionsSourceType, new () => OptionsSource>();
|
|
||||||
export abstract class OptionsSource implements IOptionsSource {
|
export abstract class OptionsSource implements IOptionsSource {
|
||||||
|
|
||||||
private _variableNames!: { [index: string]: string; };
|
|
||||||
private _type!: OptionsSourceType;
|
|
||||||
|
|
||||||
get type(): OptionsSourceType { return this._type; }
|
get type(): OptionsSourceType { return this._type; }
|
||||||
get variableNames(): { [index: string]: string; } { return this._variableNames; }
|
get variableNames(): { [index: string]: string; } { return this._variableNames; }
|
||||||
|
|
||||||
@@ -27,24 +24,12 @@ export abstract class OptionsSource implements IOptionsSource {
|
|||||||
abstract async getVariableValue(variableName: string, input: string): Promise<string>;
|
abstract async getVariableValue(variableName: string, input: string): Promise<string>;
|
||||||
abstract getIsPassword(variableName: string): boolean;
|
abstract getIsPassword(variableName: string): boolean;
|
||||||
|
|
||||||
protected constructor() {
|
constructor(private _variableNames: { [index: string]: string }, private _type: OptionsSourceType) {
|
||||||
}
|
|
||||||
|
|
||||||
static construct(optionsSourceType: OptionsSourceType, variableNames: { [index: string]: string }): OptionsSource {
|
|
||||||
const sourceConstructor = OptionsSources.get(optionsSourceType);
|
|
||||||
throwUnless(sourceConstructor !== undefined, loc.noOptionsSourceDefined(optionsSourceType));
|
|
||||||
const obj = new sourceConstructor();
|
|
||||||
obj._type = optionsSourceType;
|
|
||||||
obj._variableNames = variableNames;
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ArcControllersOptionsSource extends OptionsSource {
|
export class ArcControllersOptionsSource extends OptionsSource {
|
||||||
private _cacheManager = new CacheManager<string, string>();
|
private _cacheManager = new CacheManager<string, string>();
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
async getOptions(): Promise<string[] | CategoryValue[]> {
|
async getOptions(): Promise<string[] | CategoryValue[]> {
|
||||||
const controllers = await apiService.arcApi.getRegisteredDataControllers();
|
const controllers = await apiService.arcApi.getRegisteredDataControllers();
|
||||||
@@ -97,4 +82,3 @@ export class ArcControllersOptionsSource extends OptionsSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OptionsSources.set(<OptionsSourceType>ArcControllersOptionsSource.name, ArcControllersOptionsSource);
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { OptionsSource, OptionsSourceType } from './helpers/optionSources';
|
import { OptionsSourceType } from './helpers/optionSources';
|
||||||
|
|
||||||
export const NoteBookEnvironmentVariablePrefix = 'AZDATA_NB_VAR_';
|
export const NoteBookEnvironmentVariablePrefix = 'AZDATA_NB_VAR_';
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ export interface IOptionsSource {
|
|||||||
|
|
||||||
export interface OptionsInfo {
|
export interface OptionsInfo {
|
||||||
values?: string[] | azdata.CategoryValue[],
|
values?: string[] | azdata.CategoryValue[],
|
||||||
source?: OptionsSource,
|
source?: IOptionsSource,
|
||||||
defaultValue: string,
|
defaultValue: string,
|
||||||
optionsType?: OptionsType
|
optionsType?: OptionsType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const unknownFieldTypeError = (type: FieldType) => localize('UnknownField
|
|||||||
export const variableValueFetchForUnsupportedVariable = (variableName: string) => localize('getVariableValue.unknownVariableName', "Attempt to get variable value for unknown variable:{0}", variableName);
|
export const variableValueFetchForUnsupportedVariable = (variableName: string) => localize('getVariableValue.unknownVariableName', "Attempt to get variable value for unknown variable:{0}", variableName);
|
||||||
export const isPasswordFetchForUnsupportedVariable = (variableName: string) => localize('getIsPassword.unknownVariableName', "Attempt to get isPassword for unknown variable:{0}", variableName);
|
export const isPasswordFetchForUnsupportedVariable = (variableName: string) => localize('getIsPassword.unknownVariableName', "Attempt to get isPassword for unknown variable:{0}", variableName);
|
||||||
export const noControllersConnected = localize('noControllersConnected', "No Azure ARC controllers are currently connected. Please run the command: 'Connect to Existing Azure Arc Controller' and then try again");
|
export const noControllersConnected = localize('noControllersConnected', "No Azure ARC controllers are currently connected. Please run the command: 'Connect to Existing Azure Arc Controller' and then try again");
|
||||||
export const noOptionsSourceDefined = (optionsSourceType: OptionsSourceType) => localize('noOptionsSourceDefined', "No OptionsSource defined for type: {0}", optionsSourceType);
|
export const noOptionsSourceDefined = (optionsSourceType: string) => localize('noOptionsSourceDefined', "No OptionsSource defined for type: {0}", optionsSourceType);
|
||||||
export const noControllerInfoFound = (name: string) => localize('noControllerInfoFound', "controllerInfo could not be found with name: {0}", name);
|
export const noControllerInfoFound = (name: string) => localize('noControllerInfoFound', "controllerInfo could not be found with name: {0}", name);
|
||||||
export const noPasswordFound = (controllerName: string) => localize('noPasswordFound', "Password could not be retrieved for controller: {0} and user did not provide a password. Please retry later.", controllerName);
|
export const noPasswordFound = (controllerName: string) => localize('noPasswordFound', "Password could not be retrieved for controller: {0} and user did not provide a password. Please retry later.", controllerName);
|
||||||
export const optionsNotDefined = (fieldType: FieldType) => localize('optionsNotDefined', "FieldInfo.options was not defined for field type: {0}", fieldType);
|
export const optionsNotDefined = (fieldType: FieldType) => localize('optionsNotDefined', "FieldInfo.options was not defined for field type: {0}", fieldType);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import { EOL, homedir as os_homedir } from 'os';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
import { OptionsSource } from '../helpers/optionSources';
|
import { ArcControllersOptionsSource, OptionsSourceType } from '../helpers/optionSources';
|
||||||
import { AzureAccountFieldInfo, AzureLocationsFieldInfo, ComponentCSSStyles, DialogInfoBase, FieldInfo, FieldType, FilePickerFieldInfo, KubeClusterContextFieldInfo, LabelPosition, NoteBookEnvironmentVariablePrefix, OptionsInfo, OptionsType, PageInfoBase, RowInfo, SectionInfo, TextCSSStyles } from '../interfaces';
|
import { AzureAccountFieldInfo, AzureLocationsFieldInfo, ComponentCSSStyles, DialogInfoBase, FieldInfo, FieldType, FilePickerFieldInfo, IOptionsSource, KubeClusterContextFieldInfo, LabelPosition, NoteBookEnvironmentVariablePrefix, OptionsInfo, OptionsType, PageInfoBase, RowInfo, SectionInfo, TextCSSStyles } from '../interfaces';
|
||||||
import * as loc from '../localizedConstants';
|
import * as loc from '../localizedConstants';
|
||||||
import { apiService } from '../services/apiService';
|
import { apiService } from '../services/apiService';
|
||||||
import { getDefaultKubeConfigPath, getKubeConfigClusterContexts } from '../services/kubeService';
|
import { getDefaultKubeConfigPath, getKubeConfigClusterContexts } from '../services/kubeService';
|
||||||
@@ -419,8 +419,15 @@ async function processOptionsTypeField(context: FieldContext): Promise<void> {
|
|||||||
throwUnless('optionsType' in context.fieldInfo.options, loc.optionsTypeNotFound);
|
throwUnless('optionsType' in context.fieldInfo.options, loc.optionsTypeNotFound);
|
||||||
if (context.fieldInfo.options.source) {
|
if (context.fieldInfo.options.source) {
|
||||||
try {
|
try {
|
||||||
// if options.source still points to the IOptionsSource interface make it to point to the implementation
|
let optionsSource: IOptionsSource;
|
||||||
context.fieldInfo.options.source = OptionsSource.construct(context.fieldInfo.options.source.type, context.fieldInfo.options.source.variableNames);
|
switch (context.fieldInfo.options.source.type) {
|
||||||
|
case OptionsSourceType.ArcControllersOptionsSource:
|
||||||
|
optionsSource = new ArcControllersOptionsSource(context.fieldInfo.options.source.variableNames, context.fieldInfo.options.source.type);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(loc.noOptionsSourceDefined(context.fieldInfo.options.source.type));
|
||||||
|
}
|
||||||
|
context.fieldInfo.options.source = optionsSource;
|
||||||
context.fieldInfo.options.values = await context.fieldInfo.options.source.getOptions();
|
context.fieldInfo.options.values = await context.fieldInfo.options.source.getOptions();
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user