Skip to content

Commit c2cf739

Browse files
michellewzhangandrewshie-sentry
authored andcommitted
ref(tsc): convert installWizard to FC (#83269)
relates to getsentry/frontend-tsc#2
1 parent bb9f42d commit c2cf739

File tree

2 files changed

+58
-69
lines changed

2 files changed

+58
-69
lines changed

static/app/views/admin/installWizard/index.spec.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('InstallWizard', function () {
2020
render(<InstallWizard onConfigured={jest.fn()} />);
2121
});
2222

23-
it('has no option selected when beacon.anonymous is unset', function () {
23+
it('has no option selected when beacon.anonymous is unset', async function () {
2424
MockApiClient.addMockResponse({
2525
url: '/internal/options/?query=is:required',
2626
body: InstallWizardFixture({
@@ -38,6 +38,7 @@ describe('InstallWizard', function () {
3838
}),
3939
});
4040
render(<InstallWizard onConfigured={jest.fn()} />);
41+
expect(await screen.findByTestId('loading-indicator')).not.toBeInTheDocument();
4142
expect(
4243
screen.getByRole('radio', {
4344
name: 'Please keep my usage information anonymous',
@@ -50,7 +51,7 @@ describe('InstallWizard', function () {
5051
).not.toBeChecked();
5152
});
5253

53-
it('has no option selected even when beacon.anonymous is set', function () {
54+
it('has no option selected even when beacon.anonymous is set', async function () {
5455
MockApiClient.addMockResponse({
5556
url: '/internal/options/?query=is:required',
5657
body: InstallWizardFixture({
@@ -68,6 +69,7 @@ describe('InstallWizard', function () {
6869
}),
6970
});
7071
render(<InstallWizard onConfigured={jest.fn()} />);
72+
expect(await screen.findByTestId('loading-indicator')).not.toBeInTheDocument();
7173
expect(
7274
screen.getByRole('radio', {
7375
name: 'Please keep my usage information anonymous',

static/app/views/admin/installWizard/index.tsx

Lines changed: 54 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import styled from '@emotion/styled';
44
import sentryPattern from 'sentry-images/pattern/sentry-pattern.png';
55

66
import {Alert} from 'sentry/components/alert';
7-
import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
8-
import ApiForm from 'sentry/components/forms/apiForm';
7+
import Form from 'sentry/components/forms/form';
8+
import LoadingIndicator from 'sentry/components/loadingIndicator';
99
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
1010
import {t} from 'sentry/locale';
1111
import ConfigStore from 'sentry/stores/configStore';
1212
import {space} from 'sentry/styles/space';
13+
import {useApiQuery} from 'sentry/utils/queryClient';
1314

1415
import type {Field} from '../options';
1516
import {getForm, getOptionDefault, getOptionField} from '../options';
1617

17-
export type InstallWizardProps = DeprecatedAsyncComponent['props'] & {
18+
export type InstallWizardProps = {
1819
onConfigured: () => void;
1920
};
2021

@@ -26,21 +27,30 @@ export type InstallWizardOptions = Record<
2627
}
2728
>;
2829

29-
type State = DeprecatedAsyncComponent['state'] & {
30-
data: null | InstallWizardOptions;
31-
};
32-
33-
export default class InstallWizard extends DeprecatedAsyncComponent<
34-
InstallWizardProps,
35-
State
36-
> {
37-
getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
38-
return [['data', '/internal/options/?query=is:required']];
30+
export default function InstallWizard({onConfigured}: InstallWizardProps) {
31+
const {
32+
data: options,
33+
isPending,
34+
isError,
35+
} = useApiQuery<InstallWizardOptions>(['/internal/options/?query=is:required'], {
36+
staleTime: 0,
37+
});
38+
39+
if (isPending) {
40+
return <LoadingIndicator />;
3941
}
4042

41-
renderFormFields() {
42-
const options = this.state.data!;
43+
if (isError) {
44+
return (
45+
<Alert type="error" showIcon>
46+
{t(
47+
'We were unable to load the required configuration from the Sentry server. Please take a look at the service logs.'
48+
)}
49+
</Alert>
50+
);
51+
}
4352

53+
const renderFormFields = () => {
4454
let missingOptions = new Set(
4555
Object.keys(options).filter(option => !options[option]!.field.isSet)
4656
);
@@ -65,10 +75,9 @@ export default class InstallWizard extends DeprecatedAsyncComponent<
6575
}
6676

6777
return getForm(fields);
68-
}
78+
};
6979

70-
getInitialData() {
71-
const options = this.state.data!;
80+
const getInitialData = () => {
7281
const data = {};
7382
Object.keys(options).forEach(optionName => {
7483
const option = options[optionName]!;
@@ -93,55 +102,33 @@ export default class InstallWizard extends DeprecatedAsyncComponent<
93102
}
94103
});
95104
return data;
96-
}
97-
98-
render() {
99-
const version = ConfigStore.get('version');
100-
return (
101-
<SentryDocumentTitle noSuffix title={t('Setup Sentry')}>
102-
<Wrapper>
103-
<Pattern />
104-
<SetupWizard>
105-
<Heading>
106-
<span>{t('Welcome to Sentry')}</span>
107-
<Version>{version.current}</Version>
108-
</Heading>
109-
{this.state.loading
110-
? this.renderLoading()
111-
: this.state.error
112-
? this.renderError()
113-
: this.renderBody()}
114-
</SetupWizard>
115-
</Wrapper>
116-
</SentryDocumentTitle>
117-
);
118-
}
119-
120-
renderError() {
121-
return (
122-
<Alert type="error" showIcon>
123-
{t(
124-
'We were unable to load the required configuration from the Sentry server. Please take a look at the service logs.'
125-
)}
126-
</Alert>
127-
);
128-
}
129-
130-
renderBody() {
131-
return (
132-
<ApiForm
133-
apiMethod="PUT"
134-
apiEndpoint={this.getEndpoints()[0]![1]!}
135-
submitLabel={t('Continue')}
136-
initialData={this.getInitialData()}
137-
onSubmitSuccess={this.props.onConfigured}
138-
>
139-
<p>{t('Complete setup by filling out the required configuration.')}</p>
140-
141-
{this.renderFormFields()}
142-
</ApiForm>
143-
);
144-
}
105+
};
106+
107+
const version = ConfigStore.get('version');
108+
return (
109+
<SentryDocumentTitle noSuffix title={t('Setup Sentry')}>
110+
<Wrapper>
111+
<Pattern />
112+
<SetupWizard>
113+
<Heading>
114+
<span>{t('Welcome to Sentry')}</span>
115+
<Version>{version.current}</Version>
116+
</Heading>
117+
<Form
118+
apiMethod="PUT"
119+
apiEndpoint={'/internal/options/?query=is:required'}
120+
submitLabel={t('Continue')}
121+
initialData={getInitialData()}
122+
onSubmitSuccess={onConfigured}
123+
>
124+
<p>{t('Complete setup by filling out the required configuration.')}</p>
125+
126+
{renderFormFields()}
127+
</Form>
128+
</SetupWizard>
129+
</Wrapper>
130+
</SentryDocumentTitle>
131+
);
145132
}
146133

147134
const Wrapper = styled('div')`

0 commit comments

Comments
 (0)