-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathactivityUtils.ts
More file actions
38 lines (33 loc) · 1.88 KB
/
activityUtils.ts
File metadata and controls
38 lines (33 loc) · 1.88 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
36
37
38
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ActivityChildType, type ActivityChildItemBase, type ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
import { type AzureResourcesExtensionApiWithActivity } from "@microsoft/vscode-azext-utils/activity";
import { ext } from "../extensionVariables";
import { settingUtils } from "./settingUtils";
export async function createActivityContext(options?: { withChildren?: boolean }): Promise<ExecuteActivityContext> {
return {
registerActivity: async (activity) => (ext.rgApiV2 as AzureResourcesExtensionApiWithActivity).activity.registerActivity(activity),
suppressNotification: await settingUtils.getSetting('suppressActivityNotifications', undefined, 'azureResourceGroups'),
activityChildren: options?.withChildren ? [] : undefined,
};
}
/**
* Adds a new activity child after the last info child in the `activityChildren` array.
* If no info child already exists, the new child is prepended to the front of the array.
* (This utility function is useful for keeping the info children grouped at the front of the list)
*/
export function prependOrInsertAfterLastInfoChild(context: Partial<ExecuteActivityContext>, infoChild: ActivityChildItemBase): void {
if (!context.activityChildren) {
return;
}
const idx: number = context.activityChildren
.map(child => child.activityType)
.lastIndexOf(ActivityChildType.Info);
if (idx === -1) {
context.activityChildren.unshift(infoChild);
} else {
context.activityChildren.splice(idx + 1, 0, infoChild);
}
}