Skip to content

Commit b3d7b19

Browse files
committed
feat(insights): Refactor chart widgets to pass down prop overrides
Inside of the Releases Drawers, we are only viewing a smaller slice of time than the main PageFilters. The chart widgets and their hooks need to support a pageFilters override. I think env/projects should be the same, but I think it will be more consistent to pass around the full pageFilters object. `showReleaseAs` is also needed since we currently show lines inside of the drawer, and bubbles outside of it.
1 parent 56d8dad commit b3d7b19

10 files changed

+84
-27
lines changed

static/app/views/dashboards/widgets/timeSeriesWidget/timeSeriesWidgetVisualization.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type {
4242
LegendSelection,
4343
Release,
4444
} from 'sentry/views/dashboards/widgets/common/types';
45+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
4546
import {useReleaseBubbles} from 'sentry/views/releases/releaseBubbles/useReleaseBubbles';
4647
import {makeReleasesPathname} from 'sentry/views/releases/utils/pathnames';
4748

@@ -55,7 +56,7 @@ import {TimeSeriesWidgetYAxis} from './timeSeriesWidgetYAxis';
5556

5657
const {error, warn, info} = Sentry.logger;
5758

58-
export interface TimeSeriesWidgetVisualizationProps {
59+
export interface TimeSeriesWidgetVisualizationProps extends LoadableChartWidgetProps {
5960
/**
6061
* An array of `Plottable` objects. This can be any object that implements the `Plottable` interface.
6162
*/
@@ -95,10 +96,6 @@ export interface TimeSeriesWidgetVisualizationProps {
9596
* Default: `auto`
9697
*/
9798
showLegend?: 'auto' | 'never';
98-
/**
99-
* Show releases as either lines per release or a bubble for a group of releases.
100-
*/
101-
showReleaseAs?: 'bubble' | 'line';
10299
}
103100

104101
export function TimeSeriesWidgetVisualization(props: TimeSeriesWidgetVisualizationProps) {
@@ -114,7 +111,8 @@ export function TimeSeriesWidgetVisualization(props: TimeSeriesWidgetVisualizati
114111
const {register: registerWithWidgetSyncContext} = useWidgetSyncContext();
115112

116113
const pageFilters = usePageFilters();
117-
const {start, end, period, utc} = pageFilters.selection.datetime;
114+
const {start, end, period, utc} =
115+
props.subPageFilters?.datetime || pageFilters.selection.datetime;
118116

119117
const theme = useTheme();
120118
const organization = useOrganization();

static/app/views/insights/common/components/insightsTimeSeriesWidget.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ import {
2828
HTTP_RESPONSE_5XX_COLOR,
2929
THROUGHPUT_COLOR,
3030
} from 'sentry/views/insights/colors';
31+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
3132
import type {DiscoverSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
3233
import {convertSeriesToTimeseries} from 'sentry/views/insights/common/utils/convertSeriesToTimeseries';
3334
import {INGESTION_DELAY} from 'sentry/views/insights/settings';
3435

35-
export interface InsightsTimeSeriesWidgetProps extends WidgetTitleProps {
36+
export interface InsightsTimeSeriesWidgetProps
37+
extends WidgetTitleProps,
38+
LoadableChartWidgetProps {
3639
error: Error | null;
3740
isLoading: boolean;
3841
series: DiscoverSeries[];
3942
visualizationType: 'line' | 'area' | 'bar';
4043
aliases?: Record<string, string>;
4144
description?: React.ReactNode;
4245
height?: string | number;
43-
id?: string;
4446
interactiveTitle?: () => React.ReactNode;
4547
legendSelection?: LegendSelection | undefined;
4648
onLegendSelectionChange?: ((selection: LegendSelection) => void) | undefined;
@@ -51,7 +53,8 @@ export function InsightsTimeSeriesWidget(props: InsightsTimeSeriesWidgetProps) {
5153
const theme = useTheme();
5254
const organization = useOrganization();
5355
const pageFilters = usePageFilters();
54-
const {releases: releasesWithDate} = useReleaseStats(pageFilters.selection);
56+
const pageFiltersSelection = props.subPageFilters || pageFilters.selection;
57+
const {releases: releasesWithDate} = useReleaseStats(pageFiltersSelection);
5558
const releases =
5659
releasesWithDate?.map(({date, version}) => ({
5760
timestamp: date,
@@ -118,7 +121,7 @@ export function InsightsTimeSeriesWidget(props: InsightsTimeSeriesWidgetProps) {
118121
}
119122

120123
const enableReleaseBubblesProps = organization.features.includes('release-bubbles-ui')
121-
? ({releases, showReleaseAs: 'bubble'} as const)
124+
? ({releases, showReleaseAs: props.showReleaseAs || 'bubble'} as const)
122125
: {};
123126

124127
return (
@@ -127,6 +130,8 @@ export function InsightsTimeSeriesWidget(props: InsightsTimeSeriesWidgetProps) {
127130
Title={Title}
128131
Visualization={
129132
<TimeSeriesWidgetVisualization
133+
id={props.id}
134+
subPageFilters={props.subPageFilters}
130135
{...enableReleaseBubblesProps}
131136
legendSelection={props.legendSelection}
132137
onLegendSelectionChange={props.onLegendSelectionChange}
@@ -149,6 +154,7 @@ export function InsightsTimeSeriesWidget(props: InsightsTimeSeriesWidgetProps) {
149154
children: (
150155
<ModalChartContainer>
151156
<TimeSeriesWidgetVisualization
157+
id={props.id}
152158
{...visualizationProps}
153159
{...enableReleaseBubblesProps}
154160
onZoom={() => {}}

static/app/views/insights/common/components/widgets/httpDomainSummaryDurationChartWidget.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
22
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
33
import {useHttpDomainSummaryChartFilter} from 'sentry/views/insights/common/components/widgets/hooks/useHttpDomainSummaryChartFilter';
4+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
45
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
56
import {getDurationChartTitle} from 'sentry/views/insights/common/views/spans/types';
67
import {Referrer} from 'sentry/views/insights/http/referrers';
78
import {SpanMetricsField} from 'sentry/views/insights/types';
89

9-
export default function HttpDomainSummaryDurationChartWidget() {
10+
export default function HttpDomainSummaryDurationChartWidget(
11+
props: LoadableChartWidgetProps
12+
) {
1013
const chartFilters = useHttpDomainSummaryChartFilter();
1114
const {
1215
isPending: isDurationDataLoading,
@@ -18,11 +21,13 @@ export default function HttpDomainSummaryDurationChartWidget() {
1821
yAxis: [`avg(${SpanMetricsField.SPAN_SELF_TIME})`],
1922
transformAliasToInputFormat: true,
2023
},
21-
Referrer.DOMAIN_SUMMARY_DURATION_CHART
24+
Referrer.DOMAIN_SUMMARY_DURATION_CHART,
25+
props.subPageFilters
2226
);
2327

2428
return (
2529
<InsightsLineChartWidget
30+
{...props}
2631
id="httpDomainSummaryDurationChartWidget"
2732
title={getDurationChartTitle('http')}
2833
series={[durationData[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]]}

static/app/views/insights/common/components/widgets/httpDomainSummaryResponseCodesChartWidget.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
22
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
33
import {useHttpDomainSummaryChartFilter} from 'sentry/views/insights/common/components/widgets/hooks/useHttpDomainSummaryChartFilter';
4+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
45
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
56
import {DataTitles} from 'sentry/views/insights/common/views/spans/types';
67
import {Referrer} from 'sentry/views/insights/http/referrers';
78
import {FIELD_ALIASES} from 'sentry/views/insights/http/settings';
89

9-
export default function HttpDomainSummaryResponseCodesWidget() {
10+
export default function HttpDomainSummaryResponseCodesChartWidget(
11+
props: LoadableChartWidgetProps
12+
) {
1013
const chartFilters = useHttpDomainSummaryChartFilter();
1114
const {
1215
isPending: isResponseCodeDataLoading,
@@ -18,12 +21,14 @@ export default function HttpDomainSummaryResponseCodesWidget() {
1821
yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
1922
transformAliasToInputFormat: true,
2023
},
21-
Referrer.DOMAIN_SUMMARY_RESPONSE_CODE_CHART
24+
Referrer.DOMAIN_SUMMARY_RESPONSE_CODE_CHART,
25+
props.subPageFilters
2226
);
2327

2428
return (
2529
<InsightsLineChartWidget
26-
id="httpDomainSummaryResponseCodesWidget"
30+
{...props}
31+
id="httpDomainSummaryResponseCodesChartWidget"
2732
title={DataTitles.unsuccessfulHTTPCodes}
2833
series={[
2934
responseCodeData[`http_response_rate(3)`],

static/app/views/insights/common/components/widgets/httpDomainSummaryThroughputChartWidget.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
22
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
33
import {useHttpDomainSummaryChartFilter} from 'sentry/views/insights/common/components/widgets/hooks/useHttpDomainSummaryChartFilter';
4+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
45
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
56
import {getThroughputChartTitle} from 'sentry/views/insights/common/views/spans/types';
67
import {Referrer} from 'sentry/views/insights/http/referrers';
78

8-
export default function HttpDomainSummaryThroughputChartWidget() {
9+
export default function HttpDomainSummaryThroughputChartWidget(
10+
props: LoadableChartWidgetProps
11+
) {
912
const chartFilters = useHttpDomainSummaryChartFilter();
1013
const {
1114
isPending: isThroughputDataLoading,
@@ -17,11 +20,13 @@ export default function HttpDomainSummaryThroughputChartWidget() {
1720
yAxis: ['epm()'],
1821
transformAliasToInputFormat: true,
1922
},
20-
Referrer.DOMAIN_SUMMARY_THROUGHPUT_CHART
23+
Referrer.DOMAIN_SUMMARY_THROUGHPUT_CHART,
24+
props.subPageFilters
2125
);
2226

2327
return (
2428
<InsightsLineChartWidget
29+
{...props}
2530
id="httpDomainSummaryThroughputChartWidget"
2631
title={getThroughputChartTitle('http')}
2732
series={[throughputData['epm()']]}

static/app/views/insights/common/components/widgets/httpDurationChartWidget.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
22
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
33
import {useHttpLandingChartFilter} from 'sentry/views/insights/common/components/widgets/hooks/useHttpLandingChartFilter';
4+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
45
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
56
import {getDurationChartTitle} from 'sentry/views/insights/common/views/spans/types';
67
import {Referrer} from 'sentry/views/insights/http/referrers';
78

8-
export default function HttpDurationChartWidget() {
9+
export default function HttpDurationChartWidget(props: LoadableChartWidgetProps) {
910
const chartFilters = useHttpLandingChartFilter();
1011
const {
1112
isPending: isDurationDataLoading,
@@ -17,11 +18,13 @@ export default function HttpDurationChartWidget() {
1718
yAxis: ['avg(span.self_time)'],
1819
transformAliasToInputFormat: true,
1920
},
20-
Referrer.LANDING_DURATION_CHART
21+
Referrer.LANDING_DURATION_CHART,
22+
props.subPageFilters
2123
);
2224

2325
return (
2426
<InsightsLineChartWidget
27+
{...props}
2528
id="httpDurationChartWidget"
2629
title={getDurationChartTitle('http')}
2730
series={[durationData['avg(span.self_time)']]}

static/app/views/insights/common/components/widgets/httpResponseCodesChartWidget.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
22
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
33
import {useHttpLandingChartFilter} from 'sentry/views/insights/common/components/widgets/hooks/useHttpLandingChartFilter';
4+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
45
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
56
import {DataTitles} from 'sentry/views/insights/common/views/spans/types';
67
import {Referrer} from 'sentry/views/insights/http/referrers';
78
import {FIELD_ALIASES} from 'sentry/views/insights/http/settings';
89

9-
export default function HttpResponseCodesChartWidget() {
10+
export default function HttpResponseCodesChartWidget(props: LoadableChartWidgetProps) {
1011
const chartFilters = useHttpLandingChartFilter();
1112
const {
1213
isPending: isResponseCodeDataLoading,
@@ -18,11 +19,13 @@ export default function HttpResponseCodesChartWidget() {
1819
yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
1920
transformAliasToInputFormat: true,
2021
},
21-
Referrer.LANDING_RESPONSE_CODE_CHART
22+
Referrer.LANDING_RESPONSE_CODE_CHART,
23+
props.subPageFilters
2224
);
2325

2426
return (
2527
<InsightsLineChartWidget
28+
{...props}
2629
id="httpResponseCodesChartWidget"
2730
title={DataTitles.unsuccessfulHTTPCodes}
2831
series={[

static/app/views/insights/common/components/widgets/httpThroughputChartWidget.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
22
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
33
import {useHttpLandingChartFilter} from 'sentry/views/insights/common/components/widgets/hooks/useHttpLandingChartFilter';
4+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
45
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
56
import {getThroughputChartTitle} from 'sentry/views/insights/common/views/spans/types';
67
import {Referrer} from 'sentry/views/insights/http/referrers';
78

8-
export default function HttpThroughputChartWidget() {
9+
export default function HttpThroughputChartWidget(props: LoadableChartWidgetProps) {
910
const chartFilters = useHttpLandingChartFilter();
1011
const {
1112
isPending: isThroughputDataLoading,
@@ -17,11 +18,13 @@ export default function HttpThroughputChartWidget() {
1718
yAxis: ['epm()'],
1819
transformAliasToInputFormat: true,
1920
},
20-
Referrer.LANDING_THROUGHPUT_CHART
21+
Referrer.LANDING_THROUGHPUT_CHART,
22+
props.subPageFilters
2123
);
2224

2325
return (
2426
<InsightsLineChartWidget
27+
{...props}
2528
id="httpThroughputChartWidget"
2629
title={getThroughputChartTitle('http')}
2730
series={[throughputData['epm()']]}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type {PageFilters} from 'sentry/types/core';
2+
3+
/**
4+
* These props are common across components that are required to dynamically
5+
* render an Insight Chart Widget
6+
*/
7+
export interface LoadableChartWidgetProps {
8+
// TODO(billy): This should be required when all chart widgets are converted
9+
/**
10+
* Unique ID for the widget
11+
*/
12+
id?: string;
13+
14+
/**
15+
* Show releases as either lines per release or a bubble for a group of releases.
16+
*/
17+
showReleaseAs?: 'bubble' | 'line';
18+
19+
/**
20+
* PageFilters-like object that will override the main PageFilters e.g. in
21+
* Releases Drawer, we have a smaller timeframe to show a smaller amount of
22+
* releases.
23+
*/
24+
subPageFilters?: PageFilters;
25+
}

static/app/views/insights/common/queries/useDiscoverSeries.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import moment from 'moment-timezone';
22

3+
import type {PageFilters} from 'sentry/types/core';
34
import type {Series} from 'sentry/types/echarts';
45
import {encodeSort, type EventsMetaType} from 'sentry/utils/discover/eventView';
56
import {
@@ -51,13 +52,15 @@ interface UseMetricsSeriesOptions<Fields> {
5152

5253
export const useSpanMetricsSeries = <Fields extends SpanMetricsProperty[]>(
5354
options: UseMetricsSeriesOptions<Fields> = {},
54-
referrer: string
55+
referrer: string,
56+
subPageFilters?: PageFilters
5557
) => {
5658
const useEap = useInsightsEap();
5759
return useDiscoverSeries<Fields>(
5860
options,
5961
useEap ? DiscoverDatasets.SPANS_EAP_RPC : DiscoverDatasets.SPANS_METRICS,
60-
referrer
62+
referrer,
63+
subPageFilters
6164
);
6265
};
6366

@@ -108,7 +111,8 @@ export const useSpanIndexedSeries = <
108111
const useDiscoverSeries = <T extends string[]>(
109112
options: UseMetricsSeriesOptions<T> = {},
110113
dataset: DiscoverDatasets,
111-
referrer: string
114+
referrer: string,
115+
subPageFilters?: PageFilters
112116
) => {
113117
const {
114118
search = undefined,
@@ -127,7 +131,7 @@ const useDiscoverSeries = <T extends string[]>(
127131
const eventView = getSeriesEventView(
128132
search,
129133
undefined,
130-
pageFilters.selection,
134+
subPageFilters || pageFilters.selection,
131135
yAxis,
132136
undefined,
133137
dataset

0 commit comments

Comments
 (0)