resourcesAndPossibleSolutions.tsx 3.3 KB

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