File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed
Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 1+ import { useInstanceClient } from '@/config/useInstanceClient' ;
2+ import { authStore } from '@/features/auth/store/authStore' ;
3+ import { getClusterInfoQueryOptions } from '@/features/cluster/queries/getClusterInfoQuery' ;
4+ import { getRestUrlForCluster } from '@/lib/urls/getRestUrlForCluster' ;
5+ import { useQuery } from '@tanstack/react-query' ;
6+ import { useParams } from '@tanstack/react-router' ;
7+
8+ export function useEntityRestURL ( ) : string | null {
9+ const { clusterId, instanceId } : { clusterId ?: string ; instanceId ?: string } = useParams ( { strict : false } ) ;
10+ const instanceClient = useInstanceClient ( ) ;
11+ const { data : cluster } = useQuery (
12+ getClusterInfoQueryOptions ( clusterId ) ,
13+ ) ;
14+
15+ const isFabricConnect = ( ! ! clusterId && authStore . checkForFabricConnect ( clusterId ) )
16+ || ! ! instanceId && authStore . checkForFabricConnect ( instanceId ) ;
17+ if ( isFabricConnect ) {
18+ return getRestUrlForCluster ( cluster ) ;
19+ } else if ( instanceClient . defaults . baseURL ) {
20+ return instanceClient . defaults . baseURL . replace ( / : 9 9 2 5 \/ ? / , '' ) ;
21+ }
22+ return null ;
23+ }
Original file line number Diff line number Diff line change 11import { ErrorComponent } from '@/components/ErrorComponent' ;
22import { Loading } from '@/components/Loading' ;
33import { Button } from '@/components/ui/button' ;
4+ import { useEntityRestURL } from '@/config/useEntityRestURL' ;
45import { useInstanceClientIdParams } from '@/config/useInstanceClient' ;
56import { plugins } from '@/features/instance/apis/plugins' ;
67import { requestSnippets } from '@/features/instance/apis/requestSnippets' ;
@@ -27,11 +28,15 @@ export function APIDocs() {
2728 const { data : registrationInfo , isLoading : isLoadingRegistration } = useQuery (
2829 getRegistrationInfoQueryOptions ( operationsParams ) ,
2930 ) ;
31+ const baseURL = useEntityRestURL ( ) ;
3032 const {
3133 data : spec ,
3234 isLoading : isLoadingDocs ,
3335 error,
3436 } = useQuery ( getOpenAPIQueryOptions ( operationsParams ) ) ;
37+ if ( spec ?. servers ?. length ) {
38+ spec . servers [ 0 ] . url = baseURL ;
39+ }
3540 const http = configurationInfo ?. http ;
3641
3742 let apiInaccessibleWarning : string = '' ;
Original file line number Diff line number Diff line change 1+ import { useEntityRestURL } from '@/config/useEntityRestURL' ;
12import { useInstanceClientIdParams } from '@/config/useInstanceClient' ;
23import {
34 importedApplications ,
@@ -35,6 +36,7 @@ export function EditorViewProvider({ children }: PropsWithChildren) {
3536 const [ openedEntryContents , setOpenedEntryContents ] = useState < string | undefined > ( undefined ) ;
3637 const { setContent : setUpdatedEntryContents } = useEditorFileContent ( openedEntry ?. path ) ;
3738 const instanceParams = useInstanceClientIdParams ( ) ;
39+ const baseURL = useEntityRestURL ( ) ;
3840 const queryClient = useQueryClient ( ) ;
3941 const { open } : { open ?: string } = useSearch ( { strict : false } ) ;
4042
@@ -157,7 +159,6 @@ export function EditorViewProvider({ children }: PropsWithChildren) {
157159 if (
158160 loadedPath === pathToLoad && contents !== undefined
159161 ) {
160- const baseURL = instanceParams . instanceClient . defaults . baseURL ;
161162 if ( loadedOverviewEntry && baseURL && getComponentFileQueryData ) {
162163 contents = parseReadMe ( contents , baseURL , getComponentFileQueryData ) ;
163164 }
Original file line number Diff line number Diff line change 1+ import { Cluster } from '@/integrations/api/api.patch' ;
2+
3+ export function getRestUrlForCluster ( cluster : undefined | Pick < Cluster , 'fqdn' > ) : string | null {
4+ let fqdn = cluster ?. fqdn ;
5+ if ( ! fqdn ) {
6+ return null ;
7+ }
8+ if ( ! fqdn . match ( / ^ h t t p s ? : \/ \/ / i) ) {
9+ fqdn = `https://${ fqdn } ` ;
10+ }
11+ return new URL ( fqdn ) . toString ( ) ;
12+ }
You can’t perform that action at this time.
0 commit comments