Skip to content

Commit 7ff45f5

Browse files
committed
reafctor
1 parent 0fbe5b3 commit 7ff45f5

File tree

4 files changed

+82
-26
lines changed

4 files changed

+82
-26
lines changed

src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCardMenu.tsx

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@ import '@ui5/webcomponents-icons/dist/accept';
77
import { useTranslation } from 'react-i18next';
88

99
type ControlPlanesListMenuProps = {
10-
setDialogDeleteMcpIsOpen: Dispatch<SetStateAction<boolean>>;
11-
isDeleteMcpButtonDisabled: boolean;
1210
setIsEditManagedControlPlaneWizardOpen: Dispatch<SetStateAction<boolean>>;
1311
};
1412

15-
export const ControlPlaneCardMenu: FC<ControlPlanesListMenuProps> = ({
16-
setDialogDeleteMcpIsOpen,
17-
isDeleteMcpButtonDisabled,
18-
setIsEditManagedControlPlaneWizardOpen,
19-
}) => {
13+
export const ControlPlaneCardMenu: FC<ControlPlanesListMenuProps> = ({ setIsEditManagedControlPlaneWizardOpen }) => {
2014
const buttonRef = useRef(null);
2115
const [menuIsOpen, setMenuIsOpen] = useState(false);
2216
const { t } = useTranslation();
@@ -36,30 +30,14 @@ export const ControlPlaneCardMenu: FC<ControlPlanesListMenuProps> = ({
3630
if (action === 'editMcp') {
3731
setIsEditManagedControlPlaneWizardOpen(true);
3832
}
39-
if (action === 'deleteMcp') {
40-
setDialogDeleteMcpIsOpen(true);
41-
}
4233

4334
setMenuIsOpen(false);
4435
}}
4536
onClose={() => {
4637
setMenuIsOpen(false);
4738
}}
4839
>
49-
<MenuItem
50-
key={'delete'}
51-
text={t('ControlPlaneCard.deleteMCP')}
52-
data-action="deleteMcp"
53-
icon="delete"
54-
disabled={isDeleteMcpButtonDisabled}
55-
/>
56-
<MenuItem
57-
key={'edit'}
58-
text={t('ControlPlaneCard.editMCP')}
59-
data-action="editMcp"
60-
icon="edit"
61-
disabled={isDeleteMcpButtonDisabled}
62-
/>
40+
<MenuItem key={'edit'} text={t('ControlPlaneCard.editMCP')} data-action="editMcp" icon="edit" />
6341
</Menu>
6442
</>
6543
);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Button, Menu, MenuItem } from '@ui5/webcomponents-react';
2+
3+
import { Dispatch, FC, SetStateAction, useRef, useState } from 'react';
4+
import '@ui5/webcomponents-icons/dist/copy';
5+
import '@ui5/webcomponents-icons/dist/accept';
6+
7+
import { useTranslation } from 'react-i18next';
8+
9+
type ControlPlanesListMenuProps = {
10+
setDialogDeleteMcpIsOpen: Dispatch<SetStateAction<boolean>>;
11+
isDeleteMcpButtonDisabled: boolean;
12+
setIsEditManagedControlPlaneWizardOpen: Dispatch<SetStateAction<boolean>>;
13+
};
14+
15+
export const ControlPlanePageeMenu: FC<ControlPlanesListMenuProps> = ({
16+
setDialogDeleteMcpIsOpen,
17+
isDeleteMcpButtonDisabled,
18+
setIsEditManagedControlPlaneWizardOpen,
19+
}) => {
20+
const buttonRef = useRef(null);
21+
const [menuIsOpen, setMenuIsOpen] = useState(false);
22+
const { t } = useTranslation();
23+
24+
const handleOpenerClick = () => {
25+
setMenuIsOpen(true);
26+
};
27+
28+
return (
29+
<>
30+
<Button ref={buttonRef} icon="overflow" icon-end onClick={handleOpenerClick} />
31+
<Menu
32+
open={menuIsOpen}
33+
opener={buttonRef.current}
34+
onItemClick={(event) => {
35+
const action = (event.detail.item as HTMLElement).dataset.action;
36+
if (action === 'editMcp') {
37+
setIsEditManagedControlPlaneWizardOpen(true);
38+
}
39+
if (action === 'deleteMcp') {
40+
setDialogDeleteMcpIsOpen(true);
41+
}
42+
43+
setMenuIsOpen(false);
44+
}}
45+
onClose={() => {
46+
setMenuIsOpen(false);
47+
}}
48+
>
49+
<MenuItem
50+
key={'delete'}
51+
text={t('ControlPlaneCard.deleteMCP')}
52+
data-action="deleteMcp"
53+
icon="delete"
54+
disabled={isDeleteMcpButtonDisabled}
55+
/>
56+
<MenuItem
57+
key={'edit'}
58+
text={t('ControlPlaneCard.editMCP')}
59+
data-action="editMcp"
60+
icon="edit"
61+
disabled={isDeleteMcpButtonDisabled}
62+
/>
63+
</Menu>
64+
</>
65+
);
66+
};

src/components/Wizards/CreateManagedControlPlane/CreateManagedControlPlaneWizardContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { IllustratedBanner } from '../../Ui/IllustratedBanner/IllustratedBanner.
4848
import { ManagedControlPlaneTemplate, noTemplateValue } from '../../../lib/api/types/templates/mcpTemplate.ts';
4949
import { stripIdpPrefix } from '../../../utils/stripIdpPrefix.ts';
5050
import { buildNameWithPrefixesAndSuffixes } from '../../../utils/buildNameWithPrefixesAndSuffixes.ts';
51-
import { ManagedControlPlaneInterface } from './mcp_type.ts';
51+
import { ManagedControlPlaneInterface } from '../../../lib/api/types/mcpResource.ts';
5252

5353
type CreateManagedControlPlaneWizardContainerProps = {
5454
isOpen: boolean;

src/spaces/mcp/pages/McpPage.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ import { isNotFoundError } from '../../../lib/api/error.ts';
2727
import { NotFoundBanner } from '../../../components/Ui/NotFoundBanner/NotFoundBanner.tsx';
2828
import Graph from '../../../components/Graphs/Graph.tsx';
2929
import HintsCardsRow from '../../../components/HintsCardsRow/HintsCardsRow.tsx';
30+
import { ControlPlaneCardMenu } from '../../../components/ControlPlanes/ControlPlaneCard/ControlPlaneCardMenu.tsx';
31+
import { useState } from 'react';
32+
import { EditManagedControlPlaneWizardDataLoader } from '../../../components/Wizards/CreateManagedControlPlane/EditManagedControlPlaneWizardDataLoader.tsx';
3033

3134
export default function McpPage() {
3235
const { projectName, workspaceName, controlPlaneName } = useParams();
3336
const { t } = useTranslation();
34-
37+
const [isEditManagedControlPlaneWizardOpen, setIsEditManagedControlPlaneWizardOpen] = useState(false);
3538
const {
3639
data: mcp,
3740
error,
@@ -88,6 +91,15 @@ export default function McpPage() {
8891
resourceName={controlPlaneName}
8992
/>
9093
<CopyKubeconfigButton />
94+
<ControlPlaneCardMenu
95+
setIsEditManagedControlPlaneWizardOpen={setIsEditManagedControlPlaneWizardOpen}
96+
/>
97+
<EditManagedControlPlaneWizardDataLoader
98+
isOpen={isEditManagedControlPlaneWizardOpen}
99+
setIsOpen={setIsEditManagedControlPlaneWizardOpen}
100+
workspaceName={mcp?.status?.access?.namespace}
101+
resourceName={controlPlaneName}
102+
/>
91103
</div>
92104
}
93105
/>

0 commit comments

Comments
 (0)