Skip to content

Commit

Permalink
fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Oct 26, 2020
1 parent 378a4cb commit 6e0e5ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, {
useRef,
useState,
KeyboardEvent,
useEffect,
} from 'react';
import {
EuiFlexGroup,
Expand Down Expand Up @@ -38,6 +39,7 @@ import {
} from './RenderOption';
import { I18LABELS } from '../../translations';
import { useUiSetting$ } from '../../../../../../../../../src/plugins/kibana_react/public';
import { useUrlParams } from '../../../../../hooks/useUrlParams';

const StyledRow = styled.div<{
darkMode: boolean;
Expand Down Expand Up @@ -83,6 +85,10 @@ export function SelectableUrlList({
}: Props) {
const [darkMode] = useUiSetting$<boolean>('theme:darkMode');

const { urlParams } = useUrlParams();

const { searchTerm } = urlParams;

const [popoverRef, setPopoverRef] = useState<HTMLElement | null>(null);
const [searchRef, setSearchRef] = useState<HTMLInputElement | null>(null);

Expand Down Expand Up @@ -126,6 +132,14 @@ export function SelectableUrlList({
}
};

useEffect(() => {
if (searchRef && searchTerm) {
searchRef.value = searchTerm;
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchRef]);

const loadingMessage = (
<EuiSelectableMessage style={{ minHeight: 300 }}>
<EuiLoadingSpinner size="l" />
Expand Down Expand Up @@ -165,12 +179,12 @@ export function SelectableUrlList({
renderOption={selectableRenderOptions}
singleSelection={false}
searchProps={{
placeholder: I18LABELS.searchByUrl,
isClearable: true,
onFocus: searchOnFocus,
onBlur: searchOnBlur,
onInput: onSearchInput,
inputRef: setSearchRef,
placeholder: I18LABELS.searchByUrl,
}}
listProps={{
rowHeight: 68,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export function URLSearch({ onChange: onFilterChange }: Props) {

const [popoverIsOpen, setPopoverIsOpen] = useState(false);

const [searchValue, setSearchValue] = useState('');
const [searchValue, setSearchValue] = useState(searchTerm ?? '');

const [debouncedValue, setDebouncedValue] = useState('');
const [debouncedValue, setDebouncedValue] = useState(searchTerm ?? '');

useDebounce(
() => {
Expand All @@ -44,12 +44,16 @@ export function URLSearch({ onChange: onFilterChange }: Props) {

const updateSearchTerm = useCallback(
(searchTermN: string) => {
const newQuery = {
...toQuery(history.location.search),
searchTerm: searchTermN || undefined,
};
if (!searchTermN) {
delete newQuery.searchTerm;
}
const newLocation = {
...history.location,
search: fromQuery({
...toQuery(history.location.search),
searchTerm: searchTermN,
}),
search: fromQuery(newQuery),
};
history.push(newLocation);
},
Expand Down

0 comments on commit 6e0e5ac

Please sign in to comment.