From: Michal Klobukowski Date: Thu, 14 Mar 2019 11:43:11 +0000 (+0100) Subject: Merge branch '14917-searching-by-properties' X-Git-Tag: 1.4.0~33 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/b449a296cd8fc842ee196e1056e3be93fc9d29f5?hp=ff9d56a31288124381f58f6577a490c0d6867bc3 Merge branch '14917-searching-by-properties' refs #14917 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts index a513a6bb..bffa337b 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -178,7 +178,6 @@ export const changeData = (searchValue: string) => } else if (searchValuePresent) { dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.AUTOCOMPLETE)); dispatch(searchBarActions.SET_SELECTED_ITEM(searchValue)); - debounceStartSearch(dispatch); } else { dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC)); dispatch(searchBarActions.SET_SEARCH_RESULTS([])); @@ -199,7 +198,6 @@ export const submitData = (event: React.FormEvent) => dispatch(navigateToSearchResults); }; -const debounceStartSearch = debounce((dispatch: Dispatch) => dispatch(startSearch()), DEFAULT_SEARCH_DEBOUNCE); const startSearch = () => (dispatch: Dispatch, getState: () => RootState) => { diff --git a/src/views-components/search-bar/search-bar-view.tsx b/src/views-components/search-bar/search-bar-view.tsx index 6251308d..176ca018 100644 --- a/src/views-components/search-bar/search-bar-view.tsx +++ b/src/views-components/search-bar/search-bar-view.tsx @@ -32,6 +32,7 @@ import { SearchBarAdvancedViewActionProps } from '~/views-components/search-bar/search-bar-advanced-view'; import { KEY_CODE_DOWN, KEY_CODE_ESC, KEY_CODE_UP, KEY_ENTER } from "~/common/codes"; +import { debounce } from 'debounce'; type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'view'; @@ -145,52 +146,73 @@ const handleDropdownClick = (e: React.MouseEvent, props: SearchBarViewProps) => }; export const SearchBarView = withStyles(styles)( - (props: SearchBarViewProps) => { - const { classes, isPopoverOpen } = props; - return ( - <> - - {isPopoverOpen && - } - - -
- handleInputClick(e, props)} - onKeyDown={e => handleKeyDown(e, props)} - startAdornment={ - - - - - - - - } - endAdornment={ - - - handleDropdownClick(e, props)}> - - - - - } /> -
-
- {isPopoverOpen && getView({ ...props })} -
-
- - ); - } -); + class extends React.Component { + + debouncedSearch = debounce(() => { + this.props.onSearch(this.props.searchValue); + }, 1000); + + handleChange = (event: React.ChangeEvent) => { + this.debouncedSearch(); + this.props.onChange(event); + } + + handleSubmit = (event: React.FormEvent) => { + this.debouncedSearch.clear(); + this.props.onSubmit(event); + } + + componentWillUnmount() { + this.debouncedSearch.clear(); + } + + render() { + const { children, ...props } = this.props; + const { classes, isPopoverOpen } = this.props; + return ( + <> + + {isPopoverOpen && + } + + +
+ handleInputClick(e, props)} + onKeyDown={e => handleKeyDown(e, props)} + startAdornment={ + + + + + + + + } + endAdornment={ + + + handleDropdownClick(e, props)}> + + + + + } /> +
+
+ {isPopoverOpen && getView({ ...props })} +
+
+ + ); + } + }); const getView = (props: SearchBarViewProps) => { switch (props.currentView) {