X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/89c3c647797787377f4d950b38d320ee3b28e92c..721322dd1f2af54d1aaa831a96dcf78ed0065085:/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 ec1c8b8304..8aa8ffa7dd 100644 --- a/src/views-components/search-bar/search-bar-view.tsx +++ b/src/views-components/search-bar/search-bar-view.tsx @@ -11,7 +11,7 @@ import { WithStyles, Tooltip, InputAdornment, Input, - ClickAwayListener + Popover } from '@material-ui/core'; import SearchIcon from '@material-ui/icons/Search'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; @@ -86,6 +86,7 @@ interface SearchBarViewActionProps { loadRecentQueries: () => string[]; moveUp: () => void; moveDown: () => void; + setAdvancedDataFromSearchValue: (search: string) => void; } type SearchBarViewProps = SearchBarDataProps & SearchBarActionProps & WithStyles; @@ -94,6 +95,7 @@ const handleKeyDown = (e: React.KeyboardEvent, props: SearchBarViewProps) => { if (e.keyCode === KEY_CODE_DOWN) { e.preventDefault(); if (!props.isPopoverOpen) { + props.onSetView(SearchView.AUTOCOMPLETE); props.openSearchView(); } else { props.moveDown(); @@ -117,48 +119,99 @@ const handleKeyDown = (e: React.KeyboardEvent, props: SearchBarViewProps) => { } }; +const handleInputClick = (e: React.MouseEvent, props: SearchBarViewProps) => { + if (props.searchValue) { + props.onSetView(SearchView.AUTOCOMPLETE); + props.openSearchView(); + } else { + props.closeView(); + } +}; + +const handleDropdownClick = (e: React.MouseEvent, props: SearchBarViewProps) => { + e.stopPropagation(); + if (props.isPopoverOpen) { + if (props.currentView === SearchView.ADVANCED) { + props.closeView(); + } else { + props.setAdvancedDataFromSearchValue(props.searchValue); + props.onSetView(SearchView.ADVANCED); + } + } else { + props.setAdvancedDataFromSearchValue(props.searchValue); + props.onSetView(SearchView.ADVANCED); + } +}; + export const SearchBarView = withStyles(styles)( - (props : SearchBarViewProps) => { - const { classes, isPopoverOpen } = props; - return ( - - -
- handleKeyDown(e, props)} - startAdornment={ - - - - - - - - } - endAdornment={ - - - props.onSetView(SearchView.ADVANCED)}> - - - - - } /> -
-
- {isPopoverOpen && getView({...props})} + class SearchBarView extends React.Component { + + viewAnchorRef = React.createRef(); + + render() { + const { children, ...props } = this.props; + const { classes, isPopoverOpen } = props; + return ( + +
+
+ handleInputClick(e, props)} + onKeyDown={e => handleKeyDown(e, props)} + startAdornment={ + + + + + + + + } + endAdornment={ + + + handleDropdownClick(e, props)}> + + + + + } /> +
+ + {getView({ ...props })} +
- - ); + ); + } + + getViewWidth() { + const { current } = this.viewAnchorRef; + return current ? current.offsetWidth : 0; + } } + ); const getView = (props: SearchBarViewProps) => { @@ -172,7 +225,8 @@ const getView = (props: SearchBarViewProps) => { case SearchView.ADVANCED: return ; + tags={props.tags} + saveQuery={props.saveQuery} />; default: return