resourcesAndMaybeSolutions.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // This section provides users with resources and maybe solutions on how to resolve an issue
  22. export function ResourcesAndMaybeSolutions({event, project, group}: Props) {
  23. const organization = useOrganization();
  24. const config = getConfigForIssueType(group, project);
  25. const hasStacktrace = event.entries.some(
  26. entry => entry.type === EntryType.EXCEPTION || entry.type === EntryType.STACKTRACE
  27. );
  28. // NOTE: Autofix is for INTERNAL testing only for now.
  29. const displayAiAutofix =
  30. project.features.includes('ai-autofix') &&
  31. organization.features.includes('issue-details-autofix-ui') &&
  32. !shouldShowCustomErrorResourceConfig(group, project) &&
  33. config.autofix &&
  34. hasStacktrace;
  35. const displayAiSuggestedSolution =
  36. // Skip showing AI suggested solution if the issue has a custom resource
  37. organization.aiSuggestedSolution &&
  38. getRegionDataFromOrganization(organization)?.name !== 'de' &&
  39. !shouldShowCustomErrorResourceConfig(group, project) &&
  40. !displayAiAutofix;
  41. if (!config.resources && !(displayAiSuggestedSolution || displayAiAutofix)) {
  42. return null;
  43. }
  44. return (
  45. <Wrapper
  46. type="resources-and-maybe-solutions"
  47. title={t('Resources and Maybe Solutions')}
  48. configResources={!!config.resources}
  49. >
  50. <Content>
  51. {config.resources && (
  52. <Resources
  53. eventPlatform={event.platform}
  54. groupId={group.id}
  55. configResources={config.resources}
  56. />
  57. )}
  58. {displayAiSuggestedSolution && (
  59. <AiSuggestedSolution event={event} projectSlug={project.slug} />
  60. )}
  61. {displayAiAutofix && <Autofix event={event} group={group} />}
  62. </Content>
  63. </Wrapper>
  64. );
  65. }
  66. const Content = styled('div')`
  67. display: flex;
  68. flex-direction: column;
  69. gap: ${space(2)};
  70. `;
  71. const Wrapper = styled(EventDataSection)<{configResources: boolean}>`
  72. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  73. ${p =>
  74. !p.configResources &&
  75. css`
  76. && {
  77. padding-top: ${space(3)};
  78. }
  79. `}
  80. }
  81. `;