limitExceededMessage.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {browserHistory} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import DiscoverFeature from 'sentry/components/discover/discoverFeature';
  5. import Link from 'sentry/components/links/link';
  6. import {MessageRow} from 'sentry/components/performance/waterfall/messageRow';
  7. import {t, tct} from 'sentry/locale';
  8. import type {Organization} from 'sentry/types';
  9. import type EventView from 'sentry/utils/discover/eventView';
  10. import type {TraceMeta} from 'sentry/utils/performance/quickTrace/types';
  11. import {useLocation} from 'sentry/utils/useLocation';
  12. import type {TraceInfo} from 'sentry/views/performance/traceDetails/types';
  13. interface LimitExceededMessageProps {
  14. meta: TraceMeta | null;
  15. organization: Organization;
  16. traceEventView: EventView;
  17. traceInfo: TraceInfo;
  18. handleLimitChange?: (newLimit: number) => void;
  19. }
  20. const MAX_TRACE_ROWS_LIMIT = 2000;
  21. export const DEFAULT_TRACE_ROWS_LIMIT = 100;
  22. function LimitExceededMessage({
  23. traceInfo,
  24. traceEventView,
  25. organization,
  26. meta,
  27. handleLimitChange,
  28. }: LimitExceededMessageProps) {
  29. // Number of events part of the traceView. Includes errors/issues appearing within txn details ui
  30. // that appears when you click into a txn row.
  31. const displayedEventsCount = traceInfo.transactions.size + traceInfo.errors.size;
  32. const traceMetaEventsCount =
  33. (meta && meta.transactions + meta.errors) ?? displayedEventsCount;
  34. const location = useLocation();
  35. if (traceMetaEventsCount === null || displayedEventsCount >= traceMetaEventsCount) {
  36. return null;
  37. }
  38. const target = traceEventView.getResultsViewUrlTarget(organization.slug);
  39. // Number of rows in the trace view. Doesnot include associated errors/issues appearing in
  40. // txn detail.
  41. const displayedRowsCount = traceInfo.transactions.size + traceInfo.trailingOrphansCount;
  42. // Increment by by multiples of 500.
  43. const increment = displayedRowsCount <= 100 ? 400 : 500;
  44. const discoverLink = (
  45. <DiscoverFeature>
  46. {({hasFeature}) => (
  47. <StyledLink disabled={!hasFeature} to={target}>
  48. {t('Discover')}
  49. </StyledLink>
  50. )}
  51. </DiscoverFeature>
  52. );
  53. const limitExceededMessage = tct(
  54. 'Limited to a view of [count] rows. To view the full list, go to [discover].',
  55. {
  56. count: displayedRowsCount,
  57. discover: discoverLink,
  58. }
  59. );
  60. const loadBiggerTraceMessage = tct(
  61. '[loadMore:Show more] of this trace or go to the full list of events in [discover]',
  62. {
  63. loadMore: (
  64. <Button
  65. priority="link"
  66. onClick={() => {
  67. const newLimit = displayedRowsCount + increment;
  68. if (handleLimitChange) {
  69. handleLimitChange(newLimit);
  70. }
  71. browserHistory.push({
  72. pathname: location.pathname,
  73. query: {...location.query, limit: newLimit},
  74. });
  75. }}
  76. aria-label={t('Load more')}
  77. />
  78. ),
  79. discover: discoverLink,
  80. }
  81. );
  82. return (
  83. <MessageRow>
  84. {organization.features.includes('trace-view-load-more') &&
  85. displayedRowsCount < MAX_TRACE_ROWS_LIMIT
  86. ? loadBiggerTraceMessage
  87. : limitExceededMessage}
  88. </MessageRow>
  89. );
  90. }
  91. const StyledLink = styled(Link)`
  92. margin-left: 0;
  93. `;
  94. export default LimitExceededMessage;