Skip to content

Commit ff25588

Browse files
roggenkemperandrewshie-sentry
authored andcommitted
ref(tsc): convert RelocationArtifactDetails to FC (#90798)
getsentry/frontend-tsc#2
1 parent 5338e91 commit ff25588

File tree

1 file changed

+47
-65
lines changed

1 file changed

+47
-65
lines changed
Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,60 @@
1-
import type {Client} from 'sentry/api';
21
import {CodeSnippet} from 'sentry/components/codeSnippet';
3-
import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
2+
import LoadingError from 'sentry/components/loadingError';
3+
import LoadingIndicator from 'sentry/components/loadingIndicator';
44
import {IconFile} from 'sentry/icons/iconFile';
55
import ConfigStore from 'sentry/stores/configStore';
6-
import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
6+
import {useApiQuery} from 'sentry/utils/queryClient';
7+
import {useParams} from 'sentry/utils/useParams';
78

89
import DetailsPage from 'admin/components/detailsPage';
910

10-
type Props = DeprecatedAsyncComponent['props'] &
11-
RouteComponentProps<
12-
{artifactKind: string; fileName: string; regionName: string; relocationUuid: string},
13-
unknown
14-
> & {
15-
api: Client;
16-
};
17-
18-
type State = DeprecatedAsyncComponent['state'] & {
19-
data: any;
11+
type RelocationData = {
12+
contents: string;
2013
};
2114

22-
class RelocationDetails extends DeprecatedAsyncComponent<Props, State> {
23-
getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
24-
const region = ConfigStore.get('regions').find(
25-
(r: any) => r.name === this.props.params.regionName
26-
);
27-
return [
28-
[
29-
'data',
30-
`/relocations/${this.props.params.relocationUuid}/artifacts/${this.props.params.artifactKind}/${this.props.params.fileName}`,
31-
{
32-
host: region ? region.url : '',
33-
},
34-
],
35-
];
36-
}
15+
export default function RelocationArtifactDetails() {
16+
const {artifactKind, fileName, regionName, relocationUuid} = useParams<{
17+
artifactKind: string;
18+
fileName: string;
19+
regionName: string;
20+
relocationUuid: string;
21+
}>();
22+
const region = ConfigStore.get('regions').find((r: any) => r.name === regionName);
23+
24+
const {data, isPending, isError} = useApiQuery<RelocationData>(
25+
[
26+
`/relocations/${relocationUuid}/artifacts/${artifactKind}/${fileName}`,
27+
{
28+
host: region?.url,
29+
},
30+
],
31+
{
32+
staleTime: 0,
33+
}
34+
);
3735

38-
componentDidMount() {
39-
super.componentDidMount();
40-
this.setState({
41-
data: {contents: ''},
42-
});
36+
if (isPending) {
37+
return <LoadingIndicator />;
4338
}
4439

45-
onRequestSuccess = ({stateKey, data}: any) => {
46-
if (stateKey === 'data') {
47-
this.setState({
48-
data,
49-
});
50-
}
51-
};
52-
53-
renderBody() {
54-
return (
55-
<DetailsPage
56-
rootName="Relocation"
57-
name={`${this.props.params.artifactKind}/${this.props.params.fileName}`}
58-
crumbs={[this.props.params.relocationUuid]}
59-
sections={[
60-
{
61-
content: (
62-
<CodeSnippet
63-
dark
64-
filename={this.props.params.fileName}
65-
hideCopyButton
66-
icon={<IconFile />}
67-
>
68-
{this.state.data.contents}
69-
</CodeSnippet>
70-
),
71-
},
72-
]}
73-
/>
74-
);
40+
if (isError) {
41+
return <LoadingError />;
7542
}
76-
}
7743

78-
export default RelocationDetails;
44+
return (
45+
<DetailsPage
46+
rootName="Relocation"
47+
name={`${artifactKind}/${fileName}`}
48+
crumbs={[relocationUuid]}
49+
sections={[
50+
{
51+
content: (
52+
<CodeSnippet dark filename={fileName} hideCopyButton icon={<IconFile />}>
53+
{data?.contents ?? ''}
54+
</CodeSnippet>
55+
),
56+
},
57+
]}
58+
/>
59+
);
60+
}

0 commit comments

Comments
 (0)