1
- 'use client'
2
1
3
2
import React , { createContext , useContext , useMemo , useState } from 'react'
4
- import { KubernetesClient } from 'kubernetesjs '
3
+ import { KubernetesClient } from './swagger-client '
5
4
import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
6
5
7
6
// Configuration types
8
7
export interface KubernetesConfig {
9
8
restEndpoint : string
10
- namespace ?: string
11
9
headers ?: Record < string , string >
12
10
}
13
11
14
12
// Context types
15
13
interface KubernetesContextValue {
16
14
client : KubernetesClient
17
- config : KubernetesConfig
18
- namespace : string
19
- setNamespace : ( namespace : string ) => void
20
- updateConfig : ( config : Partial < KubernetesConfig > ) => void
21
15
}
22
16
23
17
// Create context
@@ -47,34 +41,19 @@ export function KubernetesProvider({
47
41
initialConfig
48
42
} : KubernetesProviderProps ) {
49
43
const [ config , setConfig ] = useState < KubernetesConfig > ( {
50
- restEndpoint : initialConfig ?. restEndpoint || process . env . NEXT_PUBLIC_K8S_API_URL || '/api/k8s' ,
51
- namespace : initialConfig ?. namespace || 'default' ,
44
+ restEndpoint : initialConfig ?. restEndpoint ,
52
45
headers : initialConfig ?. headers || { } ,
53
46
} )
54
47
55
- const [ namespace , setNamespace ] = useState ( config . namespace || 'default' )
56
-
57
48
// Create client instance
58
49
const client = useMemo ( ( ) => {
59
50
return new KubernetesClient ( {
60
51
restEndpoint : config . restEndpoint ,
61
52
} )
62
53
} , [ config . restEndpoint ] )
63
54
64
- // Update config function
65
- const updateConfig = ( newConfig : Partial < KubernetesConfig > ) => {
66
- setConfig ( prev => ( { ...prev , ...newConfig } ) )
67
- if ( newConfig . namespace ) {
68
- setNamespace ( newConfig . namespace )
69
- }
70
- }
71
-
72
55
const contextValue : KubernetesContextValue = {
73
- client,
74
- config,
75
- namespace,
76
- setNamespace,
77
- updateConfig,
56
+ client
78
57
}
79
58
80
59
return (
@@ -96,4 +75,4 @@ export function useKubernetes() {
96
75
}
97
76
98
77
// Export query client for use in hooks
99
- export { queryClient }
78
+ export { queryClient } ;
0 commit comments