Skip to content

Commit

Permalink
Merge branch 'master' into luhan/updateHttpSample
Browse files Browse the repository at this point in the history
  • Loading branch information
luhan2017 authored Mar 6, 2020
2 parents ed0a23e + 964b8d6 commit c04743a
Show file tree
Hide file tree
Showing 58 changed files with 1,126 additions and 985 deletions.
1 change: 1 addition & 0 deletions .github/actions/conventional-pr/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const validTypes = [
'chore',
'revert',
'release',
'a11y',
];

const typeList = validTypes.map(t => ` - ${t}`).join('\n');
Expand Down
7 changes: 2 additions & 5 deletions Composer/cypress/integration/LUPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ context('LU Page', () => {
cy.contains('ToDoBotWithLuisSample.Main');
cy.contains('All');

cy.get('.toggleEditMode button').as('switchButton');

// all multiple file, edit mode button is disabled.
cy.get('@switchButton').should('be.disabled');
cy.get('.toggleEditMode button').should('not.exist');

// by default is table view
cy.findByTestId('LUEditor')
Expand All @@ -28,7 +25,7 @@ context('LU Page', () => {
cy.findByTestId('LUEditor').within(() => {
cy.findByText('__TestToDoBotWithLuisSample.Main').click();
});

cy.get('.toggleEditMode button').as('switchButton');
// goto edit-mode
cy.get('@switchButton').click();
cy.findByTestId('LUEditor')
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@bfc/extensions": "*",
"@bfc/indexers": "*",
"@bfc/shared": "*",
"@bfcomposer/bf-lu": "^1.2.5",
"@bfcomposer/bf-lu": "^1.2.9",
"@emotion/core": "^10.0.7",
"@reach/router": "^1.2.1",
"axios": "^0.18.0",
Expand Down
21 changes: 11 additions & 10 deletions Composer/packages/client/src/pages/language-understanding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ const LUPage: React.FC<LUPageProps> = props => {
<div css={ContentHeaderStyle}>
<div css={HeaderText}>{formatMessage('User Input')}</div>
<div css={flexContent}>
<Toggle
className={'toggleEditMode'}
css={actionButton}
onText={formatMessage('Edit mode')}
offText={formatMessage('Edit mode')}
defaultChecked={false}
checked={!!edit}
disabled={isRoot && edit === false}
onChange={onToggleEditMode}
/>
{(!isRoot || edit) && (
<Toggle
className={'toggleEditMode'}
css={actionButton}
onText={formatMessage('Edit mode')}
offText={formatMessage('Edit mode')}
defaultChecked={false}
checked={!!edit}
onChange={onToggleEditMode}
/>
)}
</div>
</div>
<div css={ContentStyle} data-testid="LUEditor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { FieldProps } from '@bfcomposer/react-jsonschema-form';
import formatMessage from 'format-message';
import { JSONSchema6 } from 'json-schema';
import { SDKTypes, MicrosoftInputDialog, ChoiceInput, ConfirmInput } from '@bfc/shared';
import { DialogInfo } from '@bfc/indexers/lib/type';

import { TextWidget, SelectWidget } from '../../widgets';
import { LuEditorWidget } from '../../widgets/LuEditorWidget';

import { field } from './styles';
import { GetSchema, PromptFieldChangeHandler } from './types';
Expand All @@ -24,16 +26,28 @@ const getOptions = (enumSchema: JSONSchema6) => {
return enumSchema.enum.map(o => ({ label: o as string, value: o as string }));
};

const usesLuisRecognizer = ({ content }: DialogInfo) => {
return typeof content?.recognizer === 'string';
};

interface UserInputProps extends FieldProps<MicrosoftInputDialog> {
onChange: PromptFieldChangeHandler;
getSchema: GetSchema;
}

export const UserInput: React.FC<UserInputProps> = props => {
const { onChange, getSchema, idSchema, formData, errorSchema } = props;
const { formContext, onChange, getSchema, idSchema, formData, errorSchema } = props;
const { const: type } = getSchema('$type');
const [, promptType] = (type as string).split('.');
const intentName = `${promptType}.response-${formData?.$designer?.id}`;

return (
<Fragment>
{usesLuisRecognizer(formContext.currentDialog) && (
<div css={field}>
<LuEditorWidget name={intentName} formContext={formContext} />
</div>
)}
<div css={field}>
<TextWidget
onChange={onChange('property')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/** @jsx jsx */
import { jsx } from '@emotion/core';
import React from 'react';
import { IdSchema } from '@bfcomposer/react-jsonschema-form';
import formatMessage from 'format-message';
import { Pivot, PivotLinkSize, PivotItem } from 'office-ui-fabric-react/lib/Pivot';
import get from 'lodash/get';
Expand All @@ -13,7 +12,7 @@ import { PromptTab } from '@bfc/shared';
import { BaseField } from '../BaseField';
import { BFDFieldProps } from '../../types';

import { tabs, tabsContainer, settingsContainer } from './styles';
import { tabs } from './styles';
import { BotAsks } from './BotAsks';
import { UserInput } from './UserInput';
import { Other } from './Other';
Expand All @@ -23,7 +22,6 @@ import { GetSchema, PromptFieldChangeHandler } from './types';
export const PromptField: React.FC<BFDFieldProps> = props => {
const { formContext } = props;
const { shellApi, focusedTab, focusedSteps } = formContext;
const promptSettingsIdSchema = ({ __id: props.idSchema.__id + 'promptSettings' } as unknown) as IdSchema;

const getSchema: GetSchema = field => {
const fieldSchema = get(props.schema, ['properties', field]);
Expand All @@ -43,38 +41,23 @@ export const PromptField: React.FC<BFDFieldProps> = props => {

return (
<BaseField {...props}>
<div css={tabsContainer}>
<Pivot
linkSize={PivotLinkSize.large}
styles={tabs}
selectedKey={focusedTab || PromptTab.BOT_ASKS}
onLinkClick={handleTabChange}
>
<PivotItem headerText={formatMessage('Bot Asks')} itemKey={PromptTab.BOT_ASKS}>
<BotAsks {...props} onChange={updateField} getSchema={getSchema} />
</PivotItem>
<PivotItem headerText={formatMessage('User Input')} itemKey={PromptTab.USER_INPUT}>
<UserInput {...props} onChange={updateField} getSchema={getSchema} />
</PivotItem>
<PivotItem headerText={formatMessage('Other')} itemKey={PromptTab.OTHER}>
<Other {...props} onChange={updateField} getSchema={getSchema} />
</PivotItem>
</Pivot>
</div>

<div className="ObjectItem ObjectItemContainer" css={settingsContainer}>
<div className="ObjectItemField">
<BaseField
formContext={props.formContext}
formData={props.formData}
idSchema={promptSettingsIdSchema}
title={formatMessage('Prompt settings')}
schema={{}}
>
<PromptSettings {...props} onChange={updateField} getSchema={getSchema} />
</BaseField>
</div>
</div>
<Pivot
linkSize={PivotLinkSize.large}
styles={tabs}
selectedKey={focusedTab || PromptTab.BOT_ASKS}
onLinkClick={handleTabChange}
>
<PivotItem headerText={formatMessage('Bot Asks')} itemKey={PromptTab.BOT_ASKS}>
<BotAsks {...props} onChange={updateField} getSchema={getSchema} />
</PivotItem>
<PivotItem headerText={formatMessage('User Input')} itemKey={PromptTab.USER_INPUT}>
<UserInput {...props} onChange={updateField} getSchema={getSchema} />
</PivotItem>
<PivotItem headerText={formatMessage('Other')} itemKey={PromptTab.OTHER}>
<Other {...props} onChange={updateField} getSchema={getSchema} />
<PromptSettings {...props} onChange={updateField} getSchema={getSchema} />
</PivotItem>
</Pivot>
</BaseField>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export const tabs: Partial<IPivotStyles> = {
},
};

export const tabsContainer = css`
border-bottom: 1px solid #c8c6c4;
`;

export const validationItemInput = css`
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import React from 'react';
import { Dropdown, ResponsiveMode, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
import formatMessage from 'format-message';
import { RegexRecognizer } from '@bfc/shared';
import { DialogInfo } from '@bfc/indexers';

import { BFDWidgetProps } from '../types';
Expand All @@ -19,58 +18,35 @@ enum RecognizerType {
'luis',
}

function recognizerType(currentDialog: DialogInfo): RecognizerType | null {
const recognizer = currentDialog.content.recognizer;
if (!recognizer) {
return null;
}
function recognizerType({ content }: DialogInfo): RecognizerType | null {
const { recognizer } = content;

if (typeof recognizer === 'object' && recognizer.$type === 'Microsoft.RegexRecognizer') {
return RecognizerType.regex;
} else if (typeof recognizer === 'string') {
return RecognizerType.luis;
if (recognizer) {
if (typeof recognizer === 'object' && recognizer.$type === 'Microsoft.RegexRecognizer') {
return RecognizerType.regex;
} else if (typeof recognizer === 'string') {
return RecognizerType.luis;
}
}

return null;
}

function regexIntentOptions(currentDialog: DialogInfo): IDropdownOption[] {
const recognizer = currentDialog.content.recognizer as RegexRecognizer;
let options: IDropdownOption[] = [EMPTY_OPTION];

if (!recognizer) {
return options;
}

if (recognizer.intents) {
options = options.concat(recognizer.intents.map(i => ({ key: i.intent, text: i.intent })));
}

return options;
function regexIntentOptions({ content }: DialogInfo): IDropdownOption[] {
const { recognizer } = content;
return (recognizer?.intents || []).reduce(
(acc, { intent }) => (intent ? [...acc, { key: intent, text: intent }] : acc),
[EMPTY_OPTION]
);
}

export const IntentWidget: React.FC<BFDWidgetProps> = props => {
const { disabled, onChange, id, onFocus, onBlur, value, formContext, placeholder, label, schema } = props;
const { description } = schema;
const { currentDialog } = formContext;
let options: IDropdownOption[] = [];
let widgetLabel = label;
let isLuisSelected = false;

switch (recognizerType(currentDialog)) {
case RecognizerType.regex:
options = regexIntentOptions(currentDialog);
isLuisSelected = false;
break;
case RecognizerType.luis:
widgetLabel = `Trigger phrases(intent name: #${value || ''})`;
isLuisSelected = true;
break;
default:
options = [EMPTY_OPTION];
isLuisSelected = false;
break;
}
const type = recognizerType(currentDialog);
const options: IDropdownOption[] = type === RecognizerType.regex ? regexIntentOptions(currentDialog) : [EMPTY_OPTION];

const handleChange = (_e, option): void => {
if (option) {
Expand All @@ -80,21 +56,24 @@ export const IntentWidget: React.FC<BFDWidgetProps> = props => {

return (
<>
<WidgetLabel label={widgetLabel} description={description} id={id} />
{!isLuisSelected && (
<Dropdown
id={id.replace(/\.|#/g, '')}
onBlur={() => onBlur && onBlur(id, value)}
onChange={handleChange}
onFocus={() => onFocus && onFocus(id, value)}
options={options}
selectedKey={value || null}
responsiveMode={ResponsiveMode.large}
disabled={disabled || options.length === 1}
placeholder={options.length > 1 ? placeholder : formatMessage('No intents configured for this dialog')}
/>
{type === RecognizerType.luis ? (
<LuEditorWidget formContext={formContext} name={value} height={316} />
) : (
<>
<WidgetLabel label={label} description={description} id={id} />
<Dropdown
id={id}
onBlur={() => onBlur && onBlur(id, value)}
onChange={handleChange}
onFocus={() => onFocus && onFocus(id, value)}
options={options}
selectedKey={value || null}
responsiveMode={ResponsiveMode.large}
disabled={disabled || options.length === 1}
placeholder={options.length > 1 ? placeholder : formatMessage('No intents configured for this dialog')}
/>
</>
)}
{isLuisSelected && <LuEditorWidget formContext={formContext} onChange={onChange} name={value} height={316} />}
</>
);
};
Loading

0 comments on commit c04743a

Please sign in to comment.