|
| 1 | +import EmptyStateWarning from 'sentry/components/emptyStateWarning'; |
| 2 | +import ErrorBoundary from 'sentry/components/errorBoundary'; |
| 3 | +import LoadingIndicator from 'sentry/components/loadingIndicator'; |
| 4 | +import {t} from 'sentry/locale'; |
| 5 | +import type {Event} from 'sentry/types/event'; |
| 6 | +import type {Project} from 'sentry/types/project'; |
| 7 | +import {useApiQuery} from 'sentry/utils/queryClient'; |
| 8 | +import useOrganization from 'sentry/utils/useOrganization'; |
| 9 | +import {SectionKey} from 'sentry/views/issueDetails/streamline/context'; |
| 10 | +import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection'; |
| 11 | +import {TreemapDiffSection} from 'sentry/views/preprod/buildComparison/main/treemapDiffSection'; |
| 12 | +import type {SizeAnalysisComparisonResults} from 'sentry/views/preprod/types/appSizeTypes'; |
| 13 | + |
| 14 | +type ContentProps = { |
| 15 | + baseMetricId: string; |
| 16 | + headMetricId: string; |
| 17 | + project: Project; |
| 18 | +}; |
| 19 | + |
| 20 | +function EventXrayDiffContent({baseMetricId, headMetricId, project}: ContentProps) { |
| 21 | + const organization = useOrganization(); |
| 22 | + |
| 23 | + const query = useApiQuery<SizeAnalysisComparisonResults>( |
| 24 | + [ |
| 25 | + `/projects/${organization.slug}/${project.id}/preprodartifacts/size-analysis/compare/${headMetricId}/${baseMetricId}/download/`, |
| 26 | + ], |
| 27 | + { |
| 28 | + staleTime: 0, |
| 29 | + } |
| 30 | + ); |
| 31 | + |
| 32 | + if (query.isLoading) { |
| 33 | + return <LoadingIndicator />; |
| 34 | + } |
| 35 | + |
| 36 | + const diffItems = query.data?.diff_items; |
| 37 | + |
| 38 | + if (!diffItems || diffItems.length === 0) { |
| 39 | + return <EmptyStateWarning small>No diff found.</EmptyStateWarning>; |
| 40 | + } |
| 41 | + |
| 42 | + return <TreemapDiffSection diffItems={diffItems} />; |
| 43 | +} |
| 44 | + |
| 45 | +type SectionProps = { |
| 46 | + baseMetricId: string; |
| 47 | + headMetricId: string; |
| 48 | + project: Project; |
| 49 | +}; |
| 50 | + |
| 51 | +function EventXrayDiffSection({baseMetricId, headMetricId, project}: SectionProps) { |
| 52 | + return ( |
| 53 | + <InterimSection title={t('X-Ray diff')} type={SectionKey.XRAY_DIFF}> |
| 54 | + <ErrorBoundary mini> |
| 55 | + <EventXrayDiffContent |
| 56 | + project={project} |
| 57 | + headMetricId={headMetricId} |
| 58 | + baseMetricId={baseMetricId} |
| 59 | + /> |
| 60 | + </ErrorBoundary> |
| 61 | + </InterimSection> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +interface MetricIds { |
| 66 | + baseMetricId: string; |
| 67 | + headMetricId: string; |
| 68 | +} |
| 69 | + |
| 70 | +function getMetricIds(event: Event): MetricIds | undefined { |
| 71 | + const headMetricId = event.occurrence?.evidenceData?.headSizeMetricId; |
| 72 | + const baseMetricId = event.occurrence?.evidenceData?.baseSizeMetricId; |
| 73 | + |
| 74 | + if (baseMetricId && headMetricId) { |
| 75 | + return { |
| 76 | + baseMetricId, |
| 77 | + headMetricId, |
| 78 | + }; |
| 79 | + } |
| 80 | + return undefined; |
| 81 | +} |
| 82 | + |
| 83 | +type Props = { |
| 84 | + event: Event; |
| 85 | + project: Project; |
| 86 | +}; |
| 87 | + |
| 88 | +function EventXrayDiff(props: Props) { |
| 89 | + const ids = getMetricIds(props.event); |
| 90 | + if (ids) { |
| 91 | + return <EventXrayDiffSection {...props} {...ids} />; |
| 92 | + } |
| 93 | + return null; |
| 94 | +} |
| 95 | + |
| 96 | +export {EventXrayDiff}; |
0 commit comments