Skip to content

Commit 78b34ca

Browse files
authored
ref(settings): Refactor settings/$project/toolbar/ to not rely on deprecatedRouteProps (#96695)
1 parent b7c5dec commit 78b34ca

File tree

3 files changed

+42
-58
lines changed

3 files changed

+42
-58
lines changed

static/app/routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ function buildRoutes(): RouteObject[] {
686686
path: 'toolbar/',
687687
name: t('Developer Toolbar'),
688688
component: make(() => import('sentry/views/settings/project/projectToolbar')),
689-
deprecatedRouteProps: true,
689+
deprecatedRouteProps: true, // Should be false except for ProjectContext passed via `outletContext`
690690
},
691691
{
692692
path: 'source-maps/',

static/app/views/settings/project/projectToolbar.spec.tsx

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
44
import ProjectToolbarSettings from 'sentry/views/settings/project/projectToolbar';
55

66
describe('ProjectToolbarSettings', function () {
7-
const {routerProps, organization, project} = initializeOrg({
7+
const {organization, project} = initializeOrg({
88
organization: {
99
features: ['sentry-toolbar-ui'],
1010
},
1111
});
12-
const url = `/projects/${organization.slug}/${project.slug}/`;
12+
const initialRouterConfig = {
13+
location: {
14+
pathname: `/settings/projects/${project.slug}/toolbar/`,
15+
},
16+
route: '/settings/projects/:projectId/toolbar/',
17+
};
18+
const getProjectEndpoint = `/projects/${organization.slug}/${project.slug}/`;
1319

1420
beforeEach(function () {
1521
MockApiClient.clearMockResponses();
@@ -18,27 +24,21 @@ describe('ProjectToolbarSettings', function () {
1824
it('displays previously saved setting', function () {
1925
const initialOptionValue = 'sentry.io';
2026
project.options = {'sentry:toolbar_allowed_origins': initialOptionValue};
21-
render(
22-
<ProjectToolbarSettings
23-
{...routerProps}
24-
organization={organization}
25-
project={project}
26-
/>
27-
);
27+
render(<ProjectToolbarSettings project={project} />, {
28+
initialRouterConfig,
29+
organization,
30+
});
2831
expect(screen.getByRole('textbox')).toHaveValue(initialOptionValue);
2932
});
3033

3134
it('can submit new allowed origins', async function () {
32-
render(
33-
<ProjectToolbarSettings
34-
{...routerProps}
35-
organization={organization}
36-
project={project}
37-
/>
38-
);
35+
render(<ProjectToolbarSettings project={project} />, {
36+
initialRouterConfig,
37+
organization,
38+
});
3939

4040
const mockPut = MockApiClient.addMockResponse({
41-
url,
41+
url: getProjectEndpoint,
4242
method: 'PUT',
4343
});
4444

@@ -51,7 +51,7 @@ describe('ProjectToolbarSettings', function () {
5151
await userEvent.tab(); // unfocus ("blur") the input
5252

5353
expect(mockPut).toHaveBeenCalledWith(
54-
url,
54+
getProjectEndpoint,
5555
expect.objectContaining({
5656
method: 'PUT',
5757
data: {
@@ -63,25 +63,19 @@ describe('ProjectToolbarSettings', function () {
6363

6464
it('displays nothing when project options are undefined', function () {
6565
project.options = undefined;
66-
render(
67-
<ProjectToolbarSettings
68-
{...routerProps}
69-
organization={organization}
70-
project={project}
71-
/>
72-
);
66+
render(<ProjectToolbarSettings project={project} />, {
67+
initialRouterConfig,
68+
organization,
69+
});
7370
expect(screen.getByRole('textbox')).toHaveValue('');
7471
});
7572

7673
it('displays nothing when project options are empty', function () {
7774
project.options = {};
78-
render(
79-
<ProjectToolbarSettings
80-
{...routerProps}
81-
organization={organization}
82-
project={project}
83-
/>
84-
);
75+
render(<ProjectToolbarSettings project={project} />, {
76+
initialRouterConfig,
77+
organization,
78+
});
8579
expect(screen.getByRole('textbox')).toHaveValue('');
8680
});
8781
});

static/app/views/settings/project/projectToolbar.tsx

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
import styled from '@emotion/styled';
2-
31
import Access from 'sentry/components/acl/access';
42
import Feature from 'sentry/components/acl/feature';
53
import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
64
import {Alert} from 'sentry/components/core/alert';
75
import {LinkButton} from 'sentry/components/core/button/linkButton';
6+
import {Text} from 'sentry/components/core/text';
87
import Form from 'sentry/components/forms/form';
98
import JsonForm from 'sentry/components/forms/jsonForm';
109
import type {JsonFormObject} from 'sentry/components/forms/types';
1110
import {NoAccess} from 'sentry/components/noAccess';
1211
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
1312
import {t, tct} from 'sentry/locale';
14-
import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
15-
import type {Organization} from 'sentry/types/organization';
1613
import type {Project} from 'sentry/types/project';
1714
import {decodeScalar} from 'sentry/utils/queryString';
18-
import {useLocation} from 'sentry/utils/useLocation';
15+
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
16+
import useOrganization from 'sentry/utils/useOrganization';
17+
import {useParams} from 'sentry/utils/useParams';
1918
import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
2019
import TextBlock from 'sentry/views/settings/components/text/textBlock';
2120
import {ProjectPermissionAlert} from 'sentry/views/settings/project/projectPermissionAlert';
2221

23-
type RouteParams = {
24-
projectId: string;
25-
};
26-
type Props = RouteComponentProps<RouteParams> & {
27-
organization: Organization;
28-
project: Project;
29-
};
22+
interface Props {
23+
project: Project; // Passed in by the parent route
24+
}
3025

31-
export default function ProjectToolbarSettings({
32-
organization,
33-
project,
34-
params: {projectId},
35-
}: Props) {
36-
const location = useLocation();
37-
const domain = decodeScalar(location.query.domain);
26+
export default function ProjectToolbarSettings({project}: Props) {
27+
const organization = useOrganization();
28+
const {projectId} = useParams();
29+
const {domain} = useLocationQuery({
30+
fields: {domain: decodeScalar},
31+
});
3832

3933
const formGroups: JsonFormObject[] = [
4034
{
@@ -51,9 +45,9 @@ export default function ProjectToolbarSettings({
5145
label: t('Allowed Origins'),
5246
help: (
5347
<div>
54-
<Important>
48+
<Text bold size="sm" variant="danger">
5549
{t('Only add trusted domains, that you control, to this list.')}
56-
</Important>
50+
</Text>
5751
<br />
5852
{t('Domains where the dev toolbar is allowed to access your data.')}
5953
<br />
@@ -126,7 +120,3 @@ export default function ProjectToolbarSettings({
126120
</SentryDocumentTitle>
127121
);
128122
}
129-
130-
const Important = styled('strong')`
131-
color: ${p => p.theme.red400};
132-
`;

0 commit comments

Comments
 (0)