resourcesAndPossibleSolutions.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import {AiSuggestedSolution} from 'sentry/components/events/aiSuggestedSolution';
  4. import {Autofix} from 'sentry/components/events/autofix';
  5. import {Resources} from 'sentry/components/events/interfaces/performance/resources';
  6. import {t} from 'sentry/locale';
  7. import ConfigStore from 'sentry/stores/configStore';
  8. import {space} from 'sentry/styles/space';
  9. import {EntryType, type Event} from 'sentry/types/event';
  10. import type {Group} from 'sentry/types/group';
  11. import type {Project} from 'sentry/types/project';
  12. import {
  13. getConfigForIssueType,
  14. shouldShowCustomErrorResourceConfig,
  15. } from 'sentry/utils/issueTypeConfig';
  16. import {getRegionDataFromOrganization} from 'sentry/utils/regions';
  17. import useOrganization from 'sentry/utils/useOrganization';
  18. import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
  19. import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection';
  20. import {useIsSampleEvent} from 'sentry/views/issueDetails/utils';
  21. type Props = {
  22. event: Event;
  23. group: Group;
  24. project: Project;
  25. };
  26. // Autofix requires the event to have stack trace frames in order to work correctly.
  27. function hasStacktraceWithFrames(event: Event) {
  28. for (const entry of event.entries) {
  29. if (entry.type === EntryType.EXCEPTION) {
  30. if (entry.data.values?.some(value => value.stacktrace?.frames?.length)) {
  31. return true;
  32. }
  33. }
  34. if (entry.type === EntryType.THREADS) {
  35. if (entry.data.values?.some(thread => thread.stacktrace?.frames?.length)) {
  36. return true;
  37. }
  38. }
  39. }
  40. return false;
  41. }
  42. // This section provides users with resources and possible solutions on how to resolve an issue
  43. export function ResourcesAndPossibleSolutions({event, project, group}: Props) {
  44. const organization = useOrganization();
  45. const config = getConfigForIssueType(group, project);
  46. const isSelfHostedErrorsOnly = ConfigStore.get('isSelfHostedErrorsOnly');
  47. const isSampleError = useIsSampleEvent();
  48. // NOTE: Autofix is for INTERNAL testing only for now.
  49. const displayAiAutofix =
  50. organization.features.includes('autofix') &&
  51. organization.features.includes('issue-details-autofix-ui') &&
  52. !shouldShowCustomErrorResourceConfig(group, project) &&
  53. config.autofix &&
  54. hasStacktraceWithFrames(event) &&
  55. !isSampleError;
  56. const displayAiSuggestedSolution =
  57. // Skip showing AI suggested solution if the issue has a custom resource
  58. config.aiSuggestedSolution &&
  59. organization.aiSuggestedSolution &&
  60. getRegionDataFromOrganization(organization)?.name !== 'de' &&
  61. !shouldShowCustomErrorResourceConfig(group, project) &&
  62. !displayAiAutofix &&
  63. !isSampleError;
  64. if (
  65. isSelfHostedErrorsOnly ||
  66. (!config.resources && !(displayAiSuggestedSolution || displayAiAutofix))
  67. ) {
  68. return null;
  69. }
  70. return (
  71. <Wrapper
  72. title={t('Resources and Possible Solutions')}
  73. configResources={!!config.resources}
  74. type={SectionKey.RESOURCES}
  75. >
  76. <Content>
  77. {config.resources && (
  78. <Resources
  79. eventPlatform={event.platform}
  80. groupId={group.id}
  81. configResources={config.resources}
  82. />
  83. )}
  84. {displayAiSuggestedSolution && (
  85. <AiSuggestedSolution event={event} projectSlug={project.slug} />
  86. )}
  87. {displayAiAutofix && <Autofix event={event} group={group} />}
  88. </Content>
  89. </Wrapper>
  90. );
  91. }
  92. const Content = styled('div')`
  93. display: flex;
  94. flex-direction: column;
  95. gap: ${space(2)};
  96. `;
  97. const Wrapper = styled(InterimSection)<{configResources: boolean}>`
  98. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  99. ${p =>
  100. !p.configResources &&
  101. css`
  102. && {
  103. padding-top: ${space(3)};
  104. }
  105. `}
  106. }
  107. `;