From 3b648d73944ca68b097c3aa9358c1927dd010ce2 Mon Sep 17 00:00:00 2001 From: mrCherry97 Date: Tue, 14 Jan 2025 12:00:00 +0100 Subject: [PATCH] diable delete is some assosiated resource exist --- src/components/KymaModules/KymaModulesList.js | 15 ++ src/shared/hooks/useDeleteResource.js | 144 +++++++++--------- 2 files changed, 89 insertions(+), 70 deletions(-) diff --git a/src/components/KymaModules/KymaModulesList.js b/src/components/KymaModules/KymaModulesList.js index 1020e733c3..4cff8449ac 100644 --- a/src/components/KymaModules/KymaModulesList.js +++ b/src/components/KymaModules/KymaModulesList.js @@ -444,11 +444,26 @@ export default function KymaModulesList({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [chosenModuleIndex]); + const checkIfAssociatedResourceLeft = () => { + const resources = getAssciatedResources(); + for (const resource of resources) { + if ( + resourceCounts[ + `${resource.kind}-${resource.group}-${resource.version}` + ] > 0 + ) { + return true; + } + } + return false; + }; + return ( <> {!detailsOpen && createPortal( 0 && ( <> diff --git a/src/shared/hooks/useDeleteResource.js b/src/shared/hooks/useDeleteResource.js index 38aaf11b8f..3b0c4deeb9 100644 --- a/src/shared/hooks/useDeleteResource.js +++ b/src/shared/hooks/useDeleteResource.js @@ -174,79 +174,83 @@ export function useDeleteResource({ resourceUrl, deleteFn, additionalDeleteInfo, - }) => ( - performDelete(resource, resourceUrl, deleteFn)} + disableDeleteButton = false, + }) => { + return ( + performDelete(resource, resourceUrl, deleteFn)} + disabled={disableDeleteButton} + > + {t( + resourceIsCluster + ? 'common.buttons.disconnect' + : 'common.buttons.delete', + )} + , + , + ]} + onClose={closeDeleteDialog} + > + - {t( - resourceIsCluster - ? 'common.buttons.disconnect' - : 'common.buttons.delete', + + {t( + resourceIsCluster + ? 'common.delete-dialog.disconnect-message' + : 'common.delete-dialog.delete-message', + { + type: prettifiedResourceName, + name: resourceTitle || resource?.metadata?.name, + }, + )} + + {additionalDeleteInfo && ( + {additionalDeleteInfo} )} - , - , - ]} - onClose={closeDeleteDialog} - > - - - {t( - resourceIsCluster - ? 'common.delete-dialog.disconnect-message' - : 'common.delete-dialog.delete-message', - { - type: prettifiedResourceName, - name: resourceTitle || resource?.metadata?.name, - }, + {!forceConfirmDelete && ( + setDontConfirmDelete(prevState => !prevState)} + text={t('common.delete-dialog.delete-confirm')} + /> )} - - {additionalDeleteInfo && ( - {additionalDeleteInfo} - )} - {!forceConfirmDelete && ( - setDontConfirmDelete(prevState => !prevState)} - text={t('common.delete-dialog.delete-confirm')} - /> - )} - {dontConfirmDelete && !forceConfirmDelete && ( - - {t('common.delete-dialog.information')} - - )} - - - ); + {dontConfirmDelete && !forceConfirmDelete && ( + + {t('common.delete-dialog.information')} + + )} + + + ); + }; return [DeleteMessageBox, handleResourceDelete]; }