queryCount.tsx 719 B

123456789101112131415161718192021222324252627282930313233
  1. import {defined} from 'sentry/utils';
  2. type Props = {
  3. count?: number | null;
  4. hideIfEmpty?: boolean;
  5. hideParens?: boolean;
  6. max?: number;
  7. };
  8. /**
  9. * Displays a number count. If `max` is specified, then give representation
  10. * of count, i.e. "1000+"
  11. *
  12. * Render nothing by default if `count` is falsy.
  13. */
  14. const QueryCount = ({count, max, hideIfEmpty = true, hideParens = false}: Props) => {
  15. const countOrMax = defined(count) && defined(max) && count >= max ? `${max}+` : count;
  16. if (hideIfEmpty && !count) {
  17. return null;
  18. }
  19. return (
  20. <span>
  21. {!hideParens && <span>(</span>}
  22. <span>{countOrMax}</span>
  23. {!hideParens && <span>)</span>}
  24. </span>
  25. );
  26. };
  27. export default QueryCount;