-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathScaleRuleNameStep.ts
More file actions
41 lines (32 loc) · 1.87 KB
/
ScaleRuleNameStep.ts
File metadata and controls
41 lines (32 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep } from '@microsoft/vscode-azext-utils';
import { localize } from '../../../utils/localize';
import type { IAddScaleRuleContext } from './IAddScaleRuleContext';
export class ScaleRuleNameStep extends AzureWizardPromptStep<IAddScaleRuleContext> {
public hideStepCount: boolean = true;
public async prompt(context: IAddScaleRuleContext): Promise<void> {
context.ruleName = (await context.ui.showInputBox({
prompt: localize('scaleRuleNamePrompt', 'Enter a name for the new scale rule.'),
validateInput: (name: string | undefined) => this.validateInput(context, name)
})).trim();
}
public shouldPrompt(context: IAddScaleRuleContext): boolean {
return !context.ruleName;
}
private validateInput(context: IAddScaleRuleContext, name: string | undefined): string | undefined {
name = name ? name.trim() : '';
if (!/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/.test(name)) {
return localize('invalidChar', `A name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character.`);
}
const scaleRuleExists: boolean = !!context.scaleRules?.some((rule) => {
return rule.name?.length && rule.name === name;
});
if (scaleRuleExists) {
return localize('scaleRuleExists', 'The scale rule "{0}" already exists in container app "{1}". Please enter a unique name.', name, context.containerApp.name);
}
return undefined;
}
}