TraceViewContainer.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import TracePageSearchBar from '@jaegertracing/jaeger-ui-components/src/TracePageHeader/TracePageSearchBar';
  2. import { TopOfViewRefType } from '@jaegertracing/jaeger-ui-components/src/TraceTimelineViewer/VirtualizedTraceView';
  3. import React, { RefObject, useMemo, useState } from 'react';
  4. import { useSelector } from 'react-redux';
  5. import { DataFrame, SplitOpen, PanelData } from '@grafana/data';
  6. import { Collapse } from '@grafana/ui';
  7. import { StoreState } from 'app/types';
  8. import { ExploreId } from 'app/types/explore';
  9. import { TraceView } from './TraceView';
  10. import { useSearch } from './useSearch';
  11. import { transformDataFrames } from './utils/transform';
  12. interface Props {
  13. dataFrames: DataFrame[];
  14. splitOpenFn: SplitOpen;
  15. exploreId: ExploreId;
  16. scrollElement?: Element;
  17. queryResponse: PanelData;
  18. topOfViewRef: RefObject<HTMLDivElement>;
  19. }
  20. export function TraceViewContainer(props: Props) {
  21. // At this point we only show single trace
  22. const frame = props.dataFrames[0];
  23. const { dataFrames, splitOpenFn, exploreId, scrollElement, topOfViewRef, queryResponse } = props;
  24. const traceProp = useMemo(() => transformDataFrames(frame), [frame]);
  25. const { search, setSearch, spanFindMatches } = useSearch(traceProp?.spans);
  26. const [focusedSpanIdForSearch, setFocusedSpanIdForSearch] = useState('');
  27. const [searchBarSuffix, setSearchBarSuffix] = useState('');
  28. const datasource = useSelector(
  29. (state: StoreState) => state.explore[props.exploreId!]?.datasourceInstance ?? undefined
  30. );
  31. if (!traceProp) {
  32. return null;
  33. }
  34. return (
  35. <>
  36. <TracePageSearchBar
  37. navigable={true}
  38. searchValue={search}
  39. setSearch={setSearch}
  40. spanFindMatches={spanFindMatches}
  41. searchBarSuffix={searchBarSuffix}
  42. setSearchBarSuffix={setSearchBarSuffix}
  43. focusedSpanIdForSearch={focusedSpanIdForSearch}
  44. setFocusedSpanIdForSearch={setFocusedSpanIdForSearch}
  45. />
  46. <Collapse label="Trace View" isOpen>
  47. <TraceView
  48. exploreId={exploreId}
  49. dataFrames={dataFrames}
  50. splitOpenFn={splitOpenFn}
  51. scrollElement={scrollElement}
  52. traceProp={traceProp}
  53. spanFindMatches={spanFindMatches}
  54. search={search}
  55. focusedSpanIdForSearch={focusedSpanIdForSearch}
  56. queryResponse={queryResponse}
  57. datasource={datasource}
  58. topOfViewRef={topOfViewRef}
  59. topOfViewRefType={TopOfViewRefType.Explore}
  60. />
  61. </Collapse>
  62. </>
  63. );
  64. }