spansTable.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {Fragment, useMemo} from 'react';
  2. import Pagination from 'sentry/components/pagination';
  3. import type {NewQuery} from 'sentry/types/organization';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {useDataset} from 'sentry/views/explore/hooks/useDataset';
  7. import {useSampleFields} from 'sentry/views/explore/hooks/useSampleFields';
  8. import {useSorts} from 'sentry/views/explore/hooks/useSorts';
  9. import {useUserQuery} from 'sentry/views/explore/hooks/useUserQuery';
  10. import {useSpansQuery} from 'sentry/views/insights/common/queries/useSpansQuery';
  11. interface SpansTableProps {}
  12. export function SpansTable({}: SpansTableProps) {
  13. const {selection} = usePageFilters();
  14. const [dataset] = useDataset();
  15. const [fields] = useSampleFields();
  16. const [sorts] = useSorts({fields});
  17. const [query] = useUserQuery();
  18. const eventView = useMemo(() => {
  19. const discoverQuery: NewQuery = {
  20. id: undefined,
  21. name: 'Explore - Span Samples',
  22. fields,
  23. orderby: sorts.map(sort => `${sort.kind === 'desc' ? '-' : ''}${sort.field}`),
  24. query,
  25. version: 2,
  26. dataset,
  27. };
  28. return EventView.fromNewQueryWithPageFilters(discoverQuery, selection);
  29. }, [dataset, fields, sorts, query, selection]);
  30. const result = useSpansQuery({
  31. eventView,
  32. initialData: [],
  33. referrer: 'api.explore.spans-samples-table',
  34. });
  35. return (
  36. <Fragment>
  37. {/* TODO: make this prettier */}
  38. <table>
  39. <tr>
  40. {fields.map(field => (
  41. <th key={field}>{field}</th>
  42. ))}
  43. </tr>
  44. {result.data?.map((row, i) => (
  45. <tr key={i}>
  46. {fields.map(field => (
  47. <th key={field}>{row[field]}</th>
  48. ))}
  49. </tr>
  50. ))}
  51. </table>
  52. <Pagination pageLinks={result.pageLinks} />
  53. </Fragment>
  54. );
  55. }