1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
13 InputAdornment, Input,
15 } from '@material-ui/core';
16 import SearchIcon from '@material-ui/icons/Search';
17 import { ArvadosTheme } from '~/common/custom-theme';
18 import { SearchView } from '~/store/search-bar/search-bar-reducer';
21 SearchBarBasicViewDataProps,
22 SearchBarBasicViewActionProps
23 } from '~/views-components/search-bar/search-bar-basic-view';
25 SearchBarAutocompleteView,
26 SearchBarAutocompleteViewDataProps,
27 SearchBarAutocompleteViewActionProps
28 } from '~/views-components/search-bar/search-bar-autocomplete-view';
30 SearchBarAdvancedView,
31 SearchBarAdvancedViewDataProps,
32 SearchBarAdvancedViewActionProps
33 } from '~/views-components/search-bar/search-bar-advanced-view';
35 type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'view';
37 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => {
42 borderRadius: theme.spacing.unit / 2
44 containerSearchViewOpened: {
47 borderRadius: `${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px 0 0`
51 padding: `0px ${theme.spacing.unit}px`
61 export type SearchBarDataProps = SearchBarViewDataProps
62 & SearchBarAutocompleteViewDataProps
63 & SearchBarAdvancedViewDataProps
64 & SearchBarBasicViewDataProps;
66 interface SearchBarViewDataProps {
69 isPopoverOpen: boolean;
73 export type SearchBarActionProps = SearchBarViewActionProps
74 & SearchBarAutocompleteViewActionProps
75 & SearchBarAdvancedViewActionProps
76 & SearchBarBasicViewActionProps;
78 interface SearchBarViewActionProps {
79 onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
80 onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
81 onSetView: (currentView: string) => void;
82 closeView: () => void;
83 openSearchView: () => void;
84 loadRecentQueries: () => string[];
87 type SearchBarViewProps = SearchBarDataProps & SearchBarActionProps & WithStyles<CssRules>;
89 export const SearchBarView = withStyles(styles)(
90 (props : SearchBarViewProps) => {
91 const { classes, isPopoverOpen, closeView, searchValue, openSearchView, onChange, onSubmit } = props;
93 <ClickAwayListener onClickAway={closeView}>
94 <Paper className={isPopoverOpen ? classes.containerSearchViewOpened : classes.container} >
95 <form onSubmit={onSubmit}>
97 className={classes.input}
102 disableUnderline={true}
103 onClick={openSearchView}
105 <InputAdornment position="end">
106 <Tooltip title='Search'>
114 <div className={classes.view}>
115 {isPopoverOpen && getView({...props})}
123 const getView = (props: SearchBarViewProps) => {
124 const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue,
125 searchResults, saveQuery, onSearch, navigateTo, editSavedQuery, tags, currentView } = props;
126 switch (currentView) {
127 case SearchView.AUTOCOMPLETE:
128 return <SearchBarAutocompleteView
129 navigateTo={navigateTo}
130 searchResults={searchResults}
131 searchValue={searchValue} />;
132 case SearchView.ADVANCED:
133 return <SearchBarAdvancedView
134 onSetView={onSetView}
135 saveQuery={saveQuery}
138 return <SearchBarBasicView
139 onSetView={onSetView}
141 loadRecentQueries={loadRecentQueries}
142 savedQueries={savedQueries}
143 deleteSavedQuery={deleteSavedQuery}
144 editSavedQuery={editSavedQuery} />;