content.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import {useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import {Button} from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  9. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  10. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  11. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  12. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  13. import {
  14. EAPSpanSearchQueryBuilder,
  15. SpanSearchQueryBuilder,
  16. } from 'sentry/components/performance/spanSearchQueryBuilder';
  17. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  18. import {t} from 'sentry/locale';
  19. import {space} from 'sentry/styles/space';
  20. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  21. import {ALLOWED_EXPLORE_VISUALIZE_AGGREGATES} from 'sentry/utils/fields';
  22. import {useLocation} from 'sentry/utils/useLocation';
  23. import {useNavigate} from 'sentry/utils/useNavigate';
  24. import useOrganization from 'sentry/utils/useOrganization';
  25. import usePageFilters from 'sentry/utils/usePageFilters';
  26. import {ExploreCharts} from 'sentry/views/explore/charts';
  27. import {
  28. SpanTagsProvider,
  29. useSpanTags,
  30. } from 'sentry/views/explore/contexts/spanTagsContext';
  31. import {useDataset} from 'sentry/views/explore/hooks/useDataset';
  32. import {useUserQuery} from 'sentry/views/explore/hooks/useUserQuery';
  33. import {ExploreTables} from 'sentry/views/explore/tables';
  34. import {ExploreToolbar} from 'sentry/views/explore/toolbar';
  35. import {useResultMode} from './hooks/useResultsMode';
  36. interface ExploreContentProps {
  37. location: Location;
  38. }
  39. function ExploreContentImpl({}: ExploreContentProps) {
  40. const location = useLocation();
  41. const navigate = useNavigate();
  42. const organization = useOrganization();
  43. const {selection} = usePageFilters();
  44. const [dataset] = useDataset();
  45. const [resultMode] = useResultMode();
  46. const supportedAggregates =
  47. resultMode === 'aggregate' ? ALLOWED_EXPLORE_VISUALIZE_AGGREGATES : [];
  48. const numberTags = useSpanTags('number');
  49. const stringTags = useSpanTags('string');
  50. const [userQuery, setUserQuery] = useUserQuery();
  51. const toolbarExtras = organization.features.includes('visibility-explore-dataset')
  52. ? ['dataset toggle' as const]
  53. : [];
  54. const switchToOldTraceExplorer = useCallback(() => {
  55. navigate({
  56. ...location,
  57. query: {
  58. ...location.query,
  59. view: 'trace',
  60. },
  61. });
  62. }, [location, navigate]);
  63. return (
  64. <SentryDocumentTitle title={t('Explore')} orgSlug={organization.slug}>
  65. <PageFiltersContainer>
  66. <Layout.Page>
  67. <Layout.Header>
  68. <Layout.HeaderContent>
  69. <Layout.Title>{t('Explore')}</Layout.Title>
  70. </Layout.HeaderContent>
  71. <Layout.HeaderActions>
  72. <ButtonBar gap={1}>
  73. <Button onClick={switchToOldTraceExplorer} size="sm">
  74. {t('Switch to Old Trace Explore')}
  75. </Button>
  76. <FeedbackWidgetButton />
  77. </ButtonBar>
  78. </Layout.HeaderActions>
  79. </Layout.Header>
  80. <Body>
  81. <TopSection>
  82. <StyledPageFilterBar condensed>
  83. <ProjectPageFilter />
  84. <EnvironmentPageFilter />
  85. <DatePageFilter />
  86. </StyledPageFilterBar>
  87. {dataset === DiscoverDatasets.SPANS_INDEXED ? (
  88. <SpanSearchQueryBuilder
  89. projects={selection.projects}
  90. initialQuery={userQuery}
  91. onSearch={setUserQuery}
  92. searchSource="explore"
  93. />
  94. ) : (
  95. <EAPSpanSearchQueryBuilder
  96. projects={selection.projects}
  97. initialQuery={userQuery}
  98. onSearch={setUserQuery}
  99. searchSource="explore"
  100. supportedAggregates={supportedAggregates}
  101. numberTags={numberTags}
  102. stringTags={stringTags}
  103. />
  104. )}
  105. </TopSection>
  106. <ExploreToolbar extras={toolbarExtras} />
  107. <MainSection fullWidth>
  108. <ExploreCharts query={userQuery} />
  109. <ExploreTables />
  110. </MainSection>
  111. </Body>
  112. </Layout.Page>
  113. </PageFiltersContainer>
  114. </SentryDocumentTitle>
  115. );
  116. }
  117. export function ExploreContent(props: ExploreContentProps) {
  118. const [dataset] = useDataset();
  119. return (
  120. <SpanTagsProvider dataset={dataset}>
  121. <ExploreContentImpl {...props} />
  122. </SpanTagsProvider>
  123. );
  124. }
  125. const Body = styled(Layout.Body)`
  126. gap: ${space(2)};
  127. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  128. grid-template-columns: 300px minmax(100px, auto);
  129. }
  130. @media (min-width: ${p => p.theme.breakpoints.xxlarge}) {
  131. grid-template-columns: 350px minmax(100px, auto);
  132. }
  133. `;
  134. const TopSection = styled('div')`
  135. display: grid;
  136. gap: ${space(2)};
  137. grid-column: 1/3;
  138. margin-bottom: ${space(2)};
  139. @media (min-width: ${p => p.theme.breakpoints.large}) {
  140. grid-template-columns: minmax(300px, auto) 1fr;
  141. margin-bottom: 0;
  142. }
  143. @media (min-width: ${p => p.theme.breakpoints.xxlarge}) {
  144. grid-template-columns: minmax(350px, auto) 1fr;
  145. }
  146. `;
  147. const MainSection = styled(Layout.Main)`
  148. grid-column: 2/3;
  149. `;
  150. const StyledPageFilterBar = styled(PageFilterBar)`
  151. width: auto;
  152. `;