Skip to content

Commit 4de35c4

Browse files
committed
context
1 parent 43fa117 commit 4de35c4

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

packages/schema-sdk/templates/context.ts renamed to __fixtures__/output/context.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
'use client'
21

32
import React, { createContext, useContext, useMemo, useState } from 'react'
4-
import { KubernetesClient } from 'kubernetesjs'
3+
import { KubernetesClient } from './swagger-client'
54
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
65

76
// Configuration types
87
export interface KubernetesConfig {
98
restEndpoint: string
10-
namespace?: string
119
headers?: Record<string, string>
1210
}
1311

1412
// Context types
1513
interface KubernetesContextValue {
1614
client: KubernetesClient
17-
config: KubernetesConfig
18-
namespace: string
19-
setNamespace: (namespace: string) => void
20-
updateConfig: (config: Partial<KubernetesConfig>) => void
2115
}
2216

2317
// Create context
@@ -47,34 +41,19 @@ export function KubernetesProvider({
4741
initialConfig
4842
}: KubernetesProviderProps) {
4943
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,
5245
headers: initialConfig?.headers || {},
5346
})
5447

55-
const [namespace, setNamespace] = useState(config.namespace || 'default')
56-
5748
// Create client instance
5849
const client = useMemo(() => {
5950
return new KubernetesClient({
6051
restEndpoint: config.restEndpoint,
6152
})
6253
}, [config.restEndpoint])
6354

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-
7255
const contextValue: KubernetesContextValue = {
73-
client,
74-
config,
75-
namespace,
76-
setNamespace,
77-
updateConfig,
56+
client
7857
}
7958

8059
return (
@@ -96,4 +75,4 @@ export function useKubernetes() {
9675
}
9776

9877
// Export query client for use in hooks
99-
export { queryClient }
78+
export { queryClient };

packages/schema-sdk/__tests__/hooks.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defaultSchemaSDKOptions } from '../src/types';
33
import { generateReactQueryHooks } from '../src/openapi';
44
import { writeFileSync } from 'fs';
55
import { OpenAPIOptions } from '../dist';
6+
import { generateContext } from '../src';
67

78
/**
89
* Return a new schema object filtered to only include the given paths.
@@ -42,4 +43,12 @@ describe('generateReactQueryHooks', () => {
4243
hooks
4344
);
4445
});
46+
47+
it('generate context', () => {
48+
const context = generateContext('Kubernetes', './swagger-client');
49+
writeFileSync(
50+
__dirname + '/../../../__fixtures__/output/context.ts',
51+
context
52+
);
53+
});
4554
});

packages/schema-sdk/src/context-template.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
export const generateContext = (Type: string, pathToClient: string) => `
2-
'use client'
3-
42
import React, { createContext, useContext, useMemo, useState } from 'react'
53
import { KubernetesClient } from '${pathToClient}'
64
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
7-
import generate from '@babel/generator'
85
96
// Configuration types
107
export interface ${Type}Config {

0 commit comments

Comments
 (0)