samples.tsx 4.1 KB

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