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: use different shellData in Form and Flow's ExtensionContext #3784

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 27 additions & 23 deletions Composer/packages/client/src/pages/design/DesignPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ const DesignPage: React.FC<RouteComponentProps<{ dialogId: string; projectId: st
const [dialogJsonVisible, setDialogJsonVisibility] = useState(false);
const [currentDialog, setCurrentDialog] = useState<DialogInfo>(dialogs[0]);
const [exportSkillModalVisible, setExportSkillModalVisible] = useState(false);
const shell = useShell('ProjectTree');
const shell = useShell('DesignPage');
const shellForFlowEditor = useShell('FlowEditor');
const shellForPropertyEditor = useShell('PropertyEditor');
const triggerApi = useTriggerApi(shell.api);

useEffect(() => {
Expand Down Expand Up @@ -543,30 +545,32 @@ const DesignPage: React.FC<RouteComponentProps<{ dialogId: string; projectId: st
/>
<Toolbar toolbarItems={toolbarItems} />
</div>
<Extension plugins={pluginConfig} shell={shell.api} shellData={shell.data}>
<Conversation css={editorContainer}>
<div css={editorWrapper}>
<div aria-label={formatMessage('Authoring canvas')} css={visualPanel} role="region">
{breadcrumbItems}
{dialogJsonVisible ? (
<JsonEditor
key="dialogjson"
editorSettings={userSettings.codeEditor}
id={currentDialog.id}
schema={schemas.sdk.content}
value={currentDialog.content || undefined}
onChange={(data) => {
updateDialog({ id: currentDialog.id, content: data });
}}
/>
) : (
<Conversation css={editorContainer}>
<div css={editorWrapper}>
<div aria-label={formatMessage('Authoring canvas')} css={visualPanel} role="region">
{breadcrumbItems}
{dialogJsonVisible ? (
<JsonEditor
key="dialogjson"
editorSettings={userSettings.codeEditor}
id={currentDialog.id}
schema={schemas.sdk.content}
value={currentDialog.content || undefined}
onChange={(data) => {
updateDialog({ id: currentDialog.id, content: data });
}}
/>
) : (
<Extension plugins={pluginConfig} shell={shellForFlowEditor}>
<VisualEditor openNewTriggerModal={openNewTriggerModal} />
)}
</div>
<PropertyEditor key={focusPath} />
</Extension>
)}
</div>
</Conversation>
</Extension>
<Extension plugins={pluginConfig} shell={shellForPropertyEditor}>
<PropertyEditor key={focusPath} />
</Extension>
</div>
</Conversation>
</div>
</div>
<Suspense fallback={<LoadingSpinner />}>
Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/client/src/shell/useShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { useMemo, useRef } from 'react';
import { ShellApi, ShellData } from '@bfc/shared';
import { ShellApi, ShellData, Shell } from '@bfc/shared';
import isEqual from 'lodash/isEqual';
import { useRecoilValue } from 'recoil';
import formatMessage from 'format-message';
Expand Down Expand Up @@ -33,9 +33,9 @@ import { useLuApi } from './luApi';

const FORM_EDITOR = 'PropertyEditor';

type EventSource = 'VisualEditor' | 'PropertyEditor' | 'ProjectTree';
type EventSource = 'FlowEditor' | 'PropertyEditor' | 'DesignPage';

export function useShell(source: EventSource): { api: ShellApi; data: ShellData } {
export function useShell(source: EventSource): Shell {
const dialogMapRef = useRef({});
const botName = useRecoilValue(botNameState);
const dialogs = useRecoilValue(dialogsState);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import React, { useMemo } from 'react';
import { ShellApi, ShellData } from '@bfc/shared';
import { Shell } from '@bfc/shared';

import ExtensionContext from '../extensionContext';
import { PluginConfig } from '../types';

interface ExtensionProps {
shell: ShellApi;
shellData: ShellData;
shell: Shell;
plugins: PluginConfig;
}

export const Extension: React.FC<ExtensionProps> = function Extension(props) {
const { shell, shellData, plugins } = props;

export const Extension: React.FC<ExtensionProps> = ({ shell, plugins, children }) => {
const context = useMemo(() => {
return { shellApi: shell, shellData, plugins };
}, [shell, shellData, plugins]);
return { shellApi: shell.api, shellData: shell.data, plugins };
}, [shell.api, shell.data, plugins]);

return <ExtensionContext.Provider value={context}>{props.children}</ExtensionContext.Provider>;
return <ExtensionContext.Provider value={context}>{children}</ExtensionContext.Provider>;
};

export default Extension;
5 changes: 5 additions & 0 deletions Composer/packages/lib/shared/src/types/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ export interface ShellApi {
announce: (message: string) => void;
displayManifestModal: (manifestId: string) => void;
}

export interface Shell {
api: ShellApi;
data: ShellData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const renderSelectDialog = ({ createDialog, navTo, onChange } = {}) => {
],
};
return render(
<Extension shell={shell} shellData={shellData}>
<Extension shell={{ api: shell, data: shellData }}>
<SelectDialog {...props} />
</Extension>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const renderBeginSkillDialog = ({ value = {}, onChange = jest.fn() } = {}) => {
};

return render(
<Extension plugins={{}} shell={shell} shellData={shellData}>
<Extension plugins={{}} shell={{ api: shell, data: shellData }}>
<BeginSkillDialogField {...props} />
</Extension>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const renderSelectSkillDialog = ({ addSkillDialog, onChange } = {}) => {
};

return render(
<Extension shell={shell} shellData={shellData}>
<Extension shell={{ api: shell, data: shellData }}>
<SelectSkillDialog {...props} />
</Extension>
);
Expand Down