mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 23:20:51 +00:00
Wiki sidebar bug (#2321)
* repair rename bug * modify rename module and search module * add hight-light style for tree-node
This commit is contained in:
committed by
Daniel Pan
parent
285fa43387
commit
99e9c8b1c0
@@ -23,6 +23,7 @@ class SidePanel extends Component {
|
|||||||
isLoadFailed: false,
|
isLoadFailed: false,
|
||||||
isMenuIconShow: false
|
isMenuIconShow: false
|
||||||
}
|
}
|
||||||
|
this.searchedPath = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeSide = () => {
|
closeSide = () => {
|
||||||
@@ -120,32 +121,45 @@ class SidePanel extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onRenameNode = (newName) => {
|
onRenameNode = (newName) => {
|
||||||
var node = this.state.currentNode;
|
let tree = this.state.tree_data.copy();
|
||||||
|
let node = this.state.currentNode;
|
||||||
let type = node.type;
|
let type = node.type;
|
||||||
let filePath = node.path;
|
let filePath = node.path;
|
||||||
if (type === 'file') {
|
if (type === 'file') {
|
||||||
this.props.editorUtilities.renameFile(filePath, newName).then(res => {
|
this.props.editorUtilities.renameFile(filePath, newName).then(res => {
|
||||||
if (this.isModifyCurrentFile()) {
|
if (this.isModifyCurrentFile()) {
|
||||||
node.name = newName;
|
tree.updateNodeParamValue(node, "name", newName);
|
||||||
|
node.name = newName; //repair current node
|
||||||
this.props.onFileClick(null, node);
|
this.props.onFileClick(null, node);
|
||||||
this.changeActivedNode({node});
|
tree.setOneNodeToActived({node});
|
||||||
|
this.setState({tree_data: tree});
|
||||||
|
} else {
|
||||||
|
tree.updateNodeParamValue(node, "name", newName);
|
||||||
|
this.setState({tree_data: tree});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'dir') {
|
if (type === 'dir') {
|
||||||
|
let _this = this;
|
||||||
this.props.editorUtilities.renameDir(filePath, newName).then(res => {
|
this.props.editorUtilities.renameDir(filePath, newName).then(res => {
|
||||||
|
let tree = this.state.tree_data.copy();
|
||||||
|
let currentNode = this.state.currentNode;
|
||||||
if (this.isModifyContainsCurrentFile()) {
|
if (this.isModifyContainsCurrentFile()) {
|
||||||
let currentNode = this.state.currentNode;
|
let nodePath = currentNode.path;
|
||||||
let nodePath = encodeURI(currentNode.path);
|
let filePath = _this.props.currentFileNode.path;
|
||||||
let pathname = window.location.pathname;
|
let start = filePath.indexOf(nodePath);
|
||||||
let start = pathname.indexOf(nodePath);
|
let node = currentNode.getNodeByPath(filePath.slice(start));
|
||||||
let node = currentNode.getNodeByPath(decodeURI(pathname.slice(start)));
|
if (node) {
|
||||||
if(node){
|
tree.updateNodeParamValue(currentNode, "name", newName);
|
||||||
currentNode.name = newName;
|
currentNode.name = newName;
|
||||||
this.props.onFileClick(null, node);
|
this.props.onFileClick(null, node);
|
||||||
this.changeActivedNode({node})
|
tree.setOneNodeToActived({node});
|
||||||
|
this.setState({tree_data: tree});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
tree.updateNodeParamValue(currentNode, "name", newName);
|
||||||
|
this.setState({tree_data: tree});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -183,26 +197,17 @@ class SidePanel extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changeActivedNode(node) {
|
|
||||||
let tree = this.state.tree_data.copy();
|
|
||||||
tree.setOneNodeToActived(node);
|
|
||||||
this.setState({
|
|
||||||
tree_data: tree
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
isModifyCurrentFile() {
|
isModifyCurrentFile() {
|
||||||
let name = this.state.currentNode.name;
|
let nodeName = this.state.currentNode.name;
|
||||||
let pathname = window.location.pathname;
|
let fileName = this.props.currentFileNode.name;
|
||||||
let currentName = pathname.slice(pathname.lastIndexOf("/") + 1);
|
return nodeName === fileName;
|
||||||
return encodeURI(name) === currentName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isModifyContainsCurrentFile() {
|
isModifyContainsCurrentFile() {
|
||||||
let pathname = window.location.pathname;
|
let filePath = this.props.currentFileNode.path;
|
||||||
let nodePath = this.state.currentNode.path;
|
let nodePath = this.state.currentNode.path;
|
||||||
|
|
||||||
if (pathname.indexOf(encodeURI(nodePath)) > -1) {
|
if (filePath.indexOf(nodePath) > -1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -249,6 +254,20 @@ class SidePanel extends Component {
|
|||||||
document.addEventListener('click', this.onHideContextMenu);
|
document.addEventListener('click', this.onHideContextMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
let path = nextProps.searchedPath; //handle search module
|
||||||
|
if (path !== this.searchedPath) {
|
||||||
|
let node = this.state.tree_data.getNodeByPath(path);
|
||||||
|
this.searchedPath = path;
|
||||||
|
this.props.onFileClick(null, node);
|
||||||
|
let tree = this.state.tree_data.copy();
|
||||||
|
tree.setOneNodeToActived({node});
|
||||||
|
this.setState({
|
||||||
|
tree_data: tree
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
document.removeEventListener('click', this.onHideContextMenu);
|
document.removeEventListener('click', this.onHideContextMenu);
|
||||||
}
|
}
|
||||||
@@ -280,6 +299,7 @@ class SidePanel extends Component {
|
|||||||
{this.state.tree_data &&
|
{this.state.tree_data &&
|
||||||
<TreeView
|
<TreeView
|
||||||
permission={this.props.permission}
|
permission={this.props.permission}
|
||||||
|
currentFileNode={this.props.currentFileNode}
|
||||||
treeData={this.state.tree_data}
|
treeData={this.state.tree_data}
|
||||||
currentNode={this.state.currentNode}
|
currentNode={this.state.currentNode}
|
||||||
isNodeItemFrezee={this.state.isNodeItemFrezee}
|
isNodeItemFrezee={this.state.isNodeItemFrezee}
|
||||||
|
@@ -114,6 +114,7 @@ class TreeNodeView extends React.Component {
|
|||||||
treeView={this.props.treeView}
|
treeView={this.props.treeView}
|
||||||
isNodeItemFrezee={this.props.isNodeItemFrezee}
|
isNodeItemFrezee={this.props.isNodeItemFrezee}
|
||||||
permission={this.props.permission}
|
permission={this.props.permission}
|
||||||
|
currentFileNode={this.props.currentFileNode}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -171,9 +172,14 @@ class TreeNodeView extends React.Component {
|
|||||||
const styles = {};
|
const styles = {};
|
||||||
let node = this.props.node;
|
let node = this.props.node;
|
||||||
let { type, icon } = this.getNodeTypeAndIcon();
|
let { type, icon } = this.getNodeTypeAndIcon();
|
||||||
|
let hlClass = "";
|
||||||
|
if (node.path === this.props.currentFileNode.path) {
|
||||||
|
hlClass = "tree-node-hight-light";
|
||||||
|
}
|
||||||
|
let customClass = "tree-node " + hlClass;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div type={type} className="tree-node" style={styles}>
|
<div type={type} className={customClass} style={styles}>
|
||||||
<div
|
<div
|
||||||
onMouseLeave={this.onMouseLeave}
|
onMouseLeave={this.onMouseLeave}
|
||||||
onMouseEnter={this.onMouseEnter}
|
onMouseEnter={this.onMouseEnter}
|
||||||
|
@@ -53,6 +53,7 @@ class TreeView extends React.PureComponent {
|
|||||||
node={this.props.treeData.root}
|
node={this.props.treeData.root}
|
||||||
isNodeItemFrezee={this.props.isNodeItemFrezee}
|
isNodeItemFrezee={this.props.isNodeItemFrezee}
|
||||||
permission={this.props.permission}
|
permission={this.props.permission}
|
||||||
|
currentFileNode={this.props.currentFileNode}
|
||||||
onShowContextMenu={this.props.onShowContextMenu}
|
onShowContextMenu={this.props.onShowContextMenu}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -88,6 +88,15 @@ class Tree {
|
|||||||
return findNode;
|
return findNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateNodeParamValue(node, param, value) {
|
||||||
|
let findNode = this.getNodeByPath(node.path);
|
||||||
|
if (findNode[param]) {
|
||||||
|
findNode[param] = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
traverseDF(callback) {
|
traverseDF(callback) {
|
||||||
let stack = [];
|
let stack = [];
|
||||||
let found = false;
|
let found = false;
|
||||||
|
@@ -158,6 +158,10 @@
|
|||||||
line-height: 1.625 !important;
|
line-height: 1.625 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tree-node-hight-light {
|
||||||
|
background-color: rgb(255,239,178);
|
||||||
|
}
|
||||||
|
|
||||||
.dropdown-menu {
|
.dropdown-menu {
|
||||||
min-width: 8rem;
|
min-width: 8rem;
|
||||||
}
|
}
|
||||||
|
@@ -73,13 +73,15 @@ class Wiki extends Component {
|
|||||||
latestContributor: '',
|
latestContributor: '',
|
||||||
lastModified: '',
|
lastModified: '',
|
||||||
permission: '',
|
permission: '',
|
||||||
isFileLoading: false
|
isFileLoading: false,
|
||||||
|
currentFileNode: null,
|
||||||
|
searchedPath: null,
|
||||||
};
|
};
|
||||||
window.onpopstate = this.onpopstate;
|
window.onpopstate = this.onpopstate;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.loadFile(initialFilePath);
|
this.loadFile({path: initialFilePath});
|
||||||
}
|
}
|
||||||
|
|
||||||
fileNameFromPath(filePath) {
|
fileNameFromPath(filePath) {
|
||||||
@@ -114,14 +116,14 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSearchedClick = (path) => {
|
onSearchedClick = (path) => {
|
||||||
if (path) {
|
if (this.state.currentFileNode.path !== path) {
|
||||||
this.loadFile(path);
|
this.setState({searchedPath : path});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onFileClick = (e, node) => {
|
onFileClick = (e, node) => {
|
||||||
if (node.isMarkdown()) {
|
if (node.isMarkdown()) {
|
||||||
this.loadFile(node.path);
|
this.loadFile(node);
|
||||||
} else {
|
} else {
|
||||||
const w=window.open('about:blank');
|
const w=window.open('about:blank');
|
||||||
const url = serviceUrl + '/lib/' + repoID + '/file' + node.path;
|
const url = serviceUrl + '/lib/' + repoID + '/file' + node.path;
|
||||||
@@ -129,10 +131,9 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFile(filePath) {
|
loadFile(node) {
|
||||||
this.setState({
|
let filePath = node.path;
|
||||||
isFileLoading: true
|
this.setState({isFileLoading: true});
|
||||||
})
|
|
||||||
seafileAPI.getWikiFileContent(slug, filePath)
|
seafileAPI.getWikiFileContent(slug, filePath)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -142,7 +143,8 @@ class Wiki extends Component {
|
|||||||
permission: res.data.permission,
|
permission: res.data.permission,
|
||||||
fileName: this.fileNameFromPath(filePath),
|
fileName: this.fileNameFromPath(filePath),
|
||||||
filePath: filePath,
|
filePath: filePath,
|
||||||
isFileLoading: false
|
isFileLoading: false,
|
||||||
|
currentFileNode: node
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -178,6 +180,8 @@ class Wiki extends Component {
|
|||||||
onCloseSide ={this.onCloseSide}
|
onCloseSide ={this.onCloseSide}
|
||||||
editorUtilities={editorUtilities}
|
editorUtilities={editorUtilities}
|
||||||
permission={this.state.permission}
|
permission={this.state.permission}
|
||||||
|
currentFileNode={this.state.currentFileNode}
|
||||||
|
searchedPath={this.state.searchedPath}
|
||||||
/>
|
/>
|
||||||
<MainPanel
|
<MainPanel
|
||||||
content={this.state.content}
|
content={this.state.content}
|
||||||
|
Reference in New Issue
Block a user