Merge branch 'dev_hjm_repo_tree_click_to_expand' into dev_aliyun

dev_newshixunModel
hjm 5 years ago
commit 90e2d94cc1

@ -85,7 +85,7 @@ class VNCContainer extends Component {
}) })
} }
onTreeSelect = (selectedKeys, info) => { onTreeSelect = (selectedKeys, info) => {
const isLeaf = info.node.props.isLeaf; const isLeaf = info.node.isLeaf();
if (isLeaf) { // 叶子节点 if (isLeaf) { // 叶子节点
selectedKeys.length && this.setState({ selectedKeys.length && this.setState({
fileTreeSelectedKeys: selectedKeys fileTreeSelectedKeys: selectedKeys

@ -7,7 +7,7 @@ import 'rc-tree/assets/index.css';
const $ = window.$; const $ = window.$;
export default function RepoTree(props) { export default function RepoTree(props) {
const { fileTreeData, onLoadData, onTreeSelect, fileTreeSelectedKeys, loadRepoFiles } = props; const { fileTreeData, onLoadData, fileTreeSelectedKeys, loadRepoFiles } = props;
const [expandedKeys, setExpandedKeys] = useState([]) const [expandedKeys, setExpandedKeys] = useState([])
useEffect(() => { useEffect(() => {
loadRepoFiles() loadRepoFiles()
@ -36,7 +36,19 @@ export default function RepoTree(props) {
}; };
const treeNodes = loop(fileTreeData); const treeNodes = loop(fileTreeData);
function onTreeSelect(selectedKeys, info) {
if (!info.node.isLeaf()) {
const _expandedKeys = expandedKeys.slice(0)
const _index = _expandedKeys.indexOf(selectedKeys[0]);
if (_index == -1) {
_expandedKeys.push(selectedKeys[0])
} else {
_expandedKeys.splice( _index, 1)
}
setExpandedKeys( _expandedKeys )
}
props.onTreeSelect(selectedKeys, info)
}
// selectable={false} // selectable={false}
return ( return (
<Tree <Tree

@ -148,3 +148,7 @@
.xterm .xterm-viewport { .xterm .xterm-viewport {
overflow-y: auto !important; overflow-y: auto !important;
} }
.repoFilesDrawer .rc-tree {
user-select: none;
}

@ -65,6 +65,7 @@ class CodeRepositoryView extends Component {
expandedKeys.push( index === 0 ? item : expandedKeys[index - 1] + '/' + item) expandedKeys.push( index === 0 ? item : expandedKeys[index - 1] + '/' + item)
}) })
} }
expandedKeys.length = 1 // 没办法做到多级初始化
// 初始化时无法展开到根节点 https://github.com/fis-components/rc-tree/issues/3 // 初始化时无法展开到根节点 https://github.com/fis-components/rc-tree/issues/3
expandedKeys.length && this.setState({ expandedKeys.length && this.setState({
expandedKeys, expandedKeys,
@ -110,10 +111,23 @@ class CodeRepositoryView extends Component {
// $('#codetab_con_1 .codemirrorBackground').hide() // $('#codetab_con_1 .codemirrorBackground').hide()
} }
onTreeSelect = (selectedKeys, info) => {
if (!info.node.isLeaf()) {
const expandedKeys = this.state.expandedKeys.slice(0)
const _index = expandedKeys.indexOf(selectedKeys[0]);
if (_index == -1) {
expandedKeys.push(selectedKeys[0])
} else {
expandedKeys.splice( _index, 1)
}
this.setState({ expandedKeys })
}
this.props.onTreeSelect(selectedKeys, info)
}
buildTree() { buildTree() {
// TODO http://localhost:3007/tasks/xgffnuomytpj 这个实训没有文件树 // TODO http://localhost:3007/tasks/xgffnuomytpj 这个实训没有文件树
const { fileTreeData, onLoadData, onTreeSelect, fileTreeSelectedKeys } = this.props; const { fileTreeData, onLoadData, fileTreeSelectedKeys } = this.props;
if (!fileTreeData || fileTreeData.length === 0) { if (!fileTreeData || fileTreeData.length === 0) {
return "" return ""
} }
@ -136,7 +150,7 @@ class CodeRepositoryView extends Component {
return ( return (
<Tree <Tree
selectedKeys={fileTreeSelectedKeys} selectedKeys={fileTreeSelectedKeys}
onSelect={onTreeSelect} onSelect={this.onTreeSelect}
onExpand={this.onExpand} onExpand={this.onExpand}
expandedKeys={this.state ? this.state.expandedKeys : []} expandedKeys={this.state ? this.state.expandedKeys : []}
autoExpandParent={this.state.autoExpandParent} autoExpandParent={this.state.autoExpandParent}

@ -223,7 +223,7 @@ class CodeRepositoryViewContainer extends Component {
}); });
} }
onTreeSelect = (selectedKeys, info) => { onTreeSelect = (selectedKeys, info) => {
const isLeaf = info.node.props.isLeaf; const isLeaf = info.node.isLeaf();
if (isLeaf) { // 叶子节点 if (isLeaf) { // 叶子节点
selectedKeys.length && this.setState({ selectedKeys.length && this.setState({
fileTreeSelectedKeys: selectedKeys fileTreeSelectedKeys: selectedKeys

Loading…
Cancel
Save