Skip to content

Commit 50559a8

Browse files
authored
fix: Remaping Components names of MCP mapping fix (#335)
1 parent 4c3cee5 commit 50559a8

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

src/components/ComponentsSelection/ComponentsSelectionContainer.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { ComponentsSelection } from './ComponentsSelection.tsx';
33
import IllustratedError from '../Shared/IllustratedError.tsx';
44
import Loading from '../Shared/Loading.tsx';
5-
import { ComponentsListItem } from '../../lib/api/types/crate/createManagedControlPlane.ts';
5+
import { ComponentsListItem, replaceComponentsName } from '../../lib/api/types/crate/createManagedControlPlane.ts';
66
import { useTranslation } from 'react-i18next';
77

88
export interface ComponentsSelectionProps {
@@ -19,11 +19,16 @@ export interface ComponentsSelectionProps {
1919
*/
2020
export const getSelectedComponents = (components: ComponentsListItem[]) => {
2121
const isCrossplaneSelected = components.some(({ name, isSelected }) => name === 'crossplane' && isSelected);
22-
return components.filter((component) => {
23-
if (!component.isSelected) return false;
24-
if (component.name?.includes('provider') && !isCrossplaneSelected) return false;
25-
return true;
26-
});
22+
23+
return components
24+
.filter(({ isSelected, name }) => isSelected && (isCrossplaneSelected || !name?.includes('provider')))
25+
.map((component) => {
26+
const mapping = replaceComponentsName.find((m) => m.replaceName === component.name);
27+
return {
28+
...component,
29+
name: mapping ? mapping.originalName : component.name,
30+
};
31+
});
2732
};
2833

2934
export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> = ({

src/components/Wizards/CreateManagedControlPlane/CreateManagedControlPlaneWizardContainer.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
CreateManagedControlPlaneResource,
3535
CreateManagedControlPlaneType,
3636
UpdateManagedControlPlaneResource,
37+
replaceComponentsName,
3738
} from '../../../lib/api/types/crate/createManagedControlPlane.ts';
3839
import {
3940
CHARGING_TARGET_LABEL,
@@ -63,6 +64,16 @@ import { Infobox } from '../../Ui/Infobox/Infobox.tsx';
6364
import styles from './CreateManagedControlPlaneWizardContainer.module.css';
6465
import { useCreateManagedControlPlane as _useCreateManagedControlPlane } from '../../../hooks/useCreateManagedControlPlane.tsx';
6566

67+
// Remap MCP components keys from internal replaceName back to originalName using replaceComponentsName mapping
68+
const remapComponentsKeysToOriginalNames = (components: MCPComponentsSpec = {}): MCPComponentsSpec => {
69+
const remappedEntries = Object.entries(components).map(([key, value]) => {
70+
const mapping = replaceComponentsName.find((m) => m.replaceName === key);
71+
const newKey = mapping ? mapping.originalName : key;
72+
return [newKey, value] as const;
73+
});
74+
return Object.fromEntries(remappedEntries) as MCPComponentsSpec;
75+
};
76+
6677
type CreateManagedControlPlaneWizardContainerProps = {
6778
isOpen: boolean;
6879
setIsOpen: (isOpen: boolean) => void;
@@ -384,8 +395,11 @@ export const CreateManagedControlPlaneWizardContainer: FC<CreateManagedControlPl
384395
// Prepare initial selections for components when editing or duplicating
385396
const initialSelection = useMemo(() => {
386397
if (!isEditMode && !isDuplicateMode) return undefined;
398+
399+
const originalComponentsMap: MCPComponentsSpec = initialData?.spec.components ?? {};
400+
const componentsMap = remapComponentsKeysToOriginalNames(originalComponentsMap);
401+
387402
const selection: Record<string, { isSelected: boolean; version: string }> = {};
388-
const componentsMap: MCPComponentsSpec = initialData?.spec.components ?? {};
389403
(Object.keys(componentsMap) as (keyof MCPComponentsSpec)[]).forEach((key) => {
390404
if (key === 'apiServer') return;
391405
const value = componentsMap[key];

src/lib/api/types/crate/createManagedControlPlane.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ export interface CreateManagedControlPlaneType {
5757
spec: Spec;
5858
}
5959

60-
const componentNameMap: Record<string, string> = {
61-
'sap-btp-service-operator': 'btpServiceOperator',
62-
'external-secrets': 'externalSecretsOperator',
63-
};
60+
export const removeComponents = ['cert-manager'];
6461

65-
export const removedComponents = ['cert-manager'];
66-
export const removeComponents = removedComponents; // backward compatibility alias
62+
export const replaceComponentsName: { originalName: string; replaceName: string }[] = [
63+
{ originalName: 'sap-btp-service-operator', replaceName: 'btpServiceOperator' },
64+
{ originalName: 'external-secrets', replaceName: 'externalSecretsOperator' },
65+
];
6766

6867
export const CreateManagedControlPlane = (
6968
name: string,
@@ -83,12 +82,13 @@ export const CreateManagedControlPlane = (
8382
(component) =>
8483
component.isSelected && !component.name.includes('provider') && !component.name.includes('crossplane'),
8584
)
86-
.map((component) => ({
87-
...component,
88-
name: Object.prototype.hasOwnProperty.call(componentNameMap, component.name)
89-
? componentNameMap[component.name]
90-
: component.name,
91-
}))
85+
.map((component) => {
86+
const mapping = replaceComponentsName.find((m) => m.originalName === component.name);
87+
return {
88+
...component,
89+
name: mapping ? mapping.replaceName : component.name,
90+
};
91+
})
9292
.reduce((acc, item) => {
9393
acc[item.name] = { version: item.selectedVersion };
9494
return acc;

0 commit comments

Comments
 (0)