resourcesAndPossibleSolutions.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 {useHasStreamlinedUI, 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. const hasStreamlinedUI = useHasStreamlinedUI();
  49. const displayAiAutofix =
  50. ((organization.features.includes('autofix') &&
  51. organization.features.includes('issue-details-autofix-ui')) ||
  52. organization.genAIConsent) &&
  53. !shouldShowCustomErrorResourceConfig(group, project) &&
  54. config.autofix &&
  55. hasStacktraceWithFrames(event) &&
  56. !isSampleError;
  57. const displayAiSuggestedSolution =
  58. // Skip showing AI suggested solution if the issue has a custom resource
  59. config.aiSuggestedSolution &&
  60. organization.aiSuggestedSolution &&
  61. getRegionDataFromOrganization(organization)?.name !== 'de' &&
  62. !shouldShowCustomErrorResourceConfig(group, project) &&
  63. !displayAiAutofix &&
  64. !isSampleError;
  65. if (
  66. isSelfHostedErrorsOnly ||
  67. (!config.resources && !(displayAiSuggestedSolution || displayAiAutofix))
  68. ) {
  69. return null;
  70. }
  71. return (
  72. <Wrapper
  73. title={hasStreamlinedUI ? t('Autofix') : t('Resources and Possible Solutions')}
  74. configResources={!!config.resources}
  75. type={SectionKey.RESOURCES}
  76. >
  77. <Content>
  78. {config.resources && !hasStreamlinedUI && (
  79. <Resources
  80. eventPlatform={event.platform}
  81. groupId={group.id}
  82. configResources={config.resources}
  83. />
  84. )}
  85. {displayAiSuggestedSolution && (
  86. <AiSuggestedSolution event={event} projectSlug={project.slug} />
  87. )}
  88. {displayAiAutofix && <Autofix event={event} group={group} />}
  89. </Content>
  90. </Wrapper>
  91. );
  92. }
  93. const Content = styled('div')`
  94. display: flex;
  95. flex-direction: column;
  96. gap: ${space(2)};
  97. `;
  98. const Wrapper = styled(InterimSection)<{configResources: boolean}>`
  99. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  100. ${p =>
  101. !p.configResources &&
  102. css`
  103. && {
  104. padding-top: ${space(3)};
  105. }
  106. `}
  107. }
  108. `;