Skip to content

Commit 0751496

Browse files
committed
refactor
1 parent 5621541 commit 0751496

File tree

6 files changed

+90
-25
lines changed

6 files changed

+90
-25
lines changed

public/locales/en.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
"pageTitle": "Let's get started",
160160
"title": "Projects",
161161
"deleteProject": "Delete project",
162-
"deleteConfirmationDialog": "Project deleted"
162+
"deleteConfirmationDialog": "Project deleted"
163163
},
164164
"ControlPlaneView": {
165165
"accessError": "Managed Control Plane does not have access information yet",
@@ -192,6 +192,12 @@
192192
"mainCommandDescription": "Run this command to delete the workspace:",
193193
"verificationCommandDescription": "To verify the workspace has been deleted, run:"
194194
},
195+
"DeleteProjectDialog": {
196+
"title": "Delete a Project",
197+
"introSection1": "The below instructions will help you delete the project named \"{{projectName}}\" using kubectl.",
198+
"introSection2": "Remember that this action is <bold1>irreversible</bold1> and all resources within the project will be <bold2>permanently deleted</bold2>.",
199+
"mainCommandDescription": "Run this command to delete the project:"
200+
},
195201
"KubectlDeleteMcpDialog": {
196202
"title": "Delete a Managed Control Plane",
197203
"introSection1": "The below will help you delete the Managed Control Plane \"{{mcpName}}\" from workspace \"{{workspaceNamespace}}\" using kubectl.",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useState } from 'react';
2+
3+
import { KubectlInfoButton } from '../KubectlInfoButton';
4+
import { DeleteProjectDialog } from '../KubectlDeleteProjectDialog.tsx';
5+
6+
interface KubectlDeleteWorkspaceProps {
7+
projectName?: string;
8+
}
9+
10+
export const KubectlDeleteProject = ({ projectName }: KubectlDeleteWorkspaceProps) => {
11+
const [isInfoDialogOpen, setIsInfoDialogOpen] = useState(false);
12+
13+
const openInfoDialog = () => setIsInfoDialogOpen(true);
14+
const closeInfoDialog = () => setIsInfoDialogOpen(false);
15+
16+
return (
17+
<>
18+
<KubectlInfoButton onClick={openInfoDialog} />
19+
<DeleteProjectDialog projectName={projectName} isOpen={isInfoDialogOpen} onClose={closeInfoDialog} />
20+
</>
21+
);
22+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { KubectlBaseDialog, CustomCommand } from './KubectlBaseDialog';
2+
import { Text } from '@ui5/webcomponents-react';
3+
import { useTranslation, Trans } from 'react-i18next';
4+
import { Fragment } from 'react/jsx-runtime';
5+
6+
interface DeleteProjectDialogProps {
7+
onClose: () => void;
8+
resourceName?: string;
9+
projectName?: string;
10+
isOpen: boolean;
11+
}
12+
13+
export const DeleteProjectDialog = ({ onClose, projectName, isOpen }: DeleteProjectDialogProps) => {
14+
const { t } = useTranslation();
15+
16+
const projectNamespace = projectName ?? '<project-names>"';
17+
18+
const customCommands: CustomCommand[] = [
19+
{
20+
command: `kubectl delete project ${projectNamespace}`,
21+
description: t('DeleteProjectDialog.mainCommandDescription'),
22+
isMainCommand: true,
23+
},
24+
];
25+
26+
const introSection = [
27+
<Fragment key="intro-1">
28+
<Text>
29+
{t('DeleteProjectDialog.introSection1', {
30+
projectName,
31+
})}
32+
</Text>
33+
<Text>
34+
<Trans
35+
i18nKey={t('DeleteProjectDialog.introSection2')}
36+
components={{
37+
bold1: <b />,
38+
bold2: <b />,
39+
}}
40+
/>
41+
</Text>
42+
</Fragment>,
43+
];
44+
45+
return (
46+
<KubectlBaseDialog
47+
title={t('DeleteProjectDialog.title')}
48+
introSection={introSection}
49+
customCommands={customCommands}
50+
open={isOpen}
51+
onClose={onClose}
52+
/>
53+
);
54+
};

src/components/Dialogs/KubectlCommandInfo/KubectlDeleteWorkspaceDialog.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,27 @@ import { Fragment } from 'react/jsx-runtime';
55

66
interface DeleteWorkspaceDialogProps {
77
onClose: () => void;
8-
resourceName?: string;
98
projectName?: string;
109
isOpen: boolean;
1110
}
1211

13-
export const DeleteWorkspaceDialog = ({
14-
onClose,
15-
resourceName,
16-
projectName,
17-
isOpen,
18-
}: DeleteWorkspaceDialogProps) => {
12+
export const DeleteWorkspaceDialog = ({ onClose, projectName, isOpen }: DeleteWorkspaceDialogProps) => {
1913
const { t } = useTranslation();
2014

21-
const projectNamespace = projectName
22-
? `project-${projectName}`
23-
: '<project-namespace>"';
24-
const workspaceName = resourceName || '<workspace-name>';
15+
const projectNamespace = projectName ?? '<project-name>"';
2516

2617
const customCommands: CustomCommand[] = [
2718
{
28-
command: `kubectl delete workspace ${resourceName} -n ${projectNamespace}`,
19+
command: `kubectl delete project ${projectName}`,
2920
description: t('DeleteWorkspaceDialog.mainCommandDescription'),
3021
isMainCommand: true,
3122
},
32-
{
33-
command: `kubectl get workspace -n ${projectNamespace}`,
34-
description: t('DeleteWorkspaceDialog.verificationCommandDescription'),
35-
isMainCommand: true,
36-
},
3723
];
3824

3925
const introSection = [
4026
<Fragment key="intro-1">
4127
<Text>
4228
{t('DeleteWorkspaceDialog.introSection1', {
43-
workspaceName,
4429
projectNamespace,
4530
})}
4631
</Text>

src/components/Projects/ProjectsList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AnalyticalTable, AnalyticalTableColumnDefinition, Button, Link } from '@ui5/webcomponents-react';
2-
import { ThemingParameters } from '@ui5/webcomponents-react-base';
1+
import { AnalyticalTable, AnalyticalTableColumnDefinition, Link } from '@ui5/webcomponents-react';
2+
33
import { CopyButton } from '../Shared/CopyButton.tsx';
44
import useLuigiNavigate from '../Shared/useLuigiNavigate.tsx';
55
import IllustratedError from '../Shared/IllustratedError.tsx';

src/components/Projects/ProjectsListItemMenu.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useToast } from '../../context/ToastContext.tsx';
1111
import { useApiResourceMutation } from '../../lib/api/useApiResource.ts';
1212
import { DeleteWorkspaceType } from '../../lib/api/types/crate/deleteWorkspace.ts';
1313
import { DeleteProjectResource } from '../../lib/api/types/crate/deleteProject.ts';
14+
import { KubectlDeleteProject } from '../Dialogs/KubectlCommandInfo/Controllers/KubectlDeleteProject.tsx';
1415

1516
type ProjectsListItemMenuProps = {
1617
projectName: string;
@@ -55,10 +56,7 @@ export const ProjectsListItemMenu: FC<ProjectsListItemMenuProps> = ({ projectNam
5556
{dialogDeleteProjectIsOpen && (
5657
<DeleteConfirmationDialog
5758
resourceName={projectName}
58-
kubectl={
59-
// <KubectlDeleteWorkspace projectName={projectName} resourceName={workspaceName} />
60-
<div />
61-
}
59+
kubectl={<KubectlDeleteProject projectName={projectName} />}
6260
isOpen={dialogDeleteProjectIsOpen}
6361
setIsOpen={setDialogDeleteProjectIsOpen}
6462
onDeletionConfirmed={async () => {

0 commit comments

Comments
 (0)