traceCollapsedRow.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {useMemo} from 'react';
  2. import {t} from 'sentry/locale';
  3. import {
  4. isCollapsedNode,
  5. isTraceErrorNode,
  6. } from 'sentry/views/performance/newTraceDetails/traceGuards';
  7. import type {TraceTreeNode} from 'sentry/views/performance/newTraceDetails/traceModels/traceTreeNode';
  8. import type {CollapsedNode} from '../traceModels/traceCollapsedNode';
  9. import {TraceTree} from '../traceModels/traceTree';
  10. import type {TraceRowProps} from '../traceRow/traceRow';
  11. export function TraceCollapsedRow(props: TraceRowProps<CollapsedNode>) {
  12. const stats = useMemo(() => {
  13. const childStatistics = {issues: 0, events: 0};
  14. const seen = new Set<TraceTreeNode<any>>();
  15. TraceTree.ForEachChild(props.node, c => {
  16. // Dont count collapsed nodes and track what we've seen because
  17. // the collapsed nodes may contain duplicate children due to vertical
  18. // collapsing.
  19. if (isCollapsedNode(c) || seen.has(c)) {
  20. return;
  21. }
  22. seen.add(c);
  23. if (!isTraceErrorNode(c)) {
  24. childStatistics.events++;
  25. } else {
  26. childStatistics.issues++;
  27. }
  28. });
  29. return childStatistics;
  30. }, [props.node]);
  31. return (
  32. <div
  33. key={props.index}
  34. tabIndex={props.tabIndex}
  35. className={`Collapsed TraceRow`}
  36. onPointerDown={props.onRowClick}
  37. onKeyDown={props.onRowKeyDown}
  38. style={props.style}
  39. >
  40. <div className="TraceLeftColumn" ref={props.registerListColumnRef}>
  41. <div className="TraceLeftColumnInner" style={props.listColumnStyle}>
  42. {stats.events > 0 ? stats.events : null}{' '}
  43. {stats.events > 0
  44. ? stats.events === 1
  45. ? t('hidden span')
  46. : t('hidden spans')
  47. : null}
  48. {stats.events > 0 && ', '}
  49. {stats.issues > 0 ? stats.issues : null}{' '}
  50. {stats.issues > 0
  51. ? stats.issues === 1
  52. ? t('hidden issue')
  53. : t('hidden issues')
  54. : null}
  55. </div>
  56. </div>
  57. </div>
  58. );
  59. }