grafana/public/app/plugins/datasource/cloudwatch/Search.tsx
Erik Sundell b3540b5f46
Cloudwatch: Add feedback labels to log groups selector (#60619)
* 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
2023-01-03 09:56:01 +01:00

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;