samples.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {useMemo, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import ErrorBoundary from 'sentry/components/errorBoundary';
  4. import {SegmentedControl} from 'sentry/components/segmentedControl';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {EventSamples} from 'sentry/views/performance/mobile/appStarts/screenSummary/eventSamples';
  8. import {SpanOperationTable} from 'sentry/views/performance/mobile/appStarts/screenSummary/spanOperationTable';
  9. import {SpanOpSelector} from 'sentry/views/performance/mobile/appStarts/screenSummary/spanOpSelector';
  10. import {DeviceClassSelector} from 'sentry/views/performance/mobile/screenload/screenLoadSpans/deviceClassSelector';
  11. import {
  12. MobileCursors,
  13. MobileSortKeys,
  14. } from 'sentry/views/performance/mobile/screenload/screens/constants';
  15. import {useReleaseSelection} from 'sentry/views/starfish/queries/useReleases';
  16. const EVENT = 'event';
  17. const SPANS = 'spans';
  18. export function SamplesTables({transactionName}) {
  19. const [sampleType, setSampleType] = useState<typeof EVENT | typeof SPANS>(SPANS);
  20. const {primaryRelease, secondaryRelease} = useReleaseSelection();
  21. const content = useMemo(() => {
  22. if (sampleType === EVENT) {
  23. return (
  24. <EventSplitContainer>
  25. <ErrorBoundary mini>
  26. <div>
  27. <EventSamples
  28. cursorName={MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE}
  29. sortKey={MobileSortKeys.RELEASE_1_EVENT_SAMPLE_TABLE}
  30. release={primaryRelease}
  31. transaction={transactionName}
  32. footerAlignedPagination
  33. />
  34. </div>
  35. </ErrorBoundary>
  36. <ErrorBoundary mini>
  37. <div>
  38. <EventSamples
  39. cursorName={MobileCursors.RELEASE_2_EVENT_SAMPLE_TABLE}
  40. sortKey={MobileSortKeys.RELEASE_2_EVENT_SAMPLE_TABLE}
  41. release={secondaryRelease}
  42. transaction={transactionName}
  43. footerAlignedPagination
  44. />
  45. </div>
  46. </ErrorBoundary>
  47. </EventSplitContainer>
  48. );
  49. }
  50. return (
  51. <ErrorBoundary mini>
  52. <SpanOperationTable
  53. transaction={transactionName}
  54. primaryRelease={primaryRelease}
  55. secondaryRelease={secondaryRelease}
  56. />
  57. </ErrorBoundary>
  58. );
  59. }, [primaryRelease, sampleType, secondaryRelease, transactionName]);
  60. return (
  61. <div>
  62. <Controls>
  63. <FiltersContainer>
  64. {sampleType === SPANS && (
  65. <SpanOpSelector
  66. primaryRelease={primaryRelease}
  67. transaction={transactionName}
  68. secondaryRelease={secondaryRelease}
  69. />
  70. )}
  71. <DeviceClassSelector size="md" clearSpansTableCursor />
  72. </FiltersContainer>
  73. <SegmentedControl onChange={value => setSampleType(value)} defaultValue={SPANS}>
  74. <SegmentedControl.Item key={SPANS}>{t('By Spans')}</SegmentedControl.Item>
  75. <SegmentedControl.Item key={EVENT}>{t('By Event')}</SegmentedControl.Item>
  76. </SegmentedControl>
  77. </Controls>
  78. {content}
  79. </div>
  80. );
  81. }
  82. const EventSplitContainer = styled('div')`
  83. display: grid;
  84. grid-template-columns: 1fr 1fr;
  85. gap: ${space(1.5)};
  86. `;
  87. const Controls = styled('div')`
  88. display: flex;
  89. justify-content: space-between;
  90. align-items: center;
  91. margin-bottom: ${space(1)};
  92. `;
  93. const FiltersContainer = styled('div')`
  94. display: flex;
  95. gap: ${space(1)};
  96. align-items: center;
  97. `;