Skip to content

Commit

Permalink
fix search file when move file or dirent (#6480)
Browse files Browse the repository at this point in the history
* fix search file when move file or dirent

* change style

* change style
  • Loading branch information
Michael18811380328 authored Aug 7, 2024
1 parent 4dc0df7 commit 8d17562
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
35 changes: 18 additions & 17 deletions frontend/src/components/file-chooser/file-chooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { Input } from 'reactstrap';
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 toaster from '../toast';
import RepoInfo from '../../models/repo-info';
Expand Down Expand Up @@ -242,23 +242,23 @@ class FileChooser extends React.Component {
};

sendRequest = (queryData, cancelToken) => {
seafileAPI.searchFiles(queryData, cancelToken).then(res => {
if (!res.data.total) {
this.setState({
searchResults: [],
isResultGot: true
});
this.source = null;
return;
}

let items = this.formatResultItems(res.data.results);
this.setState({
searchResults: items,
isResultGot: true
if (isPro && enableSeasearch && !enableElasticsearch) {
seafileAPI.aiSearchFiles(queryData, cancelToken).then(res => {
this.handleSearchResult(res);
});
} else {
seafileAPI.searchFiles(queryData, cancelToken).then(res => {
this.handleSearchResult(res);
});
this.source = null;
}
};

handleSearchResult = (res) => {
this.setState({
searchResults: res.data.total ? this.formatResultItems(res.data.results) : [],
isResultGot: true
});
this.source = null;
};

cancelRequest = () => {
Expand Down Expand Up @@ -324,7 +324,8 @@ class FileChooser extends React.Component {
searchResults={this.state.searchResults}
onItemClick={this.onSearchedItemClick}
onSearchedItemDoubleClick={this.onSearchedItemDoubleClick}
/>);
/>
);
}
};

Expand Down
26 changes: 17 additions & 9 deletions frontend/src/components/file-chooser/searched-list-item.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Utils } from '../../utils/utils';

const propTypes = {
Expand Down Expand Up @@ -41,16 +42,23 @@ class SearchedListItem extends React.Component {
let { item, currentItem } = this.props;
let folderIconUrl = item.link_content ? Utils.getFolderIconUrl(false, 192) : Utils.getDefaultLibIconUrl(false);
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 (
<tr className={trClass} 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
className={classnames('searched-list-item', {
'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>
);
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/css/file-chooser.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@
background-color: #f5f5f5;
}

.file-chooser-search-container .searched-list-item {
cursor: pointer;
}

.file-chooser-search-input {
position: relative;
}

.file-chooser-search-input .search-control {
position: absolute;
top: 0.5rem;
top: 13px;
right: 1.5rem;
}

Expand Down

0 comments on commit 8d17562

Please sign in to comment.