fix: restore vm create modal behavior#1743
Conversation
There was a problem hiding this comment.
Pull request overview
This PR restores the “VM create” flow inside the component creation modal by wiring the VM entry to a real form + submission path, and improves the VM form’s initial group selection behavior.
Changes:
- Re-enable VM creation in
CreateComponentModalby adding the VM form, fetching VM images, and submitting viacreateApp/createAppByVirtualMachine. - Load existing VM images on-demand when entering the VM form.
- Avoid
NaN/incorrect defaults for the VM form’sgroup_idinitial value.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/components/ImageVirtualMachineForm/index.js | Adjusts group_id initial value logic to avoid invalid defaults and better match modal behavior. |
| src/components/CreateComponentModal/index.js | Adds VM entry as a form-based flow, including VM image fetching and VM create submission routing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| setVirtualMachineImages((data && data.list) || []); | ||
| }, | ||
| handleError: err => { | ||
| setVirtualMachineImages([]); | ||
| handleAPIError(err); |
There was a problem hiding this comment.
fetchVirtualMachineImages passes a handleError callback, but createApp/getAppByVirtualMachineImage currently delegates to getAppByVirtualMachineImage in src/services/createApp.js, which does not forward handleError to request(...). As a result, this handleError branch (and the setVirtualMachineImages([]) reset) will never run, and the UI may keep showing stale VM images after a failed request. Fix by updating the service (or model effect) to propagate/catch errors and invoke the provided handleError callback.
| if (currentFormType === 'vm') { | ||
| fetchVirtualMachineImages(); | ||
| } | ||
| } |
There was a problem hiding this comment.
This effect now depends on currentFormType, so switching between different create forms while the modal is open will re-run fetchLocalImageList() and fetchArchInfo() each time (extra network calls even when those results are unchanged). Consider splitting VM-image loading into its own useEffect (triggered only when entering vm) so fetchLocalImageList/fetchArchInfo stay tied to [visible, currentView].
| if (currentFormType === 'vm') { | |
| fetchVirtualMachineImages(); | |
| } | |
| } | |
| } | |
| }, [visible, currentView]); | |
| useEffect(() => { | |
| if (visible && currentView === 'form' && currentFormType === 'vm') { | |
| fetchVirtualMachineImages(); | |
| } |
No description provided.