Skip to content

Commit

Permalink
Merge branch 'main' into users/biddas/clientLoggerWrapper1
Browse files Browse the repository at this point in the history
  • Loading branch information
BidishaMS authored Jan 11, 2024
2 parents 61c5afb + 85d4f5e commit ee6954c
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 30 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 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,35 @@ class WebExtensionContext implements IWebExtensionContext {
public async removeConnectedUserInContext(userId: string) {
this.connectedUsers.removeUser(userId);
}

public async getMail(userId: string): Promise<string> {
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<void> {
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();
5 changes: 5 additions & 0 deletions src/web/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
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
61 changes: 56 additions & 5 deletions src/web/client/webViews/QuickPickProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.QuickPickItem>();
this.items = new Array<IQuickPickItem>();
}

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 +39,7 @@ export class QuickPickProvider {
) {
currentUsers.push({
label: value._userName,
id: value._userId,
});
}
})
Expand All @@ -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);
}
}
}
}
}
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 ee6954c

Please sign in to comment.