-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add volume mode and access mode selection for
VM related volumes in the Persistent Volume grid. This allows the user to change the volume mode and access mode for volumes that are part of a VM. Signed-off-by: Alexander Wels <[email protected]>
- Loading branch information
Showing
10 changed files
with
213 additions
and
42 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
15 changes: 7 additions & 8 deletions
15
src/app/home/pages/PlansPage/components/PlanActions/PlanActionsComponent.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
18 changes: 9 additions & 9 deletions
18
src/app/home/pages/PlansPage/components/Wizard/GeneralForm.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
66 changes: 66 additions & 0 deletions
66
src/app/home/pages/PlansPage/components/Wizard/PVAccessModeSelect.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,66 @@ | ||
import { useFormikContext } from 'formik'; | ||
import React from 'react'; | ||
import SimpleSelect, { OptionWithValue } from '../../../../../common/components/SimpleSelect'; | ||
import { | ||
IMigPlanStorageClass, | ||
IPlanPersistentVolume, | ||
IVolumeAccessModes, | ||
} from '../../../../../plan/duck/types'; | ||
import { IFormValues } from './WizardContainer'; | ||
|
||
const styles = require('./PVStorageClassSelect.module').default; | ||
|
||
interface IPVAccessModeSelectProps { | ||
pv: IPlanPersistentVolume; | ||
currentPV: IPlanPersistentVolume; | ||
storageClasses: IMigPlanStorageClass[]; | ||
} | ||
|
||
export const PVAccessModeSelect: React.FunctionComponent<IPVAccessModeSelectProps> = ({ | ||
pv, | ||
currentPV, | ||
storageClasses, | ||
}: IPVAccessModeSelectProps) => { | ||
const { values, setFieldValue } = useFormikContext<IFormValues>(); | ||
|
||
const currentStorageClass = values.pvStorageClassAssignment[currentPV.name]; | ||
const volumeAccessModes = currentStorageClass.volumeAccessModes; | ||
const currentVolumeMode = currentStorageClass.volumeMode; | ||
const possibleAccessModes = volumeAccessModes.find( | ||
(volumeAccessMode: IVolumeAccessModes) => volumeAccessMode.volumeMode === currentVolumeMode | ||
) || { accessModes: [] as string[] }; | ||
|
||
const onAccessModeChange = (currentPV: IPlanPersistentVolume, value: string) => { | ||
currentStorageClass.accessMode = value; | ||
const updatedAssignment = { | ||
...values.pvStorageClassAssignment, | ||
[currentPV.name]: currentStorageClass, | ||
}; | ||
setFieldValue('pvStorageClassAssignment', updatedAssignment); | ||
}; | ||
|
||
const accessModeOptions: OptionWithValue[] = [ | ||
...possibleAccessModes.accessModes.map((value: string) => ({ | ||
value: value, | ||
toString: () => value, | ||
})), | ||
]; | ||
accessModeOptions.splice(1, 1); // remove ReadOnly option | ||
accessModeOptions.splice(0, 0, { value: 'auto', toString: () => 'Auto' }); | ||
|
||
return ( | ||
<SimpleSelect | ||
id="select-storage-class" | ||
aria-label="Select storage class" | ||
className={styles.copySelectStyle} | ||
onChange={(option: any) => onAccessModeChange(currentPV, option.value)} | ||
options={accessModeOptions} | ||
placeholderText="Select volume mode..." | ||
value={ | ||
accessModeOptions.find( | ||
(option) => currentStorageClass && option.value === currentStorageClass.accessMode | ||
) || accessModeOptions[0] | ||
} | ||
/> | ||
); | ||
}; |
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
61 changes: 61 additions & 0 deletions
61
src/app/home/pages/PlansPage/components/Wizard/PVVolumeModeSelect.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,61 @@ | ||
import { useFormikContext } from 'formik'; | ||
import React from 'react'; | ||
import SimpleSelect, { OptionWithValue } from '../../../../../common/components/SimpleSelect'; | ||
import { | ||
IMigPlanStorageClass, | ||
IPlanPersistentVolume, | ||
IVolumeAccessModes, | ||
} from '../../../../../plan/duck/types'; | ||
import { IFormValues } from './WizardContainer'; | ||
|
||
const styles = require('./PVStorageClassSelect.module').default; | ||
|
||
interface IPVVolumeModeSelectProps { | ||
pv: IPlanPersistentVolume; | ||
currentPV: IPlanPersistentVolume; | ||
storageClasses: IMigPlanStorageClass[]; | ||
} | ||
|
||
export const PVVolumeModeSelect: React.FunctionComponent<IPVVolumeModeSelectProps> = ({ | ||
pv, | ||
currentPV, | ||
storageClasses, | ||
}: IPVVolumeModeSelectProps) => { | ||
const { values, setFieldValue } = useFormikContext<IFormValues>(); | ||
|
||
const currentStorageClass = values.pvStorageClassAssignment[currentPV.name]; | ||
const volumeAccessModes = currentStorageClass.volumeAccessModes; | ||
|
||
const onVolumeModeChange = (currentPV: IPlanPersistentVolume, value: string) => { | ||
currentStorageClass.volumeMode = value; | ||
const updatedAssignment = { | ||
...values.pvStorageClassAssignment, | ||
[currentPV.name]: currentStorageClass, | ||
}; | ||
setFieldValue('pvStorageClassAssignment', updatedAssignment); | ||
}; | ||
|
||
const volumeModeOptions: OptionWithValue[] = [ | ||
...volumeAccessModes.map((volumeAccessMode: IVolumeAccessModes) => ({ | ||
value: volumeAccessMode.volumeMode, | ||
toString: () => volumeAccessMode.volumeMode, | ||
})), | ||
]; | ||
volumeModeOptions.splice(0, 0, { value: 'auto', toString: () => 'Auto' }); | ||
|
||
return ( | ||
<SimpleSelect | ||
id="select-storage-class" | ||
aria-label="Select storage class" | ||
className={styles.copySelectStyle} | ||
onChange={(option: any) => onVolumeModeChange(currentPV, option.value)} | ||
options={volumeModeOptions} | ||
placeholderText="Select volume mode..." | ||
value={ | ||
volumeModeOptions.find( | ||
(option) => currentStorageClass && option.value === currentStorageClass.volumeMode | ||
) || volumeModeOptions[0] | ||
} | ||
/> | ||
); | ||
}; |
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
Oops, something went wrong.