Skip to content

Commit

Permalink
diable delete is some assosiated resource exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mrCherry97 committed Jan 14, 2025
1 parent 495cbd4 commit 3b648d7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 70 deletions.
15 changes: 15 additions & 0 deletions src/components/KymaModules/KymaModulesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<DeleteMessageBox
disableDeleteButton={checkIfAssociatedResourceLeft()}
additionalDeleteInfo={
getAssciatedResources().length > 0 && (
<>
Expand Down
144 changes: 74 additions & 70 deletions src/shared/hooks/useDeleteResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,79 +174,83 @@ export function useDeleteResource({
resourceUrl,
deleteFn,
additionalDeleteInfo,
}) => (
<MessageBox
type="Warning"
titleText={t(
resourceIsCluster
? 'common.delete-dialog.disconnect-title'
: 'common.delete-dialog.delete-title',
{
type: prettifiedResourceName,
},
)}
open={showDeleteDialog}
className="ui5-content-density-compact"
actions={[
<Button
key="delete-confirmation"
data-testid="delete-confirmation"
design="Emphasized"
onClick={() => performDelete(resource, resourceUrl, deleteFn)}
disableDeleteButton = false,
}) => {
return (
<MessageBox
type="Warning"
titleText={t(
resourceIsCluster
? 'common.delete-dialog.disconnect-title'
: 'common.delete-dialog.delete-title',
{
type: prettifiedResourceName,
},
)}
open={showDeleteDialog}
className="ui5-content-density-compact"
actions={[
<Button
key="delete-confirmation"
data-testid="delete-confirmation"
design="Emphasized"
onClick={() => performDelete(resource, resourceUrl, deleteFn)}
disabled={disableDeleteButton}
>
{t(
resourceIsCluster
? 'common.buttons.disconnect'
: 'common.buttons.delete',
)}
</Button>,
<Button
key="delete-cancel"
data-testid="delete-cancel"
design="Transparent"
onClick={() => setShowDeleteDialog(false)}
>
{t('common.buttons.cancel')}
</Button>,
]}
onClose={closeDeleteDialog}
>
<FlexBox
direction="Column"
style={{
gap: '10px',
padding: '15px 25px',
}}
>
{t(
resourceIsCluster
? 'common.buttons.disconnect'
: 'common.buttons.delete',
<Text style={{ paddingLeft: '7.5px' }}>
{t(
resourceIsCluster
? 'common.delete-dialog.disconnect-message'
: 'common.delete-dialog.delete-message',
{
type: prettifiedResourceName,
name: resourceTitle || resource?.metadata?.name,
},
)}
</Text>
{additionalDeleteInfo && (
<Text style={{ paddingLeft: '7.5px' }}>{additionalDeleteInfo}</Text>
)}
</Button>,
<Button
key="delete-cancel"
data-testid="delete-cancel"
design="Transparent"
onClick={() => setShowDeleteDialog(false)}
>
{t('common.buttons.cancel')}
</Button>,
]}
onClose={closeDeleteDialog}
>
<FlexBox
direction="Column"
style={{
gap: '10px',
padding: '15px 25px',
}}
>
<Text style={{ paddingLeft: '7.5px' }}>
{t(
resourceIsCluster
? 'common.delete-dialog.disconnect-message'
: 'common.delete-dialog.delete-message',
{
type: prettifiedResourceName,
name: resourceTitle || resource?.metadata?.name,
},
{!forceConfirmDelete && (
<CheckBox
checked={dontConfirmDelete}
onChange={() => setDontConfirmDelete(prevState => !prevState)}
text={t('common.delete-dialog.delete-confirm')}
/>
)}
</Text>
{additionalDeleteInfo && (
<Text style={{ paddingLeft: '7.5px' }}>{additionalDeleteInfo}</Text>
)}
{!forceConfirmDelete && (
<CheckBox
checked={dontConfirmDelete}
onChange={() => setDontConfirmDelete(prevState => !prevState)}
text={t('common.delete-dialog.delete-confirm')}
/>
)}
{dontConfirmDelete && !forceConfirmDelete && (
<MessageStrip design="Information" hideCloseButton>
{t('common.delete-dialog.information')}
</MessageStrip>
)}
</FlexBox>
</MessageBox>
);
{dontConfirmDelete && !forceConfirmDelete && (
<MessageStrip design="Information" hideCloseButton>
{t('common.delete-dialog.information')}
</MessageStrip>
)}
</FlexBox>
</MessageBox>
);
};

return [DeleteMessageBox, handleResourceDelete];
}

0 comments on commit 3b648d7

Please sign in to comment.