From 5ec00ffdcd7193f992bb2e9ea6e0a890204e0276 Mon Sep 17 00:00:00 2001 From: vichansson Date: Wed, 24 Jul 2024 18:52:10 +0300 Subject: [PATCH] F OpenNebula/one#6616: Refine VM backup dialog (#3169) * M #-: Increase zIndex for action button menu Signed-off-by: Victor Hansson * F OpenNebula/one#6616: Refine VM backup dialog * Added more context to the VM backup dialog, now displaying previous backup information Signed-off-by: Victor Hansson --------- Signed-off-by: Victor Hansson --- .../components/Forms/ButtonToTriggerForm.js | 2 +- .../Steps/BasicConfiguration/index.js | 111 ++++++++++++++++-- .../client/components/Tables/Vms/actions.js | 11 +- 3 files changed, 114 insertions(+), 10 deletions(-) diff --git a/src/fireedge/src/client/components/Forms/ButtonToTriggerForm.js b/src/fireedge/src/client/components/Forms/ButtonToTriggerForm.js index b989c52bea..aeb2ee7292 100644 --- a/src/fireedge/src/client/components/Forms/ButtonToTriggerForm.js +++ b/src/fireedge/src/client/components/Forms/ButtonToTriggerForm.js @@ -96,7 +96,7 @@ const ButtonToTriggerForm = ({ open={open} onClose={handleClose} TransitionComponent={Grow} - sx={{ zIndex: 2 }} + sx={(theme) => ({ zIndex: theme.zIndex.tooltip })} > {options.map(({ cy, disabled, icon: Icon, name, ...option }) => ( ( - FIELDS(props)} - /> -) +const Content = (props) => { + const [increments, setIncrements] = useState([]) + const { vmId: id } = props + const { + data: vm = {}, + refetch, + isFetching: fetchingVms, + } = useGetVmQuery({ id }) + + const vmBackupsConfig = vm?.BACKUPS?.BACKUP_CONFIG + + const incrementalBackupImageId = vm?.BACKUPS?.BACKUP_IDS?.ID + const incrementalBackups = + 'LAST_INCREMENT_ID' in vmBackupsConfig && + vmBackupsConfig?.MODE === 'INCREMENT' && + incrementalBackupImageId + + const [fetchBackupImage, { isFetching: fetchingImages }] = + useLazyGetImageQuery( + { incrementalBackupImageId }, + { + skip: true, + } + ) + + const fetchIncrements = async () => { + if (incrementalBackups) { + const result = await fetchBackupImage({ + id: incrementalBackupImageId, + }).unwrap() + const image = result || {} + const fetchedIncrements = image?.BACKUP_INCREMENTS?.INCREMENT + ? Array.isArray(image.BACKUP_INCREMENTS.INCREMENT) + ? image.BACKUP_INCREMENTS.INCREMENT + : [image.BACKUP_INCREMENTS.INCREMENT] + : [] + + setIncrements(fetchedIncrements) + } + } + + useEffect(() => { + fetchIncrements() + }, [incrementalBackups, fetchBackupImage]) + + const path = PATH.STORAGE.BACKUPS.DETAIL + const history = useHistory() + + const handleRowClick = (rowId) => { + history.push(generatePath(path, { id: String(rowId) })) + } + + return ( + + FIELDS(props)} + /> + + + + {Tr(`${T.Previous} ${T.Backups}`)} + + + {incrementalBackups ? ( + handleRowClick(incrementalBackupImageId)} + /> + ) : ( + handleRowClick(row.ID)} + /> + )} + + + + ) +} /** * Step to configure the marketplace app. @@ -50,6 +144,7 @@ const ConfigurationStep = (isMultiple) => ({ }) Content.propTypes = { + vmId: PropTypes.string, data: PropTypes.any, setFormData: PropTypes.func, nics: PropTypes.array, diff --git a/src/fireedge/src/client/components/Tables/Vms/actions.js b/src/fireedge/src/client/components/Tables/Vms/actions.js index 33ac269963..9fc9eb499d 100644 --- a/src/fireedge/src/client/components/Tables/Vms/actions.js +++ b/src/fireedge/src/client/components/Tables/Vms/actions.js @@ -517,7 +517,16 @@ const Actions = () => { subheader: SubHeader, dataCy: `modal-${VM_ACTIONS.BACKUP}`, }, - form: BackupForm, + form: (row) => { + const vm = row?.[0]?.original + const vmId = vm?.ID + + return BackupForm({ + stepProps: { + vmId, + }, + }) + }, onSubmit: (rows) => async (formData) => { const ids = rows?.map?.(({ original }) => original?.ID) await Promise.all(