index.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import {useCallback, useMemo, useState} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import DatePageFilter from 'sentry/components/datePageFilter';
  5. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  8. import {ProfileEventsTable} from 'sentry/components/profiling/profileEventsTable';
  9. import SmartSearchBar, {SmartSearchBarProps} from 'sentry/components/smartSearchBar';
  10. import {MAX_QUERY_LENGTH} from 'sentry/constants';
  11. import {t} from 'sentry/locale';
  12. import space from 'sentry/styles/space';
  13. import {defined} from 'sentry/utils';
  14. import EventView from 'sentry/utils/discover/eventView';
  15. import {
  16. formatSort,
  17. useProfileEvents,
  18. } from 'sentry/utils/profiling/hooks/useProfileEvents';
  19. import {useProfileFilters} from 'sentry/utils/profiling/hooks/useProfileFilters';
  20. import {decodeScalar} from 'sentry/utils/queryString';
  21. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  22. import {useLocation} from 'sentry/utils/useLocation';
  23. import useOrganization from 'sentry/utils/useOrganization';
  24. import usePageFilters from 'sentry/utils/usePageFilters';
  25. import useProjects from 'sentry/utils/useProjects';
  26. import Tab from 'sentry/views/performance/transactionSummary/tabs';
  27. import {
  28. getProfilesTableFields,
  29. ProfilingFieldType,
  30. } from 'sentry/views/profiling/profileSummary/content';
  31. import PageLayout from '../pageLayout';
  32. function Profiles(): React.ReactElement {
  33. const location = useLocation();
  34. const organization = useOrganization();
  35. const projects = useProjects();
  36. const {selection} = usePageFilters();
  37. const profilesCursor = useMemo(
  38. () => decodeScalar(location.query.cursor),
  39. [location.query.cursor]
  40. );
  41. const project = projects.projects.find(p => p.id === location.query.project);
  42. const fields = getProfilesTableFields(project?.platform);
  43. const sort = formatSort<ProfilingFieldType>(decodeScalar(location.query.sort), fields, {
  44. key: 'timestamp',
  45. order: 'desc',
  46. });
  47. const [query, setQuery] = useState(() => {
  48. // The search fields from the URL differ between profiling and
  49. // events dataset. For now, just drop everything except transaction
  50. const search = new MutableSearch('');
  51. const transaction = decodeScalar(location.query.transaction);
  52. if (defined(transaction)) {
  53. search.setFilterValues('transaction', [transaction]);
  54. }
  55. return search;
  56. });
  57. const profiles = useProfileEvents<ProfilingFieldType>({
  58. cursor: profilesCursor,
  59. fields,
  60. query: query.formatString(),
  61. sort,
  62. limit: 30,
  63. referrer: 'api.profiling.transactions-profiles-table',
  64. });
  65. const handleSearch: SmartSearchBarProps['onSearch'] = useCallback(
  66. (searchQuery: string) => {
  67. setQuery(new MutableSearch(searchQuery));
  68. browserHistory.push({
  69. ...location,
  70. query: {
  71. ...location.query,
  72. cursor: undefined,
  73. query: searchQuery || undefined,
  74. },
  75. });
  76. },
  77. [location]
  78. );
  79. const profileFilters = useProfileFilters({query: '', selection});
  80. const transaction = decodeScalar(location.query.transaction);
  81. return (
  82. <PageLayout
  83. location={location}
  84. organization={organization}
  85. projects={projects.projects}
  86. tab={Tab.Profiling}
  87. generateEventView={() => EventView.fromLocation(location)}
  88. getDocumentTitle={() => t(`Profile: %s`, transaction)}
  89. childComponent={() => {
  90. return (
  91. <Layout.Main fullWidth>
  92. <FilterActions>
  93. <PageFilterBar condensed>
  94. <EnvironmentPageFilter />
  95. <DatePageFilter alignDropdown="left" />
  96. </PageFilterBar>
  97. <SmartSearchBar
  98. organization={organization}
  99. hasRecentSearches
  100. searchSource="profile_landing"
  101. supportedTags={profileFilters}
  102. query={query.formatString()}
  103. onSearch={handleSearch}
  104. maxQueryLength={MAX_QUERY_LENGTH}
  105. />
  106. </FilterActions>
  107. <ProfileEventsTable
  108. columns={fields}
  109. data={profiles.status === 'success' ? profiles.data[0] : null}
  110. error={profiles.status === 'error' ? t('Unable to load profiles') : null}
  111. isLoading={profiles.status === 'loading'}
  112. sort={sort}
  113. />
  114. </Layout.Main>
  115. );
  116. }}
  117. />
  118. );
  119. }
  120. const FilterActions = styled('div')`
  121. margin-bottom: ${space(2)};
  122. gap: ${space(2)};
  123. display: grid;
  124. grid-template-columns: min-content 1fr;
  125. `;
  126. export default Profiles;