confidenceFooter.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import styled from '@emotion/styled';
  2. import Count from 'sentry/components/count';
  3. import {Tooltip} from 'sentry/components/tooltip';
  4. import {t, tct} from 'sentry/locale';
  5. import type {Confidence} from 'sentry/types/organization';
  6. import {defined} from 'sentry/utils';
  7. type Props = {
  8. confidence?: Confidence;
  9. sampleCount?: number;
  10. topEvents?: number;
  11. };
  12. export function ConfidenceFooter(props: Props) {
  13. return <Container>{confidenceMessage(props)}</Container>;
  14. }
  15. function confidenceMessage({sampleCount, confidence, topEvents}: Props) {
  16. const isTopN = defined(topEvents) && topEvents > 0;
  17. if (!defined(sampleCount)) {
  18. return isTopN
  19. ? t('* Chart for top %s groups extrapolated from \u2026', topEvents)
  20. : t('* Chart extrapolated from \u2026');
  21. }
  22. if (confidence === 'low') {
  23. if (isTopN) {
  24. if (sampleCount === 1) {
  25. return tct(
  26. '* Chart for top [topEvents] groups extrapolated from [sampleCount] sample ([lowAccuracy])',
  27. {
  28. topEvents,
  29. sampleCount: <Count value={sampleCount} />,
  30. lowAccuracy: <LowAccuracy />,
  31. }
  32. );
  33. }
  34. return tct(
  35. '* Chart for top [topEvents] groups extrapolated from [sampleCount] samples ([lowAccuracy])',
  36. {
  37. topEvents,
  38. sampleCount: <Count value={sampleCount} />,
  39. lowAccuracy: <LowAccuracy />,
  40. }
  41. );
  42. }
  43. if (sampleCount === 1) {
  44. return tct('* Chart extrapolated from [sampleCount] sample ([lowAccuracy])', {
  45. sampleCount: <Count value={sampleCount} />,
  46. lowAccuracy: <LowAccuracy />,
  47. });
  48. }
  49. return tct('* Chart extrapolated from [sampleCount] samples ([lowAccuracy])', {
  50. sampleCount: <Count value={sampleCount} />,
  51. lowAccuracy: <LowAccuracy />,
  52. });
  53. }
  54. if (isTopN) {
  55. if (sampleCount === 1) {
  56. return tct(
  57. '* Chart for top [topEvents] groups extrapolated from [sampleCount] sample',
  58. {
  59. topEvents,
  60. sampleCount: <Count value={sampleCount} />,
  61. }
  62. );
  63. }
  64. return tct(
  65. '* Chart for top [topEvents] groups extrapolated from [sampleCount] samples',
  66. {
  67. topEvents,
  68. sampleCount: <Count value={sampleCount} />,
  69. }
  70. );
  71. }
  72. if (sampleCount === 1) {
  73. return tct('* Chart extrapolated from [sampleCount] sample', {
  74. sampleCount: <Count value={sampleCount} />,
  75. });
  76. }
  77. return tct('* Chart extrapolated from [sampleCount] samples', {
  78. sampleCount: <Count value={sampleCount} />,
  79. });
  80. }
  81. function LowAccuracy() {
  82. return (
  83. <Tooltip
  84. title={t(
  85. 'Increase your sampling rates to get more samples and more accurate trends.'
  86. )}
  87. >
  88. <InsufficientSamples>
  89. {t('Sampling rate may be low for accuracy')}
  90. </InsufficientSamples>
  91. </Tooltip>
  92. );
  93. }
  94. const InsufficientSamples = styled('span')`
  95. text-decoration: underline dotted ${p => p.theme.gray300};
  96. `;
  97. const Container = styled('span')`
  98. color: ${p => p.theme.gray300};
  99. font-size: ${p => p.theme.fontSizeSmall};
  100. `;