Skip to content

Commit edca080

Browse files
authored
fix: Added a fix that renames some components to make the Creation of MCP work correctly (#176)
1 parent d06378d commit edca080

File tree

2 files changed

+30
-37
lines changed

2 files changed

+30
-37
lines changed

src/components/ComponentsSelection/ComponentsSelectionContainer.tsx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { sortVersions } from '../../utils/componentsVersions.ts';
77
import { ListManagedComponents } from '../../lib/api/types/crate/listManagedComponents.ts';
88
import useApiResource from '../../lib/api/useApiResource.ts';
99
import Loading from '../Shared/Loading.tsx';
10-
import { ComponentsListItem } from '../../lib/api/types/crate/createManagedControlPlane.ts';
10+
import { ComponentsListItem, removeComponents } from '../../lib/api/types/crate/createManagedControlPlane.ts';
1111
import { useTranslation } from 'react-i18next';
1212

1313
export interface ComponentsSelectionProps {
@@ -20,9 +20,7 @@ export interface ComponentsSelectionProps {
2020
* provider components are excluded.
2121
*/
2222
export const getSelectedComponents = (components: ComponentsListItem[]) => {
23-
const isCrossplaneSelected = components.some(
24-
({ name, isSelected }) => name === 'crossplane' && isSelected,
25-
);
23+
const isCrossplaneSelected = components.some(({ name, isSelected }) => name === 'crossplane' && isSelected);
2624
return components.filter((component) => {
2725
if (!component.isSelected) return false;
2826
if (component.name?.includes('provider') && !isCrossplaneSelected) {
@@ -32,14 +30,11 @@ export const getSelectedComponents = (components: ComponentsListItem[]) => {
3230
});
3331
};
3432

35-
export const ComponentsSelectionContainer: React.FC<
36-
ComponentsSelectionProps
37-
> = ({ setComponentsList, componentsList }) => {
38-
const {
39-
data: availableManagedComponentsListData,
40-
error,
41-
isLoading,
42-
} = useApiResource(ListManagedComponents());
33+
export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> = ({
34+
setComponentsList,
35+
componentsList,
36+
}) => {
37+
const { data: availableManagedComponentsListData, error, isLoading } = useApiResource(ListManagedComponents());
4338
const { t } = useTranslation();
4439
const initialized = useRef(false);
4540

@@ -52,8 +47,8 @@ export const ComponentsSelectionContainer: React.FC<
5247
return;
5348
}
5449

55-
const newComponentsList = availableManagedComponentsListData.items.map(
56-
(item) => {
50+
const newComponentsList = availableManagedComponentsListData.items
51+
.map((item) => {
5752
const versions = sortVersions(item.status.versions);
5853
return {
5954
name: item.metadata.name,
@@ -62,8 +57,8 @@ export const ComponentsSelectionContainer: React.FC<
6257
isSelected: false,
6358
documentationUrl: '',
6459
};
65-
},
66-
);
60+
})
61+
.filter((component) => !removeComponents.find((item) => item === component.name));
6762

6863
setComponentsList(newComponentsList);
6964
initialized.current = true;
@@ -82,10 +77,5 @@ export const ComponentsSelectionContainer: React.FC<
8277
return <IllustratedError title={t('componentsSelection.cannotLoad')} />;
8378
}
8479

85-
return (
86-
<ComponentsSelection
87-
componentsList={componentsList}
88-
setComponentsList={setComponentsList}
89-
/>
90-
);
80+
return <ComponentsSelection componentsList={componentsList} setComponentsList={setComponentsList} />;
9181
};

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { Resource } from '../resource';
2-
import {
3-
CHARGING_TARGET_LABEL,
4-
CHARGING_TARGET_TYPE_LABEL,
5-
DISPLAY_NAME_ANNOTATION,
6-
} from '../shared/keyNames';
2+
import { CHARGING_TARGET_LABEL, CHARGING_TARGET_TYPE_LABEL, DISPLAY_NAME_ANNOTATION } from '../shared/keyNames';
73
import { Member } from '../shared/members';
84

95
export type Annotations = Record<string, string>;
@@ -60,6 +56,14 @@ export interface CreateManagedControlPlaneType {
6056
spec: Spec;
6157
}
6258

59+
// rename is used to make creation of MCP working properly
60+
const replaceComponentsName: Record<string, string> = {
61+
'sap-btp-service-operator': 'btpServiceOperator',
62+
'external-secrets': 'externalSecretsOperator',
63+
};
64+
65+
export const removeComponents = ['cert-manager'];
66+
6367
export const CreateManagedControlPlane = (
6468
name: string,
6569
namespace: string,
@@ -76,10 +80,14 @@ export const CreateManagedControlPlane = (
7680
optional?.componentsList
7781
?.filter(
7882
(component) =>
79-
component.isSelected &&
80-
!component.name.includes('provider') &&
81-
!component.name.includes('crossplane'),
83+
component.isSelected && !component.name.includes('provider') && !component.name.includes('crossplane'),
8284
)
85+
.map((component) => ({
86+
...component,
87+
name: Object.prototype.hasOwnProperty.call(replaceComponentsName, component.name)
88+
? replaceComponentsName[component.name]
89+
: component.name,
90+
}))
8391
.reduce((acc, item) => {
8492
acc[item.name] = { version: item.selectedVersion };
8593
return acc;
@@ -90,9 +98,7 @@ export const CreateManagedControlPlane = (
9098

9199
const providersListObject: Provider[] =
92100
optional?.componentsList
93-
?.filter(
94-
({ name, isSelected }) => name.includes('provider') && isSelected,
95-
)
101+
?.filter(({ name, isSelected }) => name.includes('provider') && isSelected)
96102
.map(({ name, selectedVersion }) => ({
97103
name: name,
98104
version: selectedVersion,
@@ -140,10 +146,7 @@ export const CreateManagedControlPlane = (
140146
},
141147
};
142148
};
143-
export const CreateManagedControlPlaneResource = (
144-
projectName: string,
145-
workspaceName: string,
146-
): Resource<undefined> => {
149+
export const CreateManagedControlPlaneResource = (projectName: string, workspaceName: string): Resource<undefined> => {
147150
return {
148151
path: `/apis/core.openmcp.cloud/v1alpha1/namespaces/${projectName}--ws-${workspaceName}/managedcontrolplanes`,
149152
method: 'POST',

0 commit comments

Comments
 (0)