-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add Service Connector #381
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzureWizardPromptStep, IAzureQuickPickItem, nonNullValue } from "@microsoft/vscode-azext-utils"; | ||
import { localize } from "../../utils/localize"; | ||
import { IServiceConnectorContext } from "./IServiceConnectorContext"; | ||
|
||
export class ContainerPickStep extends AzureWizardPromptStep<IServiceConnectorContext> { | ||
public async prompt(context: IServiceConnectorContext): Promise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note, you don't have to change it, adding I saw Phil H. doing this and I like it better because it shortens line widths and makes things a bit cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer keeping |
||
const placeHolder: string = localize('selectStream', 'Select a container'); | ||
context.scope = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data; | ||
} | ||
|
||
public shouldPrompt(context: IServiceConnectorContext): boolean { | ||
return !context.scope; | ||
} | ||
|
||
public async configureBeforePrompt(context: IServiceConnectorContext): Promise<void> { | ||
const picks = await this.getPicks(context); | ||
if (picks.length === 1) { | ||
context.scope = picks[0].data; | ||
} | ||
} | ||
|
||
private async getPicks(context: IServiceConnectorContext): Promise<IAzureQuickPickItem<string>[]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need to be async. |
||
const containers = nonNullValue(context.containerApp.template?.containers); | ||
return containers.map(c => { | ||
return { | ||
label: nonNullValue(c.name), | ||
data: nonNullValue(c.name) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { ICreateLinkerContext } from "@microsoft/vscode-azext-serviceconnector"; | ||
import { ContainerAppModel } from "../../tree/ContainerAppItem"; | ||
|
||
export interface IServiceConnectorContext extends ICreateLinkerContext { | ||
containerApp: ContainerAppModel; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could extend from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I extended from the ICreateLinkerContext since I needed the scope. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is there a reason we shouldn't extend from both?
Yeah, there are a few contexts that probably still need to be migrated to extend from |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { ICreateLinkerContext, createLinker } from "@microsoft/vscode-azext-serviceconnector"; | ||
import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils"; | ||
import { ContainerAppItem } from "../../tree/ContainerAppItem"; | ||
import { createActivityContext } from "../../utils/activityUtils"; | ||
import { localize } from "../../utils/localize"; | ||
import { pickContainerApp } from "../../utils/pickContainerApp"; | ||
import { ContainerPickStep } from "./ContainerPickStep"; | ||
import { IServiceConnectorContext } from "./IServiceConnectorContext"; | ||
|
||
export async function createServiceConnector(context: ICreateLinkerContext, item?: ContainerAppItem): Promise<void> { | ||
item ??= await pickContainerApp(context); | ||
const { subscription, containerApp } = item; | ||
|
||
const activityContext = { | ||
...context, | ||
...await createActivityContext(), | ||
containerApp: containerApp, | ||
activityTitle: localize('createServiceConnector', 'Create Service Connector'), | ||
} | ||
|
||
const promptSteps: AzureWizardPromptStep<IServiceConnectorContext>[] = [ | ||
new ContainerPickStep(), | ||
]; | ||
|
||
await createLinker(activityContext, { id: containerApp.id, subscription }, promptSteps); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this is called a
ListStep
not aPickStep
.Though I get that there is already a
ContainerListStep
, I think we should rename things to be more explicit. TheContainerListStep
today is technically theReplicaContainerListStep
and has a hard requirement of having areplica
defined on the context (which happens in the previous step). So maybe just rename that one and then call thisContainerListStep
orTemplateContainerListStep
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will rename the other one!