From 93a778e423a9024fda64dd2d1264aab1769691b8 Mon Sep 17 00:00:00 2001 From: Richard Roggenkemper Date: Thu, 1 May 2025 15:29:07 -0700 Subject: [PATCH 1/2] update --- .../views/relocationArtifactDetails.tsx | 108 ++++++++---------- 1 file changed, 45 insertions(+), 63 deletions(-) diff --git a/static/gsAdmin/views/relocationArtifactDetails.tsx b/static/gsAdmin/views/relocationArtifactDetails.tsx index 4ddeebb837d3e2..04305b51d02db0 100644 --- a/static/gsAdmin/views/relocationArtifactDetails.tsx +++ b/static/gsAdmin/views/relocationArtifactDetails.tsx @@ -1,78 +1,60 @@ -import type {Client} from 'sentry/api'; import {CodeSnippet} from 'sentry/components/codeSnippet'; -import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent'; +import LoadingError from 'sentry/components/loadingError'; +import LoadingIndicator from 'sentry/components/loadingIndicator'; import {IconFile} from 'sentry/icons/iconFile'; import ConfigStore from 'sentry/stores/configStore'; import type {RouteComponentProps} from 'sentry/types/legacyReactRouter'; +import {useApiQuery} from 'sentry/utils/queryClient'; import DetailsPage from 'admin/components/detailsPage'; -type Props = DeprecatedAsyncComponent['props'] & - RouteComponentProps< - {artifactKind: string; fileName: string; regionName: string; relocationUuid: string}, - unknown - > & { - api: Client; - }; +type Props = RouteComponentProps< + {artifactKind: string; fileName: string; regionName: string; relocationUuid: string}, + unknown +>; -type State = DeprecatedAsyncComponent['state'] & { - data: any; +type RelocationData = { + contents: string; }; -class RelocationDetails extends DeprecatedAsyncComponent { - getEndpoints(): ReturnType { - const region = ConfigStore.get('regions').find( - (r: any) => r.name === this.props.params.regionName - ); - return [ - [ - 'data', - `/relocations/${this.props.params.relocationUuid}/artifacts/${this.props.params.artifactKind}/${this.props.params.fileName}`, - { - host: region ? region.url : '', - }, - ], - ]; - } +export default function RelocationArtifactDetails({params}: Props) { + const {artifactKind, fileName, regionName, relocationUuid} = params; + const region = ConfigStore.get('regions').find((r: any) => r.name === regionName); + + const {data, isPending, isError} = useApiQuery( + [ + `/relocations/${relocationUuid}/artifacts/${artifactKind}/${fileName}`, + { + host: region?.url, + }, + ], + { + staleTime: 0, + } + ); - componentDidMount() { - super.componentDidMount(); - this.setState({ - data: {contents: ''}, - }); + if (isPending) { + return ; } - onRequestSuccess = ({stateKey, data}: any) => { - if (stateKey === 'data') { - this.setState({ - data, - }); - } - }; - - renderBody() { - return ( - } - > - {this.state.data.contents} - - ), - }, - ]} - /> - ); + if (isError) { + return ; } -} -export default RelocationDetails; + return ( + }> + {data?.contents ?? ''} + + ), + }, + ]} + /> + ); +} From 0c4e34a67abf193f66e3eb719055632e28dec780 Mon Sep 17 00:00:00 2001 From: Richard Roggenkemper Date: Thu, 1 May 2025 15:57:01 -0700 Subject: [PATCH 2/2] use use params --- .../gsAdmin/views/relocationArtifactDetails.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/static/gsAdmin/views/relocationArtifactDetails.tsx b/static/gsAdmin/views/relocationArtifactDetails.tsx index 04305b51d02db0..22dabfabfe146e 100644 --- a/static/gsAdmin/views/relocationArtifactDetails.tsx +++ b/static/gsAdmin/views/relocationArtifactDetails.tsx @@ -3,22 +3,22 @@ import LoadingError from 'sentry/components/loadingError'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import {IconFile} from 'sentry/icons/iconFile'; import ConfigStore from 'sentry/stores/configStore'; -import type {RouteComponentProps} from 'sentry/types/legacyReactRouter'; import {useApiQuery} from 'sentry/utils/queryClient'; +import {useParams} from 'sentry/utils/useParams'; import DetailsPage from 'admin/components/detailsPage'; -type Props = RouteComponentProps< - {artifactKind: string; fileName: string; regionName: string; relocationUuid: string}, - unknown ->; - type RelocationData = { contents: string; }; -export default function RelocationArtifactDetails({params}: Props) { - const {artifactKind, fileName, regionName, relocationUuid} = params; +export default function RelocationArtifactDetails() { + const {artifactKind, fileName, regionName, relocationUuid} = useParams<{ + artifactKind: string; + fileName: string; + regionName: string; + relocationUuid: string; + }>(); const region = ConfigStore.get('regions').find((r: any) => r.name === regionName); const {data, isPending, isError} = useApiQuery(