From a6917d24b80fa2c4f1892e7a4f5e36768aa9b97e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 05:26:26 +0000 Subject: [PATCH 1/2] Bump follow-redirects from 1.15.3 to 1.15.4 (#810) --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 267da7ee..57dd7250 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8729,9 +8729,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "funding": [ { "type": "individual", From 85d4f5e736536a05550488d51ec7b8e6c396c750 Mon Sep 17 00:00:00 2001 From: Ritik Ramuka <56073559+ritikramuka@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:55:45 +0530 Subject: [PATCH 2/2] Added collaboration option on quick pick (#791) * added collaboration option on quick pick * added mail theme icon * spelling corrected * redundent graphclient member removed * error handlings addressed --------- Co-authored-by: tyaginidhi --- src/web/client/WebExtensionContext.ts | 37 ++++++++++- src/web/client/common/constants.ts | 5 ++ src/web/client/extension.ts | 4 +- src/web/client/webViews/QuickPickProvider.ts | 61 +++++++++++++++++-- .../webViews/userCollaborationProvider.ts | 19 ------ 5 files changed, 99 insertions(+), 27 deletions(-) diff --git a/src/web/client/WebExtensionContext.ts b/src/web/client/WebExtensionContext.ts index 67243b1b..db20e754 100644 --- a/src/web/client/WebExtensionContext.ts +++ b/src/web/client/WebExtensionContext.ts @@ -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 @@ -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; @@ -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(); @@ -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( @@ -783,6 +789,35 @@ class WebExtensionContext implements IWebExtensionContext { public async removeConnectedUserInContext(userId: string) { this.connectedUsers.removeUser(userId); } + + public async getMail(userId: string): Promise { + const mail = await this.graphClientService.getUserEmail(userId); + return mail; + } + + public openTeamsChat(userId: string) { + this.getMail(userId).then((mail) => { + if (mail === undefined) { + vscode.window.showErrorMessage(Constants.WEB_EXTENSION_TEAMS_CHAT_NOT_AVAILABLE); + return; + } else { + const teamsChatLink = getTeamChatURL(mail); + vscode.env.openExternal(vscode.Uri.parse(teamsChatLink.href)); + } + }); + } + + public async openMail(userId: string): Promise { + this.getMail(userId).then((mail) => { + if (mail === undefined) { + vscode.window.showErrorMessage(Constants.WEB_EXTENSION_SEND_EMAIL_NOT_AVAILABLE); + return; + } else { + const mailToPath = getMailToPath(mail); + vscode.env.openExternal(vscode.Uri.parse(mailToPath)); + } + }); + } } export default new WebExtensionContext(); diff --git a/src/web/client/common/constants.ts b/src/web/client/common/constants.ts index ecaaf6a3..796916f1 100644 --- a/src/web/client/common/constants.ts +++ b/src/web/client/common/constants.ts @@ -136,3 +136,8 @@ 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"; +export const WEB_EXTENSION_TEAMS_CHAT_NOT_AVAILABLE = "Teams chat is not available for this user"; +export const WEB_EXTENSION_SEND_EMAIL_NOT_AVAILABLE = "Send email is not available for this user"; diff --git a/src/web/client/extension.ts b/src/web/client/extension.ts index 3bd26eea..33bece72 100644 --- a/src/web/client/extension.ts +++ b/src/web/client/extension.ts @@ -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) } ); } diff --git a/src/web/client/webViews/QuickPickProvider.ts b/src/web/client/webViews/QuickPickProvider.ts index f86b5b60..8ada4945 100644 --- a/src/web/client/webViews/QuickPickProvider.ts +++ b/src/web/client/webViews/QuickPickProvider.ts @@ -8,17 +8,23 @@ import WebExtensionContext from "../WebExtensionContext"; import { IEntityInfo } from "../common/interfaces"; import * as Constants from "../common/constants"; +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[] = []; constructor() { - this.items = new Array(); + this.items = new Array(); } public async updateQuickPickItems(entityInfo: IEntityInfo) { const connectedUsersMap = WebExtensionContext.connectedUsers.getUserMap; - const currentUsers: vscode.QuickPickItem[] = []; + const currentUsers: IQuickPickItem[] = []; Array.from( connectedUsersMap.entries() @@ -33,6 +39,7 @@ export class QuickPickProvider { ) { currentUsers.push({ label: value._userName, + id: value._userId, }); } }) @@ -44,11 +51,55 @@ 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: vscode.Uri.joinPath(WebExtensionContext.extensionUri, 'src', 'web', 'client', 'assets', 'microsoftTeamsIcon', 'light', 'microsoftTeams.svg'), + dark: vscode.Uri.joinPath(WebExtensionContext.extensionUri, 'src', 'web', 'client', 'assets', 'microsoftTeamsIcon', 'dark', 'microsoftTeams.svg'), + } + }, + { + label: Constants.SEND_AN_EMAIL, + iconPath: new vscode.ThemeIcon(Constants.THEME_ICON_MAIL), + }, + ]; + + const collaborationOptionsSelected = await vscode.window.showQuickPick(collaborationOptions, { + title: `CONTACT ${selectedOption.label.toUpperCase()}`, + }); + + if (collaborationOptionsSelected) { + if (collaborationOptionsSelected.label === Constants.START_TEAMS_CHAT) { + if (selectedOption.id) { + WebExtensionContext.openTeamsChat(selectedOption.id); + } else { + vscode.window.showInformationMessage(Constants.WEB_EXTENSION_TEAMS_CHAT_NOT_AVAILABLE); + } + } else if (collaborationOptionsSelected.label === Constants.SEND_AN_EMAIL) { + if (selectedOption.id) { + WebExtensionContext.openMail(selectedOption.id); + } else { + vscode.window.showInformationMessage(Constants.WEB_EXTENSION_SEND_EMAIL_NOT_AVAILABLE); + } + } + } } } diff --git a/src/web/client/webViews/userCollaborationProvider.ts b/src/web/client/webViews/userCollaborationProvider.ts index f69df3ac..fcbb7070 100644 --- a/src/web/client/webViews/userCollaborationProvider.ts +++ b/src/web/client/webViews/userCollaborationProvider.ts @@ -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 { - private graphClientService: GraphClientService; private _onDidChangeTreeData: vscode.EventEmitter< UserNode | undefined | void > = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; - constructor() { - this.graphClientService = new GraphClientService(); - } - refresh(): void { this._onDidChangeTreeData.fire(); } @@ -49,18 +42,6 @@ export class UserCollaborationProvider return connectedUsers; } - - async openTeamsChat(userId: string): Promise { - const mail = await this.graphClientService.getUserEmail(userId); - const teamsChatLink = getTeamChatURL(mail); - vscode.env.openExternal(vscode.Uri.parse(teamsChatLink.href)); - } - - async openMail(userId: string): Promise { - const mail = await this.graphClientService.getUserEmail(userId); - const mailToPath = getMailToPath(mail); - vscode.env.openExternal(vscode.Uri.parse(mailToPath)); - } } export class UserNode extends vscode.TreeItem {