X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/df9ea1569dd0d4ae1c05bacc8a5e5f7695f4453b..f5127724c5ca39a59a08ba20f843e530b0650be9:/src/views-components/search-bar/search-bar-view.tsx

diff --git a/src/views-components/search-bar/search-bar-view.tsx b/src/views-components/search-bar/search-bar-view.tsx
index f26cb7e690..d096771217 100644
--- a/src/views-components/search-bar/search-bar-view.tsx
+++ b/src/views-components/search-bar/search-bar-view.tsx
@@ -21,22 +21,30 @@ import { SearchBarBasicView } from '~/views-components/search-bar/search-bar-bas
 import { SearchBarAdvancedView } from '~/views-components/search-bar/search-bar-advanced-view';
 import { SearchBarAutocompleteView, SearchBarAutocompleteViewDataProps } from '~/views-components/search-bar/search-bar-autocomplete-view';
 import { ArvadosTheme } from '~/common/custom-theme';
+import { SearchBarAdvanceFormData } from '~/models/search-bar';
 
-type CssRules = 'container' | 'input' | 'searchBar';
+type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'view';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => {
     return {
         container: {
             position: 'relative',
             width: '100%',
-            borderRadius: '0px'
+            borderRadius: theme.spacing.unit / 2
+        },
+        containerSearchViewOpened: {
+            position: 'relative',
+            width: '100%',
+            borderRadius: `${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px 0 0`
         },
         input: {
             border: 'none',
             padding: `0px ${theme.spacing.unit}px`
         },
-        searchBar: {
-            height: '30px'
+        view: {
+            position: 'absolute',
+            width: '100%',
+            zIndex: 1
         }
     };
 };
@@ -44,15 +52,20 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => {
 type SearchBarDataProps = {
     searchValue: string;
     currentView: string;
-    open: boolean;
+    isPopoverOpen: boolean;
+    savedQueries: string[];
 } & SearchBarAutocompleteViewDataProps;
 
 interface SearchBarActionProps {
     onSearch: (value: string) => any;
     debounce?: number;
     onSetView: (currentView: string) => void;
-    openView: () => void;
     closeView: () => void;
+    saveRecentQuery: (query: string) => void;
+    loadRecentQueries: () => string[];
+    saveQuery: (data: SearchBarAdvanceFormData) => void;
+    deleteSavedQuery: (id: number) => void;
+    openSearchView: () => void;
 }
 
 type SearchBarProps = SearchBarDataProps & SearchBarActionProps & WithStyles<CssRules>;
@@ -61,23 +74,29 @@ interface SearchBarState {
     value: string;
 }
 
-interface RenderQueriesProps {
+interface RenderSavedQueriesProps {
+    text: string | JSX.Element;
+    id: number;
+    deleteSavedQuery: (id: number) => void;
+}
+
+interface RenderRecentQueriesProps {
     text: string | JSX.Element;
 }
 
-export const RecentQueriesItem = (props: RenderQueriesProps) => {
+export const RecentQueriesItem = (props: RenderRecentQueriesProps) => {
     return <ListItem button>
         <ListItemText secondary={props.text} />
     </ListItem>;
 };
 
 
-export const RenderSavedQueries = (props: RenderQueriesProps) => {
+export const RenderSavedQueries = (props: RenderSavedQueriesProps) => {
     return <ListItem button>
         <ListItemText secondary={props.text} />
         <ListItemSecondaryAction>
             <Tooltip title="Remove">
-                <IconButton aria-label="Remove">
+                <IconButton aria-label="Remove" onClick={() => props.deleteSavedQuery(props.id)}>
                     <RemoveIcon />
                 </IconButton>
             </Tooltip>
@@ -96,10 +115,10 @@ export const SearchBarView = withStyles(styles)(
         timeout: number;
 
         render() {
-            const { classes, currentView, openView, closeView, open } = this.props;
+            const { classes, currentView, openSearchView, closeView, isPopoverOpen } = this.props;
             return <ClickAwayListener onClickAway={() => closeView()}>
-                <Paper className={classes.container} >
-                    <form onSubmit={this.handleSubmit} className={classes.searchBar}>
+                <Paper className={isPopoverOpen ? classes.containerSearchViewOpened : classes.container} >
+                    <form onSubmit={this.handleSubmit}>
                         <Input
                             className={classes.input}
                             onChange={this.handleChange}
@@ -107,7 +126,7 @@ export const SearchBarView = withStyles(styles)(
                             value={this.state.value}
                             fullWidth={true}
                             disableUnderline={true}
-                            onClick={() => openView()}
+                            onClick={openSearchView}
                             endAdornment={
                                 <InputAdornment position="end">
                                     <Tooltip title='Search'>
@@ -117,8 +136,10 @@ export const SearchBarView = withStyles(styles)(
                                     </Tooltip>
                                 </InputAdornment>
                             } />
-                        {open && this.getView(currentView)}
                     </form>
+                    <div className={classes.view}>
+                        {isPopoverOpen && this.getView(currentView)}
+                    </div>
                 </Paper >
             </ClickAwayListener>;
         }
@@ -138,24 +159,27 @@ export const SearchBarView = withStyles(styles)(
         }
 
         getView = (currentView: string) => {
+            const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue, searchResults, saveQuery } = this.props;
             switch (currentView) {
                 case SearchView.BASIC:
-                    return <SearchBarBasicView setView={this.props.onSetView} />;
+                    return <SearchBarBasicView setView={onSetView} recentQueries={loadRecentQueries} savedQueries={savedQueries} deleteSavedQuery={deleteSavedQuery} />;
                 case SearchView.ADVANCED:
-                    return <SearchBarAdvancedView setView={this.props.onSetView} />;
+                    return <SearchBarAdvancedView setView={onSetView} saveQuery={saveQuery}/>;
                 case SearchView.AUTOCOMPLETE:
-                    return <SearchBarAutocompleteView 
-                                searchResults={this.props.searchResults} 
-                                searchValue={this.props.searchValue} />;
+                    return <SearchBarAutocompleteView
+                        searchResults={searchResults}
+                        searchValue={searchValue} />;
                 default:
-                    return <SearchBarBasicView setView={this.props.onSetView} />;
+                    return <SearchBarBasicView setView={onSetView} recentQueries={loadRecentQueries} savedQueries={savedQueries} deleteSavedQuery={deleteSavedQuery} />;
             }
         }
 
         handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
             event.preventDefault();
             clearTimeout(this.timeout);
+            this.props.saveRecentQuery(this.state.value);
             this.props.onSearch(this.state.value);
+            this.props.loadRecentQueries();
         }
 
         handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
