1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 17:02:47 +00:00

Improve search in file move/copy dialog (#3543)

This commit is contained in:
Daniel Pan
2019-05-27 17:13:15 +08:00
committed by GitHub
parent 4ffa3c48cf
commit 07881f6ff9
13 changed files with 370 additions and 220 deletions

View File

@@ -36,6 +36,7 @@ class FileChooser extends React.Component {
isResultGot: false,
searchInfo: '',
searchResults: [],
selectedItemInfo: {},
};
this.inputValue = '';
this.timer = null;
@@ -100,6 +101,7 @@ class FileChooser extends React.Component {
this.setState({
repoList: repoList,
isOtherRepoShow: !this.state.isOtherRepoShow,
selectedItemInfo: {}
});
});
}
@@ -285,13 +287,83 @@ class FileChooser extends React.Component {
}
if (this.state.isResultGot && this.state.searchResults.length > 0) {
return (<SearchedListView searchResults={this.state.searchResults} onItemClick={this.onSearchedItemClick}/>);
return (
<SearchedListView
searchResults={this.state.searchResults}
onItemClick={this.onSearchedItemClick}
onSearchedItemDoubleClick={this.onSearchedItemDoubleClick}
/>);
}
}
onSearchedItemDoubleClick = (item) => {
let selectedItemInfo = {
repoID: item.repo_id,
filePath: item.path,
}
this.setState({
selectedItemInfo: selectedItemInfo
});
if (item.repo_id === this.props.repoID) {
seafileAPI.getRepoInfo(this.props.repoID).then(res => {
// need to optimized
let repoInfo = new RepoInfo(res.data);
let path = item.path.substring(0, (item.path.length - 1));
this.setState({
selectedRepo: repoInfo,
selectedPath: path,
isCurrentRepoShow: true,
});
});
} else {
if (!this.state.hasRequest) {
let that = this;
seafileAPI.listRepos().then(res => {
// todo optimized code
let repos = res.data.repos;
let repoList = [];
let repoIdList = [];
for (let i = 0; i < repos.length; i++) {
if (repos[i].permission !== 'rw') {
continue;
}
if (that.props.repoID && (repos[i].repo_name === that.state.currentRepoInfo.repo_name)) {
continue;
}
if (repoIdList.indexOf(repos[i].repo_id) > -1) {
continue;
}
repoList.push(repos[i]);
repoIdList.push(repos[i].repo_id);
}
repoList = Utils.sortRepos(repoList, 'name', 'asc');
let repo = repoList.filter(repoItem => repoItem.repo_id === item.repo_id);
let path = item.path.substring(0, (item.path.length - 1));
let selectRepo = repo[0];
this.setState({
repoList: repoList,
isOtherRepoShow: true,
selectedPath: path,
selectedRepo: selectRepo,
});
});
}
else {
this.setState({isOtherRepoShow: !this.state.isOtherRepoShow});
}
}
this.onCloseSearching();
}
renderRepoListView = () => {
return (
<div className="file-chooser-container">
<div className="file-chooser-container user-select-none">
{this.props.mode === 'current_repo_and_other_repos' && (
<Fragment>
<div className="list-view">
@@ -310,6 +382,7 @@ class FileChooser extends React.Component {
onDirentItemClick={this.onDirentItemClick}
isShowFile={this.props.isShowFile}
fileSuffixes={this.props.fileSuffixes}
selectedItemInfo={this.state.selectedItemInfo}
/>
}
</div>
@@ -329,6 +402,7 @@ class FileChooser extends React.Component {
onDirentItemClick={this.onDirentItemClick}
isShowFile={this.props.isShowFile}
fileSuffixes={this.props.fileSuffixes}
selectedItemInfo={this.state.selectedItemInfo}
/>
}
</div>
@@ -351,6 +425,7 @@ class FileChooser extends React.Component {
onDirentItemClick={this.onDirentItemClick}
isShowFile={this.props.isShowFile}
fileSuffixes={this.props.fileSuffixes}
selectedItemInfo={this.state.selectedItemInfo}
/>
}
</div>
@@ -371,6 +446,7 @@ class FileChooser extends React.Component {
onDirentItemClick={this.onDirentItemClick}
isShowFile={this.props.isShowFile}
fileSuffixes={this.props.fileSuffixes}
selectedItemInfo={this.state.selectedItemInfo}
/>
</div>
</div>