X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/449c296e7c60e97281f8b11f5ad193a66e1d02a8..6234908246415d038d74f9f0b69ab8ea886f9296:/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 cfab6c71..68418ba1 100644
--- a/src/views-components/search-bar/search-bar-view.tsx
+++ b/src/views-components/search-bar/search-bar-view.tsx
@@ -15,38 +15,36 @@ import {
     ClickAwayListener
 } from '@material-ui/core';
 import SearchIcon from '@material-ui/icons/Search';
-import { RemoveIcon } from '~/components/icon/icon';
+import { RemoveIcon, EditSavedQueryIcon } 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, 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' | 'view';
+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: 10000
+            zIndex: 1
         }
     };
 };
@@ -55,19 +53,23 @@ type SearchBarDataProps = {
     searchValue: string;
     currentView: string;
     isPopoverOpen: boolean;
+    savedQueries: SearchBarAdvanceFormData[];
+    tags: any;
 } & SearchBarAutocompleteViewDataProps;
 
 interface SearchBarActionProps {
     onSearch: (value: string) => any;
+    searchDataOnEnter: (value: string) => void;
     debounce?: number;
     onSetView: (currentView: string) => void;
-    openView: () => void;
     closeView: () => void;
     saveRecentQuery: (query: string) => void;
     loadRecentQueries: () => string[];
-    saveQuery: (query: string) => void;
-    loadSavedQueries: () => string[];
+    saveQuery: (data: SearchBarAdvanceFormData) => void;
     deleteSavedQuery: (id: number) => void;
+    openSearchView: () => void;
+    navigateTo: (uuid: string) => void;
+    editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void;
 }
 
 type SearchBarProps = SearchBarDataProps & SearchBarActionProps & WithStyles<CssRules>;
@@ -76,27 +78,47 @@ interface SearchBarState {
     value: string;
 }
 
-interface RenderSavedQueriesProps {
-    text: string | JSX.Element;
-    id: number;
-    deleteSavedQuery: (id: number) => void;
+interface RenderRecentQueriesProps {
+    text: string;
+    onSearch: (searchValue: string) => void;
 }
 
-interface RenderRecentQueriesProps {
+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: RenderRecentQueriesProps) => {
+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;
+    id: number;
+    deleteSavedQuery: (id: number) => void;
+    onSearch: (searchValue: string) => void;
+    editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void;
+    data: SearchBarAdvanceFormData;
+}
 
 export const RenderSavedQueries = (props: RenderSavedQueriesProps) => {
     return <ListItem button>
-        <ListItemText secondary={props.text} />
+        <ListItemText secondary={props.text} onClick={() => props.onSearch(props.text)} />
         <ListItemSecondaryAction>
+            <Tooltip title="Edit">
+                <IconButton aria-label="Edit" onClick={() => props.editSavedQuery(props.data, props.id)}>
+                    <EditSavedQueryIcon />
+                </IconButton>
+            </Tooltip>
             <Tooltip title="Remove">
                 <IconButton aria-label="Remove" onClick={() => props.deleteSavedQuery(props.id)}>
                     <RemoveIcon />
@@ -117,10 +139,10 @@ export const SearchBarView = withStyles(styles)(
         timeout: number;
 
         render() {
-            const { classes, currentView, openView, closeView, isPopoverOpen } = this.props;
-            return <ClickAwayListener onClickAway={() => closeView()}>
+            const { classes, currentView, openSearchView, closeView, isPopoverOpen } = this.props;
+            return <ClickAwayListener onClickAway={closeView}>
                 <Paper className={isPopoverOpen ? classes.containerSearchViewOpened : classes.container} >
-                    <form onSubmit={this.handleSubmit} className={classes.searchBar}>
+                    <form onSubmit={this.handleSubmit}>
                         <Input
                             className={classes.input}
                             onChange={this.handleChange}
@@ -128,7 +150,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'>
@@ -161,17 +183,19 @@ export const SearchBarView = withStyles(styles)(
         }
 
         getView = (currentView: string) => {
+            const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue, searchResults, saveQuery, onSearch, navigateTo, editSavedQuery, tags } = this.props;
             switch (currentView) {
                 case SearchView.BASIC:
-                    return <SearchBarBasicView setView={this.props.onSetView} recentQueries={this.props.loadRecentQueries} savedQueries={this.props.loadSavedQueries} deleteSavedQuery={this.props.deleteSavedQuery}/>;
+                    return <SearchBarBasicView setView={onSetView} recentQueries={loadRecentQueries} savedQueries={savedQueries} deleteSavedQuery={deleteSavedQuery} onSearch={onSearch} editSavedQuery={editSavedQuery} />;
                 case SearchView.ADVANCED:
-                    return <SearchBarAdvancedView setView={this.props.onSetView} />;
+                    return <SearchBarAdvancedView setView={onSetView} saveQuery={saveQuery} tags={tags} />;
                 case SearchView.AUTOCOMPLETE:
                     return <SearchBarAutocompleteView
-                        searchResults={this.props.searchResults}
-                        searchValue={this.props.searchValue} />;
+                        navigateTo={navigateTo}
+                        searchResults={searchResults}
+                        searchValue={searchValue} />;
                 default:
-                    return <SearchBarBasicView setView={this.props.onSetView} recentQueries={this.props.loadRecentQueries} savedQueries={this.props.loadSavedQueries} deleteSavedQuery={this.props.deleteSavedQuery}/>;
+                    return <SearchBarBasicView setView={onSetView} recentQueries={loadRecentQueries} savedQueries={savedQueries} deleteSavedQuery={deleteSavedQuery} onSearch={onSearch} editSavedQuery={editSavedQuery} />;
             }
         }
 
@@ -179,10 +203,8 @@ export const SearchBarView = withStyles(styles)(
             event.preventDefault();
             clearTimeout(this.timeout);
             this.props.saveRecentQuery(this.state.value);
-            this.props.saveQuery(this.state.value);
-            this.props.onSearch(this.state.value);
+            this.props.searchDataOnEnter(this.state.value);
             this.props.loadRecentQueries();
-            this.props.loadSavedQueries();
         }
 
         handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
