Skip to content

Commit efb07fb

Browse files
committed
init
1 parent b3f1927 commit efb07fb

File tree

2 files changed

+115
-16
lines changed

2 files changed

+115
-16
lines changed

src/components/Wizards/CreateManagedControlPlaneWizardContainer.tsx

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
import { FC, useCallback, useEffect, useRef, useState } from 'react';
2-
import {
3-
useApiResourceMutation,
4-
useRevalidateApiResource,
5-
} from '../../lib/api/useApiResource';
6-
import { ErrorDialogHandle } from '../Shared/ErrorMessageBox.tsx';
2+
import { useApiResourceMutation } from '../../lib/api/useApiResource';
73

8-
import {
9-
CreateWorkspaceResource,
10-
CreateWorkspaceType,
11-
} from '../../lib/api/types/crate/createWorkspace';
12-
import { projectnameToNamespace } from '../../utils';
13-
import { ListWorkspaces } from '../../lib/api/types/crate/listWorkspaces';
14-
import { useToast } from '../../context/ToastContext.tsx';
154
import { useAuth } from '../../spaces/onboarding/auth/AuthContext.tsx';
165
import { Member, MemberRoles } from '../../lib/api/types/shared/members.ts';
17-
import { useTranslation } from 'react-i18next';
6+
187
import { zodResolver } from '@hookform/resolvers/zod';
198
import { useForm } from 'react-hook-form';
209
import { validationSchemaProjectWorkspace } from '../../lib/api/validations/schemas.ts';
21-
import { MetadataAndMembersForm } from '../Dialogs/CreateProjectWorkspaceDialog.tsx';
10+
import {
11+
MetadataAndMembersForm,
12+
OnCreatePayload,
13+
} from '../Dialogs/CreateProjectWorkspaceDialog.tsx';
2214
import {
2315
Bar,
2416
Button,
2517
Dialog,
2618
Grid,
2719
List,
2820
ListItemStandard,
29-
Text,
3021
Wizard,
3122
WizardStep,
3223
} from '@ui5/webcomponents-react';
3324
import YamlViewer from '../Yaml/YamlViewer.tsx';
3425
import { stringify } from 'yaml';
26+
import { APIError } from '../../lib/api/error.ts';
27+
import {
28+
CreateManagedControlPlane,
29+
CreateManagedControlPlaneResource,
30+
CreateManagedControlPlaneType,
31+
} from '../../lib/api/types/crate/createManagedControlPlane.ts';
32+
import { ErrorDialogHandle } from '../Shared/ErrorMessageBox.tsx';
33+
import { useToast } from '../../context/ToastContext.tsx';
3534

3635
export type CreateDialogProps = {
3736
name: string;
@@ -67,6 +66,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<
6766
members: [],
6867
},
6968
});
69+
const errorDialogRef = useRef<ErrorDialogHandle>(null);
7070
const resetFormAndClose = () => {
7171
reset();
7272
setSelectedStep(1);
@@ -77,7 +77,7 @@ export const CreateManagedControlPlaneWizardContainer: FC<
7777
const { user } = useAuth();
7878
const [selectedStep, setSelectedStep] = useState(1);
7979
const username = user?.email;
80-
80+
const toast = useToast();
8181
const clearForm = useCallback(() => {
8282
resetField('name');
8383
resetField('chargingTarget');
@@ -94,6 +94,39 @@ export const CreateManagedControlPlaneWizardContainer: FC<
9494
clearForm();
9595
}
9696
}, [resetField, setValue, username, isOpen, clearForm]);
97+
const { trigger } = useApiResourceMutation<CreateManagedControlPlaneType>(
98+
CreateManagedControlPlaneResource(namespace),
99+
);
100+
const handleCreateManagedControlPlane = async ({
101+
name,
102+
displayName,
103+
chargingTarget,
104+
members,
105+
}: OnCreatePayload): Promise<boolean> => {
106+
try {
107+
await trigger(
108+
CreateManagedControlPlane(name, namespace, {
109+
displayName: displayName,
110+
chargingTarget: chargingTarget,
111+
members: members,
112+
}),
113+
);
114+
// await revalidate();
115+
setIsOpen(false);
116+
toast.show('mcp created');
117+
return true;
118+
} catch (e) {
119+
console.error(e);
120+
if (e instanceof APIError) {
121+
if (errorDialogRef.current) {
122+
errorDialogRef.current.showErrorDialog(
123+
`${e.message}: ${JSON.stringify(e.info)}`,
124+
);
125+
}
126+
}
127+
return false;
128+
}
129+
};
97130

98131
const onNextClick = () => {
99132
console.log('test');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Resource } from '../resource';
2+
import {
3+
CHARGING_TARGET_LABEL,
4+
DISPLAY_NAME_ANNOTATION,
5+
} from '../shared/keyNames';
6+
import { Member } from '../shared/members';
7+
8+
export interface CreateManagedControlPlaneType {
9+
apiVersion: string;
10+
kind: string;
11+
metadata: {
12+
name: string;
13+
namespace: string;
14+
annotations: {
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
[annotation: string]: any;
17+
};
18+
labels: {
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
[label: string]: any;
21+
};
22+
};
23+
spec: {
24+
members: Member[];
25+
};
26+
}
27+
28+
export const CreateManagedControlPlane = (
29+
name: string,
30+
namespace: string,
31+
optional?: {
32+
displayName?: string;
33+
chargingTarget?: string;
34+
members?: Member[];
35+
},
36+
): CreateManagedControlPlaneType => {
37+
return {
38+
apiVersion: 'core.openmcp.cloud/v1alpha1',
39+
kind: 'ControlPlane',
40+
metadata: {
41+
name: name,
42+
namespace: namespace,
43+
annotations: {
44+
[DISPLAY_NAME_ANNOTATION]: optional?.displayName ?? '',
45+
},
46+
labels: {
47+
[CHARGING_TARGET_LABEL]: optional?.chargingTarget ?? '',
48+
},
49+
},
50+
spec: {
51+
members: optional?.members ?? [],
52+
},
53+
};
54+
};
55+
56+
export const CreateManagedControlPlaneResource = (
57+
projectName: string,
58+
workspaceName: string,
59+
): Resource<undefined> => {
60+
return {
61+
path: `/apis/core.openmcp.cloud/v1alpha1/namespaces/project-${projectName}--ws-${workspaceName}/managedcontrolplanes`,
62+
method: 'POST',
63+
jq: undefined,
64+
body: undefined,
65+
};
66+
};

0 commit comments

Comments
 (0)