queuesLandingPage.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  8. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  11. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  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 * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  21. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  22. import {ModulesOnboarding} from 'sentry/views/performance/onboarding/modulesOnboarding';
  23. import {OnboardingContent} from 'sentry/views/performance/onboarding/onboardingContent';
  24. import {LatencyChart} from 'sentry/views/performance/queues/charts/latencyChart';
  25. import {ThroughputChart} from 'sentry/views/performance/queues/charts/throughputChart';
  26. import {isAValidSort, QueuesTable} from 'sentry/views/performance/queues/queuesTable';
  27. import {Referrer} from 'sentry/views/performance/queues/referrers';
  28. import {
  29. DEFAULT_QUERY_FILTER,
  30. MODULE_DESCRIPTION,
  31. MODULE_DOC_LINK,
  32. MODULE_TITLE,
  33. ONBOARDING_CONTENT,
  34. } from 'sentry/views/performance/queues/settings';
  35. import {useModuleBreadcrumbs} from 'sentry/views/performance/utils/useModuleBreadcrumbs';
  36. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  37. const DEFAULT_SORT = {
  38. field: 'time_spent_percentage(app,span.duration)' as const,
  39. kind: 'desc' as const,
  40. };
  41. function QueuesLandingPage() {
  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. const crumbs = useModuleBreadcrumbs('queue');
  69. return (
  70. <Fragment>
  71. <Layout.Header>
  72. <Layout.HeaderContent>
  73. <Breadcrumbs crumbs={crumbs} />
  74. <Layout.Title>
  75. {MODULE_TITLE}
  76. <PageHeadingQuestionTooltip
  77. docsUrl={MODULE_DOC_LINK}
  78. title={MODULE_DESCRIPTION}
  79. />
  80. </Layout.Title>
  81. </Layout.HeaderContent>
  82. <Layout.HeaderActions>
  83. <ButtonBar gap={1}>
  84. <FeedbackWidgetButton />
  85. </ButtonBar>
  86. </Layout.HeaderActions>
  87. </Layout.Header>
  88. <Layout.Body>
  89. <Layout.Main fullWidth>
  90. <ModuleLayout.Layout>
  91. <ModuleLayout.Full>
  92. <PageFilterBar condensed>
  93. <ProjectPageFilter />
  94. <EnvironmentPageFilter />
  95. <DatePageFilter />
  96. </PageFilterBar>
  97. </ModuleLayout.Full>
  98. <ModulesOnboarding
  99. moduleQueryFilter={new MutableSearch(DEFAULT_QUERY_FILTER)}
  100. onboardingContent={<OnboardingContent {...ONBOARDING_CONTENT} />}
  101. referrer={'api.performance.queues.landing-onboarding'}
  102. >
  103. <ModuleLayout.Half>
  104. <LatencyChart referrer={Referrer.QUEUES_LANDING_CHARTS} />
  105. </ModuleLayout.Half>
  106. <ModuleLayout.Half>
  107. <ThroughputChart referrer={Referrer.QUEUES_LANDING_CHARTS} />
  108. </ModuleLayout.Half>
  109. <ModuleLayout.Full>
  110. <Flex>
  111. <SearchBar
  112. query={query.destination}
  113. placeholder={t('Search for more destinations')}
  114. onSearch={handleSearch}
  115. />
  116. <QueuesTable sort={sort} destination={wildCardDestinationFilter} />
  117. </Flex>
  118. </ModuleLayout.Full>
  119. </ModulesOnboarding>
  120. </ModuleLayout.Layout>
  121. </Layout.Main>
  122. </Layout.Body>
  123. </Fragment>
  124. );
  125. }
  126. function PageWithProviders() {
  127. return (
  128. <ModulePageProviders
  129. moduleName="queue"
  130. features={['insights-addon-modules', 'performance-queues-view']}
  131. >
  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. `;