-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2091 from upalatucci/refactor-diskmodal
CNV-44890: Refactor diskmodal
- Loading branch information
Showing
53 changed files
with
1,616 additions
and
1,394 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { FC } from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
|
||
import { getNamespace } from '@kubevirt-utils/resources/shared'; | ||
import { isEmpty } from '@kubevirt-utils/utils/utils'; | ||
import { Form } from '@patternfly/react-core'; | ||
import { isRunning } from '@virtualmachines/utils'; | ||
|
||
import TabModal from '../TabModal/TabModal'; | ||
|
||
import AdvancedSettings from './components/AdvancedSettings/AdvancedSettings'; | ||
import BootSourceCheckbox from './components/BootSourceCheckbox/BootSourceCheckbox'; | ||
import DiskInterfaceSelect from './components/DiskInterfaceSelect/DiskInterfaceSelect'; | ||
import DiskNameInput from './components/DiskNameInput/DiskNameInput'; | ||
import DiskSizeInput from './components/DiskSizeInput/DiskSizeInput'; | ||
import DiskTypeSelect from './components/DiskTypeSelect/DiskTypeSelect'; | ||
import PendingChanges from './components/PendingChanges'; | ||
import StorageClassAndPreallocation from './components/StorageClassAndPreallocation/StorageClassAndPreallocation'; | ||
import { getDefaultCreateValues, getDefaultEditValues } from './utils/form'; | ||
import { diskModalTitle } from './utils/helpers'; | ||
import { submit } from './utils/submit'; | ||
import { SourceTypes, V1DiskFormState, V1DiskModalProps } from './utils/types'; | ||
|
||
const BlankDiskModal: FC<V1DiskModalProps> = ({ | ||
editDiskName, | ||
isCreated, | ||
isOpen, | ||
onClose, | ||
onSubmit, | ||
vm, | ||
}) => { | ||
const isVMRunning = isRunning(vm); | ||
|
||
const isEditDisk = !isEmpty(editDiskName); | ||
|
||
const methods = useForm<V1DiskFormState>({ | ||
defaultValues: isEditDisk | ||
? getDefaultEditValues(vm, editDiskName) | ||
: getDefaultCreateValues(vm, SourceTypes.BLANK), | ||
mode: 'all', | ||
}); | ||
|
||
const { | ||
formState: { isSubmitting, isValid }, | ||
handleSubmit, | ||
} = methods; | ||
|
||
return ( | ||
<FormProvider {...methods}> | ||
<TabModal | ||
closeOnSubmit={isValid} | ||
headerText={diskModalTitle(isEditDisk, isVMRunning)} | ||
isLoading={isSubmitting} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
onSubmit={() => handleSubmit(async (data) => submit(data, vm, editDiskName, onSubmit))()} | ||
> | ||
<PendingChanges isVMRunning={isVMRunning} /> | ||
<Form> | ||
<BootSourceCheckbox editDiskName={editDiskName} isDisabled={isVMRunning} vm={vm} /> | ||
<DiskNameInput /> | ||
<DiskSizeInput isCreated={isCreated} namespace={getNamespace(vm)} /> | ||
<DiskTypeSelect isVMRunning={isVMRunning} /> | ||
<DiskInterfaceSelect isVMRunning={isVMRunning} /> | ||
{!isCreated && <StorageClassAndPreallocation vm={vm} />} | ||
<AdvancedSettings /> | ||
</Form> | ||
</TabModal> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
export default BlankDiskModal; |
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,75 @@ | ||
import React, { FC } from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
|
||
import { getNamespace } from '@kubevirt-utils/resources/shared'; | ||
import { isEmpty } from '@kubevirt-utils/utils/utils'; | ||
import { Form } from '@patternfly/react-core'; | ||
import { isRunning } from '@virtualmachines/utils'; | ||
|
||
import TabModal from '../TabModal/TabModal'; | ||
|
||
import AdvancedSettings from './components/AdvancedSettings/AdvancedSettings'; | ||
import BootSourceCheckbox from './components/BootSourceCheckbox/BootSourceCheckbox'; | ||
import DiskInterfaceSelect from './components/DiskInterfaceSelect/DiskInterfaceSelect'; | ||
import DiskNameInput from './components/DiskNameInput/DiskNameInput'; | ||
import DiskSizeInput from './components/DiskSizeInput/DiskSizeInput'; | ||
import DiskSourceClonePVCSelect from './components/DiskSourceSelect/components/DiskSourceClonePVCSelect/DiskSourceClonePVCSelect'; | ||
import DiskTypeSelect from './components/DiskTypeSelect/DiskTypeSelect'; | ||
import PendingChanges from './components/PendingChanges'; | ||
import StorageClassAndPreallocation from './components/StorageClassAndPreallocation/StorageClassAndPreallocation'; | ||
import { getDefaultCreateValues, getDefaultEditValues } from './utils/form'; | ||
import { diskModalTitle } from './utils/helpers'; | ||
import { submit } from './utils/submit'; | ||
import { SourceTypes, V1DiskFormState, V1DiskModalProps } from './utils/types'; | ||
|
||
const ClonePVCDiskModal: FC<V1DiskModalProps> = ({ | ||
editDiskName, | ||
isCreated, | ||
isOpen, | ||
onClose, | ||
onSubmit, | ||
vm, | ||
}) => { | ||
const isVMRunning = isRunning(vm); | ||
|
||
const isEditDisk = !isEmpty(editDiskName); | ||
|
||
const methods = useForm<V1DiskFormState>({ | ||
defaultValues: isEditDisk | ||
? getDefaultEditValues(vm, editDiskName) | ||
: getDefaultCreateValues(vm, SourceTypes.CLONE_PVC), | ||
mode: 'all', | ||
}); | ||
|
||
const { | ||
formState: { isSubmitting, isValid }, | ||
handleSubmit, | ||
} = methods; | ||
|
||
return ( | ||
<FormProvider {...methods}> | ||
<TabModal | ||
closeOnSubmit={isValid} | ||
headerText={diskModalTitle(isEditDisk, isVMRunning)} | ||
isLoading={isSubmitting} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
onSubmit={() => handleSubmit(async (data) => submit(data, vm, editDiskName, onSubmit))()} | ||
> | ||
<PendingChanges isVMRunning={isVMRunning} /> | ||
<Form> | ||
<BootSourceCheckbox editDiskName={editDiskName} isDisabled={isVMRunning} vm={vm} /> | ||
<DiskNameInput /> | ||
{!isCreated && <DiskSourceClonePVCSelect />} | ||
<DiskSizeInput isCreated={isCreated} namespace={getNamespace(vm)} /> | ||
<DiskTypeSelect isVMRunning={isVMRunning} /> | ||
<DiskInterfaceSelect isVMRunning={isVMRunning} /> | ||
{!isCreated && <StorageClassAndPreallocation vm={vm} />} | ||
<AdvancedSettings /> | ||
</Form> | ||
</TabModal> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
export default ClonePVCDiskModal; |
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,73 @@ | ||
import React, { FC } from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
|
||
import { isEmpty } from '@kubevirt-utils/utils/utils'; | ||
import { Form } from '@patternfly/react-core'; | ||
import { isRunning } from '@virtualmachines/utils'; | ||
|
||
import TabModal from '../TabModal/TabModal'; | ||
|
||
import AdvancedSettings from './components/AdvancedSettings/AdvancedSettings'; | ||
import BootSourceCheckbox from './components/BootSourceCheckbox/BootSourceCheckbox'; | ||
import DiskInterfaceSelect from './components/DiskInterfaceSelect/DiskInterfaceSelect'; | ||
import DiskNameInput from './components/DiskNameInput/DiskNameInput'; | ||
import DynamicSize from './components/DiskSizeInput/DynamicSize'; | ||
import DiskSourceContainer from './components/DiskSourceSelect/components/DiskSourceContainer/DiskSourceContainer'; | ||
import DiskTypeSelect from './components/DiskTypeSelect/DiskTypeSelect'; | ||
import PendingChanges from './components/PendingChanges'; | ||
import { CONTAINERDISK_IMAGE_FIELD } from './components/utils/constants'; | ||
import { getDefaultCreateValues, getDefaultEditValues } from './utils/form'; | ||
import { diskModalTitle, getOS } from './utils/helpers'; | ||
import { submit } from './utils/submit'; | ||
import { SourceTypes, V1DiskFormState, V1DiskModalProps } from './utils/types'; | ||
|
||
const ContainerDiskModal: FC<V1DiskModalProps> = ({ | ||
editDiskName, | ||
isOpen, | ||
onClose, | ||
onSubmit, | ||
vm, | ||
}) => { | ||
const os = getOS(vm); | ||
const isVMRunning = isRunning(vm); | ||
|
||
const isEditDisk = !isEmpty(editDiskName); | ||
|
||
const methods = useForm<V1DiskFormState>({ | ||
defaultValues: isEditDisk | ||
? getDefaultEditValues(vm, editDiskName) | ||
: getDefaultCreateValues(vm, SourceTypes.EPHEMERAL), | ||
mode: 'all', | ||
}); | ||
|
||
const { | ||
formState: { isSubmitting, isValid }, | ||
handleSubmit, | ||
} = methods; | ||
|
||
return ( | ||
<FormProvider {...methods}> | ||
<TabModal | ||
closeOnSubmit={isValid} | ||
headerText={diskModalTitle(isEditDisk, isVMRunning)} | ||
isLoading={isSubmitting} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
onSubmit={() => handleSubmit(async (data) => submit(data, vm, editDiskName, onSubmit))()} | ||
> | ||
<PendingChanges isVMRunning={isVMRunning} /> | ||
<Form> | ||
<BootSourceCheckbox editDiskName={editDiskName} isDisabled={isVMRunning} vm={vm} /> | ||
<DiskNameInput /> | ||
<DiskSourceContainer fieldName={CONTAINERDISK_IMAGE_FIELD} os={os} /> | ||
<DynamicSize /> | ||
<DiskTypeSelect isVMRunning={isVMRunning} /> | ||
<DiskInterfaceSelect isVMRunning={isVMRunning} /> | ||
<AdvancedSettings /> | ||
</Form> | ||
</TabModal> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
export default ContainerDiskModal; |
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
Oops, something went wrong.