-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a011b1b
commit 132dafe
Showing
5 changed files
with
168 additions
and
26 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
58 changes: 58 additions & 0 deletions
58
frontend/src/pages/connectionTypes/DeleteConnectionTypeModal.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,58 @@ | ||
import React from 'react'; | ||
import { ConnectionTypeConfigMapObj } from '~/concepts/connectionTypes/types'; | ||
import { getDisplayNameFromK8sResource } from '~/concepts/k8s/utils'; | ||
import DeleteModal from '~/pages/projects/components/DeleteModal'; | ||
import { deleteConnectionType } from '~/services/connectionTypesService'; | ||
|
||
type DeleteConnectionTypeModalProps = { | ||
connectionType?: ConnectionTypeConfigMapObj; | ||
onClose: (deleted: boolean) => void; | ||
}; | ||
|
||
const DeleteConnectionTypeModal: React.FC<DeleteConnectionTypeModalProps> = ({ | ||
connectionType, | ||
onClose, | ||
}) => { | ||
const [isDeleting, setIsDeleting] = React.useState(false); | ||
const [error, setError] = React.useState<Error | undefined>(); | ||
|
||
const onBeforeClose = (deleted: boolean) => { | ||
onClose(deleted); | ||
setIsDeleting(false); | ||
setError(undefined); | ||
}; | ||
|
||
const deleteName = connectionType | ||
? getDisplayNameFromK8sResource(connectionType) | ||
: 'this connection type'; | ||
|
||
return ( | ||
<DeleteModal | ||
title="Delete connection type?" | ||
isOpen={!!connectionType} | ||
onClose={() => onBeforeClose(false)} | ||
submitButtonLabel="Delete" | ||
onDelete={() => { | ||
if (connectionType) { | ||
setIsDeleting(true); | ||
deleteConnectionType(connectionType.metadata.name) | ||
.then(() => { | ||
onBeforeClose(true); | ||
}) | ||
.catch((e) => { | ||
setError(e); | ||
setIsDeleting(false); | ||
}); | ||
} | ||
}} | ||
deleting={isDeleting} | ||
error={error} | ||
deleteName={deleteName} | ||
> | ||
The <b>{deleteName}</b> connection type will be deleted. Existing connections of this type | ||
will not be affected. | ||
</DeleteModal> | ||
); | ||
}; | ||
|
||
export default DeleteConnectionTypeModal; |