mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-06 09:21:54 +00:00
fix search file when move file or dirent (#6480)
* fix search file when move file or dirent * change style * change style
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { Fragment } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Input } from 'reactstrap';
|
import { Input } from 'reactstrap';
|
||||||
import { seafileAPI } from '../../utils/seafile-api';
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import { gettext, isPro } from '../../utils/constants';
|
import { gettext, isPro, enableSeasearch, enableElasticsearch } from '../../utils/constants';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
import toaster from '../toast';
|
import toaster from '../toast';
|
||||||
import RepoInfo from '../../models/repo-info';
|
import RepoInfo from '../../models/repo-info';
|
||||||
@@ -242,23 +242,23 @@ class FileChooser extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sendRequest = (queryData, cancelToken) => {
|
sendRequest = (queryData, cancelToken) => {
|
||||||
seafileAPI.searchFiles(queryData, cancelToken).then(res => {
|
if (isPro && enableSeasearch && !enableElasticsearch) {
|
||||||
if (!res.data.total) {
|
seafileAPI.aiSearchFiles(queryData, cancelToken).then(res => {
|
||||||
this.setState({
|
this.handleSearchResult(res);
|
||||||
searchResults: [],
|
|
||||||
isResultGot: true
|
|
||||||
});
|
|
||||||
this.source = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let items = this.formatResultItems(res.data.results);
|
|
||||||
this.setState({
|
|
||||||
searchResults: items,
|
|
||||||
isResultGot: true
|
|
||||||
});
|
});
|
||||||
this.source = null;
|
} else {
|
||||||
|
seafileAPI.searchFiles(queryData, cancelToken).then(res => {
|
||||||
|
this.handleSearchResult(res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleSearchResult = (res) => {
|
||||||
|
this.setState({
|
||||||
|
searchResults: res.data.total ? this.formatResultItems(res.data.results) : [],
|
||||||
|
isResultGot: true
|
||||||
});
|
});
|
||||||
|
this.source = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
cancelRequest = () => {
|
cancelRequest = () => {
|
||||||
@@ -324,7 +324,8 @@ class FileChooser extends React.Component {
|
|||||||
searchResults={this.state.searchResults}
|
searchResults={this.state.searchResults}
|
||||||
onItemClick={this.onSearchedItemClick}
|
onItemClick={this.onSearchedItemClick}
|
||||||
onSearchedItemDoubleClick={this.onSearchedItemDoubleClick}
|
onSearchedItemDoubleClick={this.onSearchedItemDoubleClick}
|
||||||
/>);
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import classnames from 'classnames';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
@@ -41,16 +42,23 @@ class SearchedListItem extends React.Component {
|
|||||||
let { item, currentItem } = this.props;
|
let { item, currentItem } = this.props;
|
||||||
let folderIconUrl = item.link_content ? Utils.getFolderIconUrl(false, 192) : Utils.getDefaultLibIconUrl(false);
|
let folderIconUrl = item.link_content ? Utils.getFolderIconUrl(false, 192) : Utils.getDefaultLibIconUrl(false);
|
||||||
let fileIconUrl = item.is_dir ? folderIconUrl : Utils.getFileIconUrl(item.name);
|
let fileIconUrl = item.is_dir ? folderIconUrl : Utils.getFileIconUrl(item.name);
|
||||||
let trClass = this.state.highlight ? 'tr-highlight' : '';
|
|
||||||
if (currentItem) {
|
|
||||||
if (item.repo_id === currentItem.repo_id && item.path === currentItem.path) {
|
|
||||||
trClass = 'tr-active';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<tr className={trClass} onClick={this.onClick} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} onDoubleClick={this.searchItemDoubleClick}>
|
<tr
|
||||||
<td className="text-center"><img className="item-img" src={fileIconUrl} alt="" width="24"/></td>
|
className={classnames('searched-list-item', {
|
||||||
<td><span className="item-link">{item.repo_name}/{item.link_content}</span></td>
|
'tr-highlight': this.state.highlight,
|
||||||
|
'tr-active': currentItem && item.repo_id === currentItem.repo_id && item.path === currentItem.path
|
||||||
|
})}
|
||||||
|
onClick={this.onClick}
|
||||||
|
onMouseEnter={this.onMouseEnter}
|
||||||
|
onMouseLeave={this.onMouseLeave}
|
||||||
|
onDoubleClick={this.searchItemDoubleClick}
|
||||||
|
>
|
||||||
|
<td className="text-center">
|
||||||
|
<img className="item-img" src={fileIconUrl} alt="" width="24"/>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span className="item-link">{item.repo_name}/{item.link_content}</span>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -98,13 +98,17 @@
|
|||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.file-chooser-search-container .searched-list-item {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.file-chooser-search-input {
|
.file-chooser-search-input {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-chooser-search-input .search-control {
|
.file-chooser-search-input .search-control {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0.5rem;
|
top: 13px;
|
||||||
right: 1.5rem;
|
right: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user