Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: visual editor lg template don't show #1707

Merged
merged 5 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions Composer/packages/client/src/ShellApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,6 @@ export const ShellApi: React.FC = () => {
return true;
}

function getLgTemplates({ id }, event) {
if (isEventSourceValid(event) === false) return false;

if (id === undefined) throw new Error('must have a file id');
const file = lgFiles.find(file => file.id === id);
if (!file) throw new Error(`lg file ${id} not found`);

return lgUtil.parse(file.content);
}

/**
*
* @param {
Expand Down Expand Up @@ -302,7 +292,6 @@ export const ShellApi: React.FC = () => {
apiClient.registerApi('copyLgTemplate', copyLgTemplateHandler);
apiClient.registerApi('removeLgTemplate', removeLgTemplateHandler);
apiClient.registerApi('removeLgTemplates', removeLgTemplatesHandler);
apiClient.registerApi('getLgTemplates', ({ id }, event) => getLgTemplates({ id }, event));
apiClient.registerApi('navTo', navTo);
apiClient.registerApi('onFocusEvent', focusEvent);
apiClient.registerApi('onFocusSteps', focusSteps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ const shellApi: ShellApi = {
return apiClient.apiCall('updateLgFile', { id, content });
},

getLgTemplates: id => {
return apiClient.apiCall('getLgTemplates', { id });
},

createLgTemplate: (id, template, position) => {
return apiClient.apiCall('createLgTemplate', { id, template, position });
},
Expand Down
16 changes: 12 additions & 4 deletions Composer/packages/extensions/obiformeditor/demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ const luFiles: LuFile[] = [
parsedContent: {
LUISJsonStructure: {
intents: [{ name: 'FirstHello' }, { name: 'FirstGoodBye' }],
utterances: [{ intent: 'FirstHello', text: 'Hi' }, { intent: 'FirstGoodBye', text: 'Goodbye' }],
utterances: [
{ intent: 'FirstHello', text: 'Hi' },
{ intent: 'FirstGoodBye', text: 'Goodbye' },
],
},
},
},
Expand All @@ -100,7 +103,10 @@ const luFiles: LuFile[] = [
parsedContent: {
LUISJsonStructure: {
intents: [{ name: 'SecondHello' }, { name: 'SecondGoodBye' }],
utterances: [{ intent: 'SecondHello', text: 'Good morning' }, { intent: 'SecondGoodBye', text: 'See ya!' }],
utterances: [
{ intent: 'SecondHello', text: 'Good morning' },
{ intent: 'SecondGoodBye', text: 'See ya!' },
],
},
},
},
Expand All @@ -111,7 +117,10 @@ const luFiles: LuFile[] = [
parsedContent: {
LUISJsonStructure: {
intents: [{ name: 'ThirdHello' }, { name: 'ThirdGoodbye' }],
utterances: [{ intent: 'ThirdHello', text: 'Hello' }, { intent: 'ThirdGoodbye', text: 'Later' }],
utterances: [
{ intent: 'ThirdHello', text: 'Hello' },
{ intent: 'ThirdGoodbye', text: 'Later' },
],
},
},
},
Expand Down Expand Up @@ -154,7 +163,6 @@ const mockShellApi = [
'updateLgFile',
'createLuFile',
'createLgFile',
'getLgTemplates',
'createLgTemplate',
'updateLgTemplate',
'validateExpression',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { jsx } from '@emotion/core';
import { useContext, FC, useEffect, useState, useRef } from 'react';
import { MarqueeSelection, Selection } from 'office-ui-fabric-react/lib/MarqueeSelection';
import { deleteAction, deleteActions, LgTemplateRef, LgMetaData } from '@bfc/shared';
import { deleteAction, deleteActions, LgTemplateRef, LgMetaData, LgFile } from '@bfc/shared';

import { NodeEventTypes } from '../constants/NodeEventTypes';
import { KeyboardCommandTypes, KeyboardPrimaryTypes } from '../constants/KeyboardCommandTypes';
Expand Down Expand Up @@ -349,6 +349,7 @@ interface ObiEditorProps {
path: string;
// Obi raw json
data: any;
lgFiles: LgFile[];
focusedSteps: string[];
onFocusSteps: (stepIds: string[], fragment?: string) => any;
focusedEvent: string;
Expand Down
5 changes: 3 additions & 2 deletions Composer/packages/extensions/visual-designer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
data: inputData,
shellApi,
hosted,
lgFiles,
}): JSX.Element => {
const dataCache = useRef({});

Expand All @@ -53,7 +54,6 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
onCopy,
saveData,
updateLgTemplate,
getLgTemplates,
copyLgTemplate,
removeLgTemplate,
removeLgTemplates,
Expand All @@ -67,9 +67,9 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
focusedId,
focusedEvent,
focusedTab,
lgFiles,
clipboardActions: clipboardActions || [],
updateLgTemplate,
getLgTemplates,
copyLgTemplate,
removeLgTemplate,
removeLgTemplates,
Expand All @@ -84,6 +84,7 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
key={dialogId}
path={dialogId}
data={data}
lgFiles={lgFiles}
focusedSteps={focusedActions}
onFocusSteps={onFocusSteps}
focusedEvent={focusedEvent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
// Licensed under the MIT License.

import React from 'react';
import { ShellApi } from '@bfc/shared';
import { ShellApi, LgFile } from '@bfc/shared';

type ShellApiFuncs =
| 'getLgTemplates'
| 'copyLgTemplate'
| 'removeLgTemplate'
| 'removeLgTemplates'
| 'updateLgTemplate';
type ShellApiFuncs = 'copyLgTemplate' | 'removeLgTemplate' | 'removeLgTemplates' | 'updateLgTemplate';

interface NodeRendererContextValue extends Pick<ShellApi, ShellApiFuncs> {
focusedId?: string;
focusedEvent?: string;
focusedTab?: string;
lgFiles: LgFile[];
clipboardActions: any[];
}

export const NodeRendererContext = React.createContext<NodeRendererContextValue>({
focusedId: '',
focusedEvent: '',
focusedTab: '',
lgFiles: [],
clipboardActions: [],
getLgTemplates: () => Promise.resolve([]),
copyLgTemplate: () => Promise.resolve(''),
removeLgTemplate: () => Promise.resolve(),
removeLgTemplates: () => Promise.resolve(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LgTemplateRef } from '@bfc/shared';
import { NodeRendererContext } from '../store/NodeRendererContext';

export const useLgTemplate = (str?: string, dialogId?: string) => {
const { getLgTemplates } = useContext(NodeRendererContext);
const { lgFiles } = useContext(NodeRendererContext);
const [templateText, setTemplateText] = useState('');
let cancelled = false;

Expand All @@ -18,12 +18,15 @@ export const useLgTemplate = (str?: string, dialogId?: string) => {

if (templateId && dialogId) {
// this is an LG template, go get it's content
if (!getLgTemplates || typeof getLgTemplates !== 'function') {

const lgFile = Array.isArray(lgFiles) ? lgFiles.find(({ id }) => id === 'common') : null;

if (!lgFile) {
setTemplateText(str || '');
return;
}

const templates = getLgTemplates ? await getLgTemplates('common') : [];
const [template] = templates.filter(({ name }) => {
const template = lgFile.templates.find(({ name }) => {
return name === templateId;
});

Expand Down
1 change: 0 additions & 1 deletion Composer/packages/lib/shared/src/types/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export interface ShellApi {
createLuFile: (id: string) => Promise<void>;
updateLuFile: (luFile: { id: string; content: string }) => Promise<void>;
updateLgFile: (id: string, content: string) => Promise<void>;
getLgTemplates: (id: string) => Promise<LgTemplate[]>;
copyLgTemplate: (id: string, fromTemplateName: string, toTemplateName?: string) => Promise<string>;
createLgTemplate: (id: string, template: Partial<LgTemplate>, position: number) => Promise<void>;
updateLgTemplate: (id: string, templateName: string, templateStr: string) => Promise<void>;
Expand Down