1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00
Files
seahub/frontend/src/components/toolbar/common-toolbar.js
cir9no 24ad6cda3e 12.0 integrate filename seasearch (#6412)
* seafevents integrate filename seasearch

* feat: integrate filename seasearch

* control seasearch open and close at seafevents conf

* fix post redundant api

* feat/seasearch: change seasearch control option

* cancel seasearch url verify

* fix bug

* add es search control  field

* delete redundant seafile ai code

* update

---------

Co-authored-by: ‘JoinTyang’ <yangtong1009@163.com>
2024-07-25 14:17:24 +08:00

118 lines
3.3 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { isPro, gettext, showLogoutIcon, enableSeasearch, enableElasticsearch } from '../../utils/constants';
import Search from '../search/search';
import AISearch from '../search/ai-search';
import SearchByName from '../search/search-by-name';
import Notification from '../common/notification';
import Account from '../common/account';
import Logout from '../common/logout';
import { EVENT_BUS_TYPE } from '../common/event-bus-type';
const propTypes = {
repoID: PropTypes.string,
path: PropTypes.string,
repoName: PropTypes.string,
isLibView: PropTypes.bool,
onSearchedClick: PropTypes.func,
searchPlaceholder: PropTypes.string,
currentRepoInfo: PropTypes.object,
eventBus: PropTypes.object,
isViewFile: PropTypes.bool,
showSearch: PropTypes.bool
};
class CommonToolbar extends React.Component {
constructor(props) {
super(props);
this.state = {
repoID: props.repoID,
repoName: props.repoName,
isLibView: props.isLibView,
path: props.path,
isViewFile: props.isViewFile,
currentRepoInfo: props.currentRepoInfo,
};
}
componentDidMount() {
if (this.props.eventBus) {
this.unsubscribeLibChange = this.props.eventBus.subscribe(EVENT_BUS_TYPE.CURRENT_LIBRARY_CHANGED, this.onRepoChange);
}
}
componentWillUnmount() {
this.unsubscribeLibChange && this.unsubscribeLibChange();
}
onRepoChange = ({ repoID, repoName, isLibView, path, isViewFile, currentRepoInfo }) => {
this.setState({ repoID, repoName, isLibView, path, isViewFile, currentRepoInfo });
};
onSearchedClick = (searchedItem) => {
// If search result is current library, use libContentView.onSearchedClick; else use app.onSearchedClick
if (this.state.isLibView && this.state.repoID === searchedItem.repo_id) {
this.props.eventBus.dispatch(EVENT_BUS_TYPE.SEARCH_LIBRARY_CONTENT, searchedItem);
} else {
this.props.onSearchedClick(searchedItem);
}
};
renderSearch = () => {
const { repoID, repoName, isLibView, path, isViewFile, currentRepoInfo } = this.state;
const { searchPlaceholder } = this.props;
const placeholder = searchPlaceholder || gettext('Search files');
if (isPro) {
if (enableSeasearch && !enableElasticsearch) {
return (
<AISearch
repoID={repoID}
path={path}
isViewFile={isViewFile}
placeholder={placeholder}
currentRepoInfo={currentRepoInfo}
onSearchedClick={this.onSearchedClick}
isLibView={isLibView}
/>
);
} else {
return (
<Search
repoID={repoID}
placeholder={placeholder}
onSearchedClick={this.onSearchedClick}
isViewFile={isViewFile}
isPublic={false}
path={path}
/>
);
}
} else {
if (isLibView) {
return (
<SearchByName repoID={repoID} repoName={repoName} />
);
}
return null;
}
};
render() {
const { showSearch = true } = this.props;
return (
<div className="common-toolbar">
{showSearch && this.renderSearch()}
<Notification />
<Account />
{showLogoutIcon && (<Logout />)}
</div>
);
}
}
CommonToolbar.propTypes = propTypes;
export default CommonToolbar;