@@ -8,7 +8,12 @@ import {
8
8
getAggregateAlias ,
9
9
isAggregateFieldOrEquation ,
10
10
} from 'sentry/utils/discover/fields' ;
11
- import { decodeBoolean , decodeList , decodeScalar } from 'sentry/utils/queryString' ;
11
+ import {
12
+ decodeBoolean ,
13
+ decodeList ,
14
+ decodeScalar ,
15
+ decodeSorts ,
16
+ } from 'sentry/utils/queryString' ;
12
17
import type { DashboardFilters , Widget } from 'sentry/views/dashboards/types' ;
13
18
import { DisplayType } from 'sentry/views/dashboards/types' ;
14
19
import {
@@ -18,21 +23,57 @@ import {
18
23
getWidgetInterval ,
19
24
} from 'sentry/views/dashboards/utils' ;
20
25
import { Mode } from 'sentry/views/explore/contexts/pageParamsContext/mode' ;
21
- import { getExploreUrl } from 'sentry/views/explore/utils' ;
26
+ import { getExploreMultiQueryUrl , getExploreUrl } from 'sentry/views/explore/utils' ;
22
27
import { ChartType } from 'sentry/views/insights/common/components/chart' ;
23
28
24
29
export function getWidgetExploreUrl (
25
30
widget : Widget ,
26
31
dashboardFilters : DashboardFilters | undefined ,
27
32
selection : PageFilters ,
28
33
organization : Organization
34
+ ) {
35
+ if ( widget . queries . length > 1 ) {
36
+ return _getWidgetExploreUrlForMultipleQueries (
37
+ widget ,
38
+ dashboardFilters ,
39
+ selection ,
40
+ organization
41
+ ) ;
42
+ }
43
+
44
+ return _getWidgetExploreUrl ( widget , dashboardFilters , selection , organization ) ;
45
+ }
46
+
47
+ function getChartType ( displayType : DisplayType ) {
48
+ let chartType : ChartType = ChartType . LINE ;
49
+ switch ( displayType ) {
50
+ case DisplayType . BAR :
51
+ chartType = ChartType . BAR ;
52
+ break ;
53
+ case DisplayType . LINE :
54
+ chartType = ChartType . LINE ;
55
+ break ;
56
+ case DisplayType . AREA :
57
+ chartType = ChartType . AREA ;
58
+ break ;
59
+ case DisplayType . TABLE :
60
+ case DisplayType . BIG_NUMBER :
61
+ break ;
62
+ default :
63
+ break ;
64
+ }
65
+
66
+ return chartType ;
67
+ }
68
+
69
+ function _getWidgetExploreUrl (
70
+ widget : Widget ,
71
+ dashboardFilters : DashboardFilters | undefined ,
72
+ selection : PageFilters ,
73
+ organization : Organization
29
74
) {
30
75
const eventView = eventViewFromWidget ( widget . title , widget . queries [ 0 ] ! , selection ) ;
31
- const { query : locationQueryParams } = eventView . getResultsViewUrlTarget (
32
- organization ,
33
- false ,
34
- undefined
35
- ) ;
76
+ const locationQueryParams = eventView . generateQueryStringObject ( ) ;
36
77
37
78
// Inject the sort field for cases of arbitrary sorting
38
79
// The sort is not picked up by eventView unless it is
@@ -50,20 +91,17 @@ export function getWidgetExploreUrl(
50
91
) ,
51
92
] . slice ( 0 , 3 ) ;
52
93
94
+ const chartType = getChartType ( widget . displayType ) ;
53
95
let exploreMode : Mode | undefined = undefined ;
54
- let chartType : ChartType = ChartType . LINE ;
55
96
switch ( widget . displayType ) {
56
97
case DisplayType . BAR :
57
98
exploreMode = Mode . AGGREGATE ;
58
- chartType = ChartType . BAR ;
59
99
break ;
60
100
case DisplayType . LINE :
61
101
exploreMode = Mode . AGGREGATE ;
62
- chartType = ChartType . LINE ;
63
102
break ;
64
103
case DisplayType . AREA :
65
104
exploreMode = Mode . AGGREGATE ;
66
- chartType = ChartType . AREA ;
67
105
break ;
68
106
case DisplayType . TABLE :
69
107
case DisplayType . BIG_NUMBER :
@@ -158,3 +196,39 @@ function _isSortIncluded(sort: string, yAxes: string[]) {
158
196
const rawSort = trimStart ( sort , '-' ) ;
159
197
return yAxes . map ( getAggregateAlias ) . includes ( getAggregateAlias ( rawSort ) ) ;
160
198
}
199
+
200
+ function _getWidgetExploreUrlForMultipleQueries (
201
+ widget : Widget ,
202
+ dashboardFilters : DashboardFilters | undefined ,
203
+ selection : PageFilters ,
204
+ organization : Organization
205
+ ) : string {
206
+ const eventView = eventViewFromWidget ( widget . title , widget . queries [ 0 ] ! , selection ) ;
207
+ const locationQueryParams = eventView . generateQueryStringObject ( ) ;
208
+ const datetime = {
209
+ end : decodeScalar ( locationQueryParams . end ) ?? null ,
210
+ period : decodeScalar ( locationQueryParams . statsPeriod ) ?? null ,
211
+ start : decodeScalar ( locationQueryParams . start ) ?? null ,
212
+ utc : decodeBoolean ( locationQueryParams . utc ) ?? null ,
213
+ } ;
214
+
215
+ const currentSelection = {
216
+ ...selection ,
217
+ datetime,
218
+ } ;
219
+
220
+ return getExploreMultiQueryUrl ( {
221
+ organization,
222
+ title : widget . title ,
223
+ selection : currentSelection ,
224
+ queries : widget . queries . map ( query => ( {
225
+ chartType : getChartType ( widget . displayType ) ,
226
+ query : applyDashboardFilters ( query . conditions , dashboardFilters ) ?? '' ,
227
+ sortBys : decodeSorts ( query . orderby ) ,
228
+ yAxes : query . aggregates ,
229
+ fields : [ ] ,
230
+ groupBys : query . columns ,
231
+ } ) ) ,
232
+ interval : getWidgetInterval ( widget , currentSelection . datetime ) ,
233
+ } ) ;
234
+ }
0 commit comments