import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import MediaQuery from 'react-responsive'; import { gettext, lang } from '../../utils/constants'; import { Button, Col, Collapse, CustomInput, FormGroup, Input, Label, Row, InputGroupAddon, InputGroup } from 'reactstrap'; import SelectDate from './select-date'; const { repo_name, search_repo } = window.search.pageOptions; class AdvancedSearch extends React.Component { constructor(props) { super(props); } getFileTypesList = (fileTypes) => { const fileTypeItems = [gettext('Text'), gettext('Document'), gettext('Image'), gettext('Video'), gettext('Audio'), 'PDF', 'Markdown']; let ftype = []; for (let i = 0, len = fileTypes.length; i < len; i++) { if (fileTypes[i]) { ftype.push(fileTypeItems[i]); } } return ftype; }; render() { const { stateAndValues } = this.props; const { errorDateMsg, errorSizeMsg } = stateAndValues; if (stateAndValues.isShowSearchFilter) { const { size_from, size_to, time_from, time_to, search_repo, fileTypeItemsStatus } = stateAndValues; const fileTypes = this.getFileTypesList(fileTypeItemsStatus); const typesLength = fileTypes.length; return (
{search_repo && {gettext('Libraries')}{': '}{search_repo == 'all'? gettext('All') : repo_name}} {typesLength > 0 && {gettext('File Types')}{': '} {fileTypes.map((type, index) => { return {type}{index !== (typesLength - 1) && ','}{' '}; })} } {(time_from && time_to ) && {gettext('Last Update')}{': '}{time_from}{' '}{gettext('to')}{' '}{time_to} } {(size_from && size_to) && {gettext('Size')}{': '}{size_from}{'MB - '}{size_to}{'MB'} }
); } else { return (
{search_repo !== 'all' &&
{gettext('Libraries')}{': '}
}
{gettext('File Types')}{': '} this.props.handlerFileTypes(0)} checked={stateAndValues.fileTypeItemsStatus[0]}/> this.props.handlerFileTypes(1)} checked={stateAndValues.fileTypeItemsStatus[1]}/> this.props.handlerFileTypes(2)} checked={stateAndValues.fileTypeItemsStatus[2]}/> this.props.handlerFileTypes(3)} checked={stateAndValues.fileTypeItemsStatus[3]}/> this.props.handlerFileTypes(4)} checked={stateAndValues.fileTypeItemsStatus[4]}/> this.props.handlerFileTypes(5)} checked={stateAndValues.fileTypeItemsStatus[5]}/> this.props.handlerFileTypes(6)} checked={stateAndValues.fileTypeItemsStatus[6]}/>
{gettext('Last Update')}{': '}
-
{errorDateMsg && {errorDateMsg}}
{gettext('Size')}{': '} {'MB'} {errorSizeMsg &&
{errorSizeMsg}
}
-
{'MB'}
{errorSizeMsg &&
{errorSizeMsg}
}
); } } } const advancedSearchPropTypes = { openFileTypeCollapse: PropTypes.func.isRequired, closeFileTypeCollapse: PropTypes.func.isRequired, handlerFileTypes: PropTypes.func.isRequired, handlerFileTypesInput: PropTypes.func.isRequired, handleSubmit: PropTypes.func.isRequired, handleReset: PropTypes.func.isRequired, handlerRepo: PropTypes.func.isRequired, handleKeyDown: PropTypes.func.isRequired, handleTimeFromInput: PropTypes.func.isRequired, handleTimeToInput: PropTypes.func.isRequired, handleSizeFromInput: PropTypes.func.isRequired, handleSizeToInput: PropTypes.func.isRequired, stateAndValues: PropTypes.object.isRequired, }; AdvancedSearch.propTypes = advancedSearchPropTypes; export default AdvancedSearch;