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
Showing
10 changed files
with
172 additions
and
9 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
frontend/packages/kubevirt-plugin/src/components/modals/vm-status-modal/index.ts
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 @@ | ||
export * from './vm-status-modal'; |
58 changes: 58 additions & 0 deletions
58
frontend/packages/kubevirt-plugin/src/components/modals/vm-status-modal/vm-status-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 { Modal } from '@patternfly/react-core'; | ||
import { HandlePromiseProps, withHandlePromise } from '@console/internal/components/utils'; | ||
import { ModalComponentProps } from '@console/internal/components/factory'; | ||
import { ModalFooter } from '../modal/modal-footer'; | ||
import { PAUSED_VM_MODAL_MESSAGE } from '../../../constants/vm'; | ||
import { VMIKind } from '../../../types'; | ||
import { unpauseVM } from '../../../k8s/requests/vmi/actions'; | ||
|
||
const modalTitle = 'Edit pause state'; | ||
|
||
const VMStatusModal = withHandlePromise<VMStatusModalProps>( | ||
({ vmi, isOpen, setOpen, title = modalTitle, handlePromise, inProgress, errorMessage }) => { | ||
const [showPatchError, setPatchError] = React.useState<boolean>(false); | ||
|
||
const onSubmit = async (event) => { | ||
event.preventDefault(); | ||
|
||
const promise = unpauseVM(vmi); | ||
handlePromise(promise) | ||
.then(() => setOpen(false)) | ||
.catch(() => setPatchError(true)); | ||
}; | ||
|
||
const footer = ( | ||
<ModalFooter | ||
errorMessage={showPatchError && errorMessage} | ||
inProgress={inProgress} | ||
onSubmit={onSubmit} | ||
onCancel={() => setOpen(false)} | ||
submitButtonText="Unpause" | ||
/> | ||
); | ||
|
||
return ( | ||
<Modal | ||
title={title} | ||
isOpen={isOpen} | ||
isSmall | ||
onClose={() => setOpen(false)} | ||
footer={footer} | ||
isFooterLeftAligned | ||
> | ||
<div>{PAUSED_VM_MODAL_MESSAGE}</div> | ||
</Modal> | ||
); | ||
}, | ||
); | ||
|
||
export type VMStatusModalProps = HandlePromiseProps & | ||
ModalComponentProps & { | ||
vmi: VMIKind; | ||
title?: string; | ||
isOpen: boolean; | ||
setOpen: (isOpen: boolean) => void; | ||
}; | ||
|
||
export default VMStatusModal; |
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
32 changes: 32 additions & 0 deletions
32
frontend/packages/kubevirt-plugin/src/k8s/requests/vmi/actions.ts
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,32 @@ | ||
import { coFetch } from '@console/internal/co-fetch'; | ||
import { resourceURL } from '@console/internal/module/k8s'; | ||
import { getName, getNamespace } from '@console/shared'; | ||
import { VirtualMachineInstanceModel } from '../../../models'; | ||
import { VMIKind } from '../../../types/vm'; | ||
|
||
export enum VMIActionType { | ||
Unpause = 'unpause', | ||
} | ||
|
||
const VMIActionRequest = async (vm: VMIKind, action: VMIActionType) => { | ||
const method = 'PUT'; | ||
let url = resourceURL( | ||
{ | ||
...VirtualMachineInstanceModel, | ||
apiGroup: `subresources.${VirtualMachineInstanceModel.apiGroup}`, | ||
}, | ||
{ | ||
ns: getNamespace(vm), | ||
name: getName(vm), | ||
}, | ||
); | ||
|
||
url = `${url}/${action}`; | ||
|
||
const response = await coFetch(url, { method }); | ||
const text = await response.text(); | ||
|
||
return text; | ||
}; | ||
|
||
export const unpauseVM = async (vmi: VMIKind) => VMIActionRequest(vmi, VMIActionType.Unpause); |
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