X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/1514f6a2ae8103f75f08034299115ad751d8a785..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 = (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 = (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; @@ -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 + props.onSearch(props.text)} /> + ; +}; + +interface RenderAutocompleteItemsProps { text: string | JSX.Element; + navigateTo: (uuid: string) => void; + uuid: string; } -export const RecentQueriesItem = (props: RenderQueriesProps) => { +export const RenderAutocompleteItems = (props: RenderAutocompleteItemsProps) => { return - + props.navigateTo(props.uuid)} /> ; }; +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 - + props.onSearch(props.text)} /> - + props.deleteSavedQuery(props.id)}> @@ -103,10 +131,10 @@ export const SearchBarView = withStyles(styles)( timeout: number; render() { - const { classes, currentView, openView, closeView, open } = this.props; - return closeView()}> - -
+ const { classes, currentView, openSearchView, closeView, isPopoverOpen } = this.props; + return + + openView()} + onClick={openSearchView} endAdornment={ @@ -124,8 +152,10 @@ export const SearchBarView = withStyles(styles)( } /> - {open && this.getView(currentView)} +
+ {isPopoverOpen && this.getView(currentView)} +
; } @@ -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 ; + return ; case SearchView.ADVANCED: - return ; + return ; case SearchView.AUTOCOMPLETE: - return ; + return ; default: - return ; + return ; } } handleSubmit = (event: React.FormEvent) => { 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) => {