|
| 1 | +import {Fragment} from 'react'; |
| 2 | +import styled from '@emotion/styled'; |
| 3 | + |
| 4 | +import {openInsightChartModal} from 'sentry/actionCreators/modal'; |
| 5 | +import {Button} from 'sentry/components/core/button'; |
| 6 | +import EventOrGroupExtraDetails from 'sentry/components/eventOrGroupExtraDetails'; |
| 7 | +import EventOrGroupHeader from 'sentry/components/eventOrGroupHeader'; |
| 8 | +import Panel from 'sentry/components/panels/panel'; |
| 9 | +import {GroupSummary} from 'sentry/components/stream/group'; |
| 10 | +import {IconExpand} from 'sentry/icons'; |
| 11 | +import {t} from 'sentry/locale'; |
| 12 | +import {space} from 'sentry/styles/space'; |
| 13 | +import type {Project} from 'sentry/types/project'; |
| 14 | +import usePageFilters from 'sentry/utils/usePageFilters'; |
| 15 | +import {useReleaseStats} from 'sentry/utils/useReleaseStats'; |
| 16 | +import type {LegendSelection} from 'sentry/views/dashboards/widgets/common/types'; |
| 17 | +import type {Plottable} from 'sentry/views/dashboards/widgets/timeSeriesWidget/plottables/plottable'; |
| 18 | +import {TimeSeriesWidgetVisualization} from 'sentry/views/dashboards/widgets/timeSeriesWidget/timeSeriesWidgetVisualization'; |
| 19 | +import {Widget} from 'sentry/views/dashboards/widgets/widget/widget'; |
| 20 | +import type {DiscoverSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries'; |
| 21 | +import {ModalChartContainer} from 'sentry/views/insights/pages/backend/laravel/styles'; |
| 22 | +import {WidgetVisualizationStates} from 'sentry/views/insights/pages/backend/laravel/widgetVisualizationStates'; |
| 23 | +import useRecentIssues from 'sentry/views/insights/sessions/queries/useRecentIssues'; |
| 24 | +import {SESSION_HEALTH_CHART_HEIGHT} from 'sentry/views/insights/sessions/utils/sessions'; |
| 25 | + |
| 26 | +export default function ChartWithIssues({ |
| 27 | + project, |
| 28 | + series, |
| 29 | + plottables, |
| 30 | + title, |
| 31 | + description, |
| 32 | + isPending, |
| 33 | + error, |
| 34 | + legendSelection, |
| 35 | +}: { |
| 36 | + description: string; |
| 37 | + error: Error | null; |
| 38 | + isPending: boolean; |
| 39 | + plottables: Plottable[]; |
| 40 | + project: Project; |
| 41 | + series: DiscoverSeries[]; |
| 42 | + title: string; |
| 43 | + legendSelection?: LegendSelection | undefined; |
| 44 | +}) { |
| 45 | + const {recentIssues, isPending: isPendingRecentIssues} = useRecentIssues({ |
| 46 | + projectId: project.id, |
| 47 | + }); |
| 48 | + const pageFilters = usePageFilters(); |
| 49 | + |
| 50 | + const {releases: releasesWithDate} = useReleaseStats(pageFilters.selection); |
| 51 | + const releases = |
| 52 | + releasesWithDate?.map(({date, version}) => ({ |
| 53 | + timestamp: date, |
| 54 | + version, |
| 55 | + })) ?? []; |
| 56 | + |
| 57 | + const hasData = series?.length; |
| 58 | + const isLoading = isPending || isPendingRecentIssues; |
| 59 | + |
| 60 | + if (isLoading) { |
| 61 | + return ( |
| 62 | + <Widget |
| 63 | + height={SESSION_HEALTH_CHART_HEIGHT} |
| 64 | + Visualization={<TimeSeriesWidgetVisualization.LoadingPlaceholder />} |
| 65 | + /> |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + const visualization = ( |
| 70 | + <WidgetVisualizationStates |
| 71 | + isEmpty={!hasData} |
| 72 | + isLoading={isLoading} |
| 73 | + error={error} |
| 74 | + VisualizationType={TimeSeriesWidgetVisualization} |
| 75 | + visualizationProps={{ |
| 76 | + legendSelection, |
| 77 | + plottables, |
| 78 | + }} |
| 79 | + /> |
| 80 | + ); |
| 81 | + |
| 82 | + const footer = hasData && recentIssues && ( |
| 83 | + <FooterIssues> |
| 84 | + {recentIssues.map((group, index) => ( |
| 85 | + <GroupWrapper canSelect key={group.id}> |
| 86 | + <EventOrGroupHeader index={index} data={group} source={'session-health'} /> |
| 87 | + <EventOrGroupExtraDetails data={group} showLifetime={false} /> |
| 88 | + </GroupWrapper> |
| 89 | + ))} |
| 90 | + </FooterIssues> |
| 91 | + ); |
| 92 | + |
| 93 | + return ( |
| 94 | + <Widget |
| 95 | + Title={<Widget.WidgetTitle title={title} />} |
| 96 | + height={SESSION_HEALTH_CHART_HEIGHT} |
| 97 | + Visualization={visualization} |
| 98 | + Actions={ |
| 99 | + <Widget.WidgetToolbar> |
| 100 | + <Widget.WidgetDescription description={description} /> |
| 101 | + <Button |
| 102 | + size="xs" |
| 103 | + aria-label={t('Open Full-Screen View')} |
| 104 | + borderless |
| 105 | + icon={<IconExpand />} |
| 106 | + onClick={() => { |
| 107 | + openInsightChartModal({ |
| 108 | + title, |
| 109 | + children: ( |
| 110 | + <Fragment> |
| 111 | + <ModalChartContainer> |
| 112 | + <TimeSeriesWidgetVisualization |
| 113 | + releases={releases ?? []} |
| 114 | + plottables={plottables} |
| 115 | + legendSelection={legendSelection} |
| 116 | + /> |
| 117 | + </ModalChartContainer> |
| 118 | + <ModalFooterWrapper>{footer}</ModalFooterWrapper> |
| 119 | + </Fragment> |
| 120 | + ), |
| 121 | + }); |
| 122 | + }} |
| 123 | + /> |
| 124 | + </Widget.WidgetToolbar> |
| 125 | + } |
| 126 | + noFooterPadding |
| 127 | + Footer={footer} |
| 128 | + /> |
| 129 | + ); |
| 130 | +} |
| 131 | + |
| 132 | +const FooterIssues = styled('div')` |
| 133 | + display: flex; |
| 134 | + flex-direction: column; |
| 135 | +`; |
| 136 | + |
| 137 | +const GroupWrapper = styled(GroupSummary)` |
| 138 | + border-top: 1px solid ${p => p.theme.border}; |
| 139 | + padding: ${space(1)} ${space(0.5)} ${space(1.5)} ${space(0.5)}; |
| 140 | +
|
| 141 | + &:first-child { |
| 142 | + border-top: none; |
| 143 | + } |
| 144 | +`; |
| 145 | + |
| 146 | +const ModalFooterWrapper = styled(Panel)` |
| 147 | + margin-top: 50px; |
| 148 | +`; |
0 commit comments