Skip to content

Commit

Permalink
improve object tree
Browse files Browse the repository at this point in the history
  • Loading branch information
rinick committed Nov 5, 2019
1 parent c370f61 commit 83897cb
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 30 deletions.
2 changes: 1 addition & 1 deletion example/simple-editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {TrackedClientConn} from '../../src/core/connect/TrackedClientConn';
import {BlockStageTab} from '../../src/panel/block/BlockStageTab';
import {Dispatcher, ValueDispatcher} from '../../src/core/block/Dispatcher';
import {PropertyListPanel} from '../../src/panel/property/PropertyListPanel';
import {ObjectTree} from '../../src/ui/object-tree/ObjectTree';
import {ObjectTree} from '../../src/editor/object-tree/ObjectTree';

const layoutGroups = {
blockStage: {
Expand Down
8 changes: 4 additions & 4 deletions src/editor/block/FieldValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {TRUNCATED} from '../../core/util/DataTypes';
import {encodeDisplay} from '../../core/util/Serialize';
import {displayNumber} from '../../ui/util/Types';
import {Popup} from '../component/ClickPopup';
import {ObjectTree} from '../../ui/object-tree/ObjectTree';
import {ObjectTree} from '../object-tree/ObjectTree';

interface Props {
conn: ClientConn;
Expand All @@ -25,7 +25,7 @@ export class FieldValue extends LazyUpdateComponent<Props, any> {
getObjectMenu = () => {
let {conn, path} = this.props;
let val = this.valueSub.value;
return <ObjectTree conn={conn} path={path} data={val} style={{width: 300, height: 300}} />;
return <ObjectTree conn={conn} path={path} data={val} />;
};

renderImpl() {
Expand All @@ -48,8 +48,8 @@ export class FieldValue extends LazyUpdateComponent<Props, any> {
<Popup
popup={this.getObjectMenu}
popupAlign={{
points: ['tl', 'tl'],
offset: [2, -3]
points: ['tl', 'tr'],
offset: [-6, 0]
}}
>
<div className="ticl-tree-arr ticl-tree-arr-expand" />
Expand Down
2 changes: 2 additions & 0 deletions src/editor/editor.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import './style';
@import '../ui/ui';

@import './block/BlockStage';
@import './block/Block';
@import './block/view/Note';
Expand All @@ -10,6 +11,7 @@
@import './property/Property';
@import './type-selector/TypeView';
@import './component/ClickPopup';
@import './object-tree/ObjectTree';
@import './antd-extra';
@import '../../node_modules/rc-dock/style/index';
@import './dock-extra';
Expand Down
2 changes: 1 addition & 1 deletion src/editor/node-tree/NodeRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class NodeTreeRenderer extends PureDataRenderer<Props, any> {

renderImpl() {
let {item, style} = this.props;
let marginLeft = item.level * 24;
let marginLeft = item.level * 20;
return (
<div style={{...style, marginLeft}} className="ticl-tree-node">
<ExpandIcon opened={item.opened} onClick={this.onExpandClicked} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import {ExpandIcon, ExpandState, TreeItem} from '../component/Tree';
import {PureDataRenderer} from '../component/DataRenderer';
import {ExpandIcon, ExpandState, TreeItem} from '../../ui/component/Tree';
import {PureDataRenderer} from '../../ui/component/DataRenderer';
import {DragDropDiv, DragState} from 'rc-dock/lib';
import {TRUNCATED} from '../../core/util/DataTypes';

Expand Down Expand Up @@ -97,7 +97,7 @@ export class ObjectTreeRenderer extends PureDataRenderer<Props, any> {

renderImpl() {
let {item, style} = this.props;
let marginLeft = item.level * 24;
let marginLeft = item.level * 16;
let onClick = item.opened !== 'empty' ? this.onExpandClicked : null;

let child: React.ReactNode;
Expand Down
13 changes: 13 additions & 0 deletions src/editor/object-tree/ObjectTree.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.ticl-object-tree {
width: 250px;
height: 250px;
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: space-evenly;
padding: 4px 1px;

& > .ticl-node-tree {
height: 100%;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import VirtualList from '../component/Virtual';
import VirtualList from '../../ui/component/Virtual';
import {ObjectTreeItem, ObjectTreeRenderer} from './ObjectRenderer';
import {ClientConn} from '../../core/connect/ClientConn';
import {LazyUpdateComponent} from '../component/LazyUpdateComponent';
import {LazyUpdateComponent} from '../../ui/component/LazyUpdateComponent';
import {DataMap, isDataTruncated} from '../../core/util/DataTypes';
import {Spin} from 'antd';

interface Props {
conn: ClientConn;
Expand All @@ -15,6 +17,26 @@ export class ObjectTree extends LazyUpdateComponent<Props, any> {
root: ObjectTreeItem;
list: ObjectTreeItem[] = [];

loading = false;
data: any;
getValueCallback = {
onUpdate: (response: DataMap) => {
this.loading = false;
this.data = response.value;
this.forceUpdate();
}
};

constructor(props: Props) {
super(props);
if (isDataTruncated(props.data)) {
this.loading = true;
props.conn.getValue(props.path, this.getValueCallback);
} else {
this.data = props.data;
}
}

renderChild = (idx: number, style: React.CSSProperties) => {
const item = this.list[idx];
return <ObjectTreeRenderer item={item} key={item.key} style={style} />;
Expand All @@ -25,10 +47,6 @@ export class ObjectTree extends LazyUpdateComponent<Props, any> {
this.root.addToList(this.list);
}

constructor(props: Props) {
super(props);
}

forceUpdateLambda = () => this.forceUpdate();

buildRoot() {
Expand All @@ -45,16 +63,27 @@ export class ObjectTree extends LazyUpdateComponent<Props, any> {
}

renderImpl() {
this.buildRoot();
this.refreshList();
let child: React.ReactNode;
if (this.loading) {
child = <Spin tip="Loading..." />;
} else {
this.buildRoot();
this.refreshList();
child = (
<VirtualList
className="ticl-node-tree"
style={this.props.style}
renderer={this.renderChild}
itemCount={this.list.length}
itemHeight={26}
/>
);
}

return (
<VirtualList
className="ticl-node-tree"
style={this.props.style}
renderer={this.renderChild}
itemCount={this.list.length}
itemHeight={30}
/>
<div className="ticl-object-tree" style={this.props.style}>
{child}
</div>
);
}

Expand Down
33 changes: 33 additions & 0 deletions src/editor/object-tree/ObjectTreePanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import {Spin} from 'antd';
import {ClientConn} from '../../core/connect/ClientConn';
import {DataMap, isDataTruncated} from '../../core/util/DataTypes';
import {LazyUpdateComponent} from '../../ui/component/LazyUpdateComponent';
import {ObjectTree} from './ObjectTree';

interface Props {
conn: ClientConn;
path: string;
val: any;
}

export class ObjectTreePanel extends LazyUpdateComponent<Props, any> {
static createDockTab(path: string, conn: ClientConn, val: any, fromElement: HTMLElement, offset: [number, number]) {
let id = `objectTree-${path}`;
let tabName = path.split('.').pop();
return {
id,
closable: true,
title: tabName,
group: 'objectTree',
cacjed: true,
content: <ObjectTreePanel conn={conn} path={path} val={val} />
};
}

renderImpl() {
let {path, conn, val} = this.props;

return <ObjectTree conn={conn} path={path} data={val} />;
}
}
10 changes: 6 additions & 4 deletions src/editor/property/PropertyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {PropertyEditor} from './PropertyEditor';
import {GroupEditor} from './GroupEditor';
import {MultiSelectComponent, MultiSelectLoader} from './MultiSelectComponent';
import {ExpandIcon} from '../../ui/component/Tree';
import {ExpandIcon, ExpandState} from '../../ui/component/Tree';
import {deepEqual} from '../../core/util/Compare';
import {Button, Empty, Tooltip} from 'antd';
import {AddMorePropertyMenu} from './AddMoreProperty';
Expand Down Expand Up @@ -327,6 +327,10 @@ export class PropertyList extends MultiSelectComponent<Props, State, BlockLoader

let allowAttribute = mode == null && keys.length === 1;

let moreExpand: ExpandState = 'empty';
if (moreMerger.isNotEmpty()) {
moreExpand = showMore ? 'opened' : 'closed';
}
return (
<div className="ticl-property-list" style={style}>
<PropertyEditor name="#is" keys={keys} conn={conn} funcDesc={funcDesc} propDesc={configDescs['#is']} />
Expand Down Expand Up @@ -358,9 +362,7 @@ export class PropertyList extends MultiSelectComponent<Props, State, BlockLoader

<div className="ticl-property-divider">
<div className="ticl-h-line" style={{maxWidth: '16px'}} />
{moreMerger.isNotEmpty() ? (
<ExpandIcon opened={showMore ? 'opened' : 'closed'} onClick={this.onShowMoreClick} />
) : null}
<ExpandIcon opened={moreExpand} onClick={this.onShowMoreClick} />
<span>more</span>
<Popup
popupVisible={showAddMorePopup}
Expand Down
2 changes: 0 additions & 2 deletions src/ui/util/Types.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {TRUNCATED} from '../../core/util/DataTypes';
import React from 'react';
import {encodeDisplay} from '../../core/util/Serialize';

export function displayNumber(val: number): string {
let rslt1 = val.toString();
Expand Down

0 comments on commit 83897cb

Please sign in to comment.