import { SearchBarBasicView } from '~/views-components/search-bar/search-bar-basic-view';
import { SearchBarAdvancedView } from '~/views-components/search-bar/search-bar-advanced-view';
import { SearchBarAutocompleteView, SearchBarAutocompleteViewDataProps } from '~/views-components/search-bar/search-bar-autocomplete-view';
-import { GroupContentsResource } from '~/services/groups-service/groups-service';
+import { ArvadosTheme } from '~/common/custom-theme';
-type CssRules = 'container' | 'input' | 'searchBar';
+type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'searchBar';
-const styles: StyleRulesCallback<CssRules> = theme => {
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => {
return {
container: {
position: 'relative',
width: '100%',
- borderRadius: '0px'
+ borderRadius: theme.spacing.unit / 4
+ },
+ containerSearchViewOpened: {
+ position: 'relative',
+ width: '100%',
+ borderRadius: `${theme.spacing.unit / 4}px ${theme.spacing.unit / 4}px 0 0`
},
input: {
border: 'none',
};
type SearchBarDataProps = {
- value: string;
+ searchValue: string;
currentView: string;
open: boolean;
} & SearchBarAutocompleteViewDataProps;
onSetView: (currentView: string) => void;
openView: () => void;
closeView: () => void;
+ saveQuery: (query: string) => void;
+ loadQueries: () => string[];
}
type SearchBarProps = SearchBarDataProps & SearchBarActionProps & WithStyles<CssRules>;
}
interface RenderQueriesProps {
- text: string;
+ text: string | JSX.Element;
}
-export const RenderRecentQueries = (props: RenderQueriesProps) => {
+export const RecentQueriesItem = (props: RenderQueriesProps) => {
return <ListItem button>
<ListItemText secondary={props.text} />
</ListItem>;
render() {
const { classes, currentView, openView, closeView, open } = this.props;
return <ClickAwayListener onClickAway={() => closeView()}>
- <Paper className={classes.container} >
+ <Paper className={open ? classes.containerSearchViewOpened : classes.container} >
<form onSubmit={this.handleSubmit} className={classes.searchBar}>
<Input
className={classes.input}
}
componentDidMount() {
- this.setState({ value: this.props.value });
+ this.setState({ value: this.props.searchValue });
}
componentWillReceiveProps(nextProps: SearchBarProps) {
- if (nextProps.value !== this.props.value) {
- this.setState({ value: nextProps.value });
+ if (nextProps.searchValue !== this.props.searchValue) {
+ this.setState({ value: nextProps.searchValue });
}
}
getView = (currentView: string) => {
switch (currentView) {
case SearchView.BASIC:
- return <SearchBarBasicView setView={this.props.onSetView} />;
+ return <SearchBarBasicView setView={this.props.onSetView} recentQueries={this.props.loadQueries} />;
case SearchView.ADVANCED:
return <SearchBarAdvancedView setView={this.props.onSetView} />;
case SearchView.AUTOCOMPLETE:
- return <SearchBarAutocompleteView searchResults={this.props.searchResults} />;
+ return <SearchBarAutocompleteView
+ searchResults={this.props.searchResults}
+ searchValue={this.props.searchValue} />;
default:
- return <SearchBarBasicView setView={this.props.onSetView} />;
+ return <SearchBarBasicView setView={this.props.onSetView} recentQueries={this.props.loadQueries} />;
}
}
handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
clearTimeout(this.timeout);
+ this.props.saveQuery(this.state.value);
this.props.onSearch(this.state.value);
+ this.props.loadQueries();
}
handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {