useSearch.ts 544 B

12345678910111213141516
  1. import { useMemo, useState } from 'react';
  2. import { filterSpans, TraceSpan } from '@jaegertracing/jaeger-ui-components';
  3. /**
  4. * Controls the state of search input that highlights spans if they match the search string.
  5. * @param spans
  6. */
  7. export function useSearch(spans?: TraceSpan[]) {
  8. const [search, setSearch] = useState('');
  9. const spanFindMatches: Set<string> | undefined = useMemo(() => {
  10. return search && spans ? filterSpans(search, spans) : undefined;
  11. }, [search, spans]);
  12. return { search, setSearch, spanFindMatches };
  13. }