This commit is contained in:
Sweatha Viswanathan 2021-02-05 12:50:50 -08:00
parent b1862bb566
commit 6852515b7c
6 changed files with 77 additions and 7 deletions

View File

@ -4,13 +4,19 @@ import ReactWebChat, { createDirectLine } from "botframework-webchat";
export interface SupportPaneComponentProps { export interface SupportPaneComponentProps {
directLineToken: string; directLineToken: string;
userToken: string;
subId: string;
rg:string;
accName:string;
} }
export class SupportPaneComponent extends React.Component<SupportPaneComponentProps> { export class SupportPaneComponent extends React.Component<SupportPaneComponentProps> {
private readonly userId: string = _.uniqueId(); private readonly userId: string = _.uniqueId();
constructor(props: SupportPaneComponentProps) { constructor(props: SupportPaneComponentProps) {
super(props); super(props);
} }
public render(): JSX.Element { public render(): JSX.Element {
@ -18,7 +24,24 @@ export class SupportPaneComponent extends React.Component<SupportPaneComponentPr
bubbleBackground: "rgba(0, 0, 255, .1)", bubbleBackground: "rgba(0, 0, 255, .1)",
bubbleFromUserBackground: "rgba(0, 255, 0, .1)" bubbleFromUserBackground: "rgba(0, 255, 0, .1)"
}; };
const directLine = createDirectLine({ token: this.props.directLineToken });
return <ReactWebChat directLine={directLine} userID={this.userId} styleOptions={styleOptions} />; const directLine = createDirectLine({ token: this.props.directLineToken });
const dl =
{
...directLine,
postActivity: (activity: any) => {
// Add whatever needs to be added.
activity.channelData.token = this.props.userToken;
activity.channelData.subId = this.props.subId;
activity.channelData.rg = this.props.rg;
activity.channelData.accName = this.props.accName;
//activity.channelData.MyKey = "hello";
return directLine.postActivity(activity)
}
}
return <ReactWebChat directLine={dl} userid={this.userId} styleOptions={styleOptions}/>;
} }
} }

View File

@ -3,26 +3,59 @@ import * as React from "react";
import { ReactAdapter } from "../../../Bindings/ReactBindingHandler"; import { ReactAdapter } from "../../../Bindings/ReactBindingHandler";
import Explorer from "../../Explorer"; import Explorer from "../../Explorer";
import { SupportPaneComponent } from "./SupportPaneComponent"; import { SupportPaneComponent } from "./SupportPaneComponent";
import { userContext } from "../../../UserContext";
export interface SupportPaneComponentParams { export interface SupportPaneComponentParams {
directLineAccessToken: string; directLineAccessToken: string;
userToken: string;
subId: string;
rg: string;
accName: string;
} }
export class SupportPaneComponentAdapter implements ReactAdapter { export class SupportPaneComponentAdapter implements ReactAdapter {
public parameters: ko.Observable<SupportPaneComponentParams>; public parameters: ko.Observable<SupportPaneComponentParams>;
constructor(private container: Explorer) { constructor(private container: Explorer) {
this.parameters = ko.observable<SupportPaneComponentParams>({ this.parameters = ko.observable<SupportPaneComponentParams>({
directLineAccessToken: this.container.conversationToken() directLineAccessToken: this.container.conversationToken(),
userToken: this.container.userToken(),
subId: this.container.subId(),
rg: this.container.rg(),
accName: this.container.accName()
}); });
this.container.conversationToken.subscribe(accessToken => { this.container.conversationToken.subscribe(accessToken => {
this.parameters().directLineAccessToken = accessToken; this.parameters().directLineAccessToken = accessToken;
this.forceRender(); this.forceRender();
}); });
this.container.userToken.subscribe(userToken => {
this.parameters().userToken = userToken;
this.forceRender();
});
this.container.subId.subscribe(subId => {
this.parameters().subId = subId;
this.forceRender();
});
this.container.rg.subscribe(rg => {
this.parameters().rg = rg;
this.forceRender();
});
this.container.accName.subscribe(accName => {
this.parameters().accName = accName;
this.forceRender();
});
} }
public renderComponent(): JSX.Element { public renderComponent(): JSX.Element {
return <SupportPaneComponent directLineToken={this.parameters().directLineAccessToken} />; return <SupportPaneComponent
directLineToken={this.parameters().directLineAccessToken}
userToken={this.parameters().userToken}
subId={this.parameters().subId}
rg={this.parameters().rg}
accName={this.parameters().accName}
/>;
} }
public forceRender(): void { public forceRender(): void {

View File

@ -177,6 +177,10 @@ export default class Explorer {
public isResourceTokenCollectionNodeSelected: ko.Computed<boolean>; public isResourceTokenCollectionNodeSelected: ko.Computed<boolean>;
private resourceTreeForResourceToken: ResourceTreeAdapterForResourceToken; private resourceTreeForResourceToken: ResourceTreeAdapterForResourceToken;
public conversationToken: ko.Observable<string>; public conversationToken: ko.Observable<string>;
public userToken: ko.Observable<string>;
public subId: ko.Observable<string>;
public rg: ko.Observable<string>;
public accName: ko.Observable<string>;
// Tabs // Tabs
public isTabsContentExpanded: ko.Observable<boolean>; public isTabsContentExpanded: ko.Observable<boolean>;
@ -329,6 +333,10 @@ export default class Explorer {
this.hasStorageAnalyticsAfecFeature.subscribe((enabled: boolean) => this.refreshCommandBarButtons()); this.hasStorageAnalyticsAfecFeature.subscribe((enabled: boolean) => this.refreshCommandBarButtons());
this.isSynapseLinkUpdating = ko.observable<boolean>(false); this.isSynapseLinkUpdating = ko.observable<boolean>(false);
this.conversationToken = ko.observable<string>(); this.conversationToken = ko.observable<string>();
this.userToken = ko.observable<string>();
this.subId = ko.observable<string>();
this.rg = ko.observable<string>();
this.accName = ko.observable<string>();
this.isAccountReady.subscribe(async (isAccountReady: boolean) => { this.isAccountReady.subscribe(async (isAccountReady: boolean) => {
if (isAccountReady) { if (isAccountReady) {
this.isAuthWithResourceToken() ? this.refreshDatabaseForResourceToken() : this.refreshAllDatabases(true); this.isAuthWithResourceToken() ? this.refreshDatabaseForResourceToken() : this.refreshAllDatabases(true);
@ -1625,7 +1633,6 @@ export default class Explorer {
const tokenResponse: { conversationId: string; token: string; expires_in: number } = await response.json(); const tokenResponse: { conversationId: string; token: string; expires_in: number } = await response.json();
this.conversationToken(tokenResponse?.token); this.conversationToken(tokenResponse?.token);
if (tokenResponse?.expires_in) { if (tokenResponse?.expires_in) {
setTimeout(() => this.generateConversationToken(), (tokenResponse?.expires_in - 1000) * 1000); setTimeout(() => this.generateConversationToken(), (tokenResponse?.expires_in - 1000) * 1000);
} }
@ -1998,6 +2005,11 @@ export default class Explorer {
resourceGroup: inputs.resourceGroup, resourceGroup: inputs.resourceGroup,
subscriptionId: inputs.subscriptionId subscriptionId: inputs.subscriptionId
}); });
this.userToken(userContext.authorizationToken);
this.subId(userContext.subscriptionId);
this.rg(userContext.resourceGroup);
this.accName(userContext.databaseAccount.name);
TelemetryProcessor.traceSuccess( TelemetryProcessor.traceSuccess(
Action.LoadDatabaseAccount, Action.LoadDatabaseAccount,
{ {

View File

@ -180,7 +180,7 @@ export class CommandBarComponentButtonFactory {
} }
if (window.authType === AuthType.AAD) { if (window.authType === AuthType.AAD) {
const label = "Support"; const label = "Chat Assistant";
const supportPaneButton: CommandButtonComponentProps = { const supportPaneButton: CommandButtonComponentProps = {
iconSrc: FeedbackIcon, iconSrc: FeedbackIcon,
iconAlt: label, iconAlt: label,

View File

@ -7,7 +7,7 @@ export class SupportPane extends ContextualPaneBase {
constructor(options: ViewModels.PaneOptions) { constructor(options: ViewModels.PaneOptions) {
super(options); super(options);
this.title("Cosmos DB Support"); this.title("Cosmos DB Chat Assistant");
this.resetData(); this.resetData();
this.supportPaneComponentAdapter = new SupportPaneComponentAdapter(this.container); this.supportPaneComponentAdapter = new SupportPaneComponentAdapter(this.container);
} }

View File

@ -7,8 +7,10 @@
<title>Azure Cosmos DB</title> <title>Azure Cosmos DB</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
</head> </head>
<body> <body>
<div class="flexContainer"> <div class="flexContainer">
<div id="divExplorer" class="flexContainer hideOverflows" style="display: none"> <div id="divExplorer" class="flexContainer hideOverflows" style="display: none">
<!-- Main Command Bar - Start --> <!-- Main Command Bar - Start -->