-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(insights): add geo region selector in web vitals landing (#76062)
Work towards #75230 Adds geo region selector, for now marked as "experimental" and internal only because we need to allow data to come in so its not always working. <img width="938" alt="image" src="https://github.com/user-attachments/assets/e60c71fc-b005-435c-a605-465f5acda2b1"> This will go in many other modules and areas of our app, but for now just web vitals landing for testing purposes. --------- Co-authored-by: Ash <[email protected]>
- Loading branch information
1 parent
33e02db
commit 8505e05
Showing
3 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
static/app/views/insights/common/views/spans/selectors/subregionSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import {Fragment} from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import FeatureBadge from 'sentry/components/badge/featureBadge'; | ||
import { | ||
CompactSelect, | ||
type SelectOption, | ||
type SelectProps, | ||
} from 'sentry/components/compactSelect'; | ||
import {t} from 'sentry/locale'; | ||
import {space} from 'sentry/styles/space'; | ||
import {trackAnalytics} from 'sentry/utils/analytics'; | ||
import {decodeList} from 'sentry/utils/queryString'; | ||
import {useLocation} from 'sentry/utils/useLocation'; | ||
import {useNavigate} from 'sentry/utils/useNavigate'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
import {useSpanMetrics} from 'sentry/views/insights/common/queries/useDiscover'; | ||
import {SpanMetricsField, subregionCodeToName} from 'sentry/views/insights/types'; | ||
|
||
export default function SubregionSelector() { | ||
const organization = useOrganization(); | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const hasGeoSelectorFeature = organization.features.includes('insights-region-filter'); | ||
|
||
const value = decodeList(location.query[SpanMetricsField.USER_GEO_SUBREGION]); | ||
const {data, isLoading} = useSpanMetrics( | ||
{fields: [SpanMetricsField.USER_GEO_SUBREGION], enabled: hasGeoSelectorFeature}, | ||
'api.insights.user-geo-subregion-selector' | ||
); | ||
|
||
type Options = SelectProps<string>['options']; | ||
|
||
const options: Options = | ||
data?.map(row => { | ||
const subregionCode = row[SpanMetricsField.USER_GEO_SUBREGION]; | ||
const text = subregionCodeToName[subregionCode] || ''; | ||
return { | ||
value: subregionCode, | ||
label: text, | ||
textValue: text, | ||
}; | ||
}) ?? []; | ||
|
||
if (!hasGeoSelectorFeature) { | ||
return <Fragment />; | ||
} | ||
|
||
return ( | ||
<CompactSelect | ||
triggerProps={{ | ||
prefix: ( | ||
<Fragment> | ||
<StyledFeatureBadge type="experimental" /> | ||
{t('Geo region')} | ||
</Fragment> | ||
), | ||
}} | ||
multiple | ||
loading={isLoading} | ||
clearable | ||
value={value} | ||
triggerLabel={value.length === 0 ? t('All') : undefined} | ||
menuTitle={t('Filter region')} | ||
options={options} | ||
onChange={(selectedOptions: SelectOption<string>[]) => { | ||
trackAnalytics('insight.vital.select_browser_value', { | ||
organization, | ||
browsers: selectedOptions.map(v => v.value), | ||
}); | ||
|
||
navigate({ | ||
...location, | ||
query: { | ||
...location.query, | ||
[SpanMetricsField.USER_GEO_SUBREGION]: selectedOptions.map( | ||
option => option.value | ||
), | ||
}, | ||
}); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
const StyledFeatureBadge = styled(FeatureBadge)` | ||
margin-right: ${space(1)}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters