-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathScaleRangePromptStep.ts
More file actions
44 lines (37 loc) · 2.14 KB
/
ScaleRangePromptStep.ts
File metadata and controls
44 lines (37 loc) · 2.14 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
42
43
44
/*---------------------------------------------------------------------------------------------
* 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 { ScaleRangeContext } from './ScaleRangeContext';
export class ScaleRangePromptStep extends AzureWizardPromptStep<ScaleRangeContext> {
public async prompt(context: ScaleRangeContext): Promise<void> {
const scaleRange: string = (await context.ui.showInputBox({
prompt: localize('editScalingRange', 'Set the range of application replicas that get created in response to a scale rule. Set any range within the minimum of 0 and the maximum of 10 replicas'),
value: `${context.scaleMinRange}-${context.scaleMaxRange}`,
validateInput: this.validateInput,
})).trim();
const [min, max] = scaleRange.split('-').map(range => Number(range));
context.newMinRange = min;
context.newMaxRange = max;
}
public shouldPrompt(context: ScaleRangeContext): boolean {
return !context.newMinRange || !context.newMaxRange;
}
private validateInput(range: string | undefined): string | undefined {
const formatRegex = /^\d{1,2}-\d{1,2}$/;
if (!range || !formatRegex.test(range)) {
return localize('enterRange', 'Please enter the range in the following format "0-10"');
}
const [min, max] = range.split('-').map(range => Number(range));
if (min > 10 || max > 10) {
return localize('maxRangeExceeded', 'The maximum number of replicas is 10.');
} else if (min > max) {
return localize('minHigherThanMax', 'The minimum range cannot be larger than the maximum range.');
} else if (max === 0) {
return localize('maxGreaterThan0', 'The maximum replicas must be greater than 0.');
}
return undefined;
}
}