Ver Fonte

fixed checkbox default value + read in values from helm revisions for basic input types

jusrhee há 4 anos atrás
pai
commit
edf1e104b4

+ 12 - 1
dashboard/src/components/form-refactor/PorterForm.tsx

@@ -39,10 +39,11 @@ interface Props {
   addendum?: any;
   saveValuesStatus?: string;
   externalValues?: any;
+  showStateDebugger?: boolean;
 }
 
 const PorterForm: React.FC<Props> = (props) => {
-  const { formData, isReadOnly, validationInfo, onSubmit } = useContext(
+  const { formData, isReadOnly, validationInfo, onSubmit, formState } = useContext(
     PorterFormContext
   );
 
@@ -185,6 +186,11 @@ const PorterForm: React.FC<Props> = (props) => {
           /> 
         )
       }
+      { 
+        props.showStateDebugger && (
+          <Pre>{JSON.stringify(formState, undefined, 2)}</Pre>
+        )
+      }
       <Spacer />
     </>
   );
@@ -192,6 +198,11 @@ const PorterForm: React.FC<Props> = (props) => {
 
 export default PorterForm;
 
+const Pre = styled.pre`
+  font-size: 13px;
+  color: #aaaabb;
+`;
+
 const Spacer = styled.div`
   height: 50px;
 `;

+ 3 - 0
dashboard/src/components/form-refactor/PorterFormWrapper.tsx

@@ -18,6 +18,7 @@ type PropsType = {
   addendum?: any,
   saveValuesStatus?: string,
   externalValues?: any,
+  showStateDebugger?: boolean;
 };
 
 const PorterFormWrapper: React.FunctionComponent<PropsType> = ({
@@ -34,6 +35,7 @@ const PorterFormWrapper: React.FunctionComponent<PropsType> = ({
   addendum,
   saveValuesStatus,
   externalValues,
+  showStateDebugger,
 }) => {
   return (
     <>
@@ -45,6 +47,7 @@ const PorterFormWrapper: React.FunctionComponent<PropsType> = ({
           onSubmit={onSubmit}
         >
           <PorterForm
+            showStateDebugger={showStateDebugger}
             addendum={addendum}
             isReadOnly={isReadOnly}
             leftTabOptions={leftTabOptions}

+ 1 - 1
dashboard/src/components/form-refactor/field-components/ArrayInput.tsx

@@ -12,7 +12,7 @@ const ArrayInput: React.FC<ArrayInputField> = (props) => {
     props.id,
     {
       initVars: {
-        [props.variable]: [],
+        [props.variable]: props.value ? props.value[0] : [],
       },
     }
   );

+ 8 - 6
dashboard/src/components/form-refactor/field-components/Checkbox.tsx

@@ -19,6 +19,7 @@ const Checkbox: React.FC<Props> = ({
   variable,
   isReadOnly,
   settings,
+  value,
 }) => {
   const { state, variables, setVars } = useFormField<CheckboxFieldState>(id, {
     initState: {},
@@ -26,7 +27,7 @@ const Checkbox: React.FC<Props> = ({
       validated: !required,
     },
     initVars: {
-      [variable]: !!settings?.default,
+      [variable]: value ? value[0] : !!settings?.default,
     },
   });
 
@@ -58,9 +59,10 @@ export const getFinalVariablesForCheckbox: GetFinalVariablesFunction = (
   vars,
   props: CheckboxField
 ) => {
-  return vars[props.variable]
-    ? {}
-    : {
-        [props.variable]: !!props.settings?.default,
-      };
+  return vars[props.variable] === false
+    ? {
+      [props.variable]: false,
+    } : {
+      [props.variable]: !!props.settings?.default,
+    };
 };

+ 2 - 1
dashboard/src/components/form-refactor/field-components/Input.tsx

@@ -17,6 +17,7 @@ const Input: React.FC<InputField> = ({
   info,
   settings,
   isReadOnly,
+  value,
 }) => {
   const {
     state,
@@ -28,7 +29,7 @@ const Input: React.FC<InputField> = ({
       validated: settings?.default != undefined,
     },
     initVars: {
-      [variable]: settings?.default,
+      [variable]: value ? value[0] : settings?.default, 
     },
   });
 

+ 1 - 1
dashboard/src/components/form-refactor/field-components/Select.tsx

@@ -14,7 +14,7 @@ const Select: React.FC<SelectField> = (props) => {
   const { currentCluster } = useContext(Context);
   const { variables, setVars } = useFormField<SelectFieldState>(props.id, {
     initVars: {
-      [props.variable]: props.settings.default
+      [props.variable]: props.value ? props.value[0] : props.settings.default
         ? props.settings.default
         : props.settings.type == "provider"
         ? ({

+ 3 - 0
dashboard/src/components/form-refactor/types.ts

@@ -16,6 +16,9 @@ export interface GenericInputField extends GenericField {
   required?: boolean;
   variable: string;
   settings?: any
+
+  // Read in value from Helm for existing revisions
+  value?: any[];
 }
 
 export interface HeadingField extends GenericField {

+ 2 - 1
dashboard/src/components/values-form/FormDebugger.tsx

@@ -68,7 +68,7 @@ export default class FormDebugger extends Component<PropsType, StateType> {
           <i className="material-icons">keyboard_backspace</i>
           Back
         </Button>
-        <Heading>✨ Form.yaml Editor</Heading>
+        <Heading isAtTop={true}>✨ Form.yaml Editor</Heading>
         <Helper>Write and test form.yaml free of consequence.</Helper>
 
         <EditorWrapper>
@@ -157,6 +157,7 @@ export default class FormDebugger extends Component<PropsType, StateType> {
         <Heading>🎨 Rendered Form</Heading>
         <Br />
         <PorterFormWrapper
+          showStateDebugger={this.state.showStateDebugger}
           formData={formData}
           valuesToOverride={{
             input_a: this.state.valuesToOverride?.input_a?.value,

+ 1 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedChart.tsx

@@ -651,6 +651,7 @@ const ExpandedChart: React.FC<Props> = (props) => {
     return () => (isSubscribed = false);
   }, [components, currentCluster, currentProject, currentChart]);
 
+  console.log("i see", props.currentChart.form)
   return (
     <>
       <StyledExpandedChart>

+ 1 - 10
dashboard/src/main/home/launch/launch-flow/SettingsPage.tsx

@@ -146,19 +146,10 @@ class SettingsPage extends Component<PropsType, StateType> {
           <PorterFormWrapper
             formData={form}
             saveValuesStatus={saveValuesStatus}
-            valuesToOverride={valuesToOverride}
-            externalValues={{
-              namespace: selectedNamespace,
-              clusterId: this.context.currentCluster.id,
-              isLaunch: true,
-            }}
             isReadOnly={
               !this.props.isAuthorized("namespace", "", ["get", "create"])
             }
-            onSubmit={(val) => {
-              console.log(val);
-              onSubmit(val)
-            }}
+            onSubmit={(val) => onSubmit(val)}
           />
         </>
       );

+ 2 - 6
dashboard/src/main/home/launch/launch-flow/SourcePage.tsx

@@ -174,12 +174,8 @@ class SourcePage extends Component<PropsType, StateType> {
           setProcfileProcess={(procfileProcess: string) => {
             setProcfileProcess(procfileProcess);
             setValuesToOverride({
-              "container.command": {
-                value: procfileProcess || "",
-              },
-              showStartCommand: {
-                value: !procfileProcess,
-              },
+              "container.command": procfileProcess || "",
+              showStartCommand: !procfileProcess,
             });
           }}
           setBranch={setBranch}

+ 7 - 6
internal/models/templates.go

@@ -66,10 +66,11 @@ type FormContent struct {
 
 // FormYAML represents a chart's values.yaml form abstraction
 type FormYAML struct {
-	Name        string     `yaml:"name" json:"name"`
-	Icon        string     `yaml:"icon" json:"icon"`
-	HasSource   string     `yaml:"hasSource" json:"hasSource"`
-	Description string     `yaml:"description" json:"description"`
-	Tags        []string   `yaml:"tags" json:"tags"`
-	Tabs        []*FormTab `yaml:"tabs" json:"tabs,omitempty"`
+	Name                string     `yaml:"name" json:"name"`
+	Icon                string     `yaml:"icon" json:"icon"`
+	HasSource           string     `yaml:"hasSource" json:"hasSource"`
+	IncludeHiddenFields string     `yaml:"includeHiddenFields,omitempty" json:"includeHiddenFields,omitempty"`
+	Description         string     `yaml:"description" json:"description"`
+	Tags                []string   `yaml:"tags" json:"tags"`
+	Tabs                []*FormTab `yaml:"tabs" json:"tabs,omitempty"`
 }