Skip to content

Commit 437cdb8

Browse files
DominikB2014andrewshie-sentry
authored andcommitted
feat(insights): changes to eap toggle for ea (#91800)
1 parent 1633d79 commit 437cdb8

File tree

8 files changed

+138
-80
lines changed

8 files changed

+138
-80
lines changed
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1+
import {defined} from 'sentry/utils';
2+
import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
3+
import {useLocation} from 'sentry/utils/useLocation';
14
import useOrganization from 'sentry/utils/useOrganization';
2-
import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
3-
import {EAP_LOCAL_STORAGE_KEY} from 'sentry/views/insights/settings';
5+
import {
6+
BACKEND_LANDING_SUB_PATH,
7+
USE_NEW_BACKEND_EXPERIENCE,
8+
} from 'sentry/views/insights/pages/backend/settings';
9+
import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
410

511
export const useInsightsEap = (): boolean => {
612
const organization = useOrganization();
7-
13+
const location = useLocation();
14+
const {isInOverviewPage, view} = useDomainViewFilters();
815
const hasEapFlag = organization.features.includes('insights-modules-use-eap');
9-
const [isEapEnabledLocalState] = useSyncedLocalStorageState(
10-
EAP_LOCAL_STORAGE_KEY,
11-
false
16+
const [isNewBackendExperienceEnabled] = useLocalStorageState(
17+
USE_NEW_BACKEND_EXPERIENCE,
18+
true
1219
);
1320

1421
if (!hasEapFlag) {
1522
return false;
1623
}
1724

18-
return isEapEnabledLocalState;
25+
if (defined(location.query.useEap)) {
26+
return location.query.useEap === '1';
27+
}
28+
29+
if (view === BACKEND_LANDING_SUB_PATH && isInOverviewPage) {
30+
return isNewBackendExperienceEnabled;
31+
}
32+
33+
return true;
1934
};

static/app/views/insights/pages/backend/backendOverviewPage.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
isAValidSort,
3636
type ValidSort,
3737
} from 'sentry/views/insights/pages/backend/backendTable';
38+
import {EAPExperimentButton} from 'sentry/views/insights/pages/backend/eapExperimentButton';
3839
import {OldBackendOverviewPage} from 'sentry/views/insights/pages/backend/oldBackendOverviewPage';
3940
import {
4041
BACKEND_LANDING_TITLE,
@@ -50,7 +51,10 @@ import {useIsLaravelInsightsAvailable} from 'sentry/views/insights/pages/platfor
5051
import {JobsWidget} from 'sentry/views/insights/pages/platform/laravel/jobsWidget';
5152
import {QueriesWidget} from 'sentry/views/insights/pages/platform/laravel/queriesWidget';
5253
import {NextJsOverviewPage} from 'sentry/views/insights/pages/platform/nextjs';
53-
import {useIsNextJsInsightsEnabled} from 'sentry/views/insights/pages/platform/nextjs/features';
54+
import {
55+
useIsNextJsInsightsAvailable,
56+
useIsNextJsInsightsEnabled,
57+
} from 'sentry/views/insights/pages/platform/nextjs/features';
5458
import {NewNextJsExperienceButton} from 'sentry/views/insights/pages/platform/nextjs/newNextjsExperienceToggle';
5559
import {DurationWidget} from 'sentry/views/insights/pages/platform/shared/durationWidget';
5660
import {IssuesWidget} from 'sentry/views/insights/pages/platform/shared/issuesWidget';
@@ -65,14 +69,14 @@ function BackendOverviewPage() {
6569
useOverviewPageTrackPageload();
6670
const isLaravelPageAvailable = useIsLaravelInsightsAvailable();
6771
const [isNextJsPageEnabled] = useIsNextJsInsightsEnabled();
68-
const useEap = useInsightsEap();
72+
const isNewBackendExperienceEnabled = useInsightsEap();
6973
if (isLaravelPageAvailable) {
7074
return <LaravelOverviewPage />;
7175
}
7276
if (isNextJsPageEnabled) {
7377
return <NextJsOverviewPage performanceType="backend" />;
7478
}
75-
if (useEap) {
79+
if (isNewBackendExperienceEnabled) {
7680
return <EAPBackendOverviewPage />;
7781
}
7882
return <OldBackendOverviewPage />;
@@ -86,6 +90,7 @@ function EAPBackendOverviewPage() {
8690
const navigate = useNavigate();
8791
const {selection} = usePageFilters();
8892
const cursor = decodeScalar(location.query?.[QueryParameterNames.PAGES_CURSOR]);
93+
const isNextJsInsightsAvailable = useIsNextJsInsightsAvailable();
8994

9095
const {query: searchBarQuery} = useLocationQuery({
9196
fields: {
@@ -198,7 +203,13 @@ function EAPBackendOverviewPage() {
198203
>
199204
<BackendHeader
200205
headerTitle={BACKEND_LANDING_TITLE}
201-
headerActions={<NewNextJsExperienceButton />}
206+
headerActions={
207+
isNextJsInsightsAvailable ? (
208+
<NewNextJsExperienceButton />
209+
) : (
210+
<EAPExperimentButton />
211+
)
212+
}
202213
/>
203214
<Layout.Body>
204215
<Layout.Main fullWidth>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import type {Key} from 'react';
2+
import styled from '@emotion/styled';
3+
4+
import DropdownButton from 'sentry/components/dropdownButton';
5+
import {DropdownMenu} from 'sentry/components/dropdownMenu';
6+
import {IconLab} from 'sentry/icons';
7+
import {trackAnalytics} from 'sentry/utils/analytics';
8+
import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
9+
import {useLocation} from 'sentry/utils/useLocation';
10+
import {useNavigate} from 'sentry/utils/useNavigate';
11+
import useOrganization from 'sentry/utils/useOrganization';
12+
import {useInsightsEap} from 'sentry/views/insights/common/utils/useEap';
13+
import {USE_NEW_BACKEND_EXPERIENCE} from 'sentry/views/insights/pages/backend/settings';
14+
import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
15+
16+
export function EAPExperimentButton() {
17+
const organization = useOrganization();
18+
const {view} = useDomainViewFilters();
19+
const location = useLocation();
20+
const isEapFlagEnabled = organization.features.includes('insights-modules-use-eap');
21+
const isNewBackendExperienceEnabled = useInsightsEap(); // useEap accounts for the local storage state
22+
const [_, setNewBackendExperienceEnabled] = useLocalStorageState(
23+
USE_NEW_BACKEND_EXPERIENCE,
24+
true
25+
);
26+
const navigate = useNavigate();
27+
28+
const toggleUseEap = () => {
29+
const newState = !isNewBackendExperienceEnabled;
30+
setNewBackendExperienceEnabled(newState);
31+
trackAnalytics('insights.eap.toggle', {
32+
organization,
33+
isEapEnabled: newState,
34+
page: 'overview',
35+
view,
36+
});
37+
navigate({
38+
pathname: location.pathname,
39+
query: {
40+
...location.query,
41+
useEap: newState ? '1' : '0',
42+
},
43+
});
44+
};
45+
46+
const handleExperimentDropdownAction = (key: Key) => {
47+
if (key === 'eap') {
48+
toggleUseEap();
49+
}
50+
};
51+
52+
if (!isEapFlagEnabled) {
53+
return null;
54+
}
55+
56+
return (
57+
<DropdownMenu
58+
trigger={triggerProps => (
59+
<StyledDropdownButton {...triggerProps} size={'sm'}>
60+
{/* Passing icon as child to avoid extra icon margin */}
61+
<IconLab isSolid />
62+
</StyledDropdownButton>
63+
)}
64+
onAction={handleExperimentDropdownAction}
65+
items={[
66+
{
67+
key: 'eap',
68+
label: isNewBackendExperienceEnabled ? 'Switch to Old UI' : 'Switch to New UI',
69+
},
70+
]}
71+
position="bottom-end"
72+
/>
73+
);
74+
}
75+
76+
const StyledDropdownButton = styled(DropdownButton)`
77+
color: ${p => p.theme.button.primary.background};
78+
:hover {
79+
color: ${p => p.theme.button.primary.background};
80+
}
81+
`;

static/app/views/insights/pages/backend/oldBackendOverviewPage.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLay
3333
import {ToolRibbon} from 'sentry/views/insights/common/components/ribbon';
3434
import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
3535
import {BackendHeader} from 'sentry/views/insights/pages/backend/backendPageHeader';
36+
import {EAPExperimentButton} from 'sentry/views/insights/pages/backend/eapExperimentButton';
3637
import {
3738
BACKEND_LANDING_TITLE,
3839
OVERVIEW_PAGE_ALLOWED_OPS,
@@ -45,6 +46,7 @@ import {
4546
MOBILE_PLATFORMS,
4647
OVERVIEW_PAGE_ALLOWED_OPS as BACKEND_OVERVIEW_PAGE_OPS,
4748
} from 'sentry/views/insights/pages/mobile/settings';
49+
import {useIsNextJsInsightsAvailable} from 'sentry/views/insights/pages/platform/nextjs/features';
4850
import {NewNextJsExperienceButton} from 'sentry/views/insights/pages/platform/nextjs/newNextjsExperienceToggle';
4951
import {
5052
generateBackendPerformanceEventView,
@@ -98,6 +100,7 @@ export function OldBackendOverviewPage() {
98100
const {teams} = useUserTeams();
99101
const mepSetting = useMEPSettingContext();
100102
const {selection} = usePageFilters();
103+
const isNextJsInsightsAvailable = useIsNextJsInsightsAvailable();
101104

102105
const withStaticFilters = canUseMetricsData(organization);
103106
const eventView = generateBackendPerformanceEventView(location, withStaticFilters);
@@ -232,7 +235,13 @@ export function OldBackendOverviewPage() {
232235
>
233236
<BackendHeader
234237
headerTitle={BACKEND_LANDING_TITLE}
235-
headerActions={<NewNextJsExperienceButton />}
238+
headerActions={
239+
isNextJsInsightsAvailable ? (
240+
<NewNextJsExperienceButton />
241+
) : (
242+
<EAPExperimentButton />
243+
)
244+
}
236245
/>
237246
<Layout.Body>
238247
<Layout.Main fullWidth>

static/app/views/insights/pages/backend/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ export const DEFAULT_SORT: ValidSort = {
2525
};
2626

2727
export const BACKEND_PLATFORMS: PlatformKey[] = [...backend];
28+
29+
export const USE_NEW_BACKEND_EXPERIENCE = 'insights-backend-use-new-backend-experience';

static/app/views/insights/pages/domainViewHeader.tsx

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import {Fragment} from 'react';
22
import styled from '@emotion/styled';
3-
import type {Key} from '@react-types/shared';
43

54
import {Breadcrumbs, type Crumb} from 'sentry/components/breadcrumbs';
65
import {FeatureBadge} from 'sentry/components/core/badge/featureBadge';
76
import {ButtonBar} from 'sentry/components/core/button/buttonBar';
8-
import DropdownButton from 'sentry/components/dropdownButton';
9-
import {DropdownMenu} from 'sentry/components/dropdownMenu';
107
import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
118
import * as Layout from 'sentry/components/layouts/thirds';
129
import {extractSelectionParameters} from 'sentry/components/organizations/pageFilters/utils';
1310
import {TabList} from 'sentry/components/tabs';
1411
import type {TabListItemProps} from 'sentry/components/tabs/item';
15-
import {IconBusiness, IconLab} from 'sentry/icons';
12+
import {IconBusiness} from 'sentry/icons';
1613
import {space} from 'sentry/styles/space';
17-
import {trackAnalytics} from 'sentry/utils/analytics';
1814
import {useLocation} from 'sentry/utils/useLocation';
1915
import useOrganization from 'sentry/utils/useOrganization';
20-
import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
21-
import {useInsightsEap} from 'sentry/views/insights/common/utils/useEap';
2216
import {useModuleTitles} from 'sentry/views/insights/common/utils/useModuleTitle';
2317
import {
2418
type RoutableModuleNames,
@@ -27,14 +21,12 @@ import {
2721
import {useIsLaravelInsightsAvailable} from 'sentry/views/insights/pages/platform/laravel/features';
2822
import {useIsNextJsInsightsEnabled} from 'sentry/views/insights/pages/platform/nextjs/features';
2923
import {OVERVIEW_PAGE_TITLE} from 'sentry/views/insights/pages/settings';
30-
import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
3124
import {
3225
isModuleConsideredNew,
3326
isModuleEnabled,
3427
isModuleVisible,
3528
} from 'sentry/views/insights/pages/utils';
3629
import FeedbackButtonTour from 'sentry/views/insights/sessions/components/tour/feedbackButtonTour';
37-
import {EAP_LOCAL_STORAGE_KEY} from 'sentry/views/insights/settings';
3830
import {ModuleName} from 'sentry/views/insights/types';
3931

4032
export type Props = {
@@ -68,24 +60,6 @@ export function DomainViewHeader({
6860
const moduleURLBuilder = useModuleURLBuilder();
6961
const isLaravelInsightsAvailable = useIsLaravelInsightsAvailable();
7062
const [isNextJsInsightsEnabled] = useIsNextJsInsightsEnabled();
71-
const useEap = useInsightsEap();
72-
const {view} = useDomainViewFilters();
73-
const hasEapFlag = organization.features.includes('insights-modules-use-eap');
74-
const [_, setIsEapEnabledLocalState] = useSyncedLocalStorageState(
75-
EAP_LOCAL_STORAGE_KEY,
76-
false
77-
);
78-
79-
const toggleUseEap = () => {
80-
const newState = !useEap;
81-
setIsEapEnabledLocalState(newState);
82-
trackAnalytics('insights.eap.toggle', {
83-
organization,
84-
isEapEnabled: newState,
85-
page: selectedModule || 'overview',
86-
view,
87-
});
88-
};
8963

9064
const crumbs: Crumb[] = [
9165
{
@@ -101,7 +75,6 @@ export function DomainViewHeader({
10175

10276
const globalQuery = {
10377
...extractSelectionParameters(location?.query),
104-
useEap: location.query?.useEap,
10578
};
10679

10780
const tabList: TabListItemProps[] = [
@@ -127,12 +100,6 @@ export function DomainViewHeader({
127100
})),
128101
];
129102

130-
const handleExperimentDropdownAction = (key: Key) => {
131-
if (key === 'eap') {
132-
toggleUseEap();
133-
}
134-
};
135-
136103
return (
137104
<Fragment>
138105
<Layout.Header>
@@ -161,28 +128,6 @@ export function DomainViewHeader({
161128
/>
162129
)}
163130
{additonalHeaderActions}
164-
{hasEapFlag && (
165-
<Fragment>
166-
<DropdownMenu
167-
trigger={triggerProps => (
168-
<StyledDropdownButton {...triggerProps} size={'sm'}>
169-
{/* Passing icon as child to avoid extra icon margin */}
170-
<IconLab isSolid />
171-
</StyledDropdownButton>
172-
)}
173-
onAction={handleExperimentDropdownAction}
174-
items={[
175-
{
176-
key: 'eap',
177-
label: useEap
178-
? 'Switch to Metrics Dataset'
179-
: 'Switch to EAP Dataset',
180-
},
181-
]}
182-
position="bottom-end"
183-
/>
184-
</Fragment>
185-
)}
186131
</ButtonBar>
187132
</Layout.HeaderActions>
188133
<Layout.HeaderTabs value={tabValue} onChange={tabs?.onTabChange}>
@@ -228,10 +173,3 @@ const TabContainer = styled('div')`
228173
text-align: left;
229174
gap: ${space(0.5)};
230175
`;
231-
232-
const StyledDropdownButton = styled(DropdownButton)`
233-
color: ${p => p.theme.button.primary.background};
234-
:hover {
235-
color: ${p => p.theme.button.primary.background};
236-
}
237-
`;

static/app/views/insights/pages/useFilters.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ const domainViews = [
2020

2121
export type DomainViewFilters = {
2222
isInDomainView?: boolean;
23+
isInOverviewPage?: boolean;
2324
view?: DomainView;
2425
};
2526

2627
export const useDomainViewFilters = () => {
2728
const location = useLocation();
2829
const pathSegments = location.pathname.split('/').filter(Boolean);
29-
const indexOfPerformance = pathSegments.indexOf(DOMAIN_VIEW_BASE_URL);
30-
const isInDomainView = indexOfPerformance !== -1;
31-
const view = pathSegments[indexOfPerformance + 1] as DomainViewFilters['view'];
30+
const indexOfInsights = pathSegments.indexOf(DOMAIN_VIEW_BASE_URL);
31+
const isInDomainView = indexOfInsights !== -1;
32+
const view = pathSegments[indexOfInsights + 1] as DomainViewFilters['view'];
33+
const isInOverviewPage = pathSegments.length === indexOfInsights + 2; // TODO: remove this with `useInsightsEap`, only needed to seperately control eap on overview page
3234

3335
if (!domainViews.includes(view || '')) {
3436
return {isInDomainView: false};
@@ -38,7 +40,9 @@ export const useDomainViewFilters = () => {
3840
return {
3941
view,
4042
isInDomainView,
43+
isInOverviewPage,
4144
};
4245
}
46+
4347
return {isInDomainView};
4448
};

static/app/views/insights/settings.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,3 @@ export const MODULES_CONSIDERED_NEW: Set<ModuleName> = new Set([
254254
]);
255255

256256
export const INGESTION_DELAY = 90;
257-
258-
export const EAP_LOCAL_STORAGE_KEY = 'insights-modules-use-eap';

0 commit comments

Comments
 (0)