import React from 'react'; import PropTypes from 'prop-types'; import { I18n } from '@lingui/react'; import { t } from '@lingui/macro'; import { Button, Dropdown, DropdownPosition, DropdownToggle, DropdownItem, TextInput } from '@patternfly/react-core'; class Search extends React.Component { constructor (props) { super(props); const { sortedColumnKey } = this.props; this.state = { isSearchDropdownOpen: false, searchKey: sortedColumnKey, searchValue: '', }; this.handleSearchInputChange = this.handleSearchInputChange.bind(this); this.onSearchDropdownToggle = this.onSearchDropdownToggle.bind(this); this.onSearchDropdownSelect = this.onSearchDropdownSelect.bind(this); this.onSearch = this.onSearch.bind(this); } onSearchDropdownToggle (isSearchDropdownOpen) { this.setState({ isSearchDropdownOpen }); } onSearchDropdownSelect ({ target }) { const { columns } = this.props; const { innerText } = target; const [{ key: searchKey }] = columns.filter(({ name }) => name === innerText); this.setState({ isSearchDropdownOpen: false, searchKey }); } onSearch () { const { searchValue } = this.state; const { onSearch } = this.props; onSearch(searchValue); } handleSearchInputChange (searchValue) { this.setState({ searchValue }); } render () { const { up } = DropdownPosition; const { columns } = this.props; const { isSearchDropdownOpen, searchKey, searchValue, } = this.state; const [{ name: searchColumnName }] = columns.filter(({ key }) => key === searchKey); const searchDropdownItems = columns .filter(({ key }) => key !== searchKey) .map(({ key, name }) => ( {name} )); return ( {({ i18n }) => (
{searchColumnName} )} dropdownItems={searchDropdownItems} />