Skip to content

Commit 0c9e96c

Browse files
committed
refactor
1 parent f9e6fd6 commit 0c9e96c

File tree

11 files changed

+61
-41
lines changed

11 files changed

+61
-41
lines changed

public/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@
405405
"syncError": "Sync error",
406406
"error": "Error",
407407
"notHealthy": "Not healthy",
408-
"notReady": "Not ready"
408+
"notReady": "Not ready",
409+
"cannotLoadSchema": "Cannot load schema for this resource"
409410
},
410411
"buttons": {
411412
"viewResource": "View resource",

src/components/ControlPlane/GitRepositories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export function GitRepositories() {
6060
isEdit={true}
6161
resource={item as unknown as Resource}
6262
filename={`${item.kind}_${item.metadata.name}`}
63-
apiConfig={apiConfig}
6463
onApply={async (parsed) => await handlePatch(item, parsed)}
6564
/>
6665
</Fragment>,

src/components/ControlPlane/Kustomizations.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function Kustomizations() {
3838
const { data, error, isLoading } = useApiResource(FluxKustomization); //404 if component not enabled
3939
const apiConfig = useContext(ApiConfigContext);
4040
const { t } = useTranslation();
41-
const { openInAside } = useSplitter();
41+
const { openInAsideWithApiConfig } = useSplitter();
4242
const errorDialogRef = useRef<ErrorDialogHandle>(null);
4343
const handlePatch = useHandleResourcePatch(errorDialogRef);
4444

@@ -54,19 +54,19 @@ export function Kustomizations() {
5454
const openEditPanel = useCallback(
5555
(item: KustomizationItem) => {
5656
const identityKey = `${item.kind}:${item.metadata.namespace ?? ''}:${item.metadata.name}`;
57-
openInAside(
57+
openInAsideWithApiConfig(
5858
<Fragment key={identityKey}>
5959
<YamlSidePanel
6060
isEdit={true}
6161
resource={item as unknown as Resource}
6262
filename={`${item.kind}_${item.metadata.name}`}
63-
apiConfig={apiConfig}
6463
onApply={async (parsed) => await handlePatch(item, parsed)}
6564
/>
6665
</Fragment>,
66+
apiConfig,
6767
);
6868
},
69-
[openInAside, handlePatch, apiConfig],
69+
[openInAsideWithApiConfig, handlePatch, apiConfig],
7070
);
7171
const hasMCPAdminRights = useHasMcpAdminRights();
7272

src/components/ControlPlane/ManagedResources.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function ManagedResources({
9090
const { t } = useTranslation();
9191
const toast = useToast();
9292
const apiConfig = useContext(ApiConfigContext);
93-
const { openInAside } = useSplitter();
93+
const { openInAsideWithApiConfig } = useSplitter();
9494
const [pendingDeleteItem, setPendingDeleteItem] = useState<ManagedResourceItem | null>(null);
9595
const errorDialogRef = useRef<ErrorDialogHandle>(null);
9696
const handlePatch = useHandleResourcePatch(errorDialogRef);
@@ -125,19 +125,19 @@ export function ManagedResources({
125125
const openEditPanel = useCallback(
126126
(item: ManagedResourceItem) => {
127127
const identityKey = `${item.kind}:${item.metadata.namespace ?? ''}:${item.metadata.name}`;
128-
openInAside(
128+
openInAsideWithApiConfig(
129129
<Fragment key={identityKey}>
130130
<YamlSidePanel
131131
isEdit={true}
132132
resource={item as unknown as Resource}
133133
filename={`${item.kind}_${item.metadata.name}`}
134-
apiConfig={apiConfig}
135134
onApply={async (parsed) => await handlePatch(item, parsed)}
136135
/>
137136
</Fragment>,
137+
apiConfig,
138138
);
139139
},
140-
[openInAside, handlePatch, apiConfig],
140+
[openInAsideWithApiConfig, handlePatch, apiConfig],
141141
);
142142
const hasMCPAdminRights = useHasMcpAdminRights();
143143
const columns = useMemo<AnalyticalTableColumnDefinition[]>(

src/components/ControlPlane/ProvidersConfig.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Rows = {
3838

3939
export function ProvidersConfig() {
4040
const { t } = useTranslation();
41-
const { openInAside } = useSplitter();
41+
const { openInAsideWithApiConfig } = useSplitter();
4242
const errorDialogRef = useRef<ErrorDialogHandle>(null);
4343
const handlePatch = useHandleResourcePatch(errorDialogRef);
4444
const apiConfig = useContext(ApiConfigContext);
@@ -65,19 +65,19 @@ export function ProvidersConfig() {
6565
const openEditPanel = useCallback(
6666
(item: ProviderConfigItem) => {
6767
const identityKey = `${item.kind}:${item.metadata.name}`;
68-
openInAside(
68+
openInAsideWithApiConfig(
6969
<Fragment key={identityKey}>
7070
<YamlSidePanel
7171
isEdit={true}
7272
resource={item as unknown as Resource}
7373
filename={`${item.kind}_${item.metadata.name}`}
74-
apiConfig={apiConfig}
7574
onApply={async (parsed) => await handlePatch(item, parsed)}
7675
/>
7776
</Fragment>,
77+
apiConfig,
7878
);
7979
},
80-
[openInAside, handlePatch, apiConfig],
80+
[openInAsideWithApiConfig, handlePatch, apiConfig],
8181
);
8282
const hasMCPAdminRights = useHasMcpAdminRights();
8383
const columns = useMemo<AnalyticalTableColumnDefinition[]>(

src/components/Graphs/Graph.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const nodeTypes = {
3131

3232
const Graph: React.FC = () => {
3333
const { t } = useTranslation();
34-
const { openInAside } = useSplitter();
34+
const { openInAsideWithApiConfig } = useSplitter();
3535
const { isDarkTheme } = useTheme();
3636
const [colorBy, setColorBy] = useState<ColorBy>('source');
3737
const apiConfig = useContext(ApiConfigContext);
@@ -41,11 +41,12 @@ const Graph: React.FC = () => {
4141
? `${item.kind ?? ''}${item.metadata?.name ? '_' : ''}${item.metadata?.name ?? ''}`
4242
: '';
4343

44-
openInAside(
45-
<YamlSidePanel apiConfig={apiConfig} resource={item as unknown as Resource} filename={yamlFilename} />,
44+
openInAsideWithApiConfig(
45+
<YamlSidePanel resource={item as unknown as Resource} filename={yamlFilename} />,
46+
apiConfig,
4647
);
4748
},
48-
[openInAside, apiConfig],
49+
[openInAsideWithApiConfig, apiConfig],
4950
);
5051

5152
const { nodes, edges, colorMap, loading, error } = useGraph(colorBy, handleYamlClick);

src/components/Splitter/SplitterContext.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { createContext, ReactNode, use, useCallback, useMemo, useState } from 'react';
2+
import { ApiConfigProvider } from '../Shared/k8s';
3+
import { ApiConfig } from '../../lib/api/types/apiConfig.ts';
24

35
interface SplitterContextType {
46
isAsideVisible: boolean;
57
asideContent: ReactNode;
68
closeAside: () => void;
79
openInAside: (content: ReactNode) => void;
10+
openInAsideWithApiConfig: (content: ReactNode, apiConfig: ApiConfig) => void;
811
}
912

1013
const SplitterContext = createContext<SplitterContextType | null>(null);
@@ -18,14 +21,37 @@ export function SplitterProvider({ children }: { children: ReactNode }) {
1821
setIsAsideVisible(true);
1922
}, []);
2023

24+
const openInAsideWithApiConfig = useCallback((node: ReactNode, apiConfig: ApiConfig) => {
25+
const projectName = apiConfig.mcpConfig?.projectName ?? '';
26+
const workspaceName = apiConfig.mcpConfig?.workspaceName ?? '';
27+
const controlPlaneName = apiConfig.mcpConfig?.controlPlaneName ?? '';
28+
setAsideContent(
29+
<ApiConfigProvider
30+
apiConfig={{
31+
mcpConfig:
32+
projectName && workspaceName && controlPlaneName
33+
? {
34+
projectName: apiConfig.mcpConfig?.projectName ?? '',
35+
workspaceName: apiConfig.mcpConfig?.workspaceName ?? '',
36+
controlPlaneName: apiConfig.mcpConfig?.controlPlaneName ?? '',
37+
}
38+
: undefined,
39+
}}
40+
>
41+
{node}
42+
</ApiConfigProvider>,
43+
);
44+
setIsAsideVisible(true);
45+
}, []);
46+
2147
const closeAside = useCallback(() => {
2248
setIsAsideVisible(false);
2349
setAsideContent(null);
2450
}, []);
2551

2652
const value = useMemo(() => {
27-
return { isAsideVisible, asideContent, closeAside, openInAside };
28-
}, [isAsideVisible, asideContent, closeAside, openInAside]);
53+
return { isAsideVisible, asideContent, closeAside, openInAside, openInAsideWithApiConfig };
54+
}, [isAsideVisible, asideContent, closeAside, openInAside, openInAsideWithApiConfig]);
2955

3056
return <SplitterContext value={value}>{children}</SplitterContext>;
3157
}

src/components/Yaml/YamlSidePanel.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { useCopyToClipboard } from '../../hooks/useCopyToClipboard.ts';
2121
import styles from './YamlSidePanel.module.css';
2222
import { IllustratedBanner } from '../Ui/IllustratedBanner/IllustratedBanner.tsx';
2323
import { YamlDiff } from '../Wizards/CreateManagedControlPlane/YamlDiff.tsx';
24-
import { ApiConfig } from '../../lib/api/types/apiConfig.ts';
2524

2625
export const SHOW_DOWNLOAD_BUTTON = false; // Download button is hidden now due to stakeholder request
2726

@@ -31,10 +30,9 @@ export interface YamlSidePanelProps {
3130
onApply?: (parsed: unknown, yaml: string) => void | boolean | Promise<void | boolean>;
3231
isEdit?: boolean;
3332
toolbarContent?: JSX.Element;
34-
apiConfig?: ApiConfig;
3533
}
3634

37-
export function YamlSidePanel({ resource, filename, onApply, isEdit, toolbarContent, apiConfig }: YamlSidePanelProps) {
35+
export function YamlSidePanel({ resource, filename, onApply, isEdit, toolbarContent }: YamlSidePanelProps) {
3836
const [showOnlyImportantData, setShowOnlyImportantData] = useState(true);
3937
const [mode, setMode] = useState<'edit' | 'review' | 'success'>('edit');
4038
const [editedYaml, setEditedYaml] = useState<string | null>(null);
@@ -170,7 +168,6 @@ export function YamlSidePanel({ resource, filename, onApply, isEdit, toolbarCont
170168
isEdit={isEdit}
171169
apiGroupName={apiGroupName}
172170
apiVersion={apiVersion}
173-
apiConfig={apiConfig}
174171
kind={kind}
175172
onApply={handleApplyFromEditor}
176173
/>

src/components/Yaml/YamlSidePanelWithLoader.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,17 @@ import IllustratedError from '../Shared/IllustratedError.tsx';
77
import { Resource } from '../../utils/removeManagedFieldsAndFilterData.ts';
88
import { YamlSidePanel } from './YamlSidePanel.tsx';
99

10-
import { ApiConfig } from '../../lib/api/types/apiConfig.ts';
11-
1210
export interface YamlSidePanelWithLoaderProps {
1311
workspaceName?: string;
1412
resourceType: 'projects' | 'workspaces' | 'managedcontrolplanes';
1513
resourceName: string;
1614
isEdit?: boolean;
17-
18-
apiConfig?: ApiConfig;
1915
}
2016
export function YamlSidePanelWithLoader({
2117
workspaceName,
2218
resourceType,
2319
resourceName,
2420
isEdit = false,
25-
apiConfig,
2621
}: YamlSidePanelWithLoaderProps) {
2722
const { t } = useTranslation();
2823
const { isLoading, data, error } = useApiResource(
@@ -36,5 +31,5 @@ export function YamlSidePanelWithLoader({
3631

3732
const filename = `${workspaceName ? `${workspaceName}_` : ''}${resourceType}_${resourceName}`;
3833

39-
return <YamlSidePanel resource={data as Resource} filename={filename} isEdit={isEdit} apiConfig={apiConfig} />;
34+
return <YamlSidePanel resource={data as Resource} filename={filename} isEdit={isEdit} />;
4035
}

src/components/Yaml/YamlViewButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,34 @@ export type YamlViewButtonProps = YamlViewButtonResourceProps | YamlViewButtonLo
2626

2727
export function YamlViewButton({ variant, ...props }: YamlViewButtonProps) {
2828
const { t } = useTranslation();
29-
const { openInAside } = useSplitter();
29+
const { openInAsideWithApiConfig } = useSplitter();
3030
const apiConfig = useContext(ApiConfigContext);
3131
const openSplitterSidePanel = () => {
3232
switch (variant) {
3333
case 'resource': {
3434
const { resource, toolbarContent } = props as YamlViewButtonResourceProps;
35-
openInAside(
35+
openInAsideWithApiConfig(
3636
<YamlSidePanel
3737
isEdit={false}
3838
resource={resource}
3939
filename={`${resource?.kind ?? ''}${resource?.metadata?.name ? '_' : ''}${resource?.metadata?.name ?? ''}`}
4040
toolbarContent={toolbarContent}
41-
apiConfig={apiConfig}
4241
/>,
42+
apiConfig,
4343
);
4444
break;
4545
}
4646

4747
case 'loader': {
4848
const { workspaceName, resourceType, resourceName } = props as YamlViewButtonLoaderProps;
49-
openInAside(
49+
openInAsideWithApiConfig(
5050
<YamlSidePanelWithLoader
5151
isEdit={false}
5252
workspaceName={workspaceName}
5353
resourceType={resourceType}
5454
resourceName={resourceName}
55-
apiConfig={apiConfig}
5655
/>,
56+
apiConfig,
5757
);
5858
break;
5959
}

0 commit comments

Comments
 (0)