samplesTables.tsx 4.0 KB

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