Skip to content

Commit

Permalink
added collaboration option on quick pick
Browse files Browse the repository at this point in the history
  • Loading branch information
ritikramuka committed Dec 11, 2023
1 parent 608dbe1 commit b76fa90
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 27 deletions.
20 changes: 19 additions & 1 deletion src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import { EntityDataMap } from "./context/entityDataMap";
import { FileDataMap } from "./context/fileDataMap";
import { IAttributePath, IEntityInfo } from "./common/interfaces";
import { ConcurrencyHandler } from "./dal/concurrencyHandler";
import { isMultifileEnabled } from "./utilities/commonUtil";
import { getMailToPath, getTeamChatURL, isMultifileEnabled } from "./utilities/commonUtil";
import { UserDataMap } from "./context/userDataMap";
import { EntityForeignKeyDataMap } from "./context/entityForeignKeyDataMap";
import { QuickPickProvider } from "./webViews/QuickPickProvider";
import { UserCollaborationProvider } from "./webViews/userCollaborationProvider";
import { GraphClientService } from "./services/graphClientService";

export interface IWebExtensionContext {
// From portalSchema properties
Expand Down Expand Up @@ -114,6 +115,7 @@ class WebExtensionContext implements IWebExtensionContext {
private _connectedUsers: UserDataMap;
private _quickPickProvider: QuickPickProvider;
private _userCollaborationProvider: UserCollaborationProvider;
private _graphClientService: GraphClientService;

public get schemaDataSourcePropertiesMap() {
return this._schemaDataSourcePropertiesMap;
Expand Down Expand Up @@ -220,6 +222,9 @@ class WebExtensionContext implements IWebExtensionContext {
public get userCollaborationProvider() {
return this._userCollaborationProvider;
}
public get graphClientService() {
return this._graphClientService;
}

constructor() {
this._schemaDataSourcePropertiesMap = new Map<string, string>();
Expand Down Expand Up @@ -255,6 +260,7 @@ class WebExtensionContext implements IWebExtensionContext {
this._connectedUsers = new UserDataMap();
this._quickPickProvider = new QuickPickProvider();
this._userCollaborationProvider = new UserCollaborationProvider();
this._graphClientService = new GraphClientService();
}

public setWebExtensionContext(
Expand Down Expand Up @@ -783,6 +789,18 @@ class WebExtensionContext implements IWebExtensionContext {
public async removeConnectedUserInContext(userId: string) {
this.connectedUsers.removeUser(userId);
}

public 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));
}

public 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 default new WebExtensionContext();
3 changes: 3 additions & 0 deletions src/web/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ export const MICROSOFT_GRAPH_PROFILE_PICTURE_SERVICE_CALL = "/photo/$value";
// User collaboration constants
export const USER_COLLABORATION_CONTEXT_VALUE = "userNode";
export const THEME_ICON_ACCOUNT = "account";
export const THEME_ICON_MAIL = "mail";
export const START_TEAMS_CHAT = "Start Teams Chat";
export const SEND_AN_EMAIL = "Send an email";
4 changes: 2 additions & 2 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ export function registerCollaborationView() {
vscode.commands.registerCommand(
"powerpages.collaboration.openTeamsChat",
(event) => {
WebExtensionContext.userCollaborationProvider.openTeamsChat(event.id)
WebExtensionContext.openTeamsChat(event.id)
}
);
vscode.commands.registerCommand(
"powerpages.collaboration.openMail",
(event) => {
WebExtensionContext.userCollaborationProvider.openMail(event.id)
WebExtensionContext.openMail(event.id)
}
);
}
Expand Down
58 changes: 53 additions & 5 deletions src/web/client/webViews/QuickPickProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@ import * as vscode from "vscode";
import WebExtensionContext from "../WebExtensionContext";
import { IEntityInfo } from "../common/interfaces";
import * as Constants from "../common/constants";
import { GraphClientService } from "../services/graphClientService";

interface IQuickPickItem extends vscode.QuickPickItem {
label: string;
id?: string;
iconPath?: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri } | vscode.ThemeIcon;
}

export class QuickPickProvider {
private items: vscode.QuickPickItem[] = [];
private items: IQuickPickItem[] = [];
graphClientService: GraphClientService;

constructor() {
this.items = new Array<vscode.QuickPickItem>();
this.items = new Array<IQuickPickItem>();
this.graphClientService = new GraphClientService();
}

public async updateQuickPickItems(entityInfo: IEntityInfo) {
const connectedUsersMap = WebExtensionContext.connectedUsers.getUserMap;

const currentUsers: vscode.QuickPickItem[] = [];
const currentUsers: IQuickPickItem[] = [];

Array.from(
connectedUsersMap.entries()
Expand All @@ -33,6 +42,7 @@ export class QuickPickProvider {
) {
currentUsers.push({
label: value._userName,
id: value._userId,
});
}
})
Expand All @@ -44,11 +54,49 @@ export class QuickPickProvider {
} else {
this.items = [{
label: Constants.WEB_EXTENSION_QUICK_PICK_DEFAULT_STRING,
id: "",
}];
}
}

public showQuickPick() {
vscode.window.showQuickPick(this.items);
public async showQuickPick() {
const selectedUSer = await vscode.window.showQuickPick(this.items);
if (selectedUSer) {
this.handleSelectedOption(selectedUSer);
}
}

private handleSelectedOption(selectedOption: IQuickPickItem) {
this.collaborationQuickPick(selectedOption);
}

public async collaborationQuickPick(selectedOption: IQuickPickItem) {
const collaborationOptions: IQuickPickItem[] = [
{
label: Constants.START_TEAMS_CHAT,
iconPath: {
light: '../assets/microsoftTeamsIcon/light/microsoftTeams.svg',
dark: '../assets/microsoftTeamsIcon/dark/microsoftTeams.svg',
}
},
{
label: Constants.SEND_AN_EMAIL,
iconPath: Constants.THEME_ICON_MAIL
},
];

const collaborationOptionsSelected = await vscode.window.showQuickPick(collaborationOptions);

if (collaborationOptionsSelected) {
if (collaborationOptionsSelected.label === Constants.START_TEAMS_CHAT) {
if (selectedOption.id) {
WebExtensionContext.openTeamsChat(selectedOption.id);
}
} else if (collaborationOptionsSelected.label === Constants.SEND_AN_EMAIL) {
if (selectedOption.id) {
WebExtensionContext.openMail(selectedOption.id);
}
}
}
}
}
19 changes: 0 additions & 19 deletions src/web/client/webViews/userCollaborationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@

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

export class UserCollaborationProvider
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();
}
Expand All @@ -49,18 +42,6 @@ export class UserCollaborationProvider

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 {
Expand Down

0 comments on commit b76fa90

Please sign in to comment.