X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/1e2635886e1342a7b29914d3a437313807676466..8623f430ea556381f8681c2aea00e43e64d3f6d1:/src/views-components/search-bar/search-bar-autocomplete-view.tsx?ds=sidebyside

diff --git a/src/views-components/search-bar/search-bar-autocomplete-view.tsx b/src/views-components/search-bar/search-bar-autocomplete-view.tsx
index faeabb17..e45197dd 100644
--- a/src/views-components/search-bar/search-bar-autocomplete-view.tsx
+++ b/src/views-components/search-bar/search-bar-autocomplete-view.tsx
@@ -3,30 +3,57 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { Paper, StyleRulesCallback, withStyles, WithStyles, List } from '@material-ui/core';
-import { RenderRecentQueries } from '~/views-components/search-bar/search-bar-view';
+import { Paper, StyleRulesCallback, withStyles, WithStyles, List, ListItem, ListItemText } from '@material-ui/core';
+import { GroupContentsResource } from '~/services/groups-service/groups-service';
+import Highlighter from "react-highlight-words";
+import { SearchBarSelectedItem } from "~/store/search-bar/search-bar-reducer";
 
-type CssRules = 'list' | 'searchView';
+type CssRules = 'searchView' | 'list' | 'listItem';
 
 const styles: StyleRulesCallback<CssRules> = theme => {
     return {
+        searchView: {
+            borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px`
+        },
         list: {
-            padding: '0px'
+            padding: 0
         },
-        searchView: {
-            borderRadius: `0 0 ${theme.spacing.unit / 4}px ${theme.spacing.unit / 4}px`
+        listItem: {
+            paddingLeft: theme.spacing.unit,
+            paddingRight: theme.spacing.unit * 2,
         }
     };
 };
 
-interface SearchBarAutocompleteViewProps {
+export interface SearchBarAutocompleteViewDataProps {
+    searchResults: GroupContentsResource[];
+    searchValue?: string;
+    selectedItem: SearchBarSelectedItem;
+}
+
+export interface SearchBarAutocompleteViewActionProps {
+    navigateTo: (uuid: string) => void;
 }
 
+type SearchBarAutocompleteViewProps = SearchBarAutocompleteViewDataProps & SearchBarAutocompleteViewActionProps & WithStyles<CssRules>;
+
 export const SearchBarAutocompleteView = withStyles(styles)(
-    ({ classes }: SearchBarAutocompleteViewProps & WithStyles<CssRules>) =>
-        <Paper className={classes.searchView}>
+    ({ classes, searchResults, searchValue, navigateTo, selectedItem }: SearchBarAutocompleteViewProps) => {
+        return <Paper className={classes.searchView}>
             <List component="nav" className={classes.list}>
-                <RenderRecentQueries text='AUTOCOMPLETE VIEW' />
+                <ListItem button className={classes.listItem} selected={!selectedItem || searchValue === selectedItem.id}>
+                    <ListItemText secondary={searchValue}/>
+                </ListItem>
+                {searchResults.map((item: GroupContentsResource) =>
+                    <ListItem button key={item.uuid} className={classes.listItem} selected={item.uuid === selectedItem.id}>
+                        <ListItemText secondary={getFormattedText(item.name, searchValue)}
+                                      onClick={() => navigateTo(item.uuid)}/>
+                    </ListItem>
+                )}
             </List>
-        </Paper>
-);
\ No newline at end of file
+        </Paper>;
+    });
+
+const getFormattedText = (textToHighlight: string, searchString = '') => {
+    return <Highlighter searchWords={[searchString]} autoEscape={true} textToHighlight={textToHighlight} />;
+};
