2019-03-09 04:06:11 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-08-07 06:01:37 +00:00
|
|
|
import classnames from 'classnames';
|
2019-03-09 04:06:11 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
currentItem: PropTypes.object,
|
|
|
|
onItemClick: PropTypes.func.isRequired,
|
2019-05-27 09:13:15 +00:00
|
|
|
onSearchedItemDoubleClick: PropTypes.func.isRequired,
|
2023-09-13 00:40:50 +00:00
|
|
|
item: PropTypes.object,
|
2019-03-09 04:06:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SearchedListItem extends React.Component {
|
2020-11-02 05:56:35 +00:00
|
|
|
|
2019-03-09 04:06:11 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
highlight: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseEnter = () => {
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ highlight: true });
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-03-09 04:06:11 +00:00
|
|
|
|
|
|
|
onMouseLeave = () => {
|
2024-07-18 03:58:42 +00:00
|
|
|
this.setState({ highlight: false });
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-03-09 04:06:11 +00:00
|
|
|
|
|
|
|
onClick = () => {
|
|
|
|
let item = this.props.item;
|
|
|
|
this.props.onItemClick(item);
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-03-09 04:06:11 +00:00
|
|
|
|
2019-05-27 09:13:15 +00:00
|
|
|
searchItemDoubleClick = (e) => {
|
|
|
|
let item = this.props.item;
|
2020-11-02 05:56:35 +00:00
|
|
|
|
2019-05-27 09:13:15 +00:00
|
|
|
this.props.onSearchedItemDoubleClick(item);
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-05-27 09:13:15 +00:00
|
|
|
|
2019-03-09 04:06:11 +00:00
|
|
|
render() {
|
|
|
|
let { item, currentItem } = this.props;
|
2019-04-10 10:08:25 +00:00
|
|
|
let folderIconUrl = item.link_content ? Utils.getFolderIconUrl(false, 192) : Utils.getDefaultLibIconUrl(false);
|
2024-08-05 13:04:31 +00:00
|
|
|
let fileIconUrl = item.is_dir ? folderIconUrl : Utils.getFileIconUrl(item.name);
|
2019-03-09 04:06:11 +00:00
|
|
|
return (
|
2024-08-07 06:01:37 +00:00
|
|
|
<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}
|
|
|
|
>
|
2024-08-13 02:21:32 +00:00
|
|
|
<td className="text-center searched-item-icon">
|
2024-08-07 06:01:37 +00:00
|
|
|
<img className="item-img" src={fileIconUrl} alt="" width="24"/>
|
|
|
|
</td>
|
2024-08-13 02:21:32 +00:00
|
|
|
<td className='searched-item-link'>
|
2024-08-07 06:01:37 +00:00
|
|
|
<span className="item-link">{item.repo_name}/{item.link_content}</span>
|
|
|
|
</td>
|
2019-03-09 04:06:11 +00:00
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchedListItem.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default SearchedListItem;
|