queuesLandingPage.tsx 5.6 KB

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