// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; import { IconButton, Paper, StyleRulesCallback, withStyles, WithStyles, Tooltip, InputAdornment, Input, ListItem, ListItemText, ListItemSecondaryAction, ClickAwayListener } from '@material-ui/core'; import SearchIcon from '@material-ui/icons/Search'; import { RemoveIcon } from '~/components/icon/icon'; import { SearchView } from '~/store/search-bar/search-bar-reducer'; import { SearchBarBasicView } from '~/views-components/search-bar/search-bar-basic-view'; import { SearchBarAdvancedView } from '~/views-components/search-bar/search-bar-advanced-view'; import { SearchBarAutocompleteView } from '~/views-components/search-bar/search-bar-autocomplete-view'; type CssRules = 'container' | 'input' | 'searchBar'; const styles: StyleRulesCallback = theme => { return { container: { position: 'relative', width: '100%', borderRadius: '0px' }, input: { border: 'none', padding: `0px ${theme.spacing.unit}px` }, searchBar: { height: '30px' } }; }; interface SearchBarDataProps { value: string; currentView: string; open: boolean; } interface SearchBarActionProps { onSearch: (value: string) => any; debounce?: number; onSetView: (currentView: string) => void; openView: () => void; closeView: () => void; } type SearchBarProps = SearchBarDataProps & SearchBarActionProps & WithStyles; interface SearchBarState { value: string; } interface RenderQueriesProps { text: string; } export const RenderRecentQueries = (props: RenderQueriesProps) => { return ; }; export const RenderSavedQueries = (props: RenderQueriesProps) => { return ; }; export const DEFAULT_SEARCH_DEBOUNCE = 1000; export const SearchBarView = withStyles(styles)( class extends React.Component { state: SearchBarState = { value: "" }; timeout: number; render() { const { classes, currentView, openView, closeView, open } = this.props; return closeView()}>
openView()} endAdornment={ } /> {open && this.getView(currentView)}
; } componentDidMount() { this.setState({ value: this.props.value }); } componentWillReceiveProps(nextProps: SearchBarProps) { if (nextProps.value !== this.props.value) { this.setState({ value: nextProps.value }); } } componentWillUnmount() { clearTimeout(this.timeout); } getView = (currentView: string) => { switch (currentView) { case SearchView.BASIC: return ; case SearchView.ADVANCED: return ; case SearchView.AUTOCOMPLETE: return ; default: return ; } } handleSubmit = (event: React.FormEvent) => { event.preventDefault(); clearTimeout(this.timeout); this.props.onSearch(this.state.value); } handleChange = (event: React.ChangeEvent) => { clearTimeout(this.timeout); this.setState({ value: event.target.value }); this.timeout = window.setTimeout( () => this.props.onSearch(this.state.value), this.props.debounce || DEFAULT_SEARCH_DEBOUNCE ); if (event.target.value.length > 0) { this.props.onSetView(SearchView.AUTOCOMPLETE); } else { this.props.onSetView(SearchView.BASIC); } } } );