-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alert when stoping a vm with logged in users
- Loading branch information
Showing
9 changed files
with
344 additions
and
74 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
.../packages/kubevirt-plugin/src/components/modals/menu-actions-modals/confirm-vmi-modal.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,69 @@ | ||
import * as React from 'react'; | ||
import { HandlePromiseProps, withHandlePromise } from '@console/internal/components/utils'; | ||
import { | ||
createModalLauncher, | ||
ModalTitle, | ||
ModalBody, | ||
ModalSubmitFooter, | ||
ModalComponentProps, | ||
} from '@console/internal/components/factory'; | ||
import { VMIKind } from '../../../types'; | ||
import { VMIUsersAlert } from './vmi-users-alert'; | ||
import { redirectAfterVMDeletion } from './utils'; | ||
|
||
export const ConfirmVMIModal = withHandlePromise((props: ConfirmVMIModalProps) => { | ||
const { | ||
inProgress, | ||
errorMessage, | ||
handlePromise, | ||
close, | ||
cancel, | ||
vmi, | ||
title, | ||
message, | ||
executeFn, | ||
btnText, | ||
cancelText, | ||
alertTitle, | ||
submitDanger, | ||
} = props; | ||
|
||
const submit = (e) => { | ||
e.preventDefault(); | ||
|
||
return handlePromise(executeFn()) | ||
.then(close) | ||
.then(() => redirectAfterVMDeletion(vmi)); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={submit} className="modal-content"> | ||
<ModalTitle>{title}</ModalTitle> | ||
<ModalBody>{message}</ModalBody> | ||
<VMIUsersAlert vmi={vmi} cancel={cancel} alertTitle={alertTitle} /> | ||
<ModalSubmitFooter | ||
errorMessage={errorMessage} | ||
submitDisabled={inProgress} | ||
inProgress={inProgress} | ||
submitText={btnText || 'Confirm'} | ||
submitDanger={submitDanger} | ||
cancel={cancel} | ||
cancelText={cancelText || 'Cancel'} | ||
/> | ||
</form> | ||
); | ||
}); | ||
|
||
export type ConfirmVMIModalProps = { | ||
vmi: VMIKind; | ||
message: React.ReactNode | string; | ||
title: React.ReactNode | string; | ||
executeFn: () => Promise<any>; | ||
btnText?: React.ReactNode | string; | ||
cancelText?: React.ReactNode | string; | ||
alertTitle?: string; | ||
submitDanger?: boolean; | ||
} & ModalComponentProps & | ||
HandlePromiseProps; | ||
|
||
export const confirmVMIModal = createModalLauncher(ConfirmVMIModal); |
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
107 changes: 107 additions & 0 deletions
107
...es/kubevirt-plugin/src/components/modals/menu-actions-modals/delete-vm-template-modal.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,107 @@ | ||
import * as React from 'react'; | ||
import { HandlePromiseProps, history, withHandlePromise } from '@console/internal/components/utils'; | ||
import { YellowExclamationTriangleIcon } from '@console/shared/src/components/status/icons'; | ||
import { getName, getNamespace } from '@console/shared/src/selectors/common'; | ||
import { | ||
createModalLauncher, | ||
ModalTitle, | ||
ModalBody, | ||
ModalSubmitFooter, | ||
ModalComponentProps, | ||
} from '@console/internal/components/factory'; | ||
import { TemplateModel } from '@console/internal/models'; | ||
import { apiVersionForModel, TemplateKind } from '@console/internal/module/k8s'; | ||
import { asVM, getVolumes } from '../../../selectors/vm'; | ||
import { useOwnedVolumeReferencedResources } from '../../../hooks/use-owned-volume-referenced-resources'; | ||
import { useUpToDateVMLikeEntity } from '../../../hooks/use-vm-like-entity'; | ||
import { deleteVMTemplate } from '../../../k8s/requests/vmtemplate/actions'; | ||
|
||
const redirectAfterDeletion = (vmLikeEntity: TemplateKind) => { | ||
// If we are currently on the deleted resource's page, redirect to the resource list page | ||
const re = new RegExp(`/${getName(vmLikeEntity)}(/|$)`); | ||
if (re.test(window.location.pathname)) { | ||
history.push(`/k8s/ns/${getNamespace(vmLikeEntity)}/virtualization/templates`); | ||
} | ||
}; | ||
|
||
export const DeleteVMTemplateModal = withHandlePromise((props: DeleteVMTemplateModalProps) => { | ||
const { inProgress, errorMessage, handlePromise, close, cancel, vmTemplate } = props; | ||
const vmTemplateUpToDate = useUpToDateVMLikeEntity<TemplateKind>(vmTemplate); | ||
const [deleteDisks, setDeleteDisks] = React.useState<boolean>(true); | ||
|
||
const namespace = getNamespace(vmTemplateUpToDate); | ||
const name = getName(vmTemplateUpToDate); | ||
|
||
const vmTemplateReference = { | ||
name, | ||
kind: TemplateModel.kind, | ||
apiVersion: apiVersionForModel(TemplateModel), | ||
} as any; | ||
|
||
const [ownedVolumeResources, isOwnedVolumeResourcesLoaded] = useOwnedVolumeReferencedResources( | ||
vmTemplateReference, | ||
namespace, | ||
getVolumes(asVM(vmTemplateUpToDate), null), | ||
); | ||
const isInProgress = inProgress || !isOwnedVolumeResourcesLoaded; | ||
const numOfAllResources = ownedVolumeResources.length; | ||
|
||
const submit = (e) => { | ||
e.preventDefault(); | ||
|
||
const promise = deleteVMTemplate(vmTemplateUpToDate, { | ||
ownedVolumeResources, | ||
deleteOwnedVolumeResources: deleteDisks, | ||
}); | ||
|
||
return handlePromise(promise) | ||
.then(close) | ||
.then(() => redirectAfterDeletion(vmTemplateUpToDate)); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={submit} className="modal-content"> | ||
<ModalTitle> | ||
<YellowExclamationTriangleIcon className="co-icon-space-r" /> Delete Virtual Machine | ||
Template? | ||
</ModalTitle> | ||
<ModalBody> | ||
Are you sure you want to delete <strong className="co-break-word">{name}</strong> in | ||
namespace <strong>{namespace}</strong>? | ||
{numOfAllResources > 0 && ( | ||
<p> | ||
The following resources will be deleted along with this virtual machine. Unchecked items | ||
will not be deleted. | ||
</p> | ||
)} | ||
{ownedVolumeResources.length > 0 && ( | ||
<div className="checkbox"> | ||
<label className="control-label"> | ||
<input | ||
type="checkbox" | ||
onChange={() => setDeleteDisks(!deleteDisks)} | ||
checked={deleteDisks} | ||
/> | ||
Delete Disks ({ownedVolumeResources.length}x) | ||
</label> | ||
</div> | ||
)} | ||
</ModalBody> | ||
<ModalSubmitFooter | ||
errorMessage={errorMessage} | ||
submitDisabled={isInProgress} | ||
inProgress={isInProgress} | ||
submitText="Delete" | ||
submitDanger | ||
cancel={cancel} | ||
/> | ||
</form> | ||
); | ||
}); | ||
|
||
export type DeleteVMTemplateModalProps = { | ||
vmTemplate: TemplateKind; | ||
} & ModalComponentProps & | ||
HandlePromiseProps; | ||
|
||
export const deleteVMTemplateModal = createModalLauncher(DeleteVMTemplateModal); |
58 changes: 58 additions & 0 deletions
58
...d/packages/kubevirt-plugin/src/components/modals/menu-actions-modals/delete-vmi-modal.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 * as React from 'react'; | ||
import { k8sKill } from '@console/internal/module/k8s'; | ||
import { HandlePromiseProps, withHandlePromise } from '@console/internal/components/utils'; | ||
import { YellowExclamationTriangleIcon } from '@console/shared/src/components/status/icons'; | ||
import { getName, getNamespace } from '@console/shared/src/selectors/common'; | ||
import { | ||
createModalLauncher, | ||
ModalTitle, | ||
ModalBody, | ||
ModalSubmitFooter, | ||
ModalComponentProps, | ||
} from '@console/internal/components/factory'; | ||
import { VMIKind } from '../../../types'; | ||
import { VirtualMachineInstanceModel } from '../../../models'; | ||
import { redirectAfterVMDeletion } from './utils'; | ||
|
||
export const DeleteVMIModal = withHandlePromise((props: DeleteVMIProps) => { | ||
const { inProgress, errorMessage, handlePromise, close, cancel, vmi } = props; | ||
|
||
const namespace = getNamespace(vmi); | ||
const name = getName(vmi); | ||
|
||
const submit = (e) => { | ||
e.preventDefault(); | ||
|
||
return handlePromise(k8sKill(VirtualMachineInstanceModel, vmi)) | ||
.then(close) | ||
.then(() => redirectAfterVMDeletion(vmi)); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={submit} className="modal-content"> | ||
<ModalTitle> | ||
<YellowExclamationTriangleIcon className="co-icon-space-r" /> Delete Virtual Machine | ||
Instanse ? | ||
</ModalTitle> | ||
<ModalBody> | ||
Are you sure you want to delete <strong className="co-break-word">{name}</strong> in | ||
namespace <strong>{namespace}</strong>? | ||
</ModalBody> | ||
<ModalSubmitFooter | ||
errorMessage={errorMessage} | ||
submitDisabled={inProgress} | ||
inProgress={inProgress} | ||
submitText="Delete" | ||
submitDanger | ||
cancel={cancel} | ||
/> | ||
</form> | ||
); | ||
}); | ||
|
||
export type DeleteVMIProps = { | ||
vmi: VMIKind; | ||
} & ModalComponentProps & | ||
HandlePromiseProps; | ||
|
||
export const deleteVMIModal = createModalLauncher(DeleteVMIModal); |
3 changes: 3 additions & 0 deletions
3
...d/packages/kubevirt-plugin/src/components/modals/menu-actions-modals/vmi-users-alert.scss
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,3 @@ | ||
.kubevirt-confirm-vmi-model__alert { | ||
padding: 0 var(--pf-global--spacer--xl) 0; | ||
} |
Oops, something went wrong.