Skip to content

Commit cc1df78

Browse files
authored
fix(spans-migration): add selection params to explore url in frontend (#101185)
add the page params to the transaction widget warning urls on the frontend so they can see the same thing if they haven't submitted their dashboard filters. NOTE: i noticed that now the entire dashboard reloads when changing dashboard filters because the urls have to be re-rendered. This kinda sucks but it will be temporary
1 parent 057a9cc commit cc1df78

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

static/app/views/dashboards/widgetCard/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ function WidgetCard(props: Props) {
191191
const extractionStatus = useExtractionStatus({queryKey: widget});
192192
const indexedEventsWarning = useIndexedEventsWarning();
193193
const onDemandWarning = useOnDemandWarning({widget});
194-
const transactionsDeprecationWarning = useTransactionsDeprecationWarning({widget});
194+
const transactionsDeprecationWarning = useTransactionsDeprecationWarning({
195+
widget,
196+
selection,
197+
});
195198
const sessionDurationWarning = hasSessionDuration ? SESSION_DURATION_ALERT_TEXT : null;
196199
const spanTimeRangeWarning = useTimeRangeWarning({widget});
197200

static/app/views/dashboards/widgetCard/widgetCardContextMenu.tsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import {useMemo} from 'react';
12
import type {Location} from 'history';
3+
import qs from 'query-string';
24

35
import {
46
openAddToDashboardModal,
@@ -15,6 +17,7 @@ import {
1517
MEPState,
1618
useMEPSettingContext,
1719
} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
20+
import {safeURL} from 'sentry/utils/url/safeURL';
1821
import useOrganization from 'sentry/utils/useOrganization';
1922
import type {DashboardFilters, Widget} from 'sentry/views/dashboards/types';
2023
import {DashboardWidgetSource, WidgetType} from 'sentry/views/dashboards/types';
@@ -31,6 +34,7 @@ import {
3134
} from 'sentry/views/dashboards/utils/getWidgetExploreUrl';
3235
import {getReferrer} from 'sentry/views/dashboards/widgetCard/genericWidgetQueries';
3336
import {Mode} from 'sentry/views/explore/contexts/pageParamsContext/mode';
37+
import {getExploreUrl} from 'sentry/views/explore/utils';
3438

3539
import {useDashboardsMEPContext} from './dashboardsMEPContext';
3640

@@ -49,26 +53,57 @@ export const useIndexedEventsWarning = (): string | null => {
4953

5054
export const useTransactionsDeprecationWarning = ({
5155
widget,
56+
selection,
5257
}: {
58+
selection: PageFilters;
5359
widget: Widget;
5460
}): React.JSX.Element | null => {
5561
const organization = useOrganization();
5662

57-
if (
58-
organization.features.includes('transaction-widget-deprecation-explore-view') &&
59-
widget.widgetType === WidgetType.TRANSACTIONS &&
60-
widget.exploreUrls &&
61-
widget.exploreUrls.length > 0
62-
) {
63-
return tct(
64-
'Transactions widgets are in the process of being migrated to spans widgets. To see what your query could look like, open it in [explore:Explore].',
65-
{
66-
explore: <Link to={widget.exploreUrls[0]!} />,
67-
}
68-
);
63+
// memoize the URL to avoid recalculating it on every render
64+
const exploreUrl = useMemo(() => {
65+
if (
66+
!organization.features.includes('transaction-widget-deprecation-explore-view') ||
67+
widget.widgetType !== WidgetType.TRANSACTIONS ||
68+
!widget.exploreUrls ||
69+
widget.exploreUrls.length === 0
70+
) {
71+
return null;
72+
}
73+
return createExploreUrl(widget.exploreUrls[0]!, selection, organization);
74+
}, [organization, widget.widgetType, widget.exploreUrls, selection]);
75+
76+
if (!exploreUrl) {
77+
return null;
6978
}
7079

71-
return null;
80+
return tct(
81+
'Transactions widgets are in the process of being migrated to spans widgets. To see what your query could look like, open it in [explore:Explore].',
82+
{
83+
explore: <Link to={exploreUrl} />,
84+
}
85+
);
86+
};
87+
88+
const createExploreUrl = (
89+
baseUrl: string,
90+
selection: PageFilters,
91+
organization: Organization
92+
): string => {
93+
const parsedUrl = safeURL(baseUrl);
94+
const queryParams = qs.parse(parsedUrl?.search ?? '');
95+
96+
if (queryParams.aggregateField) {
97+
// we need to parse the aggregateField because it comes in stringified but needs to be passed in JSON format
98+
if (typeof queryParams.aggregateField === 'string') {
99+
queryParams.aggregateField = JSON.parse(queryParams.aggregateField);
100+
} else if (Array.isArray(queryParams.aggregateField)) {
101+
queryParams.aggregateField = queryParams.aggregateField.map(item =>
102+
JSON.parse(item)
103+
);
104+
}
105+
}
106+
return getExploreUrl({organization, selection, ...queryParams});
72107
};
73108

74109
export function getMenuOptions(

0 commit comments

Comments
 (0)