Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b23816c
navigateTo dialog
zhixzhan Sep 17, 2019
26a0bdd
inline lg editor, edit on partial code range
zhixzhan Sep 18, 2019
989e96a
wrap editor event
zhixzhan Sep 18, 2019
266c3ed
update demo
zhixzhan Oct 10, 2019
2a3e43b
support code range editing
zhixzhan Oct 11, 2019
a542bcc
form lg inline editing
zhixzhan Oct 11, 2019
1f76d34
Merge branch 'master' into zhixzhan/inline-editor
zhixzhan Oct 11, 2019
1ade349
form inline lg editing
zhixzhan Oct 11, 2019
0c2bacf
upgrade lg parser
zhixzhan Oct 11, 2019
f4b4cfc
coderange -1 for end line
zhixzhan Oct 11, 2019
bcbb65a
form inline add lg template
zhixzhan Oct 11, 2019
ecab009
clean
zhixzhan Oct 11, 2019
d5b19ec
code refine
zhixzhan Oct 12, 2019
0672b31
better handle editor instance
zhixzhan Oct 12, 2019
abdd181
Merge branch 'master' into zhixzhan/inline-editor
boydc2014 Oct 14, 2019
eb9ec6b
Merge branch 'master' into zhixzhan/inline-editor
cwhitten Oct 14, 2019
367cebd
use default 'common.lg'
zhixzhan Oct 15, 2019
bbacd74
add missing dialogId
zhixzhan Oct 15, 2019
a4d9a95
Merge branch 'master' into zhixzhan/inline-editor
zhixzhan Oct 15, 2019
be6de52
CSP issue, LGbundle.js remove eval
zhixzhan Oct 15, 2019
ea6f693
Merge branch 'master' of https://github.com/Microsoft/BotFramework-Co…
cwhitten Oct 15, 2019
95f81e6
Merge branch 'master' into zhixzhan/inline-editor
cwhitten Oct 15, 2019
11c41f2
Merge branch 'master' into zhixzhan/inline-editor
cwhitten Oct 15, 2019
f5a0a47
Merge branch 'master' into zhixzhan/inline-editor
cwhitten Oct 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Composer/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"babel-plugin-named-asset-import": "^0.3.1",
"babel-preset-react-app": "^7.0.1",
"bfj": "6.1.1",
"botbuilder-lg": "https://botbuilder.myget.org/F/botbuilder-declarative/npm/botbuilder-lg/-/4.6.6.tgz",
"botbuilder-lg": "https://botbuilder.myget.org/F/botbuilder-declarative/npm/botbuilder-lg/-/4.6.8.tgz",
"case-sensitive-paths-webpack-plugin": "2.2.0",
"code-editor": "*",
"codemirror": "^5.45.0",
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/ShellApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const ShellApi: React.FC = () => {
const { dialogs, schemas, lgFiles, luFiles, designPageLocation, focusPath, breadcrumb } = state;
const updateDialog = actions.updateDialog;
const updateLuFile = actions.updateLuFile; //if debounced, error can't pass to form
const updateLgFile = useDebouncedFunc(actions.updateLgFile);
const updateLgFile = actions.updateLgFile;
const updateLgTemplate = useDebouncedFunc(actions.updateLgTemplate);
const createLuFile = actions.createLuFile;
const createLgFile = actions.createLgFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const shellApi = {
return apiClient.apiCall('updateLuFile', luFile);
},

updateLgFile: (id: string, content: string) => {
return apiClient.apiCall('updateLgFile', { id, content });
},

getLgTemplates: (id: string) => {
return apiClient.apiCall('getLgTemplates', { id });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { get, debounce, isEmpty } from 'lodash';
import * as lgUtil from '../../utils/lgUtil';

export default function CodeEditor(props) {
const { file } = props;
const { file, codeRange } = props;
const onChange = debounce(props.onChange, 500);
const [diagnostics, setDiagnostics] = useState(get(file, 'diagnostics', []));
const [content, setContent] = useState(get(file, 'content', ''));
Expand Down Expand Up @@ -41,6 +41,7 @@ export default function CodeEditor(props) {
lineDecorationsWidth: undefined,
lineNumbersMinChars: false,
}}
codeRange={codeRange}
errorMsg={errorMsg}
value={content}
onChange={_onChange}
Expand All @@ -51,4 +52,5 @@ export default function CodeEditor(props) {
CodeEditor.propTypes = {
file: PropTypes.object,
onChange: PropTypes.func,
codeRange: PropTypes.object,
};
17 changes: 14 additions & 3 deletions Composer/packages/client/src/pages/language-generation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useContext, Fragment, useEffect, useState, useMemo } from 'react
import formatMessage from 'format-message';
import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
import { Nav } from 'office-ui-fabric-react/lib/Nav';
import get from 'lodash.get';

import { OpenAlertModal, DialogStyle } from '../../components/Modal';
import { StoreContext } from '../../store';
Expand All @@ -25,6 +26,7 @@ export const LGPage = props => {
const { state, actions } = useContext(StoreContext);
const { lgFiles, dialogs } = state;
const [editMode, setEditMode] = useState(false);
const [codeRange, setCodeRange] = useState(null);

const subPath = props['*'];
const isRoot = subPath === '';
Expand Down Expand Up @@ -96,6 +98,11 @@ export const LGPage = props => {
}
}

function onToggleEditMode() {
setEditMode(!editMode);
setCodeRange(null);
}

async function onChange(newContent) {
const payload = {
id: lgFile.id,
Expand All @@ -113,7 +120,11 @@ export const LGPage = props => {

// #TODO: get line number from lg parser, then deep link to code editor this
// Line
function onTableViewClickEdit() {
function onTableViewClickEdit(template) {
setCodeRange({
startLineNumber: get(template, 'ParseTree._start._line', 0),
endLineNumber: get(template, 'ParseTree._stop._line', 0),
});
navigateTo(`/language-generation`);
setEditMode(true);
}
Expand All @@ -139,7 +150,7 @@ export const LGPage = props => {
offText={formatMessage('Edit mode')}
checked={editMode}
disabled={!isRoot && editMode === false}
onChange={() => setEditMode(!editMode)}
onChange={onToggleEditMode}
/>
</div>
</div>
Expand Down Expand Up @@ -175,7 +186,7 @@ export const LGPage = props => {
</div>
<div css={contentEditor}>
{editMode ? (
<CodeEditor file={lgFile} onChange={onChange} />
<CodeEditor file={lgFile} codeRange={codeRange} onChange={onChange} />
) : (
<TableView file={lgFile} activeDialog={activeDialog} onClickEdit={onTableViewClickEdit} />
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import { useState, useEffect } from 'react';
import { RichEditor } from 'code-editor';
import { useState } from 'react';
import { LgEditor } from 'code-editor';
import debounce from 'lodash.debounce';

import { FormContext } from '../types';

const LG_HELP =
'https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/language-generation/docs/lg-file-format.md';

const getInitialTemplate = (fieldName: string, formData?: string): string => {
let newTemplate = formData || '';
let newTemplate = formData || '- ';

if (newTemplate.includes(`bfd${fieldName}-`)) {
return '';
Expand All @@ -29,57 +30,50 @@ interface LgEditorWidgetProps {

export const LgEditorWidget: React.FC<LgEditorWidgetProps> = props => {
const { formContext, name, value, height = 250 } = props;
const [templateToRender, setTemplateToRender] = useState({ Name: '', Body: '' });
const lgId = `bfd${name}-${formContext.dialogId}`;
const [errorMsg, setErrorMsg] = useState('');

const ensureTemplate = async (newBody?: string): Promise<void> => {
const templates = await formContext.shellApi.getLgTemplates('common');
const template = templates.find(template => {
return template.Name === lgId;
});
if (template === null || template === undefined) {
const newTemplate = getInitialTemplate(name, newBody);
const lgFileId = formContext.currentDialog.lgFile || 'common';
const lgFile = formContext.lgFiles.find(file => file.id === lgFileId);
const template = lgFile
? lgFile.templates.find(template => {
return template.Name === lgId;
})
: undefined;

if (formContext.dialogId && newTemplate) {
formContext.shellApi.updateLgTemplate('common', lgId, newTemplate);
props.onChange(`[${lgId}]`);
// template body code range
const codeRange = template
? {
startLineNumber: template.Range.startLineNumber + 1, // cut template name
endLineNumber: template.Range.endLineNumber,
}
setTemplateToRender({ Name: `# ${lgId}`, Body: newTemplate });
} else {
if (templateToRender.Name === '') {
setTemplateToRender({ Name: `# ${lgId}`, Body: template.Body });
}
}
};
: -1;

let content = lgFile ? lgFile.content : '';
if (!template) {
const newTemplateBody = getInitialTemplate(name, value || '-');
content += ['\n', '# ' + lgId, newTemplateBody].join('\n');
}

const onChange = (data): void => {
const onChange = debounce((data): void => {
// hit the lg api and replace it's Body with data
if (formContext.dialogId) {
let dataToEmit = data.trim();
if (dataToEmit.length > 0 && dataToEmit[0] !== '-') {
dataToEmit = `-${dataToEmit}`;
}

if (dataToEmit.length > 0) {
setTemplateToRender({ Name: templateToRender.Name, Body: data });
formContext.shellApi
.updateLgTemplate('common', lgId, dataToEmit)
.then(() => setErrorMsg(''))
.catch(error => setErrorMsg(error));
props.onChange(`[${lgId}]`);
} else {
setTemplateToRender({ Name: templateToRender.Name, Body: '' });
formContext.shellApi.removeLgTemplate('common', lgId);
props.onChange(undefined);
}
formContext.shellApi
.updateLgFile(lgFileId, data)
.then(() => setErrorMsg(''))
.catch(error => setErrorMsg(error));
props.onChange(`[${lgId}]`);
}
};

useEffect(() => {
ensureTemplate(value);
}, [formContext.dialogId]);
}, 200);

const { Body } = templateToRender;
return <RichEditor errorMsg={errorMsg} value={Body} onChange={onChange} helpURL={LG_HELP} height={height} />;
return (
<LgEditor
codeRange={codeRange}
errorMsg={errorMsg}
value={content}
onChange={onChange}
helpURL={LG_HELP}
height={height}
/>
);
};
9 changes: 9 additions & 0 deletions Composer/packages/extensions/obiformeditor/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ export interface LuFile {
};
}

export interface CodeRange {
startLineNumber: number;
endLineNumber: number;
}

export interface LgFile {
id: string;
relativePath: string;
content: string;
templates: [LgTemplate];
}
export interface LgTemplate {
Name: string;
Body: string;
Parameters: string;
Range: CodeRange;
}

export interface FormData {
Expand All @@ -74,6 +82,7 @@ export interface ShellApi {
onFocusEvent: (eventId: string) => Promise<void>;
createLuFile: (id: string) => Promise<void>;
updateLuFile: (id: string, content: string) => Promise<void>;
updateLgFile: (id: string, content: string) => Promise<void>;
getLgTemplates: (id: string) => Promise<LgTemplate[]>;
createLgTemplate: (id: string, template: LgTemplate, position: number) => Promise<void>;
updateLgTemplate: (id: string, templateName: string, templateStr: string) => Promise<void>;
Expand Down
13 changes: 12 additions & 1 deletion Composer/packages/lib/code-editor/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ import { RichEditor } from '../../src';
const LU_HELP =
'https://github.com/Microsoft/botbuilder-tools/blob/master/packages/Ludown/docs/lu-file-format.md#lu-file-format';

const content = `# Greeting
-Good morning
-Good afternoon
-Good evening`;

export default function App() {
const [value, setValue] = useState<string>('');
const [value, setValue] = useState<string>(content);
const [showError, setShowError] = useState(true);

const placeholder = `> To learn more about the LU file format, read the documentation at
> ${LU_HELP}`;
const errorMsg = showError ? 'example error' : undefined;

const codeRange = {
startLineNumber: 2,
endLineNumber: 3,
};

return (
<div style={{ height: '99vh', width: '100%' }}>
<div style={{ marginBottom: '10px' }}>
Expand All @@ -21,6 +31,7 @@ export default function App() {
<RichEditor
onChange={newVal => setValue(newVal)}
value={value}
codeRange={codeRange}
placeholder={placeholder}
errorMsg={errorMsg}
helpURL="https://dev.botframework.com"
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/lib/code-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"dependencies": {
"@bfcomposer/monaco-editor-webpack-plugin": "^1.7.2",
"@bfcomposer/react-monaco-editor": "^0.30.4",
"@bfcomposer/react-monaco-editor": "^0.30.5",
"lodash.throttle": "^4.1.1"
}
}
Loading