|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import type { Revision, Scale } from "@azure/arm-appcontainers"; |
| 7 | +import { AzureWizard, IActionContext, createSubscriptionContext, nonNullValueAndProp } from "@microsoft/vscode-azext-utils"; |
| 8 | +import type { ContainerAppModel } from "../../../tree/ContainerAppItem"; |
| 9 | +import type { ScaleItem } from "../../../tree/scaling/ScaleItem"; |
| 10 | +import { createActivityContext } from "../../../utils/activityUtils"; |
| 11 | +import { localize } from "../../../utils/localize"; |
| 12 | +import { pickScale } from "../../../utils/pickItem/pickScale"; |
| 13 | +import { getParentResource } from "../../../utils/revisionDraftUtils"; |
| 14 | +import type { ScaleRangeContext } from "./ScaleRangeContext"; |
| 15 | +import { ScaleRangePromptStep } from "./ScaleRangePromptStep"; |
| 16 | +import { ScaleRangeUpdateStep } from "./ScaleRangeUpdateStep"; |
| 17 | + |
| 18 | +export async function editScaleRange(context: IActionContext, node?: ScaleItem): Promise<void> { |
| 19 | + const item: ScaleItem = node ?? await pickScale(context, { autoSelectDraft: true }); |
| 20 | + const { containerApp, revision, subscription } = item; |
| 21 | + |
| 22 | + const parentResource: ContainerAppModel | Revision = getParentResource(containerApp, revision); |
| 23 | + const scale: Scale = nonNullValueAndProp(parentResource.template, 'scale'); |
| 24 | + |
| 25 | + const wizardContext: ScaleRangeContext = { |
| 26 | + ...context, |
| 27 | + ...createSubscriptionContext(subscription), |
| 28 | + ...await createActivityContext(), |
| 29 | + containerApp, |
| 30 | + subscription, |
| 31 | + scaleMinRange: scale.minReplicas ?? 0, |
| 32 | + scaleMaxRange: scale.maxReplicas ?? 0 |
| 33 | + }; |
| 34 | + |
| 35 | + const wizard: AzureWizard<ScaleRangeContext> = new AzureWizard(wizardContext, { |
| 36 | + title: localize('editScaleRangePre', 'Update replica scaling range for "{0}" (draft)', parentResource.name), |
| 37 | + promptSteps: [new ScaleRangePromptStep()], |
| 38 | + executeSteps: [new ScaleRangeUpdateStep(item)], |
| 39 | + showLoadingPrompt: true |
| 40 | + }); |
| 41 | + |
| 42 | + await wizard.prompt(); |
| 43 | + wizardContext.activityTitle = localize('editScaleRange', 'Update replica scaling range to "{0}-{1}" for "{2}" (draft)', wizardContext.newMinRange, wizardContext.newMaxRange, parentResource.name); |
| 44 | + await wizard.execute(); |
| 45 | +} |
0 commit comments