samples.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 {trackAnalytics} from 'sentry/utils/analytics';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  10. import {EventSamples} from 'sentry/views/insights/mobile/appStarts/components/eventSamples';
  11. import {SpanOpSelector} from 'sentry/views/insights/mobile/appStarts/components/spanOpSelector';
  12. import {SpanOperationTable} from 'sentry/views/insights/mobile/appStarts/components/tables/spanOperationTable';
  13. import {DeviceClassSelector} from 'sentry/views/insights/mobile/common/components/deviceClassSelector';
  14. import {
  15. MobileCursors,
  16. MobileSortKeys,
  17. } from 'sentry/views/insights/mobile/screenload/constants';
  18. import {ModuleName} from 'sentry/views/insights/types';
  19. const EVENT = 'event';
  20. const SPANS = 'spans';
  21. export function SamplesTables({transactionName}) {
  22. const [sampleType, setSampleType] = useState<typeof EVENT | typeof SPANS>(SPANS);
  23. const {primaryRelease, secondaryRelease} = useReleaseSelection();
  24. const organization = useOrganization();
  25. const content = useMemo(() => {
  26. if (sampleType === EVENT) {
  27. return (
  28. <EventSplitContainer>
  29. <ErrorBoundary mini>
  30. <div>
  31. <EventSamples
  32. cursorName={MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE}
  33. sortKey={MobileSortKeys.RELEASE_1_EVENT_SAMPLE_TABLE}
  34. release={primaryRelease}
  35. transaction={transactionName}
  36. footerAlignedPagination
  37. />
  38. </div>
  39. </ErrorBoundary>
  40. <ErrorBoundary mini>
  41. <div>
  42. <EventSamples
  43. cursorName={MobileCursors.RELEASE_2_EVENT_SAMPLE_TABLE}
  44. sortKey={MobileSortKeys.RELEASE_2_EVENT_SAMPLE_TABLE}
  45. release={secondaryRelease}
  46. transaction={transactionName}
  47. footerAlignedPagination
  48. />
  49. </div>
  50. </ErrorBoundary>
  51. </EventSplitContainer>
  52. );
  53. }
  54. return (
  55. <ErrorBoundary mini>
  56. <SpanOperationTable
  57. transaction={transactionName}
  58. primaryRelease={primaryRelease}
  59. secondaryRelease={secondaryRelease}
  60. />
  61. </ErrorBoundary>
  62. );
  63. }, [primaryRelease, sampleType, secondaryRelease, transactionName]);
  64. return (
  65. <div>
  66. <Controls>
  67. <FiltersContainer>
  68. {sampleType === SPANS && (
  69. <SpanOpSelector
  70. primaryRelease={primaryRelease}
  71. transaction={transactionName}
  72. secondaryRelease={secondaryRelease}
  73. />
  74. )}
  75. <DeviceClassSelector
  76. size="md"
  77. clearSpansTableCursor
  78. moduleName={ModuleName.APP_START}
  79. />
  80. </FiltersContainer>
  81. <SegmentedControl
  82. onChange={value => {
  83. trackAnalytics('insight.app_start.spans.toggle_sample_type', {
  84. organization,
  85. type: value,
  86. });
  87. setSampleType(value);
  88. }}
  89. defaultValue={SPANS}
  90. aria-label={t('Sample Type Selection')}
  91. >
  92. <SegmentedControl.Item key={SPANS}>{t('By Spans')}</SegmentedControl.Item>
  93. <SegmentedControl.Item key={EVENT}>{t('By Event')}</SegmentedControl.Item>
  94. </SegmentedControl>
  95. </Controls>
  96. {content}
  97. </div>
  98. );
  99. }
  100. const EventSplitContainer = styled('div')`
  101. display: grid;
  102. grid-template-columns: 1fr 1fr;
  103. gap: ${space(1.5)};
  104. `;
  105. const Controls = styled('div')`
  106. display: flex;
  107. justify-content: space-between;
  108. align-items: center;
  109. margin-bottom: ${space(1)};
  110. `;
  111. const FiltersContainer = styled('div')`
  112. display: flex;
  113. gap: ${space(1)};
  114. align-items: center;
  115. `;