Skip to content

Commit 2c46615

Browse files
committed
ref: Let functional components call useProjects() & useOrganization()
1 parent 6ab175f commit 2c46615

File tree

19 files changed

+177
-106
lines changed

19 files changed

+177
-106
lines changed

static/app/views/performance/transactionEvents.spec.tsx

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import {OrganizationFixture} from 'sentry-fixture/organization';
22
import {ProjectFixture} from 'sentry-fixture/project';
33

44
import {initializeOrg} from 'sentry-test/initializeOrg';
5-
import {render, screen} from 'sentry-test/reactTestingLibrary';
5+
import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
66

77
import ProjectsStore from 'sentry/stores/projectsStore';
88
import {WebVital} from 'sentry/utils/fields';
9+
import useOrganization from 'sentry/utils/useOrganization';
10+
import useProjects from 'sentry/utils/useProjects';
911
import TransactionEvents from 'sentry/views/performance/transactionSummary/transactionEvents';
1012

13+
jest.mock('sentry/utils/useOrganization');
14+
jest.mock('sentry/utils/useProjects');
15+
1116
// XXX(epurkhiser): This appears to also be tested by ./transactionSummary/transactionEvents/index.spec.tsx
1217

1318
type Data = {
@@ -159,8 +164,18 @@ describe('Performance > TransactionSummary', function () {
159164
const {organization, router, routerContext} = initializeData();
160165

161166
ProjectsStore.loadInitialData(organization.projects);
167+
jest.mocked(useOrganization).mockReturnValue(organization);
168+
jest.mocked(useProjects).mockReturnValue({
169+
projects: organization.projects,
170+
onSearch: jest.fn(),
171+
placeholders: [],
172+
fetching: false,
173+
hasMore: null,
174+
fetchError: null,
175+
initiallyLoaded: false,
176+
});
162177

163-
render(<TransactionEvents organization={organization} location={router.location} />, {
178+
render(<TransactionEvents location={router.location} />, {
164179
context: routerContext,
165180
});
166181

@@ -193,11 +208,23 @@ describe('Performance > TransactionSummary', function () {
193208
const {organization, router, routerContext} = initializeData();
194209

195210
ProjectsStore.loadInitialData(organization.projects);
211+
jest.mocked(useOrganization).mockReturnValue(organization);
212+
jest.mocked(useProjects).mockReturnValue({
213+
projects: organization.projects,
214+
onSearch: jest.fn(),
215+
placeholders: [],
216+
fetching: false,
217+
hasMore: null,
218+
fetchError: null,
219+
initiallyLoaded: false,
220+
});
196221

197-
render(<TransactionEvents organization={organization} location={router.location} />, {
222+
render(<TransactionEvents location={router.location} />, {
198223
context: routerContext,
199224
});
200225

226+
await waitFor(() => screen.findByText('operation duration'));
227+
201228
expect(await screen.findByText('operation duration')).toBeInTheDocument();
202229
expect(screen.getAllByRole('columnheader')).toHaveLength(6);
203230

@@ -208,11 +235,23 @@ describe('Performance > TransactionSummary', function () {
208235
const {organization, router, routerContext} = initializeData();
209236

210237
ProjectsStore.loadInitialData(organization.projects);
238+
jest.mocked(useOrganization).mockReturnValue(organization);
239+
jest.mocked(useProjects).mockReturnValue({
240+
projects: organization.projects,
241+
onSearch: jest.fn(),
242+
placeholders: [],
243+
fetching: false,
244+
hasMore: null,
245+
fetchError: null,
246+
initiallyLoaded: false,
247+
});
211248

212-
render(<TransactionEvents organization={organization} location={router.location} />, {
249+
render(<TransactionEvents location={router.location} />, {
213250
context: routerContext,
214251
});
215252

253+
await waitFor(() => screen.findAllByRole('columnheader'));
254+
216255
const tableHeader = await screen.findAllByRole('columnheader');
217256
expect(tableHeader).toHaveLength(6);
218257
expect(tableHeader[0]).toHaveTextContent('event id');
@@ -239,8 +278,18 @@ describe('Performance > TransactionSummary', function () {
239278
});
240279

241280
ProjectsStore.loadInitialData(organization.projects);
281+
jest.mocked(useOrganization).mockReturnValue(organization);
282+
jest.mocked(useProjects).mockReturnValue({
283+
projects: organization.projects,
284+
onSearch: jest.fn(),
285+
placeholders: [],
286+
fetching: false,
287+
hasMore: null,
288+
fetchError: null,
289+
initiallyLoaded: false,
290+
});
242291

243-
render(<TransactionEvents organization={organization} location={router.location} />, {
292+
render(<TransactionEvents location={router.location} />, {
244293
context: routerContext,
245294
});
246295

static/app/views/performance/transactionSummary/teamKeyTransactionButton.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {t, tn} from 'sentry/locale';
77
import type {Organization, Project} from 'sentry/types';
88
import {defined} from 'sentry/utils';
99
import type EventView from 'sentry/utils/discover/eventView';
10+
import useProjects from 'sentry/utils/useProjects';
1011
import {useTeams} from 'sentry/utils/useTeams';
11-
import withProjects from 'sentry/utils/withProjects';
1212

1313
type BaseProps = {
1414
organization: Organization;
@@ -77,15 +77,14 @@ function TeamKeyTransactionButton({
7777

7878
type WrapperProps = BaseProps & {
7979
eventView: EventView;
80-
projects: Project[];
8180
};
8281

83-
function TeamKeyTransactionButtonWrapper({
82+
export default function TeamKeyTransactionButtonWrapper({
8483
eventView,
8584
organization,
86-
projects,
8785
...props
8886
}: WrapperProps) {
87+
const {projects} = useProjects();
8988
const {teams, initiallyLoaded} = useTeams({provideUserTeams: true});
9089

9190
if (eventView.project.length !== 1) {
@@ -127,5 +126,3 @@ function TeamKeyTransactionButtonWrapper({
127126
</TeamKeyTransactionManager.Provider>
128127
);
129128
}
130-
131-
export default withProjects(TeamKeyTransactionButtonWrapper);

static/app/views/performance/transactionSummary/transactionAnomalies/index.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type {Location} from 'history';
22

33
import {t} from 'sentry/locale';
4-
import type {Organization, Project} from 'sentry/types';
54
import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
6-
import withOrganization from 'sentry/utils/withOrganization';
7-
import withProjects from 'sentry/utils/withProjects';
5+
import useOrganization from 'sentry/utils/useOrganization';
6+
import useProjects from 'sentry/utils/useProjects';
87

98
import PageLayout from '../pageLayout';
109
import Tab from '../tabs';
@@ -14,12 +13,11 @@ import {generateAnomaliesEventView} from './utils';
1413

1514
type Props = {
1615
location: Location;
17-
organization: Organization;
18-
projects: Project[];
1916
};
2017

21-
function TransactionAnomalies(props: Props) {
22-
const {location, organization, projects} = props;
18+
export default function TransactionAnomalies({location}: Props) {
19+
const organization = useOrganization();
20+
const {projects} = useProjects();
2321

2422
return (
2523
<MEPSettingProvider>
@@ -46,5 +44,3 @@ function getDocumentTitle(transactionName: string): string {
4644

4745
return [t('Summary'), t('Performance')].join(' - ');
4846
}
49-
50-
export default withProjects(withOrganization(TransactionAnomalies));

static/app/views/performance/transactionSummary/transactionEvents/eventsTable.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import {
1111
SPAN_OP_BREAKDOWN_FIELDS,
1212
SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
1313
} from 'sentry/utils/discover/fields';
14+
import useOrganization from 'sentry/utils/useOrganization';
1415
import EventsTable from 'sentry/views/performance/transactionSummary/transactionEvents/eventsTable';
1516

17+
jest.mock('sentry/utils/useOrganization');
18+
1619
type Data = {
1720
features?: string[];
1821
};
@@ -93,6 +96,7 @@ describe('Performance GridEditable Table', function () {
9396
];
9497
let fields = EVENTS_TABLE_RESPONSE_FIELDS;
9598
const organization = OrganizationFixture();
99+
jest.mocked(useOrganization).mockReturnValue(organization);
96100
const transactionName = 'transactionName';
97101
let data;
98102

static/app/views/performance/transactionSummary/transactionEvents/index.spec.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
66

77
import ProjectsStore from 'sentry/stores/projectsStore';
88
import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
9+
import useOrganization from 'sentry/utils/useOrganization';
10+
import useProjects from 'sentry/utils/useProjects';
911
import TransactionEvents from 'sentry/views/performance/transactionSummary/transactionEvents';
1012

1113
import {EVENTS_TABLE_RESPONSE_FIELDS, MOCK_EVENTS_TABLE_DATA} from './eventsTable.spec';
1214

15+
jest.mock('sentry/utils/useOrganization');
16+
jest.mock('sentry/utils/useProjects');
17+
1318
function WrappedComponent({data}) {
1419
return (
1520
<MEPSettingProvider>
16-
<TransactionEvents
17-
organization={data.organization}
18-
location={data.router.location}
19-
/>
21+
<TransactionEvents location={data.router.location} />
2022
</MEPSettingProvider>
2123
);
2224
}
@@ -132,6 +134,16 @@ const initializeData = (settings?: InitializeDataSettings) => {
132134
};
133135
const data = _initializeData(settings);
134136
act(() => void ProjectsStore.loadInitialData(data.organization.projects));
137+
jest.mocked(useOrganization).mockReturnValue(data.organization);
138+
jest.mocked(useProjects).mockReturnValue({
139+
projects: data.organization.projects,
140+
onSearch: jest.fn(),
141+
placeholders: [],
142+
fetching: false,
143+
hasMore: null,
144+
fetchError: null,
145+
initiallyLoaded: false,
146+
});
135147
return data;
136148
};
137149

@@ -164,10 +176,10 @@ describe('Performance > Transaction Summary > Transaction Events > Index', () =>
164176
const data = initializeData();
165177

166178
render(<WrappedComponent data={data} />, {context: data.routerContext});
179+
167180
const percentileButton = await screen.findByRole('button', {
168181
name: /percentile p100/i,
169182
});
170-
171183
await userEvent.click(percentileButton);
172184

173185
const p50 = screen.getByRole('option', {name: 'p50'});

static/app/views/performance/transactionSummary/transactionEvents/index.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {Location} from 'history';
44
import * as Layout from 'sentry/components/layouts/thirds';
55
import LoadingIndicator from 'sentry/components/loadingIndicator';
66
import {t} from 'sentry/locale';
7-
import type {Organization, Project} from 'sentry/types';
7+
import type {Organization} from 'sentry/types';
88
import {trackAnalytics} from 'sentry/utils/analytics';
99
import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
1010
import EventView from 'sentry/utils/discover/eventView';
@@ -17,8 +17,8 @@ import {WebVital} from 'sentry/utils/fields';
1717
import {removeHistogramQueryStrings} from 'sentry/utils/performance/histogram';
1818
import {decodeScalar} from 'sentry/utils/queryString';
1919
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
20-
import withOrganization from 'sentry/utils/withOrganization';
21-
import withProjects from 'sentry/utils/withProjects';
20+
import useOrganization from 'sentry/utils/useOrganization';
21+
import useProjects from 'sentry/utils/useProjects';
2222

2323
import {
2424
decodeFilterFromLocation,
@@ -44,12 +44,11 @@ type PercentileValues = Record<EventsDisplayFilterName, number>;
4444

4545
type Props = {
4646
location: Location;
47-
organization: Organization;
48-
projects: Project[];
4947
};
5048

51-
function TransactionEvents(props: Props) {
52-
const {location, organization, projects} = props;
49+
export default function TransactionEvents({location}: Props) {
50+
const organization = useOrganization();
51+
const {projects} = useProjects();
5352

5453
return (
5554
<PageLayout
@@ -268,5 +267,3 @@ function generateEventView({
268267
location
269268
);
270269
}
271-
272-
export default withProjects(withOrganization(TransactionEvents));

static/app/views/performance/transactionSummary/transactionOverview/content.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {MAX_QUERY_LENGTH} from 'sentry/constants';
1919
import {IconWarning} from 'sentry/icons';
2020
import {t} from 'sentry/locale';
2121
import {space} from 'sentry/styles/space';
22-
import type {Organization, Project} from 'sentry/types';
22+
import type {Organization} from 'sentry/types';
2323
import {defined, generateQueryWithTag} from 'sentry/utils';
2424
import {trackAnalytics} from 'sentry/utils/analytics';
2525
import type EventView from 'sentry/utils/discover/eventView';
@@ -34,8 +34,8 @@ import type {MetricsEnhancedPerformanceDataContext} from 'sentry/utils/performan
3434
import {useMEPDataContext} from 'sentry/utils/performance/contexts/metricsEnhancedPerformanceDataContext';
3535
import {decodeScalar} from 'sentry/utils/queryString';
3636
import projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
37+
import useProjects from 'sentry/utils/useProjects';
3738
import {useRoutes} from 'sentry/utils/useRoutes';
38-
import withProjects from 'sentry/utils/withProjects';
3939
import type {Actions} from 'sentry/views/discover/table/cellAction';
4040
import {updateQuery} from 'sentry/views/discover/table/cellAction';
4141
import type {TableColumn} from 'sentry/views/discover/table/types';
@@ -81,20 +81,18 @@ type Props = {
8181
onChangeFilter: (newFilter: SpanOperationBreakdownFilter) => void;
8282
organization: Organization;
8383
projectId: string;
84-
projects: Project[];
8584
spanOperationBreakdownFilter: SpanOperationBreakdownFilter;
8685
totalValues: Record<string, number> | null;
8786
transactionName: string;
8887
unfilteredTotalValues?: Record<string, number> | null;
8988
};
9089

91-
function SummaryContent({
90+
export default function SummaryContent({
9291
eventView,
9392
location,
9493
totalValues,
9594
spanOperationBreakdownFilter,
9695
organization,
97-
projects,
9896
isLoading,
9997
error,
10098
projectId,
@@ -104,6 +102,7 @@ function SummaryContent({
104102
}: Props) {
105103
const routes = useRoutes();
106104
const mepDataContext = useMEPDataContext();
105+
const {projects} = useProjects();
107106

108107
function handleSearch(query: string) {
109108
const queryParams = normalizeDateTimeParams({
@@ -600,5 +599,3 @@ const StyledSearchBar = styled(SearchBar)`
600599
const StyledIconWarning = styled(IconWarning)`
601600
display: block;
602601
`;
603-
604-
export default withProjects(SummaryContent);

0 commit comments

Comments
 (0)