Skip to content

Commit

Permalink
Merge branch 'luhan/updateSchema' of https://github.com/microsoft/Bot…
Browse files Browse the repository at this point in the history
…Framework-Composer into luhan/updateSchema
  • Loading branch information
luhan2017 committed Dec 17, 2019
2 parents 3c411b9 + d441860 commit 006f41c
Show file tree
Hide file tree
Showing 32 changed files with 1,257 additions and 548 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import debounce from 'lodash/debounce';
import isEmpty from 'lodash/isEmpty';
import { LgFile } from '@bfc/indexers';
import { editor } from '@bfcomposer/monaco-editor/esm/vs/editor/editor.api';
import { lgIndexer, Diagnostic } from '@bfc/indexers';
import { lgIndexer, Diagnostic, combineMessage, isValid } from '@bfc/indexers';

import { StoreContext } from '../../store';
import * as lgUtil from '../../utils/lgUtil';

const { check, isValid, combineMessage } = lgIndexer;
const { check } = lgIndexer;

interface CodeEditorProps {
file: LgFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Nav, INavLinkGroup, INavLink } from 'office-ui-fabric-react/lib/Nav';
import { LGTemplate } from 'botbuilder-lg';
import { RouteComponentProps } from '@reach/router';
import get from 'lodash/get';
import { lgIndexer } from '@bfc/indexers';
import { isValid } from '@bfc/indexers';

import { LoadingSpinner } from '../../components/LoadingSpinner';
import { StoreContext } from '../../store';
Expand All @@ -35,9 +35,7 @@ const CodeEditor = React.lazy(() => import('./code-editor'));
const LGPage: React.FC<RouteComponentProps> = props => {
const { state } = useContext(StoreContext);
const { lgFiles, dialogs } = state;
const [editMode, setEditMode] = useState(
lgFiles.filter(file => lgIndexer.isValid(file.diagnostics) === false).length > 0
);
const [editMode, setEditMode] = useState(lgFiles.filter(file => !isValid(file.diagnostics)).length > 0);
const [fileValid, setFileValid] = useState(true);
const [inlineTemplate, setInlineTemplate] = useState<null | lgUtil.Template>(null);
const [line, setLine] = useState<number>(0);
Expand Down Expand Up @@ -110,7 +108,7 @@ const LGPage: React.FC<RouteComponentProps> = props => {

useEffect(() => {
const errorFiles = lgFiles.filter(file => {
return lgIndexer.isValid(file.diagnostics) === false;
return !isValid(file.diagnostics);
});
const hasError = errorFiles.length !== 0;
setFileValid(hasError === false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import formatMessage from 'format-message';
import { NeutralColors, FontSizes } from '@uifabric/fluent-theme';
import { DialogInfo, LgFile } from '@bfc/indexers';
import { LGTemplate, LGParser } from 'botbuilder-lg';
import { lgIndexer } from '@bfc/indexers';
import { isValid } from '@bfc/indexers';
import get from 'lodash/get';

import { StoreContext } from '../../store';
Expand All @@ -44,7 +44,7 @@ const TableView: React.FC<TableViewProps> = props => {
useEffect(() => {
if (isEmpty(lgFile)) return;
let allTemplates: LGTemplate[] = [];
if (lgIndexer.isValid(lgFile.diagnostics) === true) {
if (isValid(lgFile.diagnostics)) {
const resource = LGParser.parse(lgFile.content, '');
allTemplates = get(resource, 'templates', []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { LuEditor } from '@bfc/code-editor';
import get from 'lodash/get';
import debounce from 'lodash/debounce';
import isEmpty from 'lodash/isEmpty';

import * as luUtil from '../../utils/luUtil';
import { combineMessage, isValid } from '@bfc/indexers';

export default function CodeEditor(props) {
const { file, errorMsg: updateErrorMsg } = props;
Expand All @@ -34,8 +33,8 @@ export default function CodeEditor(props) {

// diagnostics is load file error,
// updateErrorMsg is save file return error.
const isInvalid = !luUtil.isValid(diagnostics) || updateErrorMsg !== '';
const errorMsg = isInvalid ? `${luUtil.combineMessage(diagnostics)}\n ${updateErrorMsg}` : '';
const isInvalid = !isValid(file.diagnostics) || updateErrorMsg !== '';
const errorMsg = isInvalid ? `${combineMessage(diagnostics)}\n ${updateErrorMsg}` : '';

return (
<LuEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import { ScrollablePane, ScrollbarVisibility } from 'office-ui-fabric-react/lib/
import { Sticky, StickyPositionType } from 'office-ui-fabric-react/lib/Sticky';
import formatMessage from 'format-message';
import { NeutralColors, FontSizes } from '@uifabric/fluent-theme';
import { isValid, combineMessage } from '@bfc/indexers';

import { OpenConfirmModal, DialogStyle } from '../../components/Modal';
import { StoreContext } from '../../store';
import * as luUtil from '../../utils/luUtil';
import { navigateTo } from '../../utils';

import { formCell, luPhraseCell } from './styles';
Expand Down Expand Up @@ -71,9 +71,7 @@ export default function TableView(props) {
}, [luFiles, activeDialog]);

function checkErrors(files) {
return files.filter(file => {
return luUtil.isValid(file.diagnostics) === false;
});
return files.filter(file => !isValid(file.diagnostics));
}

function getIntentState(file) {
Expand All @@ -90,7 +88,7 @@ export default function TableView(props) {

async function showErrors(files) {
for (const file of files) {
const errorMsg = luUtil.combineMessage(file.diagnostics);
const errorMsg = combineMessage(file.diagnostics);
const errorTitle = formatMessage('There was a problem parsing {fileId}.lu file.', { fileId: file.id });
const confirmed = await OpenConfirmModal(errorTitle, errorMsg, {
style: DialogStyle.Console,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { useContext, useMemo } from 'react';
import { lgIndexer } from '@bfc/indexers';
import { createSingleMessage } from '@bfc/indexers';

import { StoreContext } from '../../store';
import { replaceDialogDiagnosticLabel } from '../../utils';
Expand Down Expand Up @@ -35,7 +35,7 @@ export default function useNotifications(filter?: string) {
notifactions.push({
type: 'lu',
location,
message: diagnostic.text,
message: createSingleMessage(diagnostic),
severity: 'Error',
diagnostic,
id: lufile.id,
Expand All @@ -49,7 +49,7 @@ export default function useNotifications(filter?: string) {
type: 'lg',
severity: DiagnosticSeverity[diagnostic.severity] || '',
location,
message: lgIndexer.createSingleMessage(diagnostic),
message: createSingleMessage(diagnostic),
diagnostic,
id: lgFile.id,
});
Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/client/src/utils/lgUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { LGParser, LGTemplate } from 'botbuilder-lg';
import { lgIndexer } from '@bfc/indexers';
import { lgIndexer, combineMessage, isValid } from '@bfc/indexers';

const { check, isValid, combineMessage, parse } = lgIndexer;
const { check, parse } = lgIndexer;
export interface Template {
name: string;
parameters?: string[];
Expand All @@ -20,7 +20,7 @@ export interface Template {
export function checkLgContent(content: string, id: string) {
// check lg content, make up error message
const diagnostics = check(content, id);
if (isValid(diagnostics) === false) {
if (!isValid(diagnostics)) {
const errorMsg = combineMessage(diagnostics);
throw new Error(errorMsg);
}
Expand Down
13 changes: 1 addition & 12 deletions Composer/packages/client/src/utils/luUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { LuFile, DialogInfo, LuDiagnostic } from '@bfc/indexers';
import { LuFile, DialogInfo } from '@bfc/indexers';

export function getReferredFiles(luFiles: LuFile[], dialogs: DialogInfo[]) {
return luFiles.filter(file => {
Expand All @@ -11,14 +11,3 @@ export function getReferredFiles(luFiles: LuFile[], dialogs: DialogInfo[]) {
return false;
});
}

export function isValid(diagnostics: LuDiagnostic[]) {
return diagnostics.length === 0;
}

export function combineMessage(diagnostics: LuDiagnostic[]) {
return diagnostics.reduce((msg, d) => {
msg += `${d.text}\n`;
return msg;
}, '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"Microsoft.DeleteProperty": {
"title": "Delete a Property"
},
"Microsoft.DeleteProperties": {
"title": "Delete Properties"
},
"Microsoft.EditArray": {
"title": "Edit an Array Property"
},
Expand Down Expand Up @@ -128,6 +131,9 @@
"Microsoft.SetProperty": {
"title": "Set a Property"
},
"Microsoft.setProperties": {
"title": "Set Properties"
},
"Microsoft.SwitchCondition": {
"title": "Branch: Switch"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ export const UserInput: React.FC<UserInputProps> = props => {
</div>
{getSchema('outputFormat') && (
<div css={field}>
<SelectWidget
<TextWidget
onChange={onChange('outputFormat')}
schema={getSchema('outputFormat')}
id={idSchema.outputFormat.__id}
value={formData.outputFormat}
label={formatMessage('Output Format')}
formContext={props.formContext}
rawErrors={errorSchema.outputFormat && errorSchema.outputFormat.__errors}
options={{ enumOptions: getOptions(getSchema('outputFormat')) }}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import { LuEditor } from '@bfc/code-editor';
import { LuFile } from '@bfc/indexers';

Expand All @@ -13,29 +13,15 @@ interface InlineLuEditorProps {

const InlineLuEditor: React.FC<InlineLuEditorProps> = props => {
const { file, onSave, errorMsg } = props;
const { content, diagnostics } = file;
const { content } = file;
const [localContent, setLocalContent] = useState(content || '');

const errorFromDiagnostics = diagnostics
? diagnostics
.map(item => {
return item.text;
})
.join('\n')
: '';

const [localErrorMsg, setLocalErrorMsg] = useState(errorFromDiagnostics);

useEffect(() => {
setLocalErrorMsg(errorMsg);
}, [errorMsg]);

const commitChanges = value => {
setLocalContent(value);
onSave(value);
};

return <LuEditor value={localContent} onChange={commitChanges} errorMsg={localErrorMsg} height={450} />;
return <LuEditor value={localContent} onChange={commitChanges} errorMsg={errorMsg} height={450} />;
};

export default InlineLuEditor;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FieldProps } from '@bfcomposer/react-jsonschema-form';
import { Dropdown, ResponsiveMode, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner';
import { MicrosoftIRecognizer } from '@bfc/shared';
import { LuFile } from '@bfc/indexers';
import { LuFile, combineMessage } from '@bfc/indexers';

import { BaseField } from '../BaseField';
import { LoadingSpinner } from '../../../LoadingSpinner';
Expand Down Expand Up @@ -39,9 +39,7 @@ export const RecognizerField: React.FC<FieldProps<MicrosoftIRecognizer>> = props
//make the inline editor show error message
useEffect(() => {
if (selectedFile && selectedFile.diagnostics.length > 0) {
const msg = selectedFile.diagnostics.reduce((msg: string, diagnostic) => {
return (msg += `${diagnostic.text}\n`);
}, '');
const msg = combineMessage(selectedFile.diagnostics);
setErrorMsg(msg);
} else {
setErrorMsg('');
Expand Down
64 changes: 57 additions & 7 deletions Composer/packages/extensions/obiformeditor/src/schema/uischema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const uiSchema: { [key in SDKTypes]?: UiSchema } = {
options: {
'ui:field': 'CustomObjectField',
},
'ui:order': ['dialog', 'property', '*'],
'ui:order': ['dialog', 'options', 'resultProperty', 'includeActivity', '*'],
},
[SDKTypes.CancelAllDialogs]: {
eventValue: {
Expand All @@ -78,11 +78,6 @@ export const uiSchema: { [key in SDKTypes]?: UiSchema } = {
'ui:field': 'StepsField',
},
},
[SDKTypes.EmitEvent]: {
eventValue: {
'ui:field': 'CustomObjectField',
},
},
[SDKTypes.Foreach]: {
'ui:order': ['itemsProperty', 'actions', '*'],
'ui:hidden': ['actions'],
Expand All @@ -103,6 +98,31 @@ export const uiSchema: { [key in SDKTypes]?: UiSchema } = {
[SDKTypes.IfCondition]: {
'ui:hidden': ['actions', 'elseActions', ...globalHidden],
},
[SDKTypes.SetProperties]: {
assignments: {
'ui:options': {
object: true,
},
items: {
'ui:options': {
hideDescription: true,
inline: true,
},
property: {
'ui:options': {
hideLabel: true,
transparentBorder: true,
},
},
value: {
'ui:options': {
hideLabel: true,
transparentBorder: true,
},
},
},
},
},
[SDKTypes.OnActivity]: {
...triggerUiSchema,
},
Expand Down Expand Up @@ -177,7 +197,29 @@ export const uiSchema: { [key in SDKTypes]?: UiSchema } = {
'ui:order': ['connectionName', '*'],
},
[SDKTypes.QnAMakerDialog]: {
'ui:hidden': ['strictFilters'],
strictFilters: {
'ui:options': {
object: true,
},
items: {
'ui:options': {
hideDescription: true,
inline: true,
},
name: {
'ui:options': {
hideLabel: true,
transparentBorder: true,
},
},
value: {
'ui:options': {
hideLabel: true,
transparentBorder: true,
},
},
},
},
},
[SDKTypes.ReplaceDialog]: {
dialog: {
Expand All @@ -187,6 +229,14 @@ export const uiSchema: { [key in SDKTypes]?: UiSchema } = {
'ui:field': 'CustomObjectField',
},
'ui:hidden': [...globalHidden],
'ui:order': ['dialog', 'options', 'includeActivity', '*'],
},
[SDKTypes.RepeatDialog]: {
options: {
'ui:field': 'CustomObjectField',
},
'ui:hidden': [...globalHidden],
'ui:order': ['options', 'includeActivity', '*'],
},
[SDKTypes.SwitchCondition]: {
cases: {
Expand Down
Loading

0 comments on commit 006f41c

Please sign in to comment.