-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathReplicaListStep.ts
More file actions
35 lines (31 loc) · 1.98 KB
/
Copy pathReplicaListStep.ts
File metadata and controls
35 lines (31 loc) · 1.98 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type ContainerAppsAPIClient, type Replica } from "@azure/arm-appcontainers";
import { AzureWizardPromptStep, createSubscriptionContext, nonNullProp, nonNullValue, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import dayjs from 'dayjs';
import { createContainerAppsAPIClient } from "../../utils/azureClients";
import { localize } from "../../utils/localize";
import { type IStreamLogsContext } from "./IStreamLogsContext";
export class ReplicaListStep extends AzureWizardPromptStep<IStreamLogsContext> {
public async prompt(context: IStreamLogsContext): Promise<void> {
const placeHolder: string = localize('selectReplica', 'Select a replica');
context.replica = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
}
public shouldPrompt(context: IStreamLogsContext): boolean {
return !context.replica;
}
private async getPicks(context: IStreamLogsContext): Promise<IAzureQuickPickItem<Replica>[]> {
const client: ContainerAppsAPIClient = await createContainerAppsAPIClient([context, createSubscriptionContext(context.subscription)]);
const replicas = (await client.containerAppsRevisionReplicas.listReplicas(context.resourceGroupName, context.containerApp.name, nonNullValue(context.revision?.name))).value;
if (replicas.length === 0) {
throw new Error(localize('noReplicas', 'No replicas found.'));
} else {
return replicas.map(r => {
const date = r.createdTime;
return { label: nonNullProp(r, 'name'), description: dayjs(date).fromNow(), data: r };
});
}
}
}