TracesPanel.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { css } from '@emotion/css';
  2. import TracePageSearchBar from '@jaegertracing/jaeger-ui-components/src/TracePageHeader/TracePageSearchBar';
  3. import { TopOfViewRefType } from '@jaegertracing/jaeger-ui-components/src/TraceTimelineViewer/VirtualizedTraceView';
  4. import React, { useMemo, useState, createRef } from 'react';
  5. import { useAsync } from 'react-use';
  6. import { PanelProps } from '@grafana/data';
  7. import { getDataSourceSrv } from '@grafana/runtime';
  8. import { TraceView } from 'app/features/explore/TraceView/TraceView';
  9. import { useSearch } from 'app/features/explore/TraceView/useSearch';
  10. import { transformDataFrames } from 'app/features/explore/TraceView/utils/transform';
  11. const styles = {
  12. wrapper: css`
  13. height: 100%;
  14. overflow: scroll;
  15. `,
  16. };
  17. export const TracesPanel: React.FunctionComponent<PanelProps> = ({ data }) => {
  18. const topOfViewRef = createRef<HTMLDivElement>();
  19. const traceProp = useMemo(() => transformDataFrames(data.series[0]), [data.series]);
  20. const { search, setSearch, spanFindMatches } = useSearch(traceProp?.spans);
  21. const [focusedSpanIdForSearch, setFocusedSpanIdForSearch] = useState('');
  22. const [searchBarSuffix, setSearchBarSuffix] = useState('');
  23. const dataSource = useAsync(async () => {
  24. return await getDataSourceSrv().get(data.request?.targets[0].datasource?.uid);
  25. });
  26. const scrollElement = document.getElementsByClassName(styles.wrapper)[0];
  27. if (!data || !data.series.length || !traceProp) {
  28. return (
  29. <div className="panel-empty">
  30. <p>No data found in response</p>
  31. </div>
  32. );
  33. }
  34. return (
  35. <div className={styles.wrapper}>
  36. <div ref={topOfViewRef}></div>
  37. {data.series[0]?.meta?.preferredVisualisationType === 'trace' ? (
  38. <TracePageSearchBar
  39. navigable={true}
  40. searchValue={search}
  41. setSearch={setSearch}
  42. spanFindMatches={spanFindMatches}
  43. searchBarSuffix={searchBarSuffix}
  44. setSearchBarSuffix={setSearchBarSuffix}
  45. focusedSpanIdForSearch={focusedSpanIdForSearch}
  46. setFocusedSpanIdForSearch={setFocusedSpanIdForSearch}
  47. />
  48. ) : null}
  49. <TraceView
  50. dataFrames={data.series}
  51. scrollElement={scrollElement}
  52. traceProp={traceProp}
  53. spanFindMatches={spanFindMatches}
  54. search={search}
  55. focusedSpanIdForSearch={focusedSpanIdForSearch}
  56. queryResponse={data}
  57. datasource={dataSource.value}
  58. topOfViewRef={topOfViewRef}
  59. topOfViewRefType={TopOfViewRefType.Panel}
  60. />
  61. </div>
  62. );
  63. };