Add better default name prompt pre-fill values for `deployWorkspaceProjectInternal` (#671)

This commit is contained in:
Matthew Fisher 2024-04-05 14:18:44 -07:00 коммит произвёл GitHub
Родитель b6702fe9b3
Коммит 372954afa7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -4,11 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import * as path from "path";
import { ext } from "../../../extensionVariables";
import { localize } from "../../../utils/localize";
import { ContainerAppNameStep } from "../../createContainerApp/ContainerAppNameStep";
import { ImageNameStep } from "../../image/imageSource/buildImageInAzure/ImageNameStep";
import { type DeployWorkspaceProjectInternalContext } from "./DeployWorkspaceProjectInternalContext";
import { sanitizeResourceName } from "./sanitizeResourceName";
/** Names the resources unique to the individual app: `container app`, `image name` */
export class AppResourcesNameStep extends AzureWizardPromptStep<DeployWorkspaceProjectInternalContext> {
@ -22,6 +24,7 @@ export class AppResourcesNameStep extends AzureWizardPromptStep<DeployWorkspaceP
public async prompt(context: DeployWorkspaceProjectInternalContext): Promise<void> {
context.newContainerAppName = (await context.ui.showInputBox({
prompt: localize('containerAppNamePrompt', 'Enter a name for the new container app'),
value: sanitizeResourceName(context.dockerfilePath?.split(path.sep).at(-2) ?? ''),
validateInput: (name: string) => ContainerAppNameStep.validateInput(name),
asyncValidationTask: async (name: string) => {
const resourceGroupName: string = context.resourceGroup?.name || nonNullProp(context, 'newResourceGroupName');

Просмотреть файл

@ -11,6 +11,7 @@ import { localize } from "../../../utils/localize";
import { ManagedEnvironmentNameStep } from "../../createManagedEnvironment/ManagedEnvironmentNameStep";
import { RegistryNameStep } from "../../image/imageSource/containerRegistry/acr/createAcr/RegistryNameStep";
import { type DeployWorkspaceProjectInternalContext } from "./DeployWorkspaceProjectInternalContext";
import { sanitizeResourceName } from "./sanitizeResourceName";
/** Names any app environment shared resources: `resource group`, `managed environment`, `container registry` */
export class SharedResourcesNameStep extends AzureWizardPromptStep<DeployWorkspaceProjectInternalContext> {
@ -29,6 +30,7 @@ export class SharedResourcesNameStep extends AzureWizardPromptStep<DeployWorkspa
public async prompt(context: DeployWorkspaceProjectInternalContext): Promise<void> {
const resourceName: string = (await context.ui.showInputBox({
prompt: localize('sharedNamePrompt', 'Enter a name for the container app environment'),
value: sanitizeResourceName(context.rootFolder?.name ?? ''),
validateInput: (name: string) => this.validateInput(context, name),
asyncValidationTask: (name: string) => this.validateNameAvailability(context, name)
})).trim();

Просмотреть файл

@ -0,0 +1,25 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Takes a name and sanitizes it such that it can be used to create an ACA resource and pass common input validation
*/
export function sanitizeResourceName(name: string): string {
// Only alphanumeric characters or hyphens
let sanitizedName: string = name.toLowerCase().replace(/[^a-z0-9-]+/g, '');
// Remove any consecutive hyphens
sanitizedName = sanitizedName.replace(/-+/g, '-');
// Remove any leading or ending hyphens
if (sanitizedName.startsWith('-')) {
sanitizedName = sanitizedName.slice(1);
}
if (sanitizedName.endsWith('-')) {
sanitizedName = sanitizedName.slice(0, -1);
}
return sanitizedName;
}

Просмотреть файл

@ -44,6 +44,7 @@ export class SourcePathStep extends AzureWizardPromptStep<BuildImageInAzureImage
picks.push({ label: '.' + p, data: rootPath + p });
}
picks.reverse();
picks.push(browseItem);
return picks;
}