-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(spans-migration): add selection params to explore url in frontend #101185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import {useMemo} from 'react'; | ||
import type {Location} from 'history'; | ||
|
||
import { | ||
|
@@ -11,6 +12,7 @@ import {t, tct} from 'sentry/locale'; | |
import type {PageFilters} from 'sentry/types/core'; | ||
import type {Organization} from 'sentry/types/organization'; | ||
import {trackAnalytics} from 'sentry/utils/analytics'; | ||
import {getUtcDateString} from 'sentry/utils/dates'; | ||
import { | ||
MEPState, | ||
useMEPSettingContext, | ||
|
@@ -49,26 +51,63 @@ export const useIndexedEventsWarning = (): string | null => { | |
|
||
export const useTransactionsDeprecationWarning = ({ | ||
widget, | ||
selection, | ||
}: { | ||
selection: PageFilters; | ||
widget: Widget; | ||
}): React.JSX.Element | null => { | ||
const organization = useOrganization(); | ||
|
||
if ( | ||
organization.features.includes('transaction-widget-deprecation-explore-view') && | ||
widget.widgetType === WidgetType.TRANSACTIONS && | ||
widget.exploreUrls && | ||
widget.exploreUrls.length > 0 | ||
) { | ||
return tct( | ||
'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].', | ||
{ | ||
explore: <Link to={widget.exploreUrls[0]!} />, | ||
} | ||
); | ||
// memoize the URL to avoid recalculating it on every render | ||
const exploreUrl = useMemo(() => { | ||
if ( | ||
!organization.features.includes('transaction-widget-deprecation-explore-view') || | ||
widget.widgetType !== WidgetType.TRANSACTIONS || | ||
!widget.exploreUrls || | ||
widget.exploreUrls.length === 0 | ||
) { | ||
return null; | ||
} | ||
return createExploreUrl(widget.exploreUrls[0]!, selection); | ||
}, [organization.features, widget.widgetType, widget.exploreUrls, selection]); | ||
|
||
if (!exploreUrl) { | ||
return null; | ||
} | ||
|
||
return tct( | ||
'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].', | ||
{ | ||
explore: <Link to={exploreUrl} />, | ||
} | ||
); | ||
}; | ||
|
||
const createExploreUrl = (baseUrl: string, selection: PageFilters): string => { | ||
const params: string[] = []; | ||
|
||
if (selection.datetime?.start) { | ||
params.push(`start=${getUtcDateString(selection.datetime.start)}`); | ||
} | ||
if (selection.datetime?.end) { | ||
params.push(`end=${getUtcDateString(selection.datetime.end)}`); | ||
} | ||
if (selection.datetime?.period) { | ||
params.push(`statsPeriod=${selection.datetime.period}`); | ||
} | ||
if (selection.datetime?.utc) { | ||
params.push('utc=true'); | ||
} | ||
|
||
selection.projects.forEach(project => { | ||
params.push(`project=${project}`); | ||
}); | ||
|
||
selection.environments.forEach(environment => { | ||
params.push(`environment=${environment}`); | ||
}); | ||
|
||
Comment on lines
+99
to
109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bug: URL parameters are not encoded, leading to broken links for environment names with special characters.
Did we get this right? 👍 / 👎 to inform future reviews. |
||
return null; | ||
return params.length > 0 ? `${baseUrl}&${params.join('&')}` : baseUrl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; | ||
|
||
export function getMenuOptions( | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels a little janky to me, could we instead parse this URL, something like