queuesLandingPage.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import FeatureBadge from 'sentry/components/badge/featureBadge';
  4. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  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 {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  12. import SearchBar from 'sentry/components/searchBar';
  13. import {t} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import {browserHistory} from 'sentry/utils/browserHistory';
  16. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  17. import {escapeFilterValue} from 'sentry/utils/tokenizeSearch';
  18. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  19. import {useLocation} from 'sentry/utils/useLocation';
  20. import useOrganization from 'sentry/utils/useOrganization';
  21. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  22. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  23. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  24. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  25. import Onboarding from 'sentry/views/performance/onboarding';
  26. import {LatencyChart} from 'sentry/views/performance/queues/charts/latencyChart';
  27. import {ThroughputChart} from 'sentry/views/performance/queues/charts/throughputChart';
  28. import {isAValidSort, QueuesTable} from 'sentry/views/performance/queues/queuesTable';
  29. import {
  30. BASE_URL,
  31. MODULE_TITLE,
  32. RELEASE_LEVEL,
  33. } from 'sentry/views/performance/queues/settings';
  34. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  35. const DEFAULT_SORT = {
  36. field: 'time_spent_percentage(app,span.duration)' as const,
  37. kind: 'desc' as const,
  38. };
  39. function QueuesLandingPage() {
  40. const organization = useOrganization();
  41. const onboardingProject = useOnboardingProject();
  42. const location = useLocation();
  43. const query = useLocationQuery({
  44. fields: {
  45. destination: decodeScalar,
  46. [QueryParameterNames.DESTINATIONS_SORT]: decodeScalar,
  47. },
  48. });
  49. const sort =
  50. decodeSorts(query[QueryParameterNames.DESTINATIONS_SORT])
  51. .filter(isAValidSort)
  52. .at(0) ?? DEFAULT_SORT;
  53. const handleSearch = (newDestination: string) => {
  54. browserHistory.push({
  55. ...location,
  56. query: {
  57. ...location.query,
  58. destination: newDestination === '' ? undefined : newDestination,
  59. [QueryParameterNames.DESTINATIONS_CURSOR]: undefined,
  60. },
  61. });
  62. };
  63. // The QueuesTable component queries using the destination prop.
  64. // We wrap the user input in wildcards to allow for partial matches.
  65. const wildCardDestinationFilter = query.destination
  66. ? `*${escapeFilterValue(query.destination)}*`
  67. : undefined;
  68. return (
  69. <Fragment>
  70. <Layout.Header>
  71. <Layout.HeaderContent>
  72. <Breadcrumbs
  73. crumbs={[
  74. {
  75. label: t('Performance'),
  76. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  77. preservePageFilters: true,
  78. },
  79. {
  80. label: MODULE_TITLE,
  81. },
  82. ]}
  83. />
  84. <Layout.Title>
  85. {MODULE_TITLE}
  86. <FeatureBadge type={RELEASE_LEVEL} />
  87. </Layout.Title>
  88. </Layout.HeaderContent>
  89. <Layout.HeaderActions>
  90. <ButtonBar gap={1}>
  91. <FeedbackWidgetButton />
  92. </ButtonBar>
  93. </Layout.HeaderActions>
  94. </Layout.Header>
  95. <Layout.Body>
  96. <Layout.Main fullWidth>
  97. <ModuleLayout.Layout>
  98. <ModuleLayout.Full>
  99. <PageFilterBar condensed>
  100. <ProjectPageFilter />
  101. <EnvironmentPageFilter />
  102. <DatePageFilter />
  103. </PageFilterBar>
  104. </ModuleLayout.Full>
  105. {onboardingProject && (
  106. <ModuleLayout.Full>
  107. <Onboarding organization={organization} project={onboardingProject} />
  108. </ModuleLayout.Full>
  109. )}
  110. {!onboardingProject && (
  111. <Fragment>
  112. <ModuleLayout.Half>
  113. <LatencyChart />
  114. </ModuleLayout.Half>
  115. <ModuleLayout.Half>
  116. <ThroughputChart />
  117. </ModuleLayout.Half>
  118. <ModuleLayout.Full>
  119. <Flex>
  120. <SearchBar
  121. query={query.destination}
  122. placeholder={t('Search for more destinations')}
  123. onSearch={handleSearch}
  124. />
  125. <QueuesTable sort={sort} destination={wildCardDestinationFilter} />
  126. </Flex>
  127. </ModuleLayout.Full>
  128. </Fragment>
  129. )}
  130. </ModuleLayout.Layout>
  131. </Layout.Main>
  132. </Layout.Body>
  133. </Fragment>
  134. );
  135. }
  136. function PageWithProviders() {
  137. return (
  138. <ModulePageProviders
  139. title={[t('Performance'), MODULE_TITLE].join(' — ')}
  140. baseURL={`/performance/${BASE_URL}`}
  141. features="performance-queues-view"
  142. >
  143. <QueuesLandingPage />
  144. </ModulePageProviders>
  145. );
  146. }
  147. export default PageWithProviders;
  148. const Flex = styled('div')`
  149. display: flex;
  150. flex-direction: column;
  151. gap: ${space(2)};
  152. `;