Explorar o código

Add `Deploy Options` panel to Edit Transfer modal

Daniel Vincze hai 1 ano
pai
achega
e52c8a6fb9

+ 3 - 0
src/@types/MainItem.ts

@@ -31,6 +31,7 @@ export type MainItemInfo = {
 export type UpdateData = {
   destination: any;
   source: any;
+  deploy: any;
   network: NetworkMap[];
   storage: StorageMap[];
   uploadedScripts: InstanceScript[];
@@ -90,6 +91,8 @@ type BaseItem = {
   user_id: string;
   instance_osmorphing_minion_pool_mappings?: { [instanceName: string]: string };
   user_scripts?: UserScriptData;
+  clone_disks: boolean;
+  skip_os_morphing: boolean;
 };
 
 export type TransferItem = BaseItem & {

+ 56 - 1
src/components/modules/TransferModule/TransferItemModal/TransferItemModal.tsx

@@ -52,7 +52,7 @@ import {
   SecurityGroup,
 } from "@src/@types/Network";
 
-import { providerTypes } from "@src/constants";
+import { deploymentFields, providerTypes } from "@src/constants";
 import configLoader from "@src/utils/Config";
 import LoadingButton from "@src/components/ui/LoadingButton";
 import minionPoolStore from "@src/stores/MinionPoolStore";
@@ -60,6 +60,7 @@ import WizardScripts from "@src/components/modules/WizardModule/WizardScripts";
 import networkStore from "@src/stores/NetworkStore";
 import { ThemeProps } from "@src/components/Theme";
 import ObjectUtils from "@src/utils/ObjectUtils";
+import WizardExecuteOptions from "@src/components/modules/WizardModule/WizardExecuteOptions/WizardExecuteOptions";
 
 const PanelContent = styled.div<any>`
   display: flex;
@@ -117,6 +118,7 @@ type State = {
   selectedPanel: string | null;
   destinationData: any;
   sourceData: any;
+  deployData: any;
   updateDisabled: boolean;
   updating: boolean;
   selectedNetworks: NetworkMap[];
@@ -135,6 +137,7 @@ class TransferItemModal extends React.Component<Props, State> {
     selectedPanel: "source_options",
     destinationData: {},
     sourceData: {},
+    deployData: {},
     updateDisabled: false,
     updating: false,
     selectedNetworks: [],
@@ -339,6 +342,28 @@ class TransferItemModal extends React.Component<Props, State> {
     return { value: null };
   }
 
+  getDeployFieldValue(fieldName: string, defaultValue: any) {
+    const currentData = this.state.deployData;
+    if (fieldName === "clone_disks") {
+      if (currentData[fieldName] !== undefined) {
+        return currentData[fieldName];
+      }
+
+      return this.props.transfer.clone_disks !== undefined
+        ? this.props.transfer.clone_disks
+        : defaultValue;
+    }
+
+    if (fieldName === "skip_os_morphing") {
+      if (currentData[fieldName] !== undefined) {
+        return currentData[fieldName];
+      }
+      return this.props.transfer.skip_os_morphing !== undefined
+        ? this.props.transfer.skip_os_morphing
+        : defaultValue;
+    }
+  }
+
   getFieldValue(opts: {
     type: "source" | "destination";
     fieldName: string;
@@ -679,12 +704,19 @@ class TransferItemModal extends React.Component<Props, State> {
     }
   }
 
+  handleDeployFieldChange(field: Field, value: any) {
+    const data = this.state.deployData;
+    data[field.name] = value;
+    this.setState({ deployData: { ...this.state.deployData, ...data }});
+  }
+
   async handleUpdateClick() {
     this.setState({ updating: true });
 
     const updateData: UpdateData = {
       source: this.state.sourceData,
       destination: this.state.destinationData,
+      deploy: this.state.deployData,
       network:
         this.state.selectedNetworks.length > 0
           ? this.getSelectedNetworks()
@@ -952,6 +984,21 @@ class TransferItemModal extends React.Component<Props, State> {
     );
   }
 
+  renderDeployOptions() {
+    return (
+      <WizardExecuteOptions
+        options={[...deploymentFields]}
+        wizardType={"edit-deploy"}
+        layout={"modal"}
+        onChange={(f, v) => {
+          this.handleDeployFieldChange(f, v);
+        }}
+        data={this.state.deployData}
+        getFieldValue={(f, d) => this.getDeployFieldValue(f, d)}
+      />
+    )
+  }
+
   renderContent() {
     let content = null;
     switch (this.state.selectedPanel) {
@@ -970,6 +1017,9 @@ class TransferItemModal extends React.Component<Props, State> {
       case "storage_mapping":
         content = this.renderStorageMapping();
         break;
+      case "deploy_options":
+        content = this.renderDeployOptions();
+        break;
       default:
         content = null;
     }
@@ -1049,6 +1099,11 @@ class TransferItemModal extends React.Component<Props, State> {
       });
     }
 
+    navigationItems.push({
+      value: "deploy_options",
+      label: "Deploy Options"
+    })
+
     return (
       <Modal
         isOpen={this.props.isOpen}

+ 23 - 4
src/components/modules/WizardModule/WizardExecuteOptions/WizardExecuteOptions.tsx

@@ -142,13 +142,32 @@ class WizardExecuteOptions extends React.Component<Props, State> {
                     "When enabled, the instances will be shut down before the transfer is executed.",
             });
         }
+        else if (this.props.wizardType === "edit-deploy") {
+            fieldsSchema.push({
+                name: "clone_disks",
+                type: "boolean",
+                label: "Clone Disks",
+                nullableBoolean: false,
+                default: true,
+                description: "When enabled, the disks will be cloned during the deployment."
+            })
+
+            fieldsSchema.push({
+                name: "skip_os_morphing",
+                type: "boolean",
+                label: "Skip OS Morphing",
+                nullableBoolean: false,
+                default: false,
+                description: "When enabled, OS Morphing will be skipped during the deployment."
+            })
+        }
 
         return fieldsSchema;
     }
 
     generateGroups(fields: FieldRender[]) {
         let groups: Array<{ fields: FieldRender[]; name?: string }> = [{ fields }];
-    
+
         if (this.props.wizardType === "replica-execute" || this.props.wizardType === "migration-execute") {
             const deploymentFieldNames = deploymentFields.map(f => f.name);
             const deploymentFieldsInUse = fields.filter(f =>
@@ -177,13 +196,13 @@ class WizardExecuteOptions extends React.Component<Props, State> {
                 });
             }
         }
-    
+
         fields.forEach(f => {
             if (f.field.groupName) {
                 groups[0].fields = groups[0].fields
                     ? groups[0].fields.filter(gf => gf.field.name !== f.field.name)
                     : [];
-    
+
                 const group = groups.find(g => g.name && g.name === f.field.groupName);
                 if (!group) {
                     groups.push({
@@ -195,7 +214,7 @@ class WizardExecuteOptions extends React.Component<Props, State> {
                 }
             }
         });
-    
+
         return groups;
     }
 

+ 10 - 0
src/sources/TransferSource.ts

@@ -298,6 +298,16 @@ class TransferSource {
       }
     }
 
+    if (Object.keys(updateData.deploy).length > 0) {
+      if (updateData.deploy.clone_disks !== undefined) {
+        payload.transfer.clone_disks = updateData.deploy.clone_disks;
+      }
+
+      if (updateData.deploy.skip_os_morphing !== undefined) {
+        payload.transfer.skip_os_morphing = updateData.deploy.skip_os_morphing;
+      }
+    }
+
     if (defaultStorage || updateData.storage.length > 0) {
       payload.transfer.storage_mappings = destinationParser.getStorageMap(
         defaultStorage,