Skip to content

Commit 95ff0c3

Browse files
committed
feat: Add ArgoApp delete confirmation (#321)
1 parent 3d025a5 commit 95ff0c3

File tree

11 files changed

+137
-36
lines changed

11 files changed

+137
-36
lines changed

src/components/LogViewer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export function SearchPopover(props: SearchPopoverProps) {
351351
});
352352
} catch (e) {
353353
// Catch invalid regular expression error
354-
console.log('Error searching logs: ', e);
354+
// console.log('Error searching logs: ', e);
355355
searchAddonRef.current?.findNext('');
356356
}
357357

src/k8s/groups/EDP/Codemie/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const {
88
version,
99
} = CodemieKubeObjectConfig;
1010

11-
export class CodemieKubeObject extends K8s.cluster.makeKubeObject<CodemieKubeObjectInterface>(singularForm) {
11+
export class CodemieKubeObject extends K8s.cluster.makeKubeObject<CodemieKubeObjectInterface>(
12+
singularForm
13+
) {
1214
static apiEndpoint = ApiProxy.apiFactoryWithNamespace(group, version, pluralForm);
1315

1416
static get className(): string {

src/k8s/groups/EDP/CodemieProject/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const {
88
version,
99
} = CodemieProjectKubeObjectConfig;
1010

11-
export class CodemieProjectKubeObject extends K8s.cluster.makeKubeObject<CodemieProjectKubeObjectInterface>(singularForm) {
11+
export class CodemieProjectKubeObject extends K8s.cluster.makeKubeObject<CodemieProjectKubeObjectInterface>(
12+
singularForm
13+
) {
1214
static apiEndpoint = ApiProxy.apiFactoryWithNamespace(group, version, pluralForm);
1315

1416
static get className(): string {

src/pages/stage-details/components/Applications/hooks/useConfigurationHandlers.ts

+4-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import { FieldValues, useFormContext } from 'react-hook-form';
33
import { editResource } from '../../../../../k8s/common/editResource';
4-
import { ApplicationKubeObjectInterface } from '../../../../../k8s/groups/ArgoCD/Application/types';
54
import { useCreateCleanPipelineRun } from '../../../../../k8s/groups/Tekton/PipelineRun/hooks/useCreateCleanPipelineRun';
65
import { useCreateDeployPipelineRun } from '../../../../../k8s/groups/Tekton/PipelineRun/hooks/useCreateDeployPipelineRun';
76
import {
@@ -98,18 +97,14 @@ export const useConfigurationHandlers = ({
9897
setSelected,
9998
enrichedApplicationsByApplicationName,
10099
enrichedApplicationsWithArgoApplications,
101-
deleteArgoApplication,
100+
setDeleteDialogOpen,
102101
}: {
103102
values: FieldValues;
104103
selected: string[];
105104
setSelected: React.Dispatch<React.SetStateAction<string[]>>;
106105
enrichedApplicationsByApplicationName: Map<string, EnrichedApplicationWithArgoApplication>;
107106
enrichedApplicationsWithArgoApplications: EnrichedApplicationWithArgoApplication[];
108-
deleteArgoApplication: ({
109-
argoApplication,
110-
}: {
111-
argoApplication: ApplicationKubeObjectInterface;
112-
}) => Promise<void>;
107+
setDeleteDialogOpen?: React.Dispatch<React.SetStateAction<boolean>>;
113108
}) => {
114109
const { CDPipeline } = useDataContext();
115110
const {
@@ -348,27 +343,8 @@ export const useConfigurationHandlers = ({
348343
}, [handleClean, setDialog]);
349344

350345
const handleClickUninstall = React.useCallback(async () => {
351-
for (const enrichedApplication of enrichedApplicationsWithArgoApplications) {
352-
const appName = enrichedApplication.application.metadata.name;
353-
354-
if (!selected.includes(appName)) {
355-
continue;
356-
}
357-
358-
const argoApplication = enrichedApplicationsByApplicationName.get(appName)?.argoApplication;
359-
360-
await deleteArgoApplication({
361-
argoApplication,
362-
});
363-
}
364-
setSelected([]);
365-
}, [
366-
deleteArgoApplication,
367-
enrichedApplicationsByApplicationName,
368-
enrichedApplicationsWithArgoApplications,
369-
selected,
370-
setSelected,
371-
]);
346+
setDeleteDialogOpen(true);
347+
}, [setDeleteDialogOpen]);
372348

373349
return {
374350
handleClickDeploy,

src/pages/stage-details/components/Applications/index.tsx

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useCreateArgoApplication } from '../../../../k8s/groups/ArgoCD/Applicat
1212
import { APPLICATIONS_TABLE_MODE } from '../../constants';
1313
import { usePermissionsContext } from '../../providers/Permissions/hooks';
1414
import { EnrichedApplicationWithArgoApplication } from '../../types';
15+
import { ApplicationsMultiDeletion } from '../ApplicationsMultiDeletion';
1516
import { useButtonsEnabledMap } from './hooks/useButtonsEnabled';
1617
import { useColumns } from './hooks/useColumns';
1718
import { useConfigurationHandlers } from './hooks/useConfigurationHandlers';
@@ -25,6 +26,10 @@ export const Applications = ({
2526
}: ApplicationsProps) => {
2627
const permissions = usePermissionsContext();
2728

29+
const allArgoApplications = enrichedApplicationsWithArgoApplications?.map(
30+
({ argoApplication }) => argoApplication
31+
);
32+
2833
const enrichedApplicationsByApplicationName = React.useMemo(() => {
2934
return (
3035
enrichedApplicationsWithArgoApplications &&
@@ -46,7 +51,9 @@ export const Applications = ({
4651
);
4752

4853
const [selected, setSelected] = React.useState<string[]>([]);
54+
4955
const [mode, setMode] = React.useState<ApplicationsTableMode>(APPLICATIONS_TABLE_MODE.PREVIEW);
56+
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
5057

5158
const toggleMode = () =>
5259
mode === APPLICATIONS_TABLE_MODE.PREVIEW
@@ -74,8 +81,8 @@ export const Applications = ({
7481
setSelected,
7582
enrichedApplicationsByApplicationName,
7683
enrichedApplicationsWithArgoApplications,
77-
deleteArgoApplication,
7884
values,
85+
setDeleteDialogOpen,
7986
});
8087

8188
const buttonsEnabledMap = useButtonsEnabledMap({
@@ -239,6 +246,17 @@ export const Applications = ({
239246
}
240247
>
241248
<Table<EnrichedApplicationWithArgoApplication> {..._TableProps} />
249+
<ApplicationsMultiDeletion
250+
applications={allArgoApplications}
251+
selected={selected}
252+
open={deleteDialogOpen}
253+
handleClose={() => setDeleteDialogOpen(false)}
254+
onDelete={() => {
255+
setSelected([]);
256+
setDeleteDialogOpen(false);
257+
}}
258+
deleteArgoApplication={deleteArgoApplication}
259+
/>
242260
</TabSection>
243261
);
244262
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import {
2+
Button,
3+
Dialog,
4+
DialogActions,
5+
DialogContent,
6+
DialogTitle,
7+
Table,
8+
TableBody,
9+
TableCell,
10+
TableHead,
11+
TableRow,
12+
TextField,
13+
} from '@mui/material';
14+
import React from 'react';
15+
import { APPLICATION_LABEL_SELECTOR_APP_NAME } from '../../../../k8s/groups/ArgoCD/Application/labels';
16+
import { ApplicationMultiDeletionProps } from './types';
17+
18+
const CONFIRM_TEXT_VALUE = 'confirm';
19+
20+
export const ApplicationsMultiDeletion = ({
21+
applications,
22+
open,
23+
handleClose,
24+
selected,
25+
onDelete,
26+
deleteArgoApplication,
27+
}: ApplicationMultiDeletionProps) => {
28+
const [value, setValue] = React.useState('');
29+
30+
const deletionDisabled = value !== CONFIRM_TEXT_VALUE;
31+
32+
const selectedApplications = React.useMemo(
33+
() =>
34+
applications?.filter((application) =>
35+
selected.includes(application?.metadata?.labels?.[APPLICATION_LABEL_SELECTOR_APP_NAME])
36+
),
37+
[applications, selected]
38+
);
39+
40+
const handleDelete = React.useCallback(() => {
41+
if (deletionDisabled || !selectedApplications || !selectedApplications.length) {
42+
return;
43+
}
44+
45+
selectedApplications.forEach((application) => {
46+
deleteArgoApplication({ argoApplication: application });
47+
});
48+
49+
setValue('');
50+
51+
if (onDelete) {
52+
onDelete();
53+
}
54+
}, [deleteArgoApplication, deletionDisabled, onDelete, selectedApplications]);
55+
56+
return (
57+
<Dialog open={open} onClose={handleClose}>
58+
<DialogTitle>Are you sure you want to delete the selected applications?</DialogTitle>
59+
<DialogContent sx={{ pt: '20px !important' }}>
60+
<Table sx={{ mb: (t) => t.typography.pxToRem(20) }}>
61+
<TableHead>
62+
<TableRow>
63+
<TableCell>Application name</TableCell>
64+
<TableCell>ArgoCD Application name</TableCell>
65+
</TableRow>
66+
</TableHead>
67+
<TableBody>
68+
{selectedApplications &&
69+
selectedApplications?.map((application, index) => (
70+
<TableRow key={index}>
71+
<TableCell>
72+
{application?.metadata?.labels?.[APPLICATION_LABEL_SELECTOR_APP_NAME]}
73+
</TableCell>
74+
<TableCell>{application?.metadata.name}</TableCell>
75+
</TableRow>
76+
))}
77+
</TableBody>
78+
</Table>
79+
<TextField
80+
label={`Enter "${CONFIRM_TEXT_VALUE}" to start deletion`}
81+
value={value}
82+
onChange={(e) => setValue(e.target.value)}
83+
variant="outlined"
84+
fullWidth
85+
/>
86+
</DialogContent>
87+
<DialogActions>
88+
<Button onClick={handleClose}>Cancel</Button>
89+
<Button onClick={handleDelete} disabled={deletionDisabled} color="primary">
90+
Delete
91+
</Button>
92+
</DialogActions>
93+
</Dialog>
94+
);
95+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApplicationKubeObjectInterface } from '../../../../k8s/groups/ArgoCD/Application/types';
2+
3+
export interface ApplicationMultiDeletionProps {
4+
applications: ApplicationKubeObjectInterface[];
5+
selected: string[];
6+
open: boolean;
7+
handleClose: () => void;
8+
onDelete: () => void;
9+
deleteArgoApplication: ({ argoApplication }) => Promise<void>;
10+
}

src/widgets/AIChat/components/Chat/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export const Chat = ({
219219
setIsRequestLoading(true);
220220
},
221221
onFinish: (data) => {
222-
console.log('finish', data);
222+
// console.log('finish', data);
223223
},
224224
onError: (error) => console.log('error', error),
225225
});

src/widgets/AIChat/hooks/useStreaming.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const useStreaming = <I, A, C>({
9292
} catch (error) {
9393
// Request was aborted by user
9494
// if (error.name === ABORT_ERROR) return handleAbort(chat, reader);
95-
console.log(error.name);
95+
// console.log(error.name);
9696
throw error;
9797
}
9898
}

src/widgets/ManageCodeMie/components/CodemieProjectSettings/fields/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ export * from './Alias';
22
export * from './TokenName';
33
export * from './Type';
44
export * from './URL';
5-
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './Token';
2-

0 commit comments

Comments
 (0)