change NodePanel

This commit is contained in:
zhandouxiaojiji committed 2020-11-02 12:27:30 +08:00
1 parent 98f16a373d
commit c02fc34d7f
2 files changed
+74 -23

No files matched your search

+64 -13
View File
@@ -1,9 +1,15 @@
import React from 'react'; import React from 'react';
import { Card } from 'antd'; import { Card, Divider, Form, Input, AutoComplete, Select } from 'antd';
import { INode } from '@antv/g6/lib/interface/item'; import { INode } from '@antv/g6/lib/interface/item';
import { BehaviorNodeModel } from '../../common/BehaviorTreeModel';
import Settings from '../../main-process/Settings';
import { FormInstance } from 'antd/lib/form';
const { Item } = Form;
interface NodePanelProps { interface NodePanelProps {
model: BehaviorNodeModel;
settings: Settings;
} }
interface NodePanelState { interface NodePanelState {
@@ -11,22 +17,67 @@ interface NodePanelState {
} }
export default class NodePanel extends React.Component<NodePanelProps> { export default class NodePanel extends React.Component<NodePanelProps> {
componentDidMount() { formRef = React.createRef<FormInstance>();
componentDidUpdate() {
const { model, settings } = this.props;
this.formRef.current.setFieldsValue({
name: model.name,
});
} }
renderNode() { onFinish = (values: any) => {
return ( console.log('Success:', values);
<div> };
{}
</div> onFinishFailed = (errorInfo: any) => {
) console.log('Failed:', errorInfo);
} };
render() { render() {
// const { curNode } = this.props; const { model, settings } = this.props;
const conf = settings.getNodeConf(model.name);
console.log("model", model, conf);
const title = conf.desc;
const names: string[] = [];
settings.nodeConfig.map((e) => {
names.push(e.name);
})
const name = model.name;
const layout = {
labelCol: { span: 4 },
wrapperCol: { span: 20 },
};
return ( return (
<Card title="节点信息" style={{ height: "100%" }}> <Card title={title} style={{ height: "100%" }}>
{/* {curNode ? this.renderNode() : "未选中"} */} <Form
{...layout}
name="basic"
onFinish={this.onFinish}
ref={this.formRef}
>
<Item
label="节点id"
>
<Input value={model.id} disabled={true} />
</Item>
<Item
label="节点名称"
name="name"
>
<AutoComplete
dataSource={names}
filterOption={(inputValue, option: any) =>
option.props.children.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
}
onChange={this.onFinish}
defaultValue={name}
/>
</Item>
</Form>
</Card> </Card>
) )
} }
+10 -10
View File
@@ -8,8 +8,9 @@ import { TreeGraphData, IG6GraphEvent } from '@antv/g6/lib/types';
import { G6GraphEvent } from '@antv/g6/lib/interface/behavior'; import { G6GraphEvent } from '@antv/g6/lib/interface/behavior';
import './Editor.css'; import './Editor.css';
import * as Utils from '../../common/Utils'; import * as Utils from '../../common/Utils';
import { BehaviorTreeModel, GraphNodeModel } from '../../common/BehaviorTreeModel'; import { BehaviorTreeModel, GraphNodeModel, BehaviorNodeModel } from '../../common/BehaviorTreeModel';
import TreePanel from './TreePanel'; import TreePanel from './TreePanel';
import Settings from '../../main-process/Settings';
export interface EditorProps { export interface EditorProps {
filepath: string; filepath: string;
@@ -18,11 +19,12 @@ export interface EditorProps {
interface EditorState { interface EditorState {
curNodeId?: string; curNodeId?: string;
treeModel?: BehaviorTreeModel; treeModel?: BehaviorTreeModel;
settings?: Settings;
} }
export default class Editor extends React.Component<EditorProps, EditorState> { export default class Editor extends React.Component<EditorProps, EditorState> {
private ref: React.RefObject<any>; private ref: React.RefObject<any>;
state: EditorState = {} state: EditorState = {};
private graph: TreeGraph; private graph: TreeGraph;
private dragSrcId: string; private dragSrcId: string;
@@ -33,10 +35,6 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.ref = React.createRef(); this.ref = React.createRef();
} }
// shouldComponentUpdate(nextProps: EditorProps, nextState: EditorState) {
// return !this.graph || this.state.curNodeId != nextState.curNodeId;
// }
componentDidMount() { componentDidMount() {
const graph = new TreeGraph({ const graph = new TreeGraph({
container: this.ref.current, container: this.ref.current,
@@ -258,7 +256,9 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.graph = graph; this.graph = graph;
this.setState({ treeModel: tree }); const settings = Utils.getRemoteSettings();
this.setState({ treeModel: tree, settings });
} }
onSelectNode(curNodeId: string | null) { onSelectNode(curNodeId: string | null) {
@@ -281,8 +281,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
render() { render() {
console.log("render editor") console.log("render editor")
const { curNodeId, treeModel } = this.state; const { curNodeId, treeModel, settings } = this.state;
var curNode; var curNode: any;
if (curNodeId) { if (curNodeId) {
curNode = this.graph.findDataById(curNodeId); curNode = this.graph.findDataById(curNodeId);
} }
@@ -295,7 +295,7 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
ref={this.ref} ref={this.ref}
/> />
<Col span={6} className="editorSidebar"> <Col span={6} className="editorSidebar">
{curNode ? <NodePanel /> : <TreePanel model={treeModel} />} {curNode ? <NodePanel model={curNode} settings={settings} /> : <TreePanel model={treeModel} />}
</Col> </Col>
</Row> </Row>
</div> </div>