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 all commits
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
2 changes: 1 addition & 1 deletion utils/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"**/node_modules": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why this changed, but I noticed some of our other extensions are like that so I just left it.

}
}
9 changes: 9 additions & 0 deletions utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,9 +1161,11 @@ 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;
export const activityProgressIcon: ThemeIcon;
export const activityFailIcon: ThemeIcon;

export type ActivityTask<R> = (progress: Progress<{ message?: string, increment?: number }>, cancellationToken: CancellationToken) => Promise<R>;
Expand All @@ -1180,6 +1182,7 @@ export declare abstract class ActivityBase<R> implements Activity {

abstract initialState(): ActivityTreeItemOptions;
abstract successState(): ActivityTreeItemOptions;
abstract progressState(): ActivityTreeItemOptions;
abstract errorState(error: IParsedError): ActivityTreeItemOptions;

public constructor(task: ActivityTask<R>);
Expand All @@ -1206,6 +1209,7 @@ export class ExecuteActivity<C extends ExecuteActivityContext = ExecuteActivityC
public constructor(context: C, task: ActivityTask<void>);
public initialState(): ActivityTreeItemOptions;
public successState(): ActivityTreeItemOptions;
public progressState(): ActivityTreeItemOptions;
public errorState(error: IParsedError): ActivityTreeItemOptions;
protected get label(): string;
}
Expand Down Expand Up @@ -1302,6 +1306,11 @@ export declare abstract class AzureWizardExecuteStep<T extends IActionContext &
*/
public createSuccessOutput?(context: T): ExecuteActivityOutput;

/**
* Defines the output for display during execution of the step
*/
public createProgressOutput?(context: T): ExecuteActivityOutput;

/**
* Defines the output for display after unsuccessful execution of the step
*/
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');
2 changes: 1 addition & 1 deletion utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export * from './activityLog/Activity';
export { createAzExtLogOutputChannel, createAzExtOutputChannel } from './AzExtOutputChannel';
export * from './AzExtTreeFileSystem';
export * from './callWithTelemetryAndErrorHandling';
export { activityFailContext, activityFailIcon, activityInfoIcon, activitySuccessContext, activitySuccessIcon } from './constants';
export { activityFailContext, activityFailIcon, activityInfoIcon, activityProgressContext, activityProgressIcon, activitySuccessContext, activitySuccessIcon } from './constants';
export * from './createApiProvider';
export { createExperimentationService } from './createExperimentationService';
export * from './DialogResponses';
Expand Down
11 changes: 11 additions & 0 deletions utils/src/wizard/AzureWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ export class AzureWizard<T extends (IInternalActionContext & Partial<types.Execu
}

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

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

// always remove the progress item from the activity log
if (progressOutput?.item) {
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