X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/fc1ebe112503a685dbbf4acb86dca25d1073b82c..2cfb56ef5060cbad461062690fad650f15c49731:/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 b2575a8f..8e1f84b0 100644
--- a/src/views-components/search-bar/search-bar-view.tsx
+++ b/src/views-components/search-bar/search-bar-view.tsx
@@ -21,27 +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' | 'containerSearchViewOpened' | 'input' | 'searchBar';
+type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'view';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => {
     return {
         container: {
             position: 'relative',
             width: '100%',
-            borderRadius: theme.spacing.unit / 4
+            borderRadius: theme.spacing.unit / 2
         },
         containerSearchViewOpened: {
             position: 'relative',
             width: '100%',
-            borderRadius: `${theme.spacing.unit / 4}px ${theme.spacing.unit / 4}px 0 0`
+            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
         }
     };
 };
@@ -49,17 +52,21 @@ 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;
-    saveQuery: (query: string) => void;
-    loadQueries: () => string[];
+    saveRecentQuery: (query: string) => void;
+    loadRecentQueries: () => string[];
+    saveQuery: (data: SearchBarAdvanceFormData) => void;
+    deleteSavedQuery: (id: number) => void;
+    openSearchView: () => void;
+    navigateTo: (uuid: string) => void;
 }
 
 type SearchBarProps = SearchBarDataProps & SearchBarActionProps & WithStyles<CssRules>;
@@ -68,23 +75,44 @@ interface SearchBarState {
     value: string;
 }
 
-interface RenderQueriesProps {
+
+
+interface RenderRecentQueriesProps {
+    text: string | JSX.Element;
+    onSearch: (searchValue: string | JSX.Element) => void;
+}
+
+export const RenderRecentQueries = (props: RenderRecentQueriesProps) => {
+    return <ListItem button>
+        <ListItemText secondary={props.text} onClick={() => props.onSearch(props.text)} />
+    </ListItem>;
+};
+
+interface RenderAutocompleteItemsProps {
     text: string | JSX.Element;
+    navigateTo: (uuid: string) => void;
+    uuid: string;
 }
 
-export const RecentQueriesItem = (props: RenderQueriesProps) => {
+export const RenderAutocompleteItems = (props: RenderAutocompleteItemsProps) => {
     return <ListItem button>
-        <ListItemText secondary={props.text} />
+        <ListItemText secondary={props.text} onClick={() => props.navigateTo(props.uuid)} />
     </ListItem>;
 };
 
+interface RenderSavedQueriesProps {
+    text: string | JSX.Element;
+    id: number;
+    deleteSavedQuery: (id: number) => void;
+    onSearch: (searchValue: string | JSX.Element) => void;
+}
 
-export const RenderSavedQueries = (props: RenderQueriesProps) => {
+export const RenderSavedQueries = (props: RenderSavedQueriesProps) => {
     return <ListItem button>
-        <ListItemText secondary={props.text} />
+        <ListItemText secondary={props.text} onClick={() => props.onSearch(props.text)} />
         <ListItemSecondaryAction>
             <Tooltip title="Remove">
-                <IconButton aria-label="Remove">
+                <IconButton aria-label="Remove" onClick={() => props.deleteSavedQuery(props.id)}>
                     <RemoveIcon />
                 </IconButton>
             </Tooltip>
@@ -103,10 +131,10 @@ export const SearchBarView = withStyles(styles)(
         timeout: number;
 
         render() {
-            const { classes, currentView, openView, closeView, open } = this.props;
-            return <ClickAwayListener onClickAway={() => closeView()}>
-                <Paper className={open ? classes.containerSearchViewOpened : classes.container} >
-                    <form onSubmit={this.handleSubmit} className={classes.searchBar}>
+            const { classes, currentView, openSearchView, closeView, isPopoverOpen } = this.props;
+            return <ClickAwayListener onClickAway={closeView}>
+                <Paper className={isPopoverOpen ? classes.containerSearchViewOpened : classes.container} >
+                    <form onSubmit={this.handleSubmit}>
                         <Input
                             className={classes.input}
                             onChange={this.handleChange}
@@ -114,7 +142,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'>
@@ -124,8 +152,10 @@ export const SearchBarView = withStyles(styles)(
                                     </Tooltip>
                                 </InputAdornment>
                             } />
-                        {open && this.getView(currentView)}
                     </form>
+                    <div className={classes.view}>
+                        {isPopoverOpen && this.getView(currentView)}
+                    </div>
                 </Paper >
             </ClickAwayListener>;
         }
@@ -145,26 +175,28 @@ export const SearchBarView = withStyles(styles)(
         }
 
         getView = (currentView: string) => {
+            const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue, searchResults, saveQuery, onSearch, navigateTo } = this.props;
             switch (currentView) {
                 case SearchView.BASIC:
-                    return <SearchBarBasicView setView={this.props.onSetView} recentQueries={this.props.loadQueries} />;
+                    return <SearchBarBasicView setView={onSetView} recentQueries={loadRecentQueries} savedQueries={savedQueries} deleteSavedQuery={deleteSavedQuery} onSearch={onSearch} />;
                 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
+                        navigateTo={navigateTo}
+                        searchResults={searchResults}
+                        searchValue={searchValue} />;
                 default:
-                    return <SearchBarBasicView setView={this.props.onSetView} recentQueries={this.props.loadQueries} />;
+                    return <SearchBarBasicView setView={onSetView} recentQueries={loadRecentQueries} savedQueries={savedQueries} deleteSavedQuery={deleteSavedQuery} onSearch={onSearch} />;
             }
         }
 
         handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
             event.preventDefault();
             clearTimeout(this.timeout);
-            this.props.saveQuery(this.state.value);
+            this.props.saveRecentQuery(this.state.value);
             this.props.onSearch(this.state.value);
-            this.props.loadQueries();
+            this.props.loadRecentQueries();
         }
 
         handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
