-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ArgoApp delete confirmation (#321)
- Loading branch information
1 parent
3d025a5
commit 3c55435
Showing
11 changed files
with
137 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/pages/stage-details/components/ApplicationsMultiDeletion/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableRow, | ||
TextField, | ||
} from '@mui/material'; | ||
import React from 'react'; | ||
import { APPLICATION_LABEL_SELECTOR_APP_NAME } from '../../../../k8s/groups/ArgoCD/Application/labels'; | ||
import { ApplicationMultiDeletionProps } from './types'; | ||
|
||
const CONFIRM_TEXT_VALUE = 'confirm'; | ||
|
||
export const ApplicationsMultiDeletion = ({ | ||
applications, | ||
open, | ||
handleClose, | ||
selected, | ||
onDelete, | ||
deleteArgoApplication, | ||
}: ApplicationMultiDeletionProps) => { | ||
const [value, setValue] = React.useState(''); | ||
|
||
const deletionDisabled = value !== CONFIRM_TEXT_VALUE; | ||
|
||
const selectedApplications = React.useMemo( | ||
() => | ||
applications?.filter((application) => | ||
selected.includes(application?.metadata?.labels?.[APPLICATION_LABEL_SELECTOR_APP_NAME]) | ||
), | ||
[applications, selected] | ||
); | ||
|
||
const handleDelete = React.useCallback(() => { | ||
if (deletionDisabled || !selectedApplications || !selectedApplications.length) { | ||
return; | ||
} | ||
|
||
selectedApplications.forEach((application) => { | ||
deleteArgoApplication({ argoApplication: application }); | ||
}); | ||
|
||
setValue(''); | ||
|
||
if (onDelete) { | ||
onDelete(); | ||
} | ||
}, [deleteArgoApplication, deletionDisabled, onDelete, selectedApplications]); | ||
|
||
return ( | ||
<Dialog open={open} onClose={handleClose}> | ||
<DialogTitle>Are you sure you want to delete the selected applications?</DialogTitle> | ||
<DialogContent sx={{ pt: '20px !important' }}> | ||
<Table sx={{ mb: (t) => t.typography.pxToRem(20) }}> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Application name</TableCell> | ||
<TableCell>ArgoCD Application name</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{selectedApplications && | ||
selectedApplications?.map((application, index) => ( | ||
<TableRow key={index}> | ||
<TableCell> | ||
{application?.metadata?.labels?.[APPLICATION_LABEL_SELECTOR_APP_NAME]} | ||
</TableCell> | ||
<TableCell>{application?.metadata.name}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
<TextField | ||
label={`Enter "${CONFIRM_TEXT_VALUE}" to start deletion`} | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
variant="outlined" | ||
fullWidth | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={handleClose}>Cancel</Button> | ||
<Button onClick={handleDelete} disabled={deletionDisabled} color="primary"> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; |
10 changes: 10 additions & 0 deletions
10
src/pages/stage-details/components/ApplicationsMultiDeletion/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ApplicationKubeObjectInterface } from '../../../../k8s/groups/ArgoCD/Application/types'; | ||
|
||
export interface ApplicationMultiDeletionProps { | ||
applications: ApplicationKubeObjectInterface[]; | ||
selected: string[]; | ||
open: boolean; | ||
handleClose: () => void; | ||
onDelete: () => void; | ||
deleteArgoApplication: ({ argoApplication }) => Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ export * from './Alias'; | |
export * from './TokenName'; | ||
export * from './Type'; | ||
export * from './URL'; | ||
|
1 change: 0 additions & 1 deletion
1
src/widgets/ManageCodeMie/components/CodemieProjectSettingsSecret/fields/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './Token'; | ||
|