From f979c4698e497ea90c52efa6a58e634353fa54cb Mon Sep 17 00:00:00 2001 From: Long Alan Date: Thu, 5 Mar 2020 23:01:53 +0800 Subject: [PATCH 1/4] activity content truncated in visual editor --- .../src/components/elements/styledComponents.tsx | 1 + .../packages/extensions/visual-designer/src/utils/hooks.ts | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Composer/packages/extensions/visual-designer/src/components/elements/styledComponents.tsx b/Composer/packages/extensions/visual-designer/src/components/elements/styledComponents.tsx index 1bdc8fa122..e8a3e6b08d 100644 --- a/Composer/packages/extensions/visual-designer/src/components/elements/styledComponents.tsx +++ b/Composer/packages/extensions/visual-designer/src/components/elements/styledComponents.tsx @@ -47,6 +47,7 @@ export const SingleLineDiv = styled.div` export const TextDiv = styled.div` ${StandardFontCSS}; ${MultilineCSS}; + white-space: pre-wrap; line-height: 16px; display: inline-block; `; diff --git a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts index acf156af71..6de8b0afbf 100644 --- a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts +++ b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts @@ -33,8 +33,11 @@ export const useLgTemplate = (str?: string, dialogId?: string) => { } if (template && template.body) { - const [firstLine] = template.body.split('\n'); - setTemplateText(firstLine.startsWith('-') ? firstLine.substring(1) : firstLine); + const templateText = template.body + .split('\n') + .map(line => (line.startsWith('-') ? line.substring(1) : line)) + .join('\n'); + setTemplateText(templateText); } else { setTemplateText(''); } From 919f5d9b4ee8b1abbf00723f21d03e9e9adff85a Mon Sep 17 00:00:00 2001 From: Long Alan Date: Fri, 6 Mar 2020 17:05:45 +0800 Subject: [PATCH 2/4] show template in visual editor --- .../extensions/visual-designer/src/utils/hooks.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts index 6de8b0afbf..9fa8eb6efd 100644 --- a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts +++ b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts @@ -33,11 +33,15 @@ export const useLgTemplate = (str?: string, dialogId?: string) => { } if (template && template.body) { - const templateText = template.body - .split('\n') - .map(line => (line.startsWith('-') ? line.substring(1) : line)) - .join('\n'); - setTemplateText(templateText); + const templateTexts = template.body.split('\n').map(line => (line.startsWith('-') ? line.substring(1) : line)); + let showText = ''; + + if (templateTexts[0] && templateTexts[0] === '[activity') { + showText = templateTexts.find(text => text.includes('Text = '))?.split('Text = ')[1] || ''; + } else { + showText = templateTexts.join('\n'); + } + setTemplateText(showText); } else { setTemplateText(''); } From 45f619eac44da2844b8f4e427e7fcf6a7ba68fc0 Mon Sep 17 00:00:00 2001 From: Long Alan Date: Fri, 6 Mar 2020 18:05:41 +0800 Subject: [PATCH 3/4] fix data in toDobotWithLuis sample bot --- .../extensions/visual-designer/src/utils/hooks.ts | 2 +- .../ComposerDialogs/Main/Main.dialog | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts index 9fa8eb6efd..c110af5fae 100644 --- a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts +++ b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts @@ -36,7 +36,7 @@ export const useLgTemplate = (str?: string, dialogId?: string) => { const templateTexts = template.body.split('\n').map(line => (line.startsWith('-') ? line.substring(1) : line)); let showText = ''; - if (templateTexts[0] && templateTexts[0] === '[activity') { + if (templateTexts[0] && templateTexts[0].trim() === '[Activity') { showText = templateTexts.find(text => text.includes('Text = '))?.split('Text = ')[1] || ''; } else { showText = templateTexts.join('\n'); diff --git a/Composer/packages/server/assets/projects/ToDoBotWithLuisSample/ComposerDialogs/Main/Main.dialog b/Composer/packages/server/assets/projects/ToDoBotWithLuisSample/ComposerDialogs/Main/Main.dialog index d760ed5083..2145b05a40 100644 --- a/Composer/packages/server/assets/projects/ToDoBotWithLuisSample/ComposerDialogs/Main/Main.dialog +++ b/Composer/packages/server/assets/projects/ToDoBotWithLuisSample/ComposerDialogs/Main/Main.dialog @@ -314,7 +314,7 @@ { "$type": "Microsoft.SendActivity", "$designer": { - "id": "684852", + "id": "212971", "name": "Send a response" }, "activity": "${bfdactivity-212971()}" @@ -322,7 +322,7 @@ { "$type": "Microsoft.TextInput", "$designer": { - "id": "038757", + "id": "879447", "name": "Text input" }, "prompt": "${bfdprompt-879447()}", @@ -346,7 +346,7 @@ { "$type": "Microsoft.SendActivity", "$designer": { - "id": "593087", + "id": "056974", "name": "Send a response" }, "activity": "${bfdactivity-056974()}" @@ -356,7 +356,7 @@ { "$type": "Microsoft.SendActivity", "$designer": { - "id": "253146", + "id": "084161", "name": "Send a response" }, "activity": "${bfdactivity-084161()}" From 3bbb2c07f3557876030e09f229b4dfab8d85dfd9 Mon Sep 17 00:00:00 2001 From: Long Alan Date: Fri, 6 Mar 2020 20:53:41 +0800 Subject: [PATCH 4/4] refactor --- .../visual-designer/src/utils/hooks.ts | 12 +++--------- .../src/utils/normalizeLgTemplate.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 Composer/packages/extensions/visual-designer/src/utils/normalizeLgTemplate.ts diff --git a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts index c110af5fae..0ac62702d2 100644 --- a/Composer/packages/extensions/visual-designer/src/utils/hooks.ts +++ b/Composer/packages/extensions/visual-designer/src/utils/hooks.ts @@ -7,6 +7,8 @@ import { LgTemplateRef } from '@bfc/shared'; import { NodeRendererContext } from '../store/NodeRendererContext'; +import { normalizeLgTemplate } from './normalizeLgTemplate'; + export const useLgTemplate = (str?: string, dialogId?: string) => { const { getLgTemplates } = useContext(NodeRendererContext); const [templateText, setTemplateText] = useState(''); @@ -33,15 +35,7 @@ export const useLgTemplate = (str?: string, dialogId?: string) => { } if (template && template.body) { - const templateTexts = template.body.split('\n').map(line => (line.startsWith('-') ? line.substring(1) : line)); - let showText = ''; - - if (templateTexts[0] && templateTexts[0].trim() === '[Activity') { - showText = templateTexts.find(text => text.includes('Text = '))?.split('Text = ')[1] || ''; - } else { - showText = templateTexts.join('\n'); - } - setTemplateText(showText); + setTemplateText(normalizeLgTemplate(template)); } else { setTemplateText(''); } diff --git a/Composer/packages/extensions/visual-designer/src/utils/normalizeLgTemplate.ts b/Composer/packages/extensions/visual-designer/src/utils/normalizeLgTemplate.ts new file mode 100644 index 0000000000..06ff15a07b --- /dev/null +++ b/Composer/packages/extensions/visual-designer/src/utils/normalizeLgTemplate.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { LGTemplate } from 'botbuilder-lg'; + +export function normalizeLgTemplate(template: LGTemplate): string { + const templateTexts = template.body.split('\n').map(line => (line.startsWith('-') ? line.substring(1) : line)); + let showText = ''; + + if (templateTexts[0] && templateTexts[0].trim() === '[Activity') { + showText = templateTexts.find(text => text.includes('Text = '))?.split('Text = ')[1] || ''; + } else { + showText = templateTexts.join('\n'); + } + return showText; +}