|
1 | | -import type {Client} from 'sentry/api'; |
2 | 1 | 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'; |
4 | 4 | import {IconFile} from 'sentry/icons/iconFile'; |
5 | 5 | 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'; |
7 | 8 |
|
8 | 9 | import DetailsPage from 'admin/components/detailsPage'; |
9 | 10 |
|
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; |
20 | 13 | }; |
21 | 14 |
|
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 | + ); |
37 | 35 |
|
38 | | - componentDidMount() { |
39 | | - super.componentDidMount(); |
40 | | - this.setState({ |
41 | | - data: {contents: ''}, |
42 | | - }); |
| 36 | + if (isPending) { |
| 37 | + return <LoadingIndicator />; |
43 | 38 | } |
44 | 39 |
|
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 />; |
75 | 42 | } |
76 | | -} |
77 | 43 |
|
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