mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* add max item text * add tests * add selected log groups counter label * cleanup * fix styling in selector fields * remove unused imports * move selected log groups to a new component * add confirm dialog * remove not used import * set max logs groups to 6 * add margin bottom
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { debounce } from 'lodash';
|
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
|
|
import { Icon, Input } from '@grafana/ui';
|
|
|
|
// TODO: consider moving search into grafana/ui, this is mostly the same as that in azure monitor
|
|
const Search = ({ searchFn, searchPhrase }: { searchPhrase: string; searchFn: (searchPhrase: string) => void }) => {
|
|
const [searchFilter, setSearchFilter] = useState(searchPhrase);
|
|
|
|
const debouncedSearch = useMemo(() => debounce(searchFn, 600), [searchFn]);
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
// Stop the invocation of the debounced function after unmounting
|
|
debouncedSearch?.cancel();
|
|
};
|
|
}, [debouncedSearch]);
|
|
|
|
return (
|
|
<Input
|
|
aria-label="log group search"
|
|
prefix={<Icon name="search" />}
|
|
value={searchFilter}
|
|
onChange={(event) => {
|
|
const searchPhrase = event.currentTarget.value;
|
|
setSearchFilter(searchPhrase);
|
|
debouncedSearch(searchPhrase);
|
|
}}
|
|
placeholder="search by log group name prefix"
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default Search;
|