This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 375
feat: Schema-driven visual editor - migrates 15 simple types #1811
Merged
Andy Brown (a-b-r-o-w-n)
merged 26 commits into
microsoft:master
from
yeze322:visual/schema-driven--progressive
Jan 6, 2020
Merged
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ab1674c
uischema def
yeze322 3161cef
uischema v0 def (basic types)
yeze322 f012a98
consume uischema
yeze322 e5638de
fix demo
yeze322 c9eeed5
add renderSDK demo
yeze322 6f5fbf8
Merge branch 'master' into visual/schema-driven--progressive
yeze322 f6b2d0b
fix a title getter bug
yeze322 19f5e1b
better demo page
yeze322 ebe0f14
add contextProps
yeze322 ba866b3
support DeleteProperties
yeze322 098186a
fix demo page
yeze322 7dd3cc2
add specific renderer for ConditonNode
yeze322 aae85c8
retire ConditionNode from DefaultRenderer
yeze322 d8cc49a
register ForeachDetail & ForeachpageDetail in upper level
yeze322 a0e7c24
move label calculation to new renderer
yeze322 df31f77
migrate DefaultRenderer to uischema renderer
yeze322 0190245
fix lint warning
yeze322 f9e8259
apply `formatMessage` to node lib
yeze322 e2dca52
let formatMessage receive string literal
yeze322 fc2187c
Merge branch 'master' into visual/schema-driven--progressive
yeze322 e6c1cb0
move title logic into ActionCard
yeze322 edf50d5
move `generateSDKTitle` into 'shared'
yeze322 73ac22a
apply `generateSDKTitle` to all nodes
yeze322 b41dac6
retire `getFriendlyName`
yeze322 a3d179d
change title priority
yeze322 6d5eb9b
uncheck 'SampleBots' folder
yeze322 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
Composer/packages/extensions/visual-designer/demo/src/stories/VisualSDKDemo.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
Composer/packages/extensions/visual-designer/demo/src/stories/story.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Composer/packages/extensions/visual-designer/src/components/nodes/steps/ConditionNode.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'} | ||
| label={get(data, 'condition', '')} | ||
| onClick={() => { | ||
| onEvent(NodeEventTypes.Focus, { id }); | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
181 changes: 9 additions & 172 deletions
181
Composer/packages/extensions/visual-designer/src/components/nodes/steps/DefaultRenderer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }); | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
Composer/packages/extensions/visual-designer/src/components/nodes/steps/ForeachDetail.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
|
||
|
|
||
| return ( | ||
| <FormCard | ||
| nodeColors={getElementColor($type)} | ||
| icon={getElementIcon($type)} | ||
| corner={<NodeMenu id={id} onEvent={onEvent} />} | ||
| header={'Loop: For Each'} | ||
|
yeze322 marked this conversation as resolved.
Outdated
|
||
| label={label} | ||
| onClick={() => { | ||
| onEvent(NodeEventTypes.Focus, { id }); | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.