Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Oct 27, 2020
1 parent 73a26cb commit 70d0631
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ 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 @@ -69,6 +68,7 @@ interface Props {
searchValue: string;
onClose: () => void;
popoverIsOpen: boolean;
initialValue?: string;
setPopoverIsOpen: React.Dispatch<SetStateAction<boolean>>;
}

Expand All @@ -82,13 +82,10 @@ export function SelectableUrlList({
onClose,
popoverIsOpen,
setPopoverIsOpen,
initialValue,
}: 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 @@ -136,10 +133,12 @@ export function SelectableUrlList({
};

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

// only want to call it at initial render to set value
// coming from initial value/url
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchRef]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import { render } from '../../../utils/test_helper';
describe('SelectableUrlList', () => {
it('it uses search term value from url', () => {
jest.spyOn(fetcherHook, 'useFetcher').mockReturnValue({
data: {
noOfLongTasks: 3.0009765625,
sumOfLongTasks: 520.4375,
longestLongTask: 271.4375,
},
data: {},
status: fetcherHook.FETCH_STATUS.SUCCESS,
refetch: jest.fn(),
});
Expand All @@ -27,6 +23,7 @@ describe('SelectableUrlList', () => {

const { getByDisplayValue } = render(
<SelectableUrlList
initialValue={'blog'}
loading={false}
data={{ items: [], total: 0 }}
onChange={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export function URLSearch({ onChange: onFilterChange }: Props) {
<h4>{I18LABELS.url}</h4>
</EuiTitle>
<SelectableUrlList
initialValue={searchTerm}
loading={isLoading}
onInputChange={onInputChange}
onTermChange={onTermChange}
Expand Down

0 comments on commit 70d0631

Please sign in to comment.