profilesTable.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import Pagination from 'sentry/components/pagination';
  4. import {ProfileEventsTable} from 'sentry/components/profiling/profileEventsTable';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {defined} from 'sentry/utils';
  8. import {useProfileEvents} from 'sentry/utils/profiling/hooks/useProfileEvents';
  9. import {formatSort} from 'sentry/utils/profiling/hooks/utils';
  10. import {decodeScalar} from 'sentry/utils/queryString';
  11. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. const FIELDS = [
  14. 'profile.id',
  15. 'timestamp',
  16. 'profile.duration',
  17. 'release',
  18. 'environment',
  19. 'os.name',
  20. 'os.version',
  21. 'trace',
  22. 'trace.transaction',
  23. ] as const;
  24. type FieldType = (typeof FIELDS)[number];
  25. export function ProfilesTable() {
  26. const location = useLocation();
  27. const sort = useMemo(() => {
  28. return formatSort<FieldType>(decodeScalar(location.query.sort), FIELDS, {
  29. key: 'timestamp',
  30. order: 'desc',
  31. });
  32. }, [location.query.sort]);
  33. const rawQuery = useMemo(() => {
  34. return decodeScalar(location.query.query, '');
  35. }, [location.query.query]);
  36. const query = useMemo(() => {
  37. const search = new MutableSearch(rawQuery);
  38. const transaction = decodeScalar(location.query.transaction);
  39. if (defined(transaction)) {
  40. search.setFilterValues('transaction', [transaction]);
  41. }
  42. return search.formatString();
  43. }, [rawQuery, location.query.transaction]);
  44. const profilesCursor = useMemo(
  45. () => decodeScalar(location.query.cursor),
  46. [location.query.cursor]
  47. );
  48. const profiles = useProfileEvents<FieldType>({
  49. cursor: profilesCursor,
  50. fields: FIELDS,
  51. query,
  52. sort,
  53. limit: 20,
  54. referrer: 'api.profiling.profile-summary-table',
  55. });
  56. const eventsTableProps = useMemo(() => {
  57. return {columns: FIELDS.slice(), sortableColumns: new Set(FIELDS)};
  58. }, []);
  59. return (
  60. <ProfileEvents>
  61. <ProfileEventsTableContainer>
  62. <ProfileEventsTable
  63. sort={sort}
  64. data={profiles.status === 'success' ? profiles.data : null}
  65. error={profiles.status === 'error' ? t('Unable to load profiles') : null}
  66. isLoading={profiles.status === 'loading'}
  67. {...eventsTableProps}
  68. />
  69. </ProfileEventsTableContainer>
  70. <StyledPagination pageLinks={profiles.getResponseHeader?.('Link')} />
  71. </ProfileEvents>
  72. );
  73. }
  74. const ProfileEvents = styled('div')``;
  75. const StyledPagination = styled(Pagination)`
  76. margin-top: ${space(1)};
  77. margin-right: ${space(1)};
  78. margin-bottom: ${space(2)};
  79. `;
  80. const ProfileEventsTableContainer = styled('div')`
  81. th,
  82. tr {
  83. border-radius: 0 !important;
  84. }
  85. > div {
  86. border-radius: 0;
  87. border-top: none;
  88. margin-bottom: 0;
  89. }
  90. `;