diff --git a/frontend/src/components/file-chooser/repo-list-item.js b/frontend/src/components/file-chooser/repo-list-item.js index 95c39414ed..dafd92e584 100644 --- a/frontend/src/components/file-chooser/repo-list-item.js +++ b/frontend/src/components/file-chooser/repo-list-item.js @@ -10,6 +10,8 @@ import { Utils } from '../../utils/utils'; import toaster from '../toast'; const propTypes = { + isCurrentRepo: PropTypes.bool, + currentPath: PropTypes.string, isShowFile: PropTypes.bool, isCurrentRepo: PropTypes.bool, selectedPath: PropTypes.string, @@ -30,11 +32,43 @@ class RepoListItem extends React.Component { this.state = { isShowChildren: this.props.initToShowChildren, treeData: treeHelper.buildTree(), + hasLoaded: false, }; } componentDidMount () { - const repoID = this.props.repo.repo_id; + const { isCurrentRepo, currentPath, repo, selectedItemInfo } = this.props; + + // render search result + const { repoID, filePath } = selectedItemInfo || {}; + if (repoID && repoID === repo.repo_id) { + this.loadRepoDirentList(repo); + setTimeout(() => { + this.setState({isShowChildren: true}); + this.loadNodeAndParentsByPath(repoID, filePath); + }, 0); + return; + } + + // the repo is current repo and currentPath is not '/' + if (isCurrentRepo && !repoID) { + this.loadRepoDirentList(repo); + setTimeout(() => { + const repoID = repo.repo_id; + if (isCurrentRepo && currentPath && currentPath != '/') { + const expandNode = true; + this.loadNodeAndParentsByPath(repoID, currentPath, expandNode); + } + }, 0); + } + } + + loadRepoDirentList = (repo) => { + const { hasLoaded } = this.state; + if (hasLoaded) return; + + const repoID = repo.repo_id; + seafileAPI.listDir(repoID, '/').then(res => { let tree = this.state.treeData.clone(); let direntList = []; @@ -45,22 +79,11 @@ class RepoListItem extends React.Component { } this.addResponseListToNode(direntList, tree.root); - this.setState({treeData: tree}, () => { - const { isCurrentRepo, currentPath } = this.props; - if (isCurrentRepo && currentPath && currentPath != '/') { - const expandNode = true; - this.loadNodeAndParentsByPath(repoID, currentPath, expandNode); - } - }); + this.setState({ treeData: tree, hasLoaded: true }); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); - - if (this.props.selectedItemInfo.repoID === this.props.repo.repo_id) { - this.setState({isShowChildren: true}); - this.loadNodeAndParentsByPath(this.props.selectedItemInfo.repoID, this.props.selectedItemInfo.filePath); - } } addResponseListToNode = (list, node) => { @@ -145,6 +168,8 @@ class RepoListItem extends React.Component { onToggleClick = (e) => { e.stopPropagation(); + let repo = this.props.repo; + this.loadRepoDirentList(repo); this.setState({isShowChildren: !this.state.isShowChildren}); }; @@ -154,8 +179,9 @@ class RepoListItem extends React.Component { }; onRepoItemClick = (e) => { - if (!this.isCurrentRepo() || this.props.selectedPath !== '') { - this.props.onRepoItemClick(this.props.repo); + const { repo, selectedPath } = this.props; + if (!this.isCurrentRepo() || (selectedPath !== '' && selectedPath !== '/')) { + this.props.onRepoItemClick(repo); } else { this.onToggleClick(e); } diff --git a/seahub/templates/react_app.html b/seahub/templates/react_app.html index 7be753d8d6..342eda4a87 100644 --- a/seahub/templates/react_app.html +++ b/seahub/templates/react_app.html @@ -28,7 +28,7 @@ "displayName": "{{request.user.username|email2nickname|escapejs}}", "email": "{{request.user.username|escapejs}}", "domain": "{{service_url}}", - "provider": "{{site_name}}", + "provider": "seafile", "userId": "{{request.user.username|escapejs}}", }; window.AscDesktopEditor.execCommand('portal:login', JSON.stringify(params)); diff --git a/seahub/templates/view_file_onlyoffice.html b/seahub/templates/view_file_onlyoffice.html index 53c6358dc0..58ffb7ebd3 100644 --- a/seahub/templates/view_file_onlyoffice.html +++ b/seahub/templates/view_file_onlyoffice.html @@ -125,7 +125,7 @@ html, body { padding:0; margin:0; height:100%; } "displayName": "{{request.user.username|email2nickname|escapejs}}", "email": "{{request.user.username|escapejs}}", "domain": "{{service_url}}", - "provider": "{{site_name}}", + "provider": "seafile", "userId": "{{request.user.username|escapejs}}", }; window.AscDesktopEditor.execCommand('portal:login', JSON.stringify(params));