Fix undefined error in VM edit as yaml page (#233)

* fix undefined error whenclick save in  edit as yaml

Signed-off-by: Andy Lee <andy.lee@suse.com>

* fix VM isEqual logic and fix undefined error

Signed-off-by: Andy Lee <andy.lee@suse.com>

---------

Signed-off-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
Andy Lee 2025-04-07 15:30:59 +08:00 committed by GitHub
parent 19bea97106
commit 238c660796
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 9 deletions

View File

@ -97,11 +97,13 @@ export default {
});
const devices = [
...this.otherDevices(this.value.domain.devices.hostDevices || []),
...this.otherDevices(this.value?.domain?.devices?.hostDevices || []),
...formatted,
];
set(this.value.domain.devices, 'hostDevices', devices);
if (devices.length > 0) {
set(this.value.domain.devices, 'hostDevices', devices);
}
}
},
@ -121,7 +123,9 @@ export default {
return inUse;
}
vm.hostDevices.forEach((device) => {
const hostDevices = vm?.hostDevices || [];
hostDevices.forEach((device) => {
inUse[device.name] = { usedBy: [vm.metadata.name] };
});

View File

@ -80,11 +80,13 @@ export default {
});
const devices = [
...this.otherDevices(this.value.domain.devices.hostDevices || []),
...this.otherDevices(this.value?.domain?.devices?.hostDevices || []),
...formatted,
];
set(this.value.domain.devices, 'hostDevices', devices);
if (devices.length > 0) {
set(this.value.domain.devices, 'hostDevices', devices);
}
}
},
@ -121,7 +123,9 @@ export default {
return inUse;
}
vm.hostDevices.forEach((device) => {
const hostDevices = vm?.hostDevices || [];
hostDevices.forEach((device) => {
inUse[device.name] = { usedBy: [vm.metadata.name] };
});

View File

@ -2,6 +2,7 @@
import { isEqual } from 'lodash';
import { mapGetters } from 'vuex';
import Tabbed from '@shell/components/Tabbed';
import { clone } from '@shell/utils/object';
import Tab from '@shell/components/Tabbed/Tab';
import { Checkbox } from '@components/Form/Checkbox';
import CruResource from '@shell/components/CruResource';
@ -17,7 +18,6 @@ import UsbDevices from './VirtualMachineUSBDevices/index';
import KeyValue from '@shell/components/form/KeyValue';
import { clear } from '@shell/utils/array';
import { clone } from '@shell/utils/object';
import { saferDump } from '@shell/utils/create-yaml';
import { exceptionToErrorsArray } from '@shell/utils/error';
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
@ -410,12 +410,16 @@ export default {
const cloneDeepNewVM = clone(this.value);
delete cloneDeepNewVM?.metadata;
delete cloneDeepNewVM?.__clone;
delete this.cloneVM?.metadata;
delete this.cloneVM?.__clone;
const oldVM = JSON.parse(JSON.stringify(this.cloneVM));
const newVM = JSON.parse(JSON.stringify(cloneDeepNewVM));
// we won't show restart dialog in yaml page as we don't have a way to detect change in yaml editor.
// only check VM is changed in form page.
if (isEqual(oldVM, newVM)) {
return;
}
@ -424,7 +428,11 @@ export default {
this.isOpen = true;
this.$nextTick(() => {
this.$refs.restartDialog.resolve = resolve;
if (this?.$refs?.restartDialog) {
this.$refs.restartDialog.resolve = resolve;
} else {
return resolve();
}
});
});
},

View File

@ -871,7 +871,7 @@ export default {
}
}
if (out.length === 0 && !!this.spec.template.spec.accessCredentials) {
if (out.length === 0 && !!this.spec.template.spec.accessCredentials === false) {
delete this.spec.template.spec.accessCredentials;
} else {
this.spec.template.spec.accessCredentials = out;