Skip to content

Commit bce63fe

Browse files
committed
Requested Refactoring changes
1 parent b0c7deb commit bce63fe

14 files changed

+109
-4866
lines changed

public/locales/en.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@
145145
"mainCommandDescription": "Run this command to delete the workspace:",
146146
"verificationCommandDescription": "To verify the workspace has been deleted, run:"
147147
},
148-
"DeleteMcpDialog": {
148+
"KubectlDeleteMcpDialog": {
149149
"title": "Delete a Managed Control Plane",
150150
"introSection1": "The below will help you delete the Managed Control Plane \"{{mcpName}}\" from workspace \"{{workspaceNamespace}}\" using kubectl.",
151151
"introSection2": "Remember that this action is <bold1>irreversible</bold1> and all resources managed by this control plane will be <bold2>permanently deleted</bold2>.",
152152
"annotateCommand": "First, annotate the ManagedControlPlane to confirm deletion:",
153153
"deleteCommand": "Run this command to delete the Managed Control Plane:",
154154
"verificationCommandDescription": "To verify the MCP has been deleted, run:"
155155
},
156-
"KubectlProjectDialog": {
156+
"KubectlCreateProjectDialog": {
157157
"title": "Create a Project",
158158
"introSection": "A Project is the starting point to our ManagedControlPlane offering. Projects are usually created for each Organization/Team or similar root setups.",
159159
"formFields": {
@@ -176,7 +176,7 @@
176176
"resultCommandDescription": "To see the result of the project creation, run the below command:",
177177
"namespaceCommandDescription": "A namespace is automatically generated for your project:"
178178
},
179-
"KubectlWorkspaceDialog": {
179+
"KubectlCreateWorkspaceDialog": {
180180
"title": "Create a Workspace",
181181
"introSection": "Let's add a Workspace to our Project. We use workspaces to separate productive and non-productive ManagedControlPlanes.",
182182
"formFields": {

src/components/ControlPlanes/ControlPlaneCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function ControlPlaneCard({
9999
</Card>
100100
<DeleteConfirmationDialog
101101
resourceName={controlPlane.metadata.name}
102-
resourceComponent={
102+
kubectl={
103103
<KubectlDeleteMcp
104104
projectName={projectName}
105105
workspaceName={workspace.metadata.name}

src/components/ControlPlanes/List/ControlPlaneListWorkspaceGridTile.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ export function ControlPlaneListWorkspaceGridTile({
155155
</ObjectPageSection>
156156
<DeleteConfirmationDialog
157157
resourceName={workspaceName}
158-
projectName={projectName}
159-
resourceComponent={
158+
kubectl={
160159
<KubectlDeleteWorkspace
161160
projectName={projectName}
162161
resourceName={workspaceName}

src/components/Dialogs/CreateProjectWorkspaceDialog.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ import {
1212
import { Member } from '../../lib/api/types/shared/members';
1313
import { ErrorDialog, ErrorDialogHandle } from '../Shared/ErrorMessageBox.tsx';
1414

15-
import { FormEvent } from 'react';
15+
import { FormEvent, useState } from 'react';
1616
import { KubectlInfoButton } from './KubectlCommandInfo/KubectlInfoButton.tsx';
17-
import { KubectlWorkspaceDialog } from './KubectlCommandInfo/KubectlCreateWorkspaceDialog.tsx';
18-
import { KubectlProjectDialog } from './KubectlCommandInfo/KubectlCreateProjectDialog.tsx';
17+
import { KubectlCreateWorkspaceDialog } from './KubectlCommandInfo/KubectlCreateWorkspaceDialog.tsx';
18+
import { KubectlCreateProjectDialog } from './KubectlCommandInfo/KubectlCreateProjectDialog.tsx';
1919

2020
import { EditMembers } from '../Members/EditMembers.tsx';
2121
// import { useFrontendConfig } from '../../context/FrontendConfigContext.tsx';
2222
import { useTranslation } from 'react-i18next';
23-
import { useDialog } from './UseDialog.tsx';
2423

2524
import { CreateDialogProps } from './CreateWorkspaceDialogContainer.tsx';
2625
import { FieldErrors, UseFormRegister, UseFormSetValue } from 'react-hook-form';
@@ -59,7 +58,11 @@ export function CreateProjectWorkspaceDialog({
5958
}: CreateProjectWorkspaceDialogProps) {
6059
// const { links } = useFrontendConfig();
6160
const { t } = useTranslation();
62-
const kubectlDialog = useDialog();
61+
const [isKubectlDialogOpen, setIsKubectlDialogOpen] = useState(false);
62+
63+
const openKubectlDialog = () => setIsKubectlDialogOpen(true);
64+
const closeKubectlDialog = () => setIsKubectlDialogOpen(false);
65+
6366
return (
6467
<>
6568
<Dialog
@@ -74,7 +77,7 @@ export function CreateProjectWorkspaceDialog({
7477
<div
7578
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
7679
>
77-
<KubectlInfoButton onClick={kubectlDialog.open} />
80+
<KubectlInfoButton onClick={openKubectlDialog} />
7881
<Button onClick={() => setIsOpen(false)}>
7982
{' '}
8083
{t('CreateProjectWorkspaceDialog.cancelButton')}
@@ -95,14 +98,14 @@ export function CreateProjectWorkspaceDialog({
9598
setValue={setValue}
9699
/>
97100
</Dialog>
98-
<KubectlWorkspaceDialog
101+
<KubectlCreateWorkspaceDialog
99102
project={projectName}
100-
isOpen={kubectlDialog.isOpen && !!projectName}
101-
onClose={kubectlDialog.close}
103+
isOpen={isKubectlDialogOpen && !!projectName}
104+
onClose={closeKubectlDialog}
102105
/>
103-
<KubectlProjectDialog
104-
isOpen={kubectlDialog.isOpen && !projectName}
105-
onClose={kubectlDialog.close}
106+
<KubectlCreateProjectDialog
107+
isOpen={isKubectlDialogOpen && !projectName}
108+
onClose={closeKubectlDialog}
106109
/>
107110
<ErrorDialog ref={errorDialogRef} />
108111
</>

src/components/Dialogs/DeleteConfirmationDialog.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('DeleteConfirmationDialog', () => {
88
isOpen={true}
99
setIsOpen={cy.stub().as('setIsOpen')}
1010
resourceName="test-resource"
11-
resourceComponent={<div>Resource Component</div>}
11+
kubectl={<div>Resource Component</div>}
1212
onDeletionConfirmed={cy.stub().as('onDeletionConfirmed')}
1313
onCanceled={cy.stub().as('onCanceled')}
1414
{...props}

src/components/Dialogs/DeleteConfirmationDialog.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ interface DeleteConfirmationDialogProps {
1717
isOpen: boolean;
1818
setIsOpen: (isOpen: boolean) => void;
1919
resourceName: string;
20-
projectName?: string;
21-
resourceComponent: ReactNode;
20+
kubectl: ReactNode;
2221
onDeletionConfirmed?: () => void;
2322
onCanceled?: () => void;
2423
}
@@ -29,7 +28,7 @@ export function DeleteConfirmationDialog({
2928
resourceName,
3029
onDeletionConfirmed,
3130
onCanceled,
32-
resourceComponent,
31+
kubectl,
3332
}: DeleteConfirmationDialogProps) {
3433
const [confirmed, setConfirmed] = useState(false);
3534
const confirmationInput = useRef<InputDomRef>(null);
@@ -116,7 +115,7 @@ export function DeleteConfirmationDialog({
116115
onInput={onConfirmationInputChange}
117116
/>
118117
</FormItem>
119-
<FormItem>{resourceComponent}</FormItem>
118+
<FormItem>{kubectl}</FormItem>
120119
</FormGroup>
121120
</Form>
122121
</Dialog>

src/components/Dialogs/KubectlCommandInfo/Controllers/KubectlDeleteMcp.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { DeleteMcpDialog } from '../KubectlDeleteMcpDialog';
1+
import { useState } from 'react';
2+
import { KubectlDeleteMcpDialog } from '../KubectlDeleteMcpDialog';
23
import { KubectlInfoButton } from '../KubectlInfoButton';
3-
import { useDialog } from '../../UseDialog';
44

55
interface KubectlDeleteMcpProps {
6-
projectName?: string;
6+
projectName: string;
77
workspaceName: string;
88
resourceName: string;
99
}
@@ -13,17 +13,20 @@ export const KubectlDeleteMcp = ({
1313
workspaceName,
1414
resourceName,
1515
}: KubectlDeleteMcpProps) => {
16-
const infoDialog = useDialog();
16+
const [isInfoDialogOpen, setIsInfoDialogOpen] = useState(false);
17+
18+
const openInfoDialog = () => setIsInfoDialogOpen(true);
19+
const closeInfoDialog = () => setIsInfoDialogOpen(false);
1720

1821
return (
1922
<>
20-
<KubectlInfoButton onClick={infoDialog.open} />
21-
<DeleteMcpDialog
23+
<KubectlInfoButton onClick={openInfoDialog} />
24+
<KubectlDeleteMcpDialog
2225
projectName={projectName}
2326
workspaceName={workspaceName}
2427
resourceName={resourceName}
25-
isOpen={infoDialog.isOpen}
26-
onClose={infoDialog.close}
28+
isOpen={isInfoDialogOpen}
29+
onClose={closeInfoDialog}
2730
/>
2831
</>
2932
);
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { useState } from 'react';
12
import { DeleteWorkspaceDialog } from '../KubectlDeleteWorkspaceDialog';
23
import { KubectlInfoButton } from '../KubectlInfoButton';
3-
import { useDialog } from '../../UseDialog';
44

55
interface KubectlDeleteWorkspaceProps {
66
projectName?: string;
@@ -11,17 +11,20 @@ export const KubectlDeleteWorkspace = ({
1111
projectName,
1212
resourceName,
1313
}: KubectlDeleteWorkspaceProps) => {
14-
const infoDialog = useDialog();
14+
const [isInfoDialogOpen, setIsInfoDialogOpen] = useState(false);
15+
16+
const openInfoDialog = () => setIsInfoDialogOpen(true);
17+
const closeInfoDialog = () => setIsInfoDialogOpen(false);
1518

1619
return (
1720
<>
18-
<KubectlInfoButton onClick={infoDialog.open} />
21+
<KubectlInfoButton onClick={openInfoDialog} />
1922
<DeleteWorkspaceDialog
2023
projectName={projectName}
2124
resourceName={resourceName}
22-
isOpen={infoDialog.isOpen}
23-
onClose={infoDialog.close}
25+
isOpen={isInfoDialogOpen}
26+
onClose={closeInfoDialog}
2427
/>
2528
</>
2629
);
27-
};
30+
};

src/components/Dialogs/KubectlCommandInfo/KubectlCreateProjectDialog.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,46 @@ import {
55
} from './KubectlBaseDialog';
66
import { useTranslation } from 'react-i18next';
77

8-
interface KubectlProjectDialogProps {
8+
interface KubectlCreateProjectDialogProps {
99
onClose: () => void;
1010
isOpen: boolean;
1111
}
1212

13-
export const KubectlProjectDialog = ({
13+
export const KubectlCreateProjectDialog = ({
1414
onClose,
1515
isOpen,
16-
}: KubectlProjectDialogProps) => {
16+
}: KubectlCreateProjectDialogProps) => {
1717
const { t } = useTranslation();
1818
const randomProjectName = Math.random().toString(36).substring(2, 8);
1919

2020
const formFields: FormField[] = [
2121
{
2222
id: 'projectName',
23-
label: t('KubectlProjectDialog.formFields.projectName.label'),
24-
placeholder: t('KubectlProjectDialog.formFields.projectName.placeholder'),
23+
label: t('KubectlCreateProjectDialog.formFields.projectName.label'),
24+
placeholder: t(
25+
'KubectlCreateProjectDialog.formFields.projectName.placeholder',
26+
),
2527
defaultValue: randomProjectName,
2628
},
2729
{
2830
id: 'chargingTargetId',
29-
label: t('KubectlProjectDialog.formFields.chargingTargetId.label'),
31+
label: t('KubectlCreateProjectDialog.formFields.chargingTargetId.label'),
3032
placeholder: t(
31-
'KubectlProjectDialog.formFields.chargingTargetId.placeholder',
33+
'KubectlCreateProjectDialog.formFields.chargingTargetId.placeholder',
3234
),
3335
defaultValue: t(
34-
'KubectlProjectDialog.formFields.chargingTargetId.defaultValue',
36+
'KubectlCreateProjectDialog.formFields.chargingTargetId.defaultValue',
3537
),
3638
},
3739
{
3840
id: 'userEmail',
39-
label: t('KubectlProjectDialog.formFields.userEmail.label'),
40-
placeholder: t('KubectlProjectDialog.formFields.userEmail.placeholder'),
41-
defaultValue: t('KubectlProjectDialog.formFields.userEmail.defaultValue'),
41+
label: t('KubectlCreateProjectDialog.formFields.userEmail.label'),
42+
placeholder: t(
43+
'KubectlCreateProjectDialog.formFields.userEmail.placeholder',
44+
),
45+
defaultValue: t(
46+
'KubectlCreateProjectDialog.formFields.userEmail.defaultValue',
47+
),
4248
},
4349
];
4450

@@ -61,24 +67,24 @@ export const KubectlProjectDialog = ({
6167
roles:
6268
- admin
6369
' | kubectl create -f -`,
64-
description: t('KubectlProjectDialog.mainCommandDescription'),
70+
description: t('KubectlCreateProjectDialog.mainCommandDescription'),
6571
isMainCommand: true,
6672
},
6773
{
6874
command: `kubectl get project \${projectName}`,
69-
description: t('KubectlProjectDialog.resultCommandDescription'),
75+
description: t('KubectlCreateProjectDialog.resultCommandDescription'),
7076
},
7177
{
7278
command: `kubectl get namespace project-\${projectName}`,
73-
description: t('KubectlProjectDialog.namespaceCommandDescription'),
79+
description: t('KubectlCreateProjectDialog.namespaceCommandDescription'),
7480
},
7581
];
7682

77-
const introSection = [t('KubectlProjectDialog.introSection')];
83+
const introSection = [t('KubectlCreateProjectDialog.introSection')];
7884

7985
return (
8086
<KubectlBaseDialog
81-
title={t('KubectlProjectDialog.title')}
87+
title={t('KubectlCreateProjectDialog.title')}
8288
introSection={introSection}
8389
formFields={formFields}
8490
customCommands={customCommands}

src/components/Dialogs/KubectlCommandInfo/KubectlCreateWorkspaceDialog.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import {
55
} from './KubectlBaseDialog';
66
import { useTranslation } from 'react-i18next';
77

8-
interface KubectlWorkspaceDialogProps {
8+
interface KubectlCreateWorkspaceDialogProps {
99
onClose: () => void;
1010
isOpen: boolean;
1111
project?: string;
1212
}
1313

14-
export const KubectlWorkspaceDialog = ({
14+
export const KubectlCreateWorkspaceDialog = ({
1515
onClose,
1616
isOpen,
1717
project,
18-
}: KubectlWorkspaceDialogProps) => {
18+
}: KubectlCreateWorkspaceDialogProps) => {
1919
const { t } = useTranslation();
2020
const randomWorkspaceName = Math.random().toString(36).substring(2, 8);
2121
const projectName = project || '<Project Namespace>';
@@ -24,28 +24,32 @@ export const KubectlWorkspaceDialog = ({
2424
const formFields: FormField[] = [
2525
{
2626
id: 'workspaceName',
27-
label: t('KubectlWorkspaceDialog.formFields.workspaceName.label'),
27+
label: t('KubectlCreateWorkspaceDialog.formFields.workspaceName.label'),
2828
placeholder: t(
29-
'KubectlWorkspaceDialog.formFields.workspaceName.placeholder',
29+
'KubectlCreateWorkspaceDialog.formFields.workspaceName.placeholder',
3030
),
3131
defaultValue: randomWorkspaceName,
3232
},
3333
{
3434
id: 'chargingTargetId',
35-
label: t('KubectlWorkspaceDialog.formFields.chargingTargetId.label'),
35+
label: t(
36+
'KubectlCreateWorkspaceDialog.formFields.chargingTargetId.label',
37+
),
3638
placeholder: t(
37-
'KubectlWorkspaceDialog.formFields.chargingTargetId.placeholder',
39+
'KubectlCreateWorkspaceDialog.formFields.chargingTargetId.placeholder',
3840
),
3941
defaultValue: t(
40-
'KubectlWorkspaceDialog.formFields.chargingTargetId.defaultValue',
42+
'KubectlCreateWorkspaceDialog.formFields.chargingTargetId.defaultValue',
4143
),
4244
},
4345
{
4446
id: 'userEmail',
45-
label: t('KubectlWorkspaceDialog.formFields.userEmail.label'),
46-
placeholder: t('KubectlWorkspaceDialog.formFields.userEmail.placeholder'),
47+
label: t('KubectlCreateWorkspaceDialog.formFields.userEmail.label'),
48+
placeholder: t(
49+
'KubectlCreateWorkspaceDialog.formFields.userEmail.placeholder',
50+
),
4751
defaultValue: t(
48-
'KubectlWorkspaceDialog.formFields.userEmail.defaultValue',
52+
'KubectlCreateWorkspaceDialog.formFields.userEmail.defaultValue',
4953
),
5054
},
5155
];
@@ -69,20 +73,20 @@ export const KubectlWorkspaceDialog = ({
6973
roles:
7074
- admin
7175
' | kubectl create -f -`,
72-
description: t('KubectlWorkspaceDialog.mainCommandDescription'),
76+
description: t('KubectlCreateWorkspaceDialog.mainCommandDescription'),
7377
isMainCommand: true,
7478
},
7579
{
7680
command: `kubectl get workspace \${workspaceName} -n ${projectNamespace}`,
77-
description: t('KubectlWorkspaceDialog.resultCommandDescription'),
81+
description: t('KubectlCreateWorkspaceDialog.resultCommandDescription'),
7882
},
7983
];
8084

81-
const introSection = [t('KubectlWorkspaceDialog.introSection')];
85+
const introSection = [t('KubectlCreateWorkspaceDialog.introSection')];
8286

8387
return (
8488
<KubectlBaseDialog
85-
title={t('KubectlWorkspaceDialog.title')}
89+
title={t('KubectlCreateWorkspaceDialog.title')}
8690
introSection={introSection}
8791
formFields={formFields}
8892
customCommands={customCommands}

0 commit comments

Comments
 (0)