2020-04-15 09:04:01 -05:00
|
|
|
import { useMemo, useState } from 'react';
|
2021-03-02 06:59:35 -06:00
|
|
|
import { filterSpans, TraceSpan } from '@jaegertracing/jaeger-ui-components';
|
2020-04-08 10:16:22 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controls the state of search input that highlights spans if they match the search string.
|
|
|
|
* @param spans
|
|
|
|
*/
|
2020-06-24 13:58:42 -05:00
|
|
|
export function useSearch(spans?: TraceSpan[]) {
|
2020-04-08 10:16:22 -05:00
|
|
|
const [search, setSearch] = useState('');
|
2020-07-09 08:16:35 -05:00
|
|
|
const spanFindMatches: Set<string> | undefined | null = useMemo(() => {
|
2020-04-15 09:04:01 -05:00
|
|
|
return search && spans ? filterSpans(search, spans) : undefined;
|
|
|
|
}, [search, spans]);
|
|
|
|
|
2020-04-08 10:16:22 -05:00
|
|
|
return { search, setSearch, spanFindMatches };
|
|
|
|
}
|