Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/commands/logStream/RevisionListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import { IStreamLogsContext } from "./IStreamLogsContext";

export class RevisionListStep extends AzureWizardPromptStep<IStreamLogsContext> {
public async prompt(context: IStreamLogsContext): Promise<void> {
if (context.containerApp.revisionsMode === 'Multiple') {
const placeHolder: string = localize('selectRevision', 'Select a revision');
context.revision = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
} else {
(await this.getPicks(context)).forEach(revision => {
if (revision.data.active === true) {
context.revision = revision.data;
}
});
const placeHolder: string = localize('selectRevision', 'Select a revision');
context.revision = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
}

public async configureBeforePrompt(context: IStreamLogsContext): Promise<void> {
const picks = await this.getPicks(context);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to call this first. In the event that this is single revision mode, this call was pointless and makes the wizard slightly more sluggish.

I'd suggestion that you first check if the revisionsMode is single, then in your else clause, do the logic to see how many revisions there are.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also want to cache the results of this.getPicks in the wizard step, otherwise we will call it again needlessly if the event we actually do prompt the users.

Since it's pretty rare to actually have multiple revision mode, I wouldn't mind too much if you don't cache it, but I thought I'd mention it for best practice :)

if (context.containerApp.revisionsMode === 'Multiple' && picks.length === 1) {
context.revision = picks[0].data;
} else if (context.containerApp.revisionsMode === 'Single') {
const client: ContainerAppsAPIClient = await createContainerAppsAPIClient([context, createSubscriptionContext(context.subscription)]);
const revisionData = await client.containerAppsRevisions.getRevision(context.resourceGroupName, context.containerApp.name, nonNullProp(context.containerApp, 'latestRevisionName'));
context.revision = revisionData;
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/commands/logStream/StreamListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ILogStream, getActiveLogStreams } from "./logStreamRequest";
export class StreamListStep extends AzureWizardPromptStep<IStreamLogsContext> {
public async prompt(context: IStreamLogsContext): Promise<void> {
const placeHolder: string = localize('selectStream', 'Select a stream');
const picks: IAzureQuickPickItem<ILogStream | undefined>[] = await this.getPicks(context);
const picks: IAzureQuickPickItem<ILogStream | undefined>[] = this.getPicks(context);
if (picks.length > 1) {
picks.push({ label: localize('stopAll', 'Stop all Streams'), data: undefined });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol.... nit: I'm not sure if it should just be Stop all streams since it's not exactly a title.

}
Expand All @@ -22,11 +22,9 @@ export class StreamListStep extends AzureWizardPromptStep<IStreamLogsContext> {
return !context.logStreamToStop;
}

private async getPicks(context: IStreamLogsContext): Promise<IAzureQuickPickItem<ILogStream>[]> {
private getPicks(context: IStreamLogsContext): IAzureQuickPickItem<ILogStream>[] {
const logStreams = getActiveLogStreams(context);
if (logStreams.size === 0) {
throw new Error(localize('noActiveStreams', 'There are no active log streams.'));
}

return Array.from(logStreams).map(l => {
return {
label: nonNullValue(l[1].data.container),
Expand Down
5 changes: 5 additions & 0 deletions src/commands/logStream/logStreamRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export function getActiveLogStreams(context: IStreamLogsContext): Map<string, IL
activeStreams.set(key, value);
}
}

if (activeStreams.size === 0) {
throw new Error(localize('noActiveStreams', 'There are no active log streams.'));
}

return activeStreams;
}

Expand Down