Skip to content

Commit 39c1a09

Browse files
committed
DocumentationUrl ONLY implementation
1 parent d4fd7cb commit 39c1a09

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

src/context/FrontendConfigContext.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ReactNode, createContext, use } from 'react';
2-
import { DocLinkCreator } from '../lib/shared/links';
32
import { z } from 'zod';
43

54
export enum Landscape {
@@ -10,16 +9,11 @@ export enum Landscape {
109
Local = 'LOCAL',
1110
}
1211

12+
export const FrontendConfigContext = createContext<FrontendConfig | null>(null);
1313

14-
15-
interface FrontendConfigContextType extends FrontendConfig {
16-
links: DocLinkCreator;
17-
}
18-
19-
export const FrontendConfigContext =
20-
createContext<FrontendConfigContextType | null>(null);
21-
22-
const fetchPromise = fetch('/frontend-config.json').then((res) => res.json()).then((data) => validateAndCastFrontendConfig(data));
14+
const fetchPromise = fetch('/frontend-config.json')
15+
.then((res) => res.json())
16+
.then((data) => validateAndCastFrontendConfig(data));
2317

2418
interface FrontendConfigProviderProps {
2519
children: ReactNode;
@@ -29,13 +23,11 @@ export function FrontendConfigProvider({
2923
children,
3024
}: FrontendConfigProviderProps) {
3125
const config = use(fetchPromise);
32-
const docLinks = new DocLinkCreator(config.documentationBaseUrl);
33-
const value: FrontendConfigContextType = {
34-
links: docLinks,
35-
...config,
36-
};
26+
3727
return (
38-
<FrontendConfigContext value={value}>{children}</FrontendConfigContext>
28+
<FrontendConfigContext.Provider value={config}>
29+
{children}
30+
</FrontendConfigContext.Provider>
3931
);
4032
}
4133

@@ -72,4 +64,4 @@ function validateAndCastFrontendConfig(config: unknown): FrontendConfig {
7264
} catch (error) {
7365
throw new Error(`Invalid frontend config: ${error}`);
7466
}
75-
}
67+
}

src/lib/shared/links.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
export class DocLinkCreator {
2-
private baseUrl: string;
1+
import { useFrontendConfig } from '../../context/FrontendConfigContext';
32

4-
constructor(baseUrl: string) {
5-
this.baseUrl = baseUrl;
6-
}
7-
private createLink(path: string) {
8-
return `${this.baseUrl}${path}`;
9-
}
3+
export function useLink() {
4+
const { documentationBaseUrl } = useFrontendConfig();
105

11-
public get COMMUNITY_PAGE(): string {
12-
return this.createLink('/');
6+
if (!documentationBaseUrl) {
7+
throw new Error('useLink must be used within a FrontendConfigProvider');
138
}
14-
public get COM_PAGE_GETTING_STARTED(): string {
15-
return this.createLink(
9+
10+
const createLink = (path: string) => `${documentationBaseUrl}${path}`;
11+
12+
return {
13+
documentationHomepage: createLink('/'),
14+
gettingStartedGuide: createLink(
1615
'/docs/managed-control-planes/get-started/get-started-mcp',
17-
);
18-
}
19-
public get COM_PAGE_GETTING_STARTED_WORKSPACE(): string {
20-
return this.createLink(
16+
),
17+
workspaceCreationGuide: createLink(
2118
'/docs/managed-control-planes/get-started/get-started-mcp#4-create-workspace',
22-
);
23-
}
24-
public get COM_PAGE_GETTING_STARTED_MCP(): string {
25-
return this.createLink(
19+
),
20+
mcpCreationGuide: createLink(
2621
'/docs/managed-control-planes/get-started/get-started-mcp#5-create-managedcontrolplane',
27-
);
28-
}
22+
),
23+
};
2924
}

0 commit comments

Comments
 (0)