X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/84e4588aed7bea1bcf5727ef2eea1a692b4e3bab..f5127724c5ca39a59a08ba20f843e530b0650be9:/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 f26cb7e690..d096771217 100644 --- a/src/views-components/search-bar/search-bar-view.tsx +++ b/src/views-components/search-bar/search-bar-view.tsx @@ -21,22 +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' | 'input' | 'searchBar'; +type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'view'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => { return { container: { position: 'relative', width: '100%', - borderRadius: '0px' + borderRadius: theme.spacing.unit / 2 + }, + containerSearchViewOpened: { + position: 'relative', + width: '100%', + 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 } }; }; @@ -44,15 +52,20 @@ 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; + saveRecentQuery: (query: string) => void; + loadRecentQueries: () => string[]; + saveQuery: (data: SearchBarAdvanceFormData) => void; + deleteSavedQuery: (id: number) => void; + openSearchView: () => void; } type SearchBarProps = SearchBarDataProps & SearchBarActionProps & WithStyles; @@ -61,23 +74,29 @@ interface SearchBarState { value: string; } -interface RenderQueriesProps { +interface RenderSavedQueriesProps { + text: string | JSX.Element; + id: number; + deleteSavedQuery: (id: number) => void; +} + +interface RenderRecentQueriesProps { text: string | JSX.Element; } -export const RecentQueriesItem = (props: RenderQueriesProps) => { +export const RecentQueriesItem = (props: RenderRecentQueriesProps) => { return ; }; -export const RenderSavedQueries = (props: RenderQueriesProps) => { +export const RenderSavedQueries = (props: RenderSavedQueriesProps) => { return - + props.deleteSavedQuery(props.id)}> @@ -96,10 +115,10 @@ export const SearchBarView = withStyles(styles)( timeout: number; render() { - const { classes, currentView, openView, closeView, open } = this.props; + const { classes, currentView, openSearchView, closeView, isPopoverOpen } = this.props; return closeView()}> - -
+ + openView()} + onClick={openSearchView} endAdornment={ @@ -117,8 +136,10 @@ export const SearchBarView = withStyles(styles)( } /> - {open && this.getView(currentView)} +
+ {isPopoverOpen && this.getView(currentView)} +
; } @@ -138,24 +159,27 @@ export const SearchBarView = withStyles(styles)( } getView = (currentView: string) => { + const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue, searchResults, saveQuery } = 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.saveRecentQuery(this.state.value); this.props.onSearch(this.state.value); + this.props.loadRecentQueries(); } handleChange = (event: React.ChangeEvent) => {