exception.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {useState} from 'react';
  2. import EventDataSection from 'app/components/events/eventDataSection';
  3. import CrashContent from 'app/components/events/interfaces/crashContent';
  4. import CrashActions from 'app/components/events/interfaces/crashHeader/crashActions';
  5. import CrashTitle from 'app/components/events/interfaces/crashHeader/crashTitle';
  6. import {isStacktraceNewestFirst} from 'app/components/events/interfaces/stacktrace';
  7. import {t} from 'app/locale';
  8. import {ExceptionType, Group} from 'app/types';
  9. import {Event} from 'app/types/event';
  10. import {STACK_TYPE, STACK_VIEW} from 'app/types/stacktrace';
  11. type Props = {
  12. event: Event;
  13. type: string;
  14. data: ExceptionType;
  15. projectId: string;
  16. hasGroupingTreeUI: boolean;
  17. groupingCurrentLevel?: Group['metadata']['current_level'];
  18. hideGuide?: boolean;
  19. };
  20. function Exception({
  21. event,
  22. type,
  23. data,
  24. projectId,
  25. hasGroupingTreeUI,
  26. groupingCurrentLevel,
  27. hideGuide = false,
  28. }: Props) {
  29. const [stackView, setStackView] = useState<STACK_VIEW>(
  30. data.hasSystemFrames ? STACK_VIEW.APP : STACK_VIEW.FULL
  31. );
  32. const [stackType, setStackType] = useState<STACK_TYPE>(STACK_TYPE.ORIGINAL);
  33. const [newestFirst, setNewestFirst] = useState(isStacktraceNewestFirst());
  34. const eventHasThreads = !!event.entries.find(entry => entry.type === 'threads');
  35. /* in case there are threads in the event data, we don't render the
  36. exception block. Instead the exception is contained within the
  37. thread interface. */
  38. if (eventHasThreads) {
  39. return null;
  40. }
  41. function handleChange({
  42. stackView: newStackView,
  43. stackType: newStackType,
  44. newestFirst: newNewestFirst,
  45. }: {
  46. stackView?: STACK_VIEW;
  47. stackType?: STACK_TYPE;
  48. newestFirst?: boolean;
  49. }) {
  50. if (newStackView) {
  51. setStackView(newStackView);
  52. }
  53. if (newNewestFirst) {
  54. setNewestFirst(newNewestFirst);
  55. }
  56. if (newStackType) {
  57. setStackType(newStackType);
  58. }
  59. }
  60. const commonCrashHeaderProps = {
  61. newestFirst,
  62. hideGuide,
  63. onChange: handleChange,
  64. };
  65. return (
  66. <EventDataSection
  67. type={type}
  68. title={<CrashTitle title={t('Exception')} {...commonCrashHeaderProps} />}
  69. actions={
  70. <CrashActions
  71. stackType={stackType}
  72. stackView={stackView}
  73. platform={event.platform}
  74. exception={data}
  75. hasGroupingTreeUI={hasGroupingTreeUI}
  76. {...commonCrashHeaderProps}
  77. />
  78. }
  79. wrapTitle={false}
  80. >
  81. <CrashContent
  82. projectId={projectId}
  83. event={event}
  84. stackType={stackType}
  85. stackView={stackView}
  86. newestFirst={newestFirst}
  87. exception={data}
  88. hasGroupingTreeUI={hasGroupingTreeUI}
  89. groupingCurrentLevel={groupingCurrentLevel}
  90. />
  91. </EventDataSection>
  92. );
  93. }
  94. export default Exception;