Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serviceconnector: Add database subtypes #1581

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions serviceconnector/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type TargetServiceType = {
name: string;
id: string;
type: TargetServiceTypeName;
group: TargetServiceTypeName;
}

export enum TargetServiceTypeName {
Expand Down
36 changes: 12 additions & 24 deletions serviceconnector/src/createLinker/TargetServiceListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export class TargetServiceListStep extends AzureWizardPromptStep<ICreateLinkerCo
public async prompt(context: ICreateLinkerContext): Promise<void> {
const placeHolder = vscode.l10n.t('Select Target Service Type');
const picks: IAzureQuickPickItem<TargetServiceType>[] = [
{ label: vscode.l10n.t('Blob'), data: { name: "storageBlob", type: TargetServiceTypeName.Storage, id: '/blobServices/default' }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('Queue'), data: { name: "storageQueue", type: TargetServiceTypeName.Storage, id: '/queueServices/default' }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('Table'), data: { name: "storageTable", type: TargetServiceTypeName.Storage, id: '/tableServices/default' }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('File'), data: { name: "storageFile", type: TargetServiceTypeName.Storage, id: '/fileServices/default' }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('MongoDB'), data: { name: "mongodb", type: TargetServiceTypeName.MongoDB, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Cassandra'), data: { name: "cassandra", type: TargetServiceTypeName.Cassandra, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Apache Gremlin'), data: { name: "gremlin", type: TargetServiceTypeName.Gremlin, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('NoSQL'), data: { name: "sql", type: TargetServiceTypeName.NoSQL, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Table'), data: { name: "table", type: TargetServiceTypeName.Table, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Key Vault'), data: { name: "keyVault", type: TargetServiceTypeName.KeyVault, id: '/keyVault' }, group: TargetServiceTypeName.KeyVault },
{ label: vscode.l10n.t('Blob'), data: { name: "storageBlob", type: TargetServiceTypeName.Storage, id: '/blobServices/default', group: TargetServiceTypeName.Storage }, group: TargetServiceTypeName.Storage },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, this is a little bit goofy. It definitely works, but the repeat code hurts my eyes 😭

Could I suggest that rather than duplicating the group property in data, that you instead save the result of the quickPick item instead of just the data?

Something like this

const result = await context.ui.showQuickPick(picks, { placeHolder, enableGrouping: true };
context.targetServiceType = result.data;

switch (result.group) {
...

{ label: vscode.l10n.t('Queue'), data: { name: "storageQueue", type: TargetServiceTypeName.Storage, id: '/queueServices/default', group: TargetServiceTypeName.Storage }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('Table'), data: { name: "storageTable", type: TargetServiceTypeName.Storage, id: '/tableServices/default', group: TargetServiceTypeName.Storage }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('File'), data: { name: "storageFile", type: TargetServiceTypeName.Storage, id: '/fileServices/default', group: TargetServiceTypeName.Storage }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('MongoDB'), data: { name: "mongodb", type: TargetServiceTypeName.MongoDB, id: '/databases', group: TargetServiceTypeName.CosmosDB }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Cassandra'), data: { name: "cassandra", type: TargetServiceTypeName.Cassandra, id: '/databases', group: TargetServiceTypeName.CosmosDB }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Apache Gremlin'), data: { name: "gremlin", type: TargetServiceTypeName.Gremlin, id: '/databases', group: TargetServiceTypeName.CosmosDB }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('NoSQL'), data: { name: "sql", type: TargetServiceTypeName.NoSQL, id: '/databases', group: TargetServiceTypeName.CosmosDB }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Table'), data: { name: "table", type: TargetServiceTypeName.Table, id: '/databases', group: TargetServiceTypeName.CosmosDB }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Key Vault'), data: { name: "keyVault", type: TargetServiceTypeName.KeyVault, id: '/keyVault', group: TargetServiceTypeName.KeyVault }, group: TargetServiceTypeName.KeyVault },
];

context.targetServiceType = (await context.ui.showQuickPick(picks, { placeHolder, enableGrouping: true })).data
Expand All @@ -43,23 +43,11 @@ export class TargetServiceListStep extends AzureWizardPromptStep<ICreateLinkerCo
replication: StorageAccountReplication.LRS
};

switch (context.targetServiceType?.type) {
switch (context.targetServiceType?.group) {
case TargetServiceTypeName.Storage:
promptSteps.push(new StorageAccountListStep(storageAccountCreateOptions));
break;
case TargetServiceTypeName.Cassandra:
promptSteps.push(new CosmosDBAccountListStep());
break;
case TargetServiceTypeName.Gremlin:
promptSteps.push(new CosmosDBAccountListStep());
break;
case TargetServiceTypeName.MongoDB:
promptSteps.push(new CosmosDBAccountListStep());
break;
case TargetServiceTypeName.NoSQL:
promptSteps.push(new CosmosDBAccountListStep());
break;
case TargetServiceTypeName.Table:
case TargetServiceTypeName.CosmosDB:
promptSteps.push(new CosmosDBAccountListStep());
break;
case TargetServiceTypeName.KeyVault:
Expand Down