Skip to content

Commit 6653985

Browse files
committed
fix
1 parent 6ce7759 commit 6653985

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/components/ComponentsSelection/ComponentsSelectionContainer.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface ComponentsSelectionProps {
1818
managedControlPlaneTemplate?: ManagedControlPlaneTemplate;
1919
initialSelection?: Record<string, { isSelected: boolean; version: string }>;
2020
isOnMcpPage?: boolean;
21+
initializedComponents: React.RefObject<boolean>;
2122
}
2223

2324
/**
@@ -46,14 +47,15 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
4647
initialSelection,
4748
isOnMcpPage,
4849
setInitialComponentsList,
50+
initializedComponents,
4951
}) => {
5052
const {
5153
data: availableManagedComponentsListData,
5254
error,
5355
isLoading,
5456
} = useApiResource(ListManagedComponents(), undefined, !!isOnMcpPage);
5557
const { t } = useTranslation();
56-
const initialized = useRef(false);
58+
5759
const [templateDefaultsError, setTemplateDefaultsError] = useState<string | null>(null);
5860
const defaultComponents = useMemo<TemplateDefaultComponent[]>(
5961
() => managedControlPlaneTemplate?.spec?.spec?.components?.defaultComponents ?? [],
@@ -62,7 +64,7 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
6264

6365
useEffect(() => {
6466
if (
65-
initialized.current ||
67+
initializedComponents.current ||
6668
!availableManagedComponentsListData?.items ||
6769
availableManagedComponentsListData.items.length === 0
6870
) {
@@ -98,7 +100,7 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
98100
.filter((component) => !removeComponents.find((item) => item === component.name));
99101
setInitialComponentsList(newComponentsList);
100102
setComponentsList(newComponentsList);
101-
initialized.current = true;
103+
initializedComponents.current = true;
102104
}, [setComponentsList, defaultComponents, initialSelection, availableManagedComponentsListData?.items]);
103105

104106
useEffect(() => {
@@ -126,7 +128,7 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
126128
}, [availableManagedComponentsListData, defaultComponents]);
127129

128130
useEffect(() => {
129-
if (!initialized.current) return;
131+
if (!initializedComponents.current) return;
130132
if (!defaultComponents?.length) return;
131133
if (!componentsList?.length) return;
132134
// If initialSelection is provided, do not auto-apply template defaults

src/components/Wizards/CreateManagedControlPlane/CreateManagedControlPlaneWizardContainer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
124124
}, [isOpen, initialTemplateName]);
125125

126126
const validationSchemaCreateManagedControlPlane = useMemo(() => createManagedControlPlaneSchema(t), [t]);
127-
127+
const initializedComponents = useRef(false);
128128
const {
129129
register,
130130
handleSubmit,
@@ -406,8 +406,8 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
406406
namespace: s.namespace,
407407
})),
408408
);
409-
const labels = (initialData?.metadata.labels as unknown as Record<string, string>) ?? {};
410-
const annotations = (initialData?.metadata.annotations as unknown as Record<string, string>) ?? {};
409+
const labels = (initialData?.metadata?.labels as unknown as Record<string, string>) ?? {};
410+
const annotations = (initialData?.metadata?.annotations as unknown as Record<string, string>) ?? {};
411411
const data = {
412412
name: initialData?.metadata.name ?? '',
413413
displayName: annotations?.[DISPLAY_NAME_ANNOTATION] ?? '',
@@ -609,6 +609,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
609609
managedControlPlaneTemplate={selectedTemplate}
610610
isOnMcpPage={isOnMcpPage}
611611
setInitialComponentsList={setInitialComponentsListHandler}
612+
initializedComponents={initializedComponents}
612613
/>
613614
)}
614615
</WizardStep>

0 commit comments

Comments
 (0)