From 3d337d9ff53f1661945c35c569aab0fbe9b60b8d Mon Sep 17 00:00:00 2001 From: vichansson Date: Fri, 27 Sep 2024 14:19:04 +0300 Subject: [PATCH] B OpenNebula/one#6739: Fix VM restore disk selection (#3248) * Correctly displays the VM disks when restoring a backup from the VM action menu Signed-off-by: Victor Hansson (cherry picked from commit 8f0d20580e6c56d768f5d1ec7fde0bea9e7c1dec) --- .../Backup/RestoreForm/Steps/VmDisksTable/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/fireedge/src/client/components/Forms/Backup/RestoreForm/Steps/VmDisksTable/index.js b/src/fireedge/src/client/components/Forms/Backup/RestoreForm/Steps/VmDisksTable/index.js index 2911815d3b..afe4f43bcc 100644 --- a/src/fireedge/src/client/components/Forms/Backup/RestoreForm/Steps/VmDisksTable/index.js +++ b/src/fireedge/src/client/components/Forms/Backup/RestoreForm/Steps/VmDisksTable/index.js @@ -21,11 +21,20 @@ import { SCHEMA } from 'client/components/Forms/Backup/RestoreForm/Steps/VmDisks import { Step } from 'client/utils' import { T } from 'client/constants' +import { STEP_ID as IMAGE_STEP_ID } from 'client/components/Forms/Backup/RestoreForm/Steps/BackupsTable' export const STEP_ID = 'vmdisk' const Content = ({ data, app: { backupDiskIds = [], vmsId = [] } = {} }) => { - const { setValue } = useFormContext() + const { setValue, getValues } = useFormContext() + const BACKUP_IMAGE = getValues(IMAGE_STEP_ID)?.[0] + const BACKUP_IMAGE_DISK_IDS = BACKUP_IMAGE?.BACKUP_DISK_IDS?.ID + + const getValidArray = (arr) => + Array.isArray(arr) && arr?.length > 0 ? arr : false + + const formatBackupDiskIds = + getValidArray(backupDiskIds) || getValidArray(BACKUP_IMAGE_DISK_IDS) || [] const selectedRow = data?.[0] const handleSelectedRows = (rows) => { @@ -51,7 +60,7 @@ const Content = ({ data, app: { backupDiskIds = [], vmsId = [] } = {} }) => { filter={(disks) => disks && disks?.length > 0 && - disks?.filter((disk) => backupDiskIds?.includes(disk?.DISK_ID)) + disks?.filter((disk) => formatBackupDiskIds?.includes(disk?.DISK_ID)) } /> )