content.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {useCallback, useMemo} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  6. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  7. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  8. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  9. import type {CursorHandler} from 'sentry/components/pagination';
  10. import type {SmartSearchBarProps} from 'sentry/components/smartSearchBar';
  11. import {space} from 'sentry/styles/space';
  12. import {decodeInteger, decodeScalar} from 'sentry/utils/queryString';
  13. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  14. import {useLocation} from 'sentry/utils/useLocation';
  15. import {useIndexedSpans} from 'sentry/views/starfish/queries/useIndexedSpans';
  16. import {SpanIndexedField} from 'sentry/views/starfish/types';
  17. import {TracesSearchBar} from './tracesSearchBar';
  18. import {TracesSpansTable} from './tracesSpansTable';
  19. const DEFAULT_PER_PAGE = 50;
  20. export function Content() {
  21. const location = useLocation();
  22. const query = useMemo(() => {
  23. return decodeScalar(location.query.query, '');
  24. }, [location.query.query]);
  25. const limit = useMemo(() => {
  26. return decodeInteger(location.query.perPage, DEFAULT_PER_PAGE);
  27. }, [location.query.perPage]);
  28. const handleSearch: SmartSearchBarProps['onSearch'] = useCallback(
  29. (searchQuery: string) => {
  30. browserHistory.push({
  31. ...location,
  32. query: {
  33. ...location.query,
  34. cursor: undefined,
  35. query: searchQuery || undefined,
  36. },
  37. });
  38. },
  39. [location]
  40. );
  41. const handleCursor: CursorHandler = useCallback((newCursor, pathname, newQuery) => {
  42. browserHistory.push({
  43. pathname,
  44. query: {...newQuery, cursor: newCursor},
  45. });
  46. }, []);
  47. const filters = useMemo(() => new MutableSearch(query ?? '').filters, [query]);
  48. const fields = useMemo(() => {
  49. // TODO: make this dynamic
  50. return [
  51. SpanIndexedField.PROJECT,
  52. SpanIndexedField.ID,
  53. SpanIndexedField.TRANSACTION_ID,
  54. SpanIndexedField.TRACE,
  55. SpanIndexedField.SPAN_OP,
  56. SpanIndexedField.SPAN_DESCRIPTION,
  57. SpanIndexedField.TRANSACTION_OP,
  58. SpanIndexedField.TRANSACTION,
  59. SpanIndexedField.SPAN_DURATION,
  60. SpanIndexedField.SPAN_SELF_TIME,
  61. SpanIndexedField.TIMESTAMP,
  62. ];
  63. }, []);
  64. const spans = useIndexedSpans({
  65. fields,
  66. filters,
  67. limit,
  68. sorts: [],
  69. referrer: 'api.trace-explorer.table',
  70. });
  71. return (
  72. <LayoutMain fullWidth>
  73. <PageFilterBar condensed>
  74. <ProjectPageFilter />
  75. <EnvironmentPageFilter />
  76. <DatePageFilter />
  77. </PageFilterBar>
  78. <TracesSearchBar query={query} handleSearch={handleSearch} />
  79. <TracesSpansTable
  80. fields={fields}
  81. isLoading={spans.isLoading}
  82. data={spans.data ?? []}
  83. pageLinks={spans.pageLinks}
  84. handleCursor={handleCursor}
  85. />
  86. </LayoutMain>
  87. );
  88. }
  89. const LayoutMain = styled(Layout.Main)`
  90. display: flex;
  91. flex-direction: column;
  92. gap: ${space(2)};
  93. `;