Skip to content

Commit 2ecb4a8

Browse files
committed
fix
1 parent 94f247a commit 2ecb4a8

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

src/components/Wizards/CreateManagedControlPlane/CreateManagedControlPlaneWizardContainer.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ import {
3737
CHARGING_TARGET_LABEL,
3838
CHARGING_TARGET_TYPE_LABEL,
3939
DISPLAY_NAME_ANNOTATION,
40-
PROJECT_NAME_LABEL,
41-
WORKSPACE_LABEL,
4240
} from '../../../lib/api/types/shared/keyNames.ts';
4341
import { OnCreatePayload } from '../../Dialogs/CreateProjectWorkspaceDialog.tsx';
4442
import { idpPrefix } from '../../../utils/idpPrefix.ts';
@@ -50,6 +48,7 @@ import { IllustratedBanner } from '../../Ui/IllustratedBanner/IllustratedBanner.
5048
import { ManagedControlPlaneTemplate, noTemplateValue } from '../../../lib/api/types/templates/mcpTemplate.ts';
5149
import { stripIdpPrefix } from '../../../utils/stripIdpPrefix.ts';
5250
import { buildNameWithPrefixesAndSuffixes } from '../../../utils/buildNameWithPrefixesAndSuffixes.ts';
51+
import { ManagedControlPlaneInterface } from './mcp_type.ts';
5352

5453
type CreateManagedControlPlaneWizardContainerProps = {
5554
isOpen: boolean;
@@ -58,7 +57,7 @@ type CreateManagedControlPlaneWizardContainerProps = {
5857
workspaceName?: string;
5958
isEditMode: boolean;
6059
initialTemplateName?: string;
61-
initialData?: any;
60+
initialData?: ManagedControlPlaneInterface;
6261
};
6362

6463
type WizardStepType = 'metadata' | 'members' | 'componentSelection' | 'summarize' | 'success';
@@ -195,7 +194,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
195194
CreateManagedControlPlaneResource(projectName, workspaceName),
196195
);
197196
const { trigger: triggerUpdate } = useApiResourceMutation<CreateManagedControlPlaneType>(
198-
UpdateManagedControlPlaneResource(projectName, workspaceName, initialData?.metadata?.name),
197+
UpdateManagedControlPlaneResource(projectName, workspaceName, initialData?.metadata?.name ?? ''),
199198
);
200199
const componentsList = watch('componentsList');
201200

@@ -214,7 +213,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
214213
if (isEditMode) {
215214
await triggerUpdate(
216215
CreateManagedControlPlane(
217-
initialData.metadata.name,
216+
initialData?.metadata?.name ?? '',
218217
`${projectName}--ws-${workspaceName}`,
219218
{
220219
displayName,
@@ -354,10 +353,10 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
354353
const initialSelection = useMemo(() => {
355354
if (!isEditMode) return undefined;
356355
const selection: Record<string, { isSelected: boolean; version: string }> = {};
357-
const components = initialData.spec.components as any;
358-
Object.keys(components).forEach((key) => {
356+
const components = initialData?.spec.components;
357+
Object.keys(components ?? {}).forEach((key) => {
359358
if (key === 'apiServer' || key === 'landscaper') return;
360-
const value = components[key];
359+
const value = components?.[key];
361360
if (key === 'crossplane') {
362361
selection[key] = { isSelected: true, version: value.version ?? '' };
363362
(value.providers ?? []).forEach((prov: { name: string; version: string }) => {
@@ -373,7 +372,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
373372
// Prefill form when editing
374373
useEffect(() => {
375374
if (!isOpen || !isEditMode) return;
376-
const roleBindings = initialData.spec.authorization.roleBindings ?? [];
375+
const roleBindings = initialData?.spec?.authorization?.roleBindings ?? [];
377376
const members: Member[] = roleBindings.flatMap((rb) =>
378377
(rb.subjects ?? []).map((s: any) => ({
379378
kind: s.kind,
@@ -382,11 +381,11 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
382381
namespace: s.namespace,
383382
})),
384383
);
385-
const labels = (initialData.metadata.labels as unknown as Record<string, string>) ?? {};
386-
const annotations = (initialData.metadata.annotations as unknown as Record<string, string>) ?? {};
384+
const labels = (initialData?.metadata.labels as unknown as Record<string, string>) ?? {};
385+
const annotations = (initialData?.metadata.annotations as unknown as Record<string, string>) ?? {};
387386

388387
reset({
389-
name: initialData.metadata.name,
388+
name: initialData?.metadata.name,
390389
displayName: annotations?.[DISPLAY_NAME_ANNOTATION] ?? '',
391390
chargingTarget: labels?.[CHARGING_TARGET_LABEL] ?? '',
392391
chargingTargetType: labels?.[CHARGING_TARGET_TYPE_LABEL] ?? '',

src/components/Wizards/CreateManagedControlPlane/EditManagedControlPlaneWizardDataLoader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styles from './EditManagedControlPlaneWizardDataLoader.module.css';
55
import Loading from '../../Shared/Loading.tsx';
66
import { CreateManagedControlPlaneWizardContainer } from './CreateManagedControlPlaneWizardContainer.tsx';
77
import { PROJECT_NAME_LABEL, WORKSPACE_LABEL } from '../../../lib/api/types/shared/keyNames.ts';
8+
import { ManagedControlPlaneInterface } from './mcp_type.ts';
89

910
export type EditManagedControlPlaneWizardDataLoaderProps = {
1011
workspaceName?: string;
@@ -20,7 +21,7 @@ export const EditManagedControlPlaneWizardDataLoader: FC<EditManagedControlPlane
2021
setIsOpen,
2122
}) => {
2223
const { isLoading, data, error } = useApiResource(
23-
ResourceObject(workspaceName ?? '', 'managedcontrolplanes', resourceName),
24+
ResourceObject<ManagedControlPlaneInterface>(workspaceName ?? '', 'managedcontrolplanes', resourceName),
2425
undefined,
2526
true,
2627
!isOpen,

src/components/Wizards/CreateManagedControlPlane/mcp_type.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// ManagedControlPlane TypeScript interfaces generated from example JSON
2-
// These interfaces are intentionally permissive (optional fields, string unions with fallbacks)
3-
// to remain forward-compatible with the API while providing strong typing for known fields.
4-
5-
export interface ManagedControlPlane {
1+
export interface ManagedControlPlaneInterface {
62
apiVersion: 'core.openmcp.cloud/v1alpha1' | string;
73
kind: 'ManagedControlPlane' | string;
84
metadata: KubernetesObjectMeta;

0 commit comments

Comments
 (0)