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

People Present On The Site Tree Webview #788

Merged
merged 13 commits into from
Dec 8, 2023
Merged
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@
}
],
"commands": [
{
"command": "powerpages.powerPagesPeopleOnTheSite.openTeamsChat",
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
"title": "Open Teams Chat",
"icon": "$(person)"
},
{
"command": "powerpages.powerPagesPeopleOnTheSite.openMail",
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
"title": "Open Mail",
"icon": "$(mail)"
},
{
"command": "powerpages.powerPagesFileExplorer.powerPagesRuntimePreview",
"title": "Preview site",
Expand Down Expand Up @@ -862,6 +872,16 @@
{
"command": "pacCLI.envAndSolutionsPanel.copyOrganizationId",
"when": "!virtualWorkspace && view == pacCLI.envAndSolutionsPanel && viewItem == ENVIRONMENT"
},
{
"command": "powerpages.powerPagesPeopleOnTheSite.openTeamsChat",
"group": "inline",
"when": "viewItem == userNode"
},
{
"command": "powerpages.powerPagesPeopleOnTheSite.openMail",
"group": "inline",
"when": "viewItem == userNode"
}
]
},
Expand Down Expand Up @@ -913,6 +933,13 @@
"icon": "./src/web/client/assets/powerPages.svg",
"contextualTitle": "%microsoft-powerplatform-portals.navigation-loop.powerPagesFileExplorer.title%",
"visibility": "visible"
},
{
"id": "powerpages.powerPagesPeopleOnTheSite",
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
"name": "People On The Site",
"when": "isWeb && virtualWorkspace",
"contextualTitle": "People On The Site",
"visibility": "visible"
}
]
},
Expand Down
8 changes: 7 additions & 1 deletion src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { isMultifileEnabled } from "./utilities/commonUtil";
import { UserDataMap } from "./context/userDataMap";
import { EntityForeignKeyDataMap } from "./context/entityForeignKeyDataMap";
import { QuickPickProvider } from "./webViews/QuickPickProvider";
import { PowerPagesUserCollaborationProvider } from "./webViews/powerPagesUserCollaborationProvider";
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved

export interface IWebExtensionContext {
// From portalSchema properties
Expand Down Expand Up @@ -112,6 +113,7 @@ class WebExtensionContext implements IWebExtensionContext {
private _containerId: string;
private _connectedUsers: UserDataMap;
private _quickPickProvider: QuickPickProvider;
private _powerPagesUserCollaborationProvider: PowerPagesUserCollaborationProvider;

public get schemaDataSourcePropertiesMap() {
return this._schemaDataSourcePropertiesMap;
Expand Down Expand Up @@ -215,7 +217,10 @@ class WebExtensionContext implements IWebExtensionContext {
public get quickPickProvider() {
return this._quickPickProvider;
}

public get powerPagesUserCollaborationProvider() {
return this._powerPagesUserCollaborationProvider;
}

constructor() {
this._schemaDataSourcePropertiesMap = new Map<string, string>();
this._schemaEntitiesMap = new Map<string, Map<string, string>>();
Expand Down Expand Up @@ -249,6 +254,7 @@ class WebExtensionContext implements IWebExtensionContext {
this._containerId = "";
this._connectedUsers = new UserDataMap();
this._quickPickProvider = new QuickPickProvider();
this._powerPagesUserCollaborationProvider = new PowerPagesUserCollaborationProvider();
}

public setWebExtensionContext(
Expand Down
19 changes: 19 additions & 0 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ export function activate(context: vscode.ExtensionContext): void {
showWalkthrough(context, WebExtensionContext.telemetry);
}

export function powerPagesOnTheSite() {
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
vscode.window.registerTreeDataProvider('powerpages.powerPagesPeopleOnTheSite', WebExtensionContext.powerPagesUserCollaborationProvider);
vscode.commands.registerCommand(
"powerpages.powerPagesPeopleOnTheSite.openTeamsChat",
(event) => {
WebExtensionContext.powerPagesUserCollaborationProvider.openTeamsChat(event.id)
}
);
vscode.commands.registerCommand(
"powerpages.powerPagesPeopleOnTheSite.openMail",
(event) => {
WebExtensionContext.powerPagesUserCollaborationProvider.openMail(event.id)
}
);
}

export function powerPagesNavigation() {
const powerPagesNavigationProvider = new PowerPagesNavigationProvider();
vscode.window.registerTreeDataProvider('powerpages.powerPagesFileExplorer', powerPagesNavigationProvider);
Expand Down Expand Up @@ -301,6 +317,7 @@ export function processWillSaveDocument(context: vscode.ExtensionContext) {
export function processWillStartCollaboartion(context: vscode.ExtensionContext) {
// feature in progress, hence disabling it
if (isCoPresenceEnabled()) {
powerPagesOnTheSite();
vscode.commands.registerCommand('powerPlatform.previewCurrentActiveUsers', () => WebExtensionContext.quickPickProvider.showQuickPick());
createWebWorkerInstance(context);
}
Expand Down Expand Up @@ -339,6 +356,7 @@ export function createWebWorkerInstance(
WebExtensionContext.removeConnectedUserInContext(
data.userId
);
WebExtensionContext.powerPagesUserCollaborationProvider.refresh();
}
if (data.type === Constants.workerEventMessages.UPDATE_CONNECTED_USERS) {
WebExtensionContext.updateConnectedUsersInContext(
Expand All @@ -347,6 +365,7 @@ export function createWebWorkerInstance(
data.userId,
data.entityId
);
WebExtensionContext.powerPagesUserCollaborationProvider.refresh();
}
};
}
Expand Down
8 changes: 8 additions & 0 deletions src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,11 @@ export function getImageFileContent(fileFsPath: string, fileContent: Uint8Array)

return webFileV2 ? fileContent : convertContentToString(fileContent, true);
}

export function getTeamChatURL (mail: string) {
return new URL(mail, "https://teams.microsoft.com/l/chat/0/0?users=");
}

export function getMailToPath (mail: string) {
return `mailto:${mail}`;
}
78 changes: 78 additions & 0 deletions src/web/client/webViews/powerPagesUserCollaborationProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import * as vscode from "vscode";
import WebExtensionContext from "../WebExtensionContext";
import { GraphClientService } from "../services/graphClientService";
import { getMailToPath, getTeamChatURL } from "../utilities/commonUtil";

export class PowerPagesUserCollaborationProvider
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
implements vscode.TreeDataProvider<UserNode>
{
private graphClientService: GraphClientService;
private _onDidChangeTreeData: vscode.EventEmitter<
UserNode | undefined | void
> = new vscode.EventEmitter<UserNode | undefined | void>();
readonly onDidChangeTreeData: vscode.Event<UserNode | undefined | void> =
this._onDidChangeTreeData.event;

constructor() {
this.graphClientService = new GraphClientService();
}

refresh(): void {
this._onDidChangeTreeData.fire();
}

getTreeItem(element: UserNode): vscode.TreeItem {
return element;
}

getChildren(): Thenable<UserNode[]> {
return Promise.resolve(this.getConnectedUsers());
}

getConnectedUsers(): UserNode[] {
const connectedUsersMap = WebExtensionContext.connectedUsers.getUserMap;
const connectedUsers: UserNode[] = Array.from(
connectedUsersMap.entries()
).map(([, value]) => {
return new UserNode(
value._userName,
value._userId,
vscode.TreeItemCollapsibleState.None
);
});

return connectedUsers;
}

async openTeamsChat(userId: string): Promise<void> {
const mail = await this.graphClientService.getUserEmail(userId);
const teamsChatLink = getTeamChatURL(mail);
vscode.env.openExternal(vscode.Uri.parse(teamsChatLink.href));
}

async openMail(userId: string): Promise<void> {
const mail = await this.graphClientService.getUserEmail(userId);
const mailToPath = getMailToPath(mail);
vscode.env.openExternal(vscode.Uri.parse(mailToPath));
}
}

export class UserNode extends vscode.TreeItem {
constructor(
public readonly label: string,
public readonly id: string,
public readonly collapsibleState: vscode.TreeItemCollapsibleState
) {
super(label, collapsibleState);

this.tooltip = this.label;
this.iconPath = new vscode.ThemeIcon("account");
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
}

contextValue = "userNode";
ritikramuka marked this conversation as resolved.
Show resolved Hide resolved
}
Loading