Skip to content

Commit

Permalink
Merge pull request #1108 from Microsoft/jwilaby/#935-app-insights
Browse files Browse the repository at this point in the history
#935 - added the ability to input App insights manually
  • Loading branch information
Justin Wilaby committed Nov 20, 2018
2 parents e92dd0a + 1f8fe7e commit 1aa9477
Show file tree
Hide file tree
Showing 20 changed files with 503 additions and 376 deletions.
366 changes: 183 additions & 183 deletions package-lock.json

Large diffs are not rendered by default.

@@ -1,7 +1,7 @@
import {
AzureLoginFailedDialogContainer,
AzureLoginSuccessDialogContainer,
ConnectLuisAppPromptDialogContainer,
ConnectServicePromptDialogContainer,
GetStartedWithCSDialogContainer
} from '../../ui/dialogs';
import { DialogService } from '../../ui/dialogs/service'; // ☣☣ careful! ☣☣
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('The ServiceExplorerSagas', () => {
azureAuthWorkflowComponents: {
loginFailedDialog: AzureLoginFailedDialogContainer,
loginSuccessDialog: AzureLoginSuccessDialogContainer,
promptDialog: ConnectLuisAppPromptDialogContainer
promptDialog: ConnectServicePromptDialogContainer
},
getStartedDialog: GetStartedWithCSDialogContainer,
editorComponent: ConnectedServiceEditorContainer,
Expand Down Expand Up @@ -371,7 +371,7 @@ describe('The ServiceExplorerSagas', () => {
azureAuthWorkflowComponents: {
loginFailedDialog: AzureLoginFailedDialogContainer,
loginSuccessDialog: AzureLoginSuccessDialogContainer,
promptDialog: ConnectLuisAppPromptDialogContainer
promptDialog: ConnectServicePromptDialogContainer
},
getStartedDialog: GetStartedWithCSDialogContainer,
editorComponent: ConnectedServiceEditorContainer,
Expand Down
8 changes: 5 additions & 3 deletions packages/app/client/src/data/sagas/servicesExplorerSagas.ts
Expand Up @@ -220,9 +220,11 @@ function* openContextMenuForService(action: ConnectedServiceAction<ConnectedServ
function* openAddConnectedServiceContextMenu(action: ConnectedServiceAction<ConnectedServicePickerPayload>)
: IterableIterator<any> {
const menuItems = [
{ label: 'Language Understanding (LUIS)', id: ServiceTypes.Luis },
{ label: 'QnA Maker', id: ServiceTypes.QnA },
{ label: 'Dispatch', id: ServiceTypes.Dispatch }
{ label: 'Add Language Understanding (LUIS)', id: ServiceTypes.Luis },
{ label: 'Add QnA Maker', id: ServiceTypes.QnA },
{ label: 'Add Dispatch', id: ServiceTypes.Dispatch },
{ type: 'separator' },
{ label: 'Add Azure Application Insights', id: ServiceTypes.AppInsights}
];

const response = yield CommandServiceImpl.remoteCall(SharedConstants.Commands.Electron.DisplayContextMenu, menuItems);
Expand Down

This file was deleted.

Expand Up @@ -3,9 +3,10 @@ import { Provider } from 'react-redux';
import { mount } from 'enzyme';
import { createStore } from 'redux';
import { azureAuth } from '../../../data/reducer/azureAuthReducer';
import { ConnectLuisAppPromptDialog } from './connectLuisAppPromptDialog';
import { ConnectLuisAppPromptDialogContainer } from './connectLuisAppPromptDialogContainer';
import { ConnectServicePromptDialog } from './connectServicePromptDialog';
import { ConnectServicePromptDialogContainer } from './connectServicePromptDialogContainer';
import { DialogService } from '../service';
import { ServiceTypes } from 'botframework-config';

jest.mock('../service', () => ({
DialogService: {
Expand All @@ -24,23 +25,23 @@ jest.mock('../../dialogs/', () => ({
SecretPromptDialog: () => undefined
}));

describe('The ConnectLuisAppPromptDialog component should', () => {
describe('The ConnectServicePromptDialog component should', () => {
let parent;
let node;

beforeEach(() => {
parent = mount(<Provider store={ createStore(azureAuth) }>
<ConnectLuisAppPromptDialogContainer />
<ConnectServicePromptDialogContainer serviceType={ ServiceTypes.Luis }/>
</Provider>);
node = parent.find(ConnectLuisAppPromptDialog);
node = parent.find(ConnectServicePromptDialog);
});

it('should render deeply', () => {
expect(parent.find(ConnectLuisAppPromptDialogContainer)).not.toBe(null);
expect(parent.find(ConnectServicePromptDialogContainer)).not.toBe(null);
});

it('should contain both a cancel and confirm function in the props', () => {
const prompt = parent.find(ConnectLuisAppPromptDialog);
const prompt = parent.find(ConnectServicePromptDialog);
expect(typeof (prompt.props() as any).cancel).toBe('function');
expect(typeof (prompt.props() as any).confirm).toBe('function');
});
Expand All @@ -62,7 +63,7 @@ describe('The ConnectLuisAppPromptDialog component should', () => {
it('should exit with code 2 when add luis apps manually is selected', () => {
const spy = jest.spyOn(DialogService, 'hideDialog');
const instance = node.instance();
instance.props.addLuisAppManually();
instance.props.addServiceManually();
expect(spy).toHaveBeenCalledWith(2);
});
});
@@ -0,0 +1,145 @@
import { DefaultButton, Dialog, DialogFooter, PrimaryButton } from '@bfemulator/ui-react';
import { ServiceTypes } from 'botframework-config/lib/schema';
import * as React from 'react';
import { Component, MouseEvent, ReactNode } from 'react';
import * as styles from '../dialogStyles.scss';

export interface ConnectServicePromptDialogProps {
cancel: () => void;
confirm: () => void;
addServiceManually: () => void;
onAnchorClick: (url: string) => void;
serviceType?: ServiceTypes;
}

const titleMap = {
[ServiceTypes.Luis]: 'Connect your bot to a LUIS application',
[ServiceTypes.Dispatch]: 'Connect your bot to a Dispatch model',
[ServiceTypes.QnA]: 'Connect your bot to a QnA Maker knowledge base',
[ServiceTypes.AppInsights]: 'Connect to an Azure Application Insights resource'
};

export class ConnectServicePromptDialog extends Component<ConnectServicePromptDialogProps, {}> {

public render() {
return (
<Dialog
className={ styles.dialogMedium }
cancel={ this.props.cancel }
title={ titleMap[this.props.serviceType] }>
{ this.dialogContent }
<DialogFooter>
<DefaultButton text="Cancel" onClick={ this.props.cancel }/>
<PrimaryButton text="Sign in with Azure" onClick={ this.props.confirm }/>
</DialogFooter>
</Dialog>
);
}

private get dialogContent(): ReactNode {
const { serviceType } = this.props;
switch (serviceType) {
case ServiceTypes.Luis:
return this.luisContent;

case ServiceTypes.QnA:
return this.qnaContent;

case ServiceTypes.Dispatch:
return this.dispatchContent;

case ServiceTypes.AppInsights:
return this.appInsightsContent;

default:
throw new TypeError(`${serviceType} is not a known service type`);
}
}

private get luisContent(): ReactNode {
return (
<>
<p>
{ `Sign in to your Azure account to select the LUIS applications you'd like to associate with this bot. ` }
<a href="javascript:void(0);"
data-href="http://aka.ms/bot-framework-emulator-LUIS-docs-home"
onClick={ this.onAnchorClick }>Learn more about LUIS.
</a>
</p>
<p>
{ `Alternatively, you can ` }
<a href="javascript:void(0);" onClick={ this.props.addServiceManually }>add a LUIS app manually</a>
{ ` with the app ID, version, and authoring key.` }
</p>
</>
);
}

private get qnaContent(): JSX.Element {
return (
<>
<p>
{ 'Sign in to your Azure account to select the QnA ' +
'Maker knowledge bases you\'d like to associate with this bot. ' }
<a href="javascript:void(0);"
data-href="http://aka.ms/bot-framework-emulator-qna-docs-home"
onClick={ this.onAnchorClick }>Learn more about QnA Maker.
</a>
</p>
<p>
{ `Alternatively, you can ` } <a href="javascript:void(0);" onClick={ this.props.addServiceManually }>
connect to a QnA Maker knowledge base manually
</a>
{ ' with the app ID, version, and authoring key.' }
</p>
</>
);
}

private get dispatchContent(): JSX.Element {
return (
<>
<p>
{ `Sign in to your Azure account to select the Dispatch model you'd like to associate with this bot. ` }
<a href="javascript:void(0);"
data-href="https://aka.ms/bot-framework-emulator-create-dispatch"
onClick={ this.onAnchorClick }>Learn more about Dispatch models.
</a>
</p>
<p>
{ `Alternatively, you can ` }
<a href="javascript:void(0);" onClick={ this.props.addServiceManually }>
connect to a Dispatch model manually
</a>
{ ` with the app ID, version, and authoring key.` }
</p>
</>
);
}

private get appInsightsContent(): JSX.Element {
return (
<>
<p>
{ 'Sign in to your Azure account to select the Azure Application ' +
'Insights you\'d like to associate with this bot. ' }
<a href="javascript:void(0);" onClick={ this.onAnchorClick }>
Learn more about Azure Application Insights.
</a>
</p>
<p>
{ `Alternatively, you can ` }
<a href="javascript:void(0);" onClick={ this.props.addServiceManually }>
connect to a azure Application Insights manually
</a>
{ ` with the app ID, version, and authoring key.` }
</p>
</>
);
}

private onAnchorClick = (event: MouseEvent<HTMLAnchorElement>) => {
const { href } = event.currentTarget.dataset;
this.props.onAnchorClick(href);
}
}
Expand Up @@ -31,27 +31,27 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { SharedConstants } from '@bfemulator/app-shared';
import { connect } from 'react-redux';
import { CommandServiceImpl } from '../../../platform/commands/commandServiceImpl';
import { ConnectLuisAppPromptDialog, ConnectLuisAppPromptDialogProps } from './connectLuisAppPromptDialog';
import { DialogService } from '../service';
import { SharedConstants } from '@bfemulator/app-shared';
import { ConnectServicePromptDialog, ConnectServicePromptDialogProps } from './connectServicePromptDialog';

const mapDispatchToProps = (
_dispatch: () => void, ownProps: { [propName: string]: any }
): ConnectLuisAppPromptDialogProps => {
): ConnectServicePromptDialogProps => {
return {
...ownProps,
cancel: () => DialogService.hideDialog(0),
confirm: () => DialogService.hideDialog(1),
addLuisAppManually: () => DialogService.hideDialog(2),
addServiceManually: () => DialogService.hideDialog(2),
onAnchorClick: (url) => {
CommandServiceImpl.remoteCall(SharedConstants.Commands.Electron.OpenExternal, url).catch();
}
};
};

export const ConnectLuisAppPromptDialogContainer = connect(
export const ConnectServicePromptDialogContainer = connect(
null,
mapDispatchToProps
)(ConnectLuisAppPromptDialog);
)(ConnectServicePromptDialog);
2 changes: 1 addition & 1 deletion packages/app/client/src/ui/dialogs/index.ts
Expand Up @@ -39,7 +39,7 @@ export * from './service';
export * from './azureLoginSuccessDialog/azureLoginSuccessDialogContainer';
export * from './azureLoginPromptDialog/azureLoginPromptDialogContainer';
export * from './azureLoginFailedDialog/azureLoginFailedDialogContainer';
export * from './connectLuisAppPromptDialog/connectLuisAppPromptDialogContainer';
export * from './connectServicePromptDialog/connectServicePromptDialogContainer';
export * from './getStartedWithCSDialog/getStartedWithCSDialogContainer';
export * from './postMigrationDialog/postMigrationDialogContainer';
export * from './progressIndicator/progressIndicatorContainer';
Expand Down
@@ -0,0 +1,3 @@
.connectedServiceEditor {
width: 400px;
}
@@ -0,0 +1,2 @@
// This is a generated file. Changes are likely to result in being overwritten
export const connectedServiceEditor: string;

0 comments on commit 1aa9477

Please sign in to comment.