queuesLandingPage.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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, MutableSearch} 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 * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  23. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  24. import {ModulesOnboarding} from 'sentry/views/performance/onboarding/modulesOnboarding';
  25. import {OnboardingContent} from 'sentry/views/performance/onboarding/onboardingContent';
  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. DEFAULT_QUERY_FILTER,
  31. MODULE_TITLE,
  32. ONBOARDING_CONTENT,
  33. RELEASE_LEVEL,
  34. } from 'sentry/views/performance/queues/settings';
  35. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  36. const DEFAULT_SORT = {
  37. field: 'time_spent_percentage(app,span.duration)' as const,
  38. kind: 'desc' as const,
  39. };
  40. function QueuesLandingPage() {
  41. const organization = useOrganization();
  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. <ModulesOnboarding
  106. moduleQueryFilter={new MutableSearch(DEFAULT_QUERY_FILTER)}
  107. onboardingContent={<OnboardingContent {...ONBOARDING_CONTENT} />}
  108. referrer={'api.performance.queues.landing-onboarding'}
  109. >
  110. <ModuleLayout.Half>
  111. <LatencyChart />
  112. </ModuleLayout.Half>
  113. <ModuleLayout.Half>
  114. <ThroughputChart />
  115. </ModuleLayout.Half>
  116. <ModuleLayout.Full>
  117. <Flex>
  118. <SearchBar
  119. query={query.destination}
  120. placeholder={t('Search for more destinations')}
  121. onSearch={handleSearch}
  122. />
  123. <QueuesTable sort={sort} destination={wildCardDestinationFilter} />
  124. </Flex>
  125. </ModuleLayout.Full>
  126. </ModulesOnboarding>
  127. </ModuleLayout.Layout>
  128. </Layout.Main>
  129. </Layout.Body>
  130. </Fragment>
  131. );
  132. }
  133. function PageWithProviders() {
  134. return (
  135. <ModulePageProviders
  136. title={[t('Performance'), MODULE_TITLE].join(' — ')}
  137. features="performance-queues-view"
  138. >
  139. <QueuesLandingPage />
  140. </ModulePageProviders>
  141. );
  142. }
  143. export default PageWithProviders;
  144. const Flex = styled('div')`
  145. display: flex;
  146. flex-direction: column;
  147. gap: ${space(2)};
  148. `;