-
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
371 additions
and
66 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...packages/kubevirt-plugin/src/components/modals/menu-actions-modals/confirm-vmi-modal.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; | ||
} |
79 changes: 79 additions & 0 deletions
79
.../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,79 @@ | ||
import * as React from 'react'; | ||
import { HandlePromiseProps, history, withHandlePromise } from '@console/internal/components/utils'; | ||
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 { VMIUsersAlert } from './vmi-users-alert'; | ||
|
||
import './confirm-vmi-modal.scss'; | ||
|
||
const redirectFn = (vmi: VMIKind) => { | ||
// If we are currently on the deleted resource's page, redirect to the resource list page | ||
const re = new RegExp(`/${getName(vmi)}(/|$)`); | ||
if (re.test(window.location.pathname)) { | ||
history.push(`/k8s/ns/${getNamespace(vmi)}/virtualization`); | ||
} | ||
}; | ||
|
||
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(() => redirectFn(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 redirectFn = (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 vmLikeEntity = useUpToDateVMLikeEntity<TemplateKind>(vmTemplate); | ||
const [deleteDisks, setDeleteDisks] = React.useState<boolean>(true); | ||
|
||
const namespace = getNamespace(vmLikeEntity); | ||
const name = getName(vmLikeEntity); | ||
|
||
const vmLikeReference = { | ||
name, | ||
kind: TemplateModel.kind, | ||
apiVersion: apiVersionForModel(TemplateModel), | ||
} as any; | ||
|
||
const [ownedVolumeResources, isOwnedVolumeResourcesLoaded] = useOwnedVolumeReferencedResources( | ||
vmLikeReference, | ||
namespace, | ||
getVolumes(asVM(vmLikeEntity), null), | ||
); | ||
const isInProgress = inProgress || !isOwnedVolumeResourcesLoaded; | ||
const numOfAllResources = ownedVolumeResources.length; | ||
|
||
const submit = (e) => { | ||
e.preventDefault(); | ||
|
||
const promise = deleteVMTemplate(vmLikeEntity, { | ||
ownedVolumeResources, | ||
deleteOwnedVolumeResources: deleteDisks, | ||
}); | ||
|
||
return handlePromise(promise) | ||
.then(close) | ||
.then(() => redirectFn(vmLikeEntity)); | ||
}; | ||
|
||
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); |
65 changes: 65 additions & 0 deletions
65
...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,65 @@ | ||
import * as React from 'react'; | ||
import { k8sKill } from '@console/internal/module/k8s'; | ||
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 { VMIKind } from '../../../types'; | ||
import { VirtualMachineInstanceModel } from '../../../models'; | ||
|
||
const redirectFn = (vmi: VMIKind) => { | ||
// If we are currently on the deleted resource's page, redirect to the resource list page | ||
const re = new RegExp(`/${getName(vmi)}(/|$)`); | ||
if (re.test(window.location.pathname)) { | ||
history.push(`/k8s/ns/${getNamespace(vmi)}/virtualization`); | ||
} | ||
}; | ||
|
||
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(() => redirectFn(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); |
Oops, something went wrong.