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
50 commits
Select commit Hold shift + click to select a range
2f4ca8e
move copyUtils to folder
yeze322 Nov 5, 2019
8fd2c88
move DesignerData into SDK types
yeze322 Nov 5, 2019
7097919
reorg file
yeze322 Nov 5, 2019
71b0206
add a batch copy api
yeze322 Nov 5, 2019
7f5d900
copyIfCondition
yeze322 Nov 5, 2019
b208d9c
add a common shallow copy api
yeze322 Nov 5, 2019
5a7367b
apply shallow copy api in IfCondition
yeze322 Nov 5, 2019
5cfbffb
copySwitchCondition
yeze322 Nov 5, 2019
9cc211a
add sdk type SendActivity
yeze322 Nov 5, 2019
aea252f
copySendActivity
yeze322 Nov 5, 2019
9b0e28f
copyInputDialog
yeze322 Nov 5, 2019
dba2194
apply ExternalApi type in copyAdaptiveActionList
yeze322 Nov 5, 2019
e8aa0aa
implement the parent copier `copyAdaptiveAction`
yeze322 Nov 5, 2019
e71023a
update interface `deepCopyAction` inside 'shared'
yeze322 Nov 5, 2019
0d0a494
remove dup lisense
yeze322 Nov 5, 2019
bb16187
change `copyLgTemplate` interface
yeze322 Nov 5, 2019
48d1328
Merge branch 'master' into zeye/copy-constructor
yeze322 Nov 6, 2019
6eb943b
rename copyUtils.test to copyAdaptiveAction.test
yeze322 Nov 6, 2019
0cc40b2
add test cases for SwitchCondition and IfCondition
yeze322 Nov 6, 2019
d41f324
copyForeach
yeze322 Nov 6, 2019
aa34f7b
copyEditActions
yeze322 Nov 6, 2019
c829101
copyForeach UT
yeze322 Nov 6, 2019
931de23
copyEditActions UT
yeze322 Nov 6, 2019
5e97653
register new copiers to copyAdaptiveAction
yeze322 Nov 6, 2019
cea8619
Merge branch 'master' into zeye/copy-constructor
yeze322 Nov 7, 2019
fee44ab
Merge branch 'master' into zeye/copy-constructor
yeze322 Nov 11, 2019
3bbc01c
make top level copy interface typed
yeze322 Nov 11, 2019
5562a51
make `copyAdaptiveActionList` return value typed
yeze322 Nov 11, 2019
17452c1
Merge branch 'master' into zeye/copy-constructor
yeze322 Nov 13, 2019
a27e55b
leverage function template to omit type conversion
yeze322 Nov 13, 2019
a51cb16
add new schema types in `MicrosoftIDialog`
yeze322 Nov 13, 2019
190a4c3
split test cases in copyAdaptiveAction to certain files
yeze322 Nov 13, 2019
69c3767
improve the test case of `copyAdaptiveAction`
yeze322 Nov 13, 2019
c44d0fa
fix a build error related to DesingerData type
yeze322 Nov 13, 2019
b7d55eb
pass in `copyLgTemplate` from ShellApi to json tracker
yeze322 Nov 13, 2019
ac9834e
connect copyLgTemplate with deepCopyAction via ObiEditor
yeze322 Nov 13, 2019
5f55c39
extract all externalApi stub in copyUtils test
yeze322 Nov 13, 2019
fbb7afe
move stub to `jestMocks`
yeze322 Nov 13, 2019
a78b75e
optimize `updateBotInfo` due to designer schema changes
yeze322 Nov 14, 2019
9e94ad6
update test to not expect called times = 2
yeze322 Nov 14, 2019
3dda6f6
split CopyConstructorMap to another file
yeze322 Nov 14, 2019
3b1d600
mock CopyConstructorMap in test
yeze322 Nov 14, 2019
533c420
Merge branch 'master' into zeye/copy-constructor
yeze322 Nov 14, 2019
bebbb86
fix jest config in shared lib by excluding jestMocks
yeze322 Nov 14, 2019
cf331a3
fix the copy filed name in copyInputDialog
yeze322 Nov 14, 2019
2d1c076
Merge branch 'master' into zeye/copy-constructor
yeze322 Nov 15, 2019
cf03122
Merge branch 'master' into zeye/copy-constructor
cwhitten Nov 16, 2019
9f4dfdc
more strict type checking for copying prompt
yeze322 Nov 18, 2019
faffd24
add default strings for prompt types
yeze322 Nov 18, 2019
126eb5a
fix broken UT
yeze322 Nov 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ describe('<IDialogArray />', () => {
id: expect.any(String),
name: 'Send a response',
},
activity: '',
data: {
$type: 'Microsoft.SendActivity',
$designer: {
id: expect.any(String),
name: 'Send a response',
},
activity: '',
},
key: 'Microsoft.SendActivity',
name: 'Send a response',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ export const ObiEditor: FC<ObiEditorProps> = ({
}): JSX.Element | null => {
let divRef;

const { focusedId, focusedEvent, clipboardActions, updateLgTemplate, getLgTemplates, removeLgTemplates } = useContext(
const { focusedId, focusedEvent, clipboardActions, copyLgTemplate, removeLgTemplates } = useContext(
NodeRendererContext
);
const lgApi = { getLgTemplates, removeLgTemplates, updateLgTemplate };
const dispatchEvent = (eventName: NodeEventTypes, eventData: any): any => {
let handler;
switch (eventName) {
Expand Down Expand Up @@ -107,7 +106,19 @@ export const ObiEditor: FC<ObiEditorProps> = ({
case NodeEventTypes.Insert:
if (eventData.$type === 'PASTE') {
handler = e => {
pasteNodes(data, e.id, e.position, clipboardActions, lgApi).then(dialog => {
// TODO: clean this along with node deletion.
const copyLgTemplateToNewNode = async (lgTemplateName: string, newNodeId: string) => {
const matches = /\[(bfd\w+-(\d+))\]/.exec(lgTemplateName);
if (Array.isArray(matches) && matches.length === 3) {
const originLgId = matches[1];
const originNodeId = matches[2];
const newLgId = originLgId.replace(originNodeId, newNodeId);
await copyLgTemplate('common', originLgId, newLgId);
return `[${newLgId}]`;
}
return lgTemplateName;
};
pasteNodes(data, e.id, e.position, clipboardActions, copyLgTemplateToNewNode).then(dialog => {
onChange(dialog);
});
};
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/extensions/visual-designer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
saveData,
updateLgTemplate,
getLgTemplates,
copyLgTemplate,
removeLgTemplate,
removeLgTemplates,
undo,
Expand All @@ -69,6 +70,7 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
clipboardActions: clipboardActions || [],
updateLgTemplate,
getLgTemplates,
copyLgTemplate,
removeLgTemplate,
removeLgTemplates,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const NodeRendererContext = React.createContext({
focusedTab: '',
clipboardActions: [] as any[],
getLgTemplates: (_id: string, _templateName: string) => Promise.resolve([] as LgTemplate[]),
copyLgTemplate: (_id: string, _fromTemplateName: string, _toTemplateName: string) => Promise.resolve(''),
removeLgTemplate: (_id: string, _templateName: string) => Promise.resolve(),
removeLgTemplates: (_id: string, _templateNames: string[]) => Promise.resolve(),
updateLgTemplate: (_id: string, _templateName: string, _template: string) => Promise.resolve('' as string),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function appendNodesAfter(inputDialog, targetId, newNodes) {
return dialog;
}

export async function pasteNodes(inputDialog, arrayPath, arrayIndex, newNodes, lgApi) {
export async function pasteNodes(inputDialog, arrayPath, arrayIndex, newNodes, copyLgTemplate) {
if (!Array.isArray(newNodes) || newNodes.length === 0) {
return inputDialog;
}
Expand All @@ -219,7 +219,7 @@ export async function pasteNodes(inputDialog, arrayPath, arrayIndex, newNodes, l
const copiedNodes: any[] = [];
for (const node of newNodes) {
// Deep copy nodes with external resources
const copy = await deepCopyAction(node, lgApi);
const copy = await deepCopyAction(node, copyLgTemplate);
copiedNodes.push(copy);
}

Expand Down
105 changes: 0 additions & 105 deletions Composer/packages/lib/shared/__tests__/copyUtils.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { externalApiStub as externalApi } from '../jestMocks/externalApiStub';
import { SDKTypes } from '../../src';
import CopyConstructorMap from '../../src/copyUtils/CopyConstructorMap';
import { copyAdaptiveAction } from '../../src/copyUtils';

// NOTES: Cannot use SDKTypes here. `jest.mock` has to have zero dependency.
jest.mock('../../src/copyUtils/CopyConstructorMap', () => ({
'Microsoft.SendActivity': jest.fn(),
'Microsoft.IfCondition': jest.fn(),
'Microsoft.SwitchCondition': jest.fn(),
'Microsoft.EditActions': jest.fn(),
'Microsoft.ChoiceInput': jest.fn(),
'Microsoft.Foreach': jest.fn(),
default: jest.fn(),
}));

describe('copyAdaptiveAction', () => {
it('should return {} when input is invalid', async () => {
expect(await copyAdaptiveAction('hello', externalApi)).toEqual('hello');

expect(await copyAdaptiveAction(null as any, externalApi)).toEqual({});
expect(await copyAdaptiveAction({} as any, externalApi)).toEqual({});
expect(await copyAdaptiveAction({ name: 'hi' } as any, externalApi)).toEqual({});
});

const registeredTypes = [
SDKTypes.SendActivity,
SDKTypes.IfCondition,
SDKTypes.SwitchCondition,
SDKTypes.EditActions,
SDKTypes.ChoiceInput,
SDKTypes.Foreach,
];
for (const $type of registeredTypes) {
it(`should invoke registered handler for ${$type}`, async () => {
await copyAdaptiveAction({ $type }, externalApi);
expect(CopyConstructorMap[$type]).toHaveReturnedTimes(1);
});
}

it('should invoke default handler for other types', async () => {
await copyAdaptiveAction({ $type: SDKTypes.BeginDialog }, externalApi);
expect(CopyConstructorMap.default).toHaveReturnedTimes(1);

await copyAdaptiveAction({ $type: SDKTypes.HttpRequest }, externalApi);
expect(CopyConstructorMap.default).toHaveReturnedTimes(2);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { copyEditActions } from '../../src/copyUtils/copyEditActions';
import { externalApiStub as externalApi } from '../jestMocks/externalApiStub';

describe('#copyEditActions', () => {
it('can copy EditActions', async () => {
const editActions = {
$type: 'Microsoft.EditActions',
changeType: 'InsertActions',
actions: [
{
$type: 'Microsoft.BeginDialog',
dialog: 'AddToDo',
},
],
};

expect(await copyEditActions(editActions, externalApi)).toEqual({
$type: 'Microsoft.EditActions',
$designer: {
id: '5678',
},
changeType: 'InsertActions',
actions: [
{
$type: 'Microsoft.BeginDialog',
$designer: {
id: '5678',
},
dialog: 'AddToDo',
},
],
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License

import { copyForeach } from '../../src/copyUtils/copyForeach';
import { externalApiStub as externalApi } from '../jestMocks/externalApiStub';

describe('#copyForeach', () => {
it('can copy Foreach action', async () => {
const foreachInstance = {
$type: 'Microsoft.Foreach',
itemsProperty: 'name',
actions: [
{
$type: 'Microsoft.SendActivity',
activity: 'hello',
},
],
};

expect(await copyForeach(foreachInstance, externalApi)).toEqual({
$type: 'Microsoft.Foreach',
itemsProperty: 'name',
$designer: {
id: '5678',
},
actions: [
{
$type: 'Microsoft.SendActivity',
$designer: {
id: '5678',
},
activity: 'hello',
},
],
});
});

it('can copy ForeachPage action', async () => {
const foreachPageInstance = {
$type: 'Microsoft.Foreach',
itemsProperty: 'name',
pageSize: 10,
actions: [
{
$type: 'Microsoft.SendActivity',
activity: 'hello',
},
],
};

expect(await copyForeach(foreachPageInstance, externalApi)).toEqual({
$type: 'Microsoft.Foreach',
itemsProperty: 'name',
pageSize: 10,
$designer: {
id: '5678',
},
actions: [
{
$type: 'Microsoft.SendActivity',
$designer: {
id: '5678',
},
activity: 'hello',
},
],
});
});
});
Loading