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

feat: Schema-driven visual editor - migrates 15 simple types #1811

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ab1674c
uischema def
yeze322 Dec 27, 2019
3161cef
uischema v0 def (basic types)
yeze322 Dec 27, 2019
f012a98
consume uischema
yeze322 Dec 27, 2019
e5638de
fix demo
yeze322 Dec 27, 2019
c9eeed5
add renderSDK demo
yeze322 Dec 27, 2019
6f5fbf8
Merge branch 'master' into visual/schema-driven--progressive
yeze322 Dec 31, 2019
f6b2d0b
fix a title getter bug
yeze322 Dec 31, 2019
19f5e1b
better demo page
yeze322 Dec 31, 2019
ebe0f14
add contextProps
yeze322 Jan 2, 2020
ba866b3
support DeleteProperties
yeze322 Jan 2, 2020
098186a
fix demo page
yeze322 Jan 2, 2020
7dd3cc2
add specific renderer for ConditonNode
yeze322 Jan 2, 2020
aae85c8
retire ConditionNode from DefaultRenderer
yeze322 Jan 2, 2020
d8cc49a
register ForeachDetail & ForeachpageDetail in upper level
yeze322 Jan 2, 2020
a0e7c24
move label calculation to new renderer
yeze322 Jan 2, 2020
df31f77
migrate DefaultRenderer to uischema renderer
yeze322 Jan 2, 2020
0190245
fix lint warning
yeze322 Jan 2, 2020
f9e8259
apply `formatMessage` to node lib
yeze322 Jan 3, 2020
e2dca52
let formatMessage receive string literal
yeze322 Jan 3, 2020
fc2187c
Merge branch 'master' into visual/schema-driven--progressive
yeze322 Jan 4, 2020
e6c1cb0
move title logic into ActionCard
yeze322 Jan 4, 2020
edf50d5
move `generateSDKTitle` into 'shared'
yeze322 Jan 4, 2020
73ac22a
apply `generateSDKTitle` to all nodes
yeze322 Jan 4, 2020
b41dac6
retire `getFriendlyName`
yeze322 Jan 4, 2020
a3d179d
change title priority
yeze322 Jan 6, 2020
6d5eb9b
uncheck 'SampleBots' folder
yeze322 Jan 6, 2020
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 @@ -8,6 +8,7 @@ import { EditorConfig } from '../../src/editors/editorConfig';
import { VisualEditorDemo } from './stories/VisualEditorDemo';
import { StepEditorDemo } from './stories/StepEditorDemo';
import { EventsEditorDemo } from './stories/EventsEditorDemo';
import { VisualSDKDemo } from './stories/VisualSDKDemo';
import './index.css';

initializeIcons(undefined, { disableWarnings: true });
Expand All @@ -27,6 +28,10 @@ const DemoMaps = {
key: 'EventsEditorDemo',
component: EventsEditorDemo,
},
VisualSDKDemo: {
key: 'VisualSDKDemo',
component: VisualSDKDemo,
},
};

class Demo extends Component {
Expand Down Expand Up @@ -61,6 +66,10 @@ class Demo extends Component {
key: DemoMaps.EventsEditorDemo.key,
name: 'Event Editor',
},
{
key: DemoMaps.VisualSDKDemo.key,
name: 'Visual SDK',
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { Component } from 'react';
import { seedNewDialog, SDKTypes } from '@bfc/shared';

import { renderSDKType } from '../../../src/schema/uischemaRenderer';
import { EdgeMenu } from '../../../src/components/menus/EdgeMenu';
import { JsonBlock } from '../components/json-block';

import './story.css';

export class VisualSDKDemo extends Component {
state = {
actions: this.seedInitialActions(),
};

seedInitialActions() {
const initialTypes = [
SDKTypes.EditArray,
SDKTypes.InitProperty,
SDKTypes.SetProperties,
SDKTypes.SetProperty,
SDKTypes.DeleteProperties,
SDKTypes.DeleteProperty,
SDKTypes.EndDialog,
SDKTypes.CancelAllDialogs,
SDKTypes.EmitEvent,
];
const initalActions = initialTypes.map(t => seedNewDialog(t));
return initalActions;
}

appendActionPreview($type) {
this.setState({
actions: [...this.state.actions, seedNewDialog($type)],
});
}

renderActionPreview(action, index) {
return (
<div
className="action-preview"
key={`action-preview-${index}`}
style={{ display: 'flex', flexDirection: 'row', margin: 10 }}
>
<div className="action-preview--raw">
<JsonBlock
styles={{
width: '200px',
height: '80px',
fontSize: '8px',
}}
defaultValue={action}
onSubmit={newAction => {
const newActions = [...this.state.actions];
newActions[index] = newAction;
this.setState({
actions: newActions,
});
}}
/>
</div>
<div className="action-preview--visual">{renderSDKType(action)}</div>
</div>
);
}

renderActionFactory() {
return (
<div style={{ height: 100, margin: 20 }}>
<h3>Create action by $type</h3>
<EdgeMenu id="visual-sdk-demo" onClick={$type => this.appendActionPreview($type)} />
</div>
);
}

render() {
return (
<div className="story-container">
<h1 className="story-title">Visual SDK Demo</h1>
<div className="story-content" style={{ display: 'flex', flexFlow: 'wrap' }}>
{this.state.actions.map((action, index) => this.renderActionPreview(action, index))}
{this.renderActionFactory()}
</div>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.story-container {
height: 100%;
}

.story-title {
height: 50px;
margin: 0;
}

.story-content {
display: flex;
flex-direction: row;
height: calc(100% - 60px);
}

.block {
border: 1px solid grey;
margin: 10px;
width: 50%;
overflow: auto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module.exports = {
port: 3001,
stats: 'errors-only',
},
node: {
fs: 'empty',
},
module: {
rules: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React, { FC } from 'react';
import get from 'lodash/get';

import { FormCard } from '../templates/FormCard';
import { NodeProps } from '../nodeProps';
import { getElementIcon, getElementColor } from '../../../utils/obiPropertyResolver';
import { NodeMenu } from '../../menus/NodeMenu';
import { NodeEventTypes } from '../../../constants/NodeEventTypes';

export const ConditionNode: FC<NodeProps> = ({ id, data, onEvent }) => {
const { $type } = data;

return (
<FormCard
nodeColors={getElementColor($type)}
icon={getElementIcon($type)}
corner={<NodeMenu id={id} onEvent={onEvent} />}
header={'Branch'}
yeze322 marked this conversation as resolved.
Show resolved Hide resolved
label={get(data, 'condition', '')}
onClick={() => {
onEvent(NodeEventTypes.Focus, { id });
}}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,179 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React from 'react';
import React, { FC } from 'react';

import { NodeEventTypes } from '../../../constants/NodeEventTypes';
import { ObiTypes } from '../../../constants/ObiTypes';
import { getElementColor, getElementIcon } from '../../../utils/obiPropertyResolver';
import { NodeProps } from '../nodeProps';
import { renderSDKType } from '../../../schema/uischemaRenderer';
import { NodeMenu } from '../../menus/NodeMenu';
import { FormCard } from '../templates/FormCard';
import { NodeProps, defaultNodeProps } from '../nodeProps';
import { getFriendlyName } from '../utils';

const truncateType = $type => (typeof $type === 'string' ? $type.split('Microsoft.')[1] : '');

const DefaultKeyMap = {
label: 'property',
};

/**
* Create labels out of compound values
*/
function makeLabel(data) {
switch (data.$type) {
case ObiTypes.SetProperty:
return `{${data.property || '?'}} = ${data.value || '?'}`;
case ObiTypes.SetProperties:
return `Set ${Array.isArray(data.assignments) ? data.assignments.length : 0} property values`;
case ObiTypes.DeleteProperties:
return `Delete ${Array.isArray(data.properties) ? data.properties.length : 0} properties`;
case ObiTypes.InitProperty:
return `{${data.property || '?'}} = new ${data.type || '?'}`;
case ObiTypes.EditArray:
return `${data.changeType} {${data.itemsProperty || '?'}}`;
case ObiTypes.ForeachDetail:
return `Each value in {${data.itemsProperty || '?'}}`;
case ObiTypes.ForeachPageDetail:
return `Each page of ${data.pageSize || '?'} in {${data.itemsProperty || '?'}}`;

default:
return '';
}
}
import { NodeEventTypes } from '../../../constants/NodeEventTypes';

const ContentKeyByTypes: {
[key: string]: {
[key: string]: string;
};
} = {
[ObiTypes.EditArray]: {
label: 'changeType',
details: 'arrayProperty',
},
[ObiTypes.InitProperty]: {
label: 'property',
},
[ObiTypes.SetProperty]: {
label: 'property',
},
[ObiTypes.ConditionNode]: {
header: 'Branch',
label: 'condition',
},
[ObiTypes.DeleteProperty]: {
label: 'property',
},
[ObiTypes.IfCondition]: {
label: 'condition',
},
[ObiTypes.SwitchCondition]: {
label: 'condition',
},
[ObiTypes.ForeachDetail]: {
header: 'Loop: For Each',
label: 'itemsProperty',
},
[ObiTypes.ForeachPageDetail]: {
header: 'Loop: For Each Page',
label: 'itemsProperty',
},
[ObiTypes.TextInput]: {
label: 'prompt',
details: 'property',
},
[ObiTypes.NumberInput]: {
label: 'prompt',
details: 'property',
},
[ObiTypes.ConfirmInput]: {
label: 'prompt',
details: 'property',
},
[ObiTypes.AttachmentInput]: {
label: 'prompt',
details: 'property',
},
[ObiTypes.EndDialog]: {
details: 'property',
text: 'End this dialog',
},
[ObiTypes.CancelAllDialogs]: {
label: 'eventName',
text: 'Cancel all active dialogs',
},
[ObiTypes.EndTurn]: {
text: 'Wait for another message',
},
[ObiTypes.EmitEvent]: {
label: 'eventName',
},
[ObiTypes.HttpRequest]: {
label: 'url',
},
[ObiTypes.TraceActivity]: {
label: 'name',
},
[ObiTypes.LogAction]: {
label: 'text',
},
[ObiTypes.EditActions]: {
label: 'changeType',
},
[ObiTypes.QnAMakerDialog]: {
label: 'hostname',
},
[ObiTypes.OAuthInput]: {
label: 'tokenProperty',
},
export const DefaultRenderer: FC<NodeProps> = ({ id, data, onEvent }) => {
return renderSDKType(data, {
menu: <NodeMenu id={id} onEvent={onEvent} />,
onClick: () => onEvent(NodeEventTypes.Focus, { id }),
});
};

/**
* DefaultRenderer is designed for rendering simple or unrecognized OBI elements.
* Only the 'Focus' event could be triggered in it, if an element wants trigger
* more events like 'Expand' or 'Open', it should define a renderer it self to
* control its behavior.
*/

export class DefaultRenderer extends React.Component<NodeProps, {}> {
static defaultProps = defaultNodeProps;
render() {
const { id, data, onEvent } = this.props;
let header = getFriendlyName(data),
label = '';

const keyMap = data.$type ? ContentKeyByTypes[data.$type] || DefaultKeyMap : { label: '', details: '' };
const icon = getElementIcon(data.$type);
const nodeColors = getElementColor(data.$type);

if (keyMap) {
header = header || keyMap.header || '';
label = data[keyMap.label] || label;
}

if (makeLabel(data)) {
label = makeLabel(data);
}

if (data.$type && ContentKeyByTypes[data.$type] && ContentKeyByTypes[data.$type].text) {
label = ContentKeyByTypes[data.$type].text;
}

if (!header) {
header = truncateType(data.$type);
}

return (
<FormCard
nodeColors={nodeColors}
header={header}
corner={<NodeMenu id={id} onEvent={onEvent} />}
icon={icon}
label={label}
onClick={() => {
onEvent(NodeEventTypes.Focus, { id });
}}
/>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React, { FC } from 'react';

import { FormCard } from '../templates/FormCard';
import { NodeProps } from '../nodeProps';
import { getElementIcon, getElementColor } from '../../../utils/obiPropertyResolver';
import { NodeMenu } from '../../menus/NodeMenu';
import { NodeEventTypes } from '../../../constants/NodeEventTypes';

export const ForeachDetail: FC<NodeProps> = ({ id, data, onEvent }) => {
const { $type } = data;
const label = `Each value in {${data.itemsProperty || '?'}}`;
yeze322 marked this conversation as resolved.
Show resolved Hide resolved

return (
<FormCard
nodeColors={getElementColor($type)}
icon={getElementIcon($type)}
corner={<NodeMenu id={id} onEvent={onEvent} />}
header={'Loop: For Each'}
yeze322 marked this conversation as resolved.
Show resolved Hide resolved
label={label}
onClick={() => {
onEvent(NodeEventTypes.Focus, { id });
}}
/>
);
};
Loading