Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: Add onProgress state to show activity log creating in real-time #1767

Merged
merged 8 commits into from
Aug 22, 2024
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
Next Next commit
Add onProgress state to show activity log creating in real-time
  • Loading branch information
nturinski committed Aug 12, 2024
commit 13eba613575ea2d78ba7d0079caa54b036e7bda1
1 change: 1 addition & 0 deletions utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ export interface IWizardOptions<T extends IActionContext> {

export const activitySuccessContext: string;
export const activityFailContext: string;
export const activityProgressContext: string;

export const activityInfoIcon: ThemeIcon;
export const activitySuccessIcon: ThemeIcon;
Expand Down
4 changes: 2 additions & 2 deletions utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-utils",
"author": "Microsoft Corporation",
"version": "2.5.4",
"version": "2.5.5",
"description": "Common UI tools for developing Azure extensions for VS Code",
"tags": [
"azure",
Expand Down
4 changes: 4 additions & 0 deletions utils/src/activityLog/Activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export abstract class ActivityBase<R> implements hTypes.Activity {

abstract initialState(): hTypes.ActivityTreeItemOptions;
abstract successState(): hTypes.ActivityTreeItemOptions;
abstract progressState(): hTypes.ActivityTreeItemOptions;
abstract errorState(error?: types.IParsedError): hTypes.ActivityTreeItemOptions;

public constructor(task: types.ActivityTask<R>) {
Expand All @@ -51,6 +52,7 @@ export abstract class ActivityBase<R> implements hTypes.Activity {

private report(progress: { message?: string; increment?: number }): void {
this._onProgressEmitter.fire({ ...this.getState(), message: progress.message });
this.status = ActivityStatus.Running;
}

public async run(): Promise<R> {
Expand All @@ -74,6 +76,8 @@ export abstract class ActivityBase<R> implements hTypes.Activity {
return this.errorState(this.error);
case ActivityStatus.Succeeded:
return this.successState();
case ActivityStatus.Running:
return this.progressState();
default:
return this.initialState();
}
Expand Down
10 changes: 10 additions & 0 deletions utils/src/activityLog/activities/ExecuteActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export class ExecuteActivity<TContext extends types.ExecuteActivityContext = typ
}
}

public progressState(): hTypes.ActivityTreeItemOptions {
return {
label: this.label,
getChildren: this.context.activityChildren ? ((parent: AzExtParentTreeItem) => {
parent.compareChildrenImpl = () => 0; // Don't sort
return this.context.activityChildren || [];
}) : undefined
}
}

private appendErrorItemToActivityChildren(errorItem: AzExtTreeItem): void {
// Honor any error suppression flag
if ((this.context as unknown as types.IActionContext).errorHandling?.suppressDisplay) {
Expand Down
2 changes: 2 additions & 0 deletions utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export namespace AzExtQuickInputButtons {

export const activitySuccessContext: string = 'activity:success';
export const activityFailContext: string = 'activity:fail';
export const activityProgressContext: string = 'activity:progress';

export const activityInfoIcon: ThemeIcon = new ThemeIcon('info', new ThemeColor('charts.blue'));
export const activitySuccessIcon: ThemeIcon = new ThemeIcon('pass', new ThemeColor('testing.iconPassed'));
export const activityFailIcon: ThemeIcon = new ThemeIcon('error', new ThemeColor('testing.iconFailed'));
export const activityProgressIcon: ThemeIcon = new ThemeIcon('loading~spin', new ThemeColor('testing.iconQueued'));
6 changes: 6 additions & 0 deletions utils/src/wizard/AzureWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ export class AzureWizard<T extends (IInternalActionContext & Partial<types.Execu
}

let output: types.ExecuteActivityOutput | undefined;
const progressOutput = step.createProgressOutput?.(this._context) ?? {};
this.displayActivityOutput(progressOutput, step.options);

try {
this._context.telemetry.properties.lastStep = `execute-${getEffectiveStepId(step)}`;
await step.execute(this._context, internalProgress);
Expand All @@ -204,6 +207,9 @@ export class AzureWizard<T extends (IInternalActionContext & Partial<types.Execu
}
} finally {
output ??= {};

// always remove the progress item from the activity log
this._context.activityChildren = this._context.activityChildren?.filter(t => t !== progressOutput.item)
this.displayActivityOutput(output, step.options);

currentStep += 1;
Expand Down
2 changes: 2 additions & 0 deletions utils/src/wizard/AzureWizardExecuteStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export abstract class AzureWizardExecuteStep<T extends types.IActionContext & Pa

public createSuccessOutput?(context: T): types.ExecuteActivityOutput;
public createFailOutput?(context: T): types.ExecuteActivityOutput;
public createProgressOutput?(context: T): types.ExecuteActivityOutput;

}
Loading