content.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import {useCallback, useMemo} 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 {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
  33. import {useUserQuery} from 'sentry/views/explore/hooks/useUserQuery';
  34. import {ExploreTables} from 'sentry/views/explore/tables';
  35. import {ExploreToolbar} from 'sentry/views/explore/toolbar';
  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 [resultsMode] = useResultMode();
  46. const numberTags = useSpanTags('number');
  47. const stringTags = useSpanTags('string');
  48. const supportedAggregates = useMemo(() => {
  49. return resultsMode === 'aggregate' ? ALLOWED_EXPLORE_VISUALIZE_AGGREGATES : [];
  50. }, [resultsMode]);
  51. const [userQuery, setUserQuery] = useUserQuery();
  52. const toolbarExtras = organization.features.includes('visibility-explore-dataset')
  53. ? ['dataset toggle' as const]
  54. : [];
  55. const switchToOldTraceExplorer = useCallback(() => {
  56. navigate({
  57. ...location,
  58. query: {
  59. ...location.query,
  60. view: 'trace',
  61. },
  62. });
  63. }, [location, navigate]);
  64. return (
  65. <SentryDocumentTitle title={t('Explore')} orgSlug={organization.slug}>
  66. <PageFiltersContainer>
  67. <Layout.Page>
  68. <Layout.Header>
  69. <Layout.HeaderContent>
  70. <Layout.Title>{t('Explore')}</Layout.Title>
  71. </Layout.HeaderContent>
  72. <Layout.HeaderActions>
  73. <ButtonBar gap={1}>
  74. <Button onClick={switchToOldTraceExplorer} size="sm">
  75. {t('Switch to Old Trace Explore')}
  76. </Button>
  77. <FeedbackWidgetButton />
  78. </ButtonBar>
  79. </Layout.HeaderActions>
  80. </Layout.Header>
  81. <Body>
  82. <TopSection>
  83. <StyledPageFilterBar condensed>
  84. <ProjectPageFilter />
  85. <EnvironmentPageFilter />
  86. <DatePageFilter />
  87. </StyledPageFilterBar>
  88. {dataset === DiscoverDatasets.SPANS_INDEXED ? (
  89. <SpanSearchQueryBuilder
  90. supportedAggregates={supportedAggregates}
  91. projects={selection.projects}
  92. initialQuery={userQuery}
  93. onSearch={setUserQuery}
  94. searchSource="explore"
  95. />
  96. ) : (
  97. <EAPSpanSearchQueryBuilder
  98. supportedAggregates={supportedAggregates}
  99. projects={selection.projects}
  100. initialQuery={userQuery}
  101. onSearch={setUserQuery}
  102. searchSource="explore"
  103. numberTags={numberTags}
  104. stringTags={stringTags}
  105. />
  106. )}
  107. </TopSection>
  108. <ExploreToolbar extras={toolbarExtras} />
  109. <MainSection fullWidth>
  110. <ExploreCharts query={userQuery} />
  111. <ExploreTables />
  112. </MainSection>
  113. </Body>
  114. </Layout.Page>
  115. </PageFiltersContainer>
  116. </SentryDocumentTitle>
  117. );
  118. }
  119. export function ExploreContent(props: ExploreContentProps) {
  120. const [dataset] = useDataset();
  121. return (
  122. <SpanTagsProvider dataset={dataset}>
  123. <ExploreContentImpl {...props} />
  124. </SpanTagsProvider>
  125. );
  126. }
  127. const Body = styled(Layout.Body)`
  128. gap: ${space(2)};
  129. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  130. grid-template-columns: 300px minmax(100px, auto);
  131. }
  132. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  133. grid-template-columns: 350px minmax(100px, auto);
  134. }
  135. `;
  136. const TopSection = styled('div')`
  137. display: grid;
  138. gap: ${space(2)};
  139. grid-column: 1/3;
  140. margin-bottom: ${space(2)};
  141. @media (min-width: ${p => p.theme.breakpoints.large}) {
  142. grid-template-columns: minmax(300px, auto) 1fr;
  143. margin-bottom: 0;
  144. }
  145. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  146. grid-template-columns: minmax(350px, auto) 1fr;
  147. }
  148. `;
  149. const MainSection = styled(Layout.Main)`
  150. grid-column: 2/3;
  151. `;
  152. const StyledPageFilterBar = styled(PageFilterBar)`
  153. width: auto;
  154. `;