|
@@ -1,94 +1,123 @@
|
|
|
import React, { Component } from 'react';
|
|
import React, { Component } from 'react';
|
|
|
import styled from 'styled-components';
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
|
|
+import { FormYAML, Section, FormElement } from '../../shared/types';
|
|
|
|
|
+
|
|
|
import SaveButton from '../SaveButton';
|
|
import SaveButton from '../SaveButton';
|
|
|
import CheckboxRow from './CheckboxRow';
|
|
import CheckboxRow from './CheckboxRow';
|
|
|
import InputRow from './InputRow';
|
|
import InputRow from './InputRow';
|
|
|
import SelectRow from './SelectRow';
|
|
import SelectRow from './SelectRow';
|
|
|
|
|
|
|
|
type PropsType = {
|
|
type PropsType = {
|
|
|
|
|
+ formData?: FormYAML
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
type StateType = any;
|
|
type StateType = any;
|
|
|
|
|
|
|
|
-const naiveFormArray = [
|
|
|
|
|
- { type: 'heading', data: '⚡ Wordpress Settings' },
|
|
|
|
|
- { type: 'helper', data: 'Enable persistent volume for WordPress' },
|
|
|
|
|
- { field: 'pv-enabled', type: 'checkbox', data: { label: 'Persistent volume enabled' } },
|
|
|
|
|
- { field: 'name', type: 'input', data: { type: 'number', label: 'WordPress volume size', unit: 'Gi' } },
|
|
|
|
|
- {
|
|
|
|
|
- field: 'ocean', type: 'select', data: {
|
|
|
|
|
- label: 'Default StorageClass for WordPress',
|
|
|
|
|
- options: [
|
|
|
|
|
- { label: 'Standard', value: 'A' },
|
|
|
|
|
- { label: 'Custom Storage Class', value: 'B' },
|
|
|
|
|
- ]
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
-];
|
|
|
|
|
-
|
|
|
|
|
export default class ValuesForm extends Component<PropsType, StateType> {
|
|
export default class ValuesForm extends Component<PropsType, StateType> {
|
|
|
|
|
|
|
|
// Initialize corresponding state fields for form blocks
|
|
// Initialize corresponding state fields for form blocks
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
let formState: any = {};
|
|
let formState: any = {};
|
|
|
- naiveFormArray.forEach((item: any, i: number) => {
|
|
|
|
|
- switch (item.type) {
|
|
|
|
|
|
|
+ this.props.formData.Sections.forEach((section: Section, i: number) => {
|
|
|
|
|
+ section.Contents.forEach((item: FormElement, i: number) => {
|
|
|
|
|
+
|
|
|
|
|
+ // If no name is assigned use values.yaml variable as identifier
|
|
|
|
|
+ let key = item.Name || item.Variable;
|
|
|
|
|
+
|
|
|
|
|
+ let def = item.Settings.Default;
|
|
|
|
|
+ switch (item.Type) {
|
|
|
|
|
+ case 'checkbox':
|
|
|
|
|
+ formState[key] = def ? def : false;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'string-input':
|
|
|
|
|
+ formState[key] = def ? def : '';
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'number-input':
|
|
|
|
|
+ formState[key] = def ? def : '';
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'select':
|
|
|
|
|
+ formState[key] = def ? def : item.Settings.Options[0].Value;
|
|
|
|
|
+ default:
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ this.setState(formState);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ renderSection = (section: Section) => {
|
|
|
|
|
+ return section.Contents.map((item: FormElement, i: number) => {
|
|
|
|
|
+
|
|
|
|
|
+ // If no name is assigned use values.yaml variable as identifier
|
|
|
|
|
+ let key = item.Name || item.Variable;
|
|
|
|
|
+ switch (item.Type) {
|
|
|
|
|
+ case 'heading':
|
|
|
|
|
+ return <Heading key={i}>{item.Label}</Heading>
|
|
|
|
|
+ case 'subtitle':
|
|
|
|
|
+ return <Helper key={i}>{item.Label}</Helper>
|
|
|
case 'checkbox':
|
|
case 'checkbox':
|
|
|
- formState[item.field] = false;
|
|
|
|
|
- break;
|
|
|
|
|
- case 'input':
|
|
|
|
|
- formState[item.field] = '';
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ <CheckboxRow
|
|
|
|
|
+ key={i}
|
|
|
|
|
+ checked={this.state[key]}
|
|
|
|
|
+ toggle={() => this.setState({ [key]: !this.state[key] })}
|
|
|
|
|
+ label={item.Label}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'string-input':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <InputRow
|
|
|
|
|
+ key={i}
|
|
|
|
|
+ type={'text'}
|
|
|
|
|
+ value={this.state[key]}
|
|
|
|
|
+ setValue={(x: string) => this.setState({ [key]: x })}
|
|
|
|
|
+ label={item.Label}
|
|
|
|
|
+ unit={item.Settings ? item.Settings.Unit : null}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'number-input':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <InputRow
|
|
|
|
|
+ key={i}
|
|
|
|
|
+ type={'number'}
|
|
|
|
|
+ value={this.state[key]}
|
|
|
|
|
+ setValue={(x: string) => this.setState({ [key]: parseInt(x) })}
|
|
|
|
|
+ label={item.Label}
|
|
|
|
|
+ unit={item.Settings ? item.Settings.Unit : null}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
case 'select':
|
|
case 'select':
|
|
|
- formState[item.field] = item.data.options[0].value;
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ <SelectRow
|
|
|
|
|
+ key={i}
|
|
|
|
|
+ value={this.state[key]}
|
|
|
|
|
+ setActiveValue={(val) => this.setState({ [key]: val })}
|
|
|
|
|
+ options={item.Settings.Options}
|
|
|
|
|
+ dropdownLabel=''
|
|
|
|
|
+ label={item.Label}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
default:
|
|
default:
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- this.setState(formState);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
renderFormContents = () => {
|
|
renderFormContents = () => {
|
|
|
if (this.state) {
|
|
if (this.state) {
|
|
|
- return naiveFormArray.map((item: any, i: number) => {
|
|
|
|
|
- switch (item.type) {
|
|
|
|
|
- case 'heading':
|
|
|
|
|
- return <Heading key={i}>{item.data}</Heading>
|
|
|
|
|
- case 'helper':
|
|
|
|
|
- return <Helper key={i}>{item.data}</Helper>
|
|
|
|
|
- case 'checkbox':
|
|
|
|
|
- return (
|
|
|
|
|
- <CheckboxRow
|
|
|
|
|
- key={i}
|
|
|
|
|
- checked={this.state[item.field]}
|
|
|
|
|
- toggle={() => this.setState({ [item.field]: !this.state[item.field] })}
|
|
|
|
|
- label={item.data.label}
|
|
|
|
|
- />
|
|
|
|
|
- );
|
|
|
|
|
- case 'input':
|
|
|
|
|
- return (
|
|
|
|
|
- <InputRow
|
|
|
|
|
- key={i}
|
|
|
|
|
- type={item.data.type}
|
|
|
|
|
- value={this.state[item.field]}
|
|
|
|
|
- label={item.data.label}
|
|
|
|
|
- unit={item.data.unit}
|
|
|
|
|
- />
|
|
|
|
|
- );
|
|
|
|
|
- case 'select':
|
|
|
|
|
- return (
|
|
|
|
|
- <SelectRow
|
|
|
|
|
- key={i}
|
|
|
|
|
- value={this.state[item.field]}
|
|
|
|
|
- setActiveValue={(val) => this.setState({ [item.field]: val })}
|
|
|
|
|
- options={item.data.options}
|
|
|
|
|
- dropdownLabel=''
|
|
|
|
|
- label={item.data.label}
|
|
|
|
|
- />
|
|
|
|
|
- );
|
|
|
|
|
- default:
|
|
|
|
|
|
|
+ return this.props.formData.Sections.map((section: Section, i: number) => {
|
|
|
|
|
+
|
|
|
|
|
+ // Hide collapsible section if deciding field is false
|
|
|
|
|
+ if (section.ShowIf) {
|
|
|
|
|
+ if (!this.state[section.ShowIf]) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div key={i}>
|
|
|
|
|
+ {this.renderSection(section)}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -111,7 +140,7 @@ export default class ValuesForm extends Component<PropsType, StateType> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const DarkMatter = styled.div`
|
|
const DarkMatter = styled.div`
|
|
|
- margin-top: -5px;
|
|
|
|
|
|
|
+ margin-top: 0px;
|
|
|
`;
|
|
`;
|
|
|
|
|
|
|
|
const Wrapper = styled.div`
|
|
const Wrapper = styled.div`
|
|
@@ -121,6 +150,7 @@ const Wrapper = styled.div`
|
|
|
|
|
|
|
|
const Helper = styled.div`
|
|
const Helper = styled.div`
|
|
|
color: #aaaabb;
|
|
color: #aaaabb;
|
|
|
|
|
+ line-height: 1.6em;
|
|
|
font-size: 13px;
|
|
font-size: 13px;
|
|
|
margin-bottom: 15px;
|
|
margin-bottom: 15px;
|
|
|
margin-top: 20px;
|
|
margin-top: 20px;
|
|
@@ -130,7 +160,7 @@ const Heading = styled.div`
|
|
|
color: white;
|
|
color: white;
|
|
|
font-weight: 500;
|
|
font-weight: 500;
|
|
|
font-size: 16px;
|
|
font-size: 16px;
|
|
|
- margin-top: 35px;
|
|
|
|
|
|
|
+ margin-top: 30px;
|
|
|
margin-bottom: 5px;
|
|
margin-bottom: 5px;
|
|
|
`;
|
|
`;
|
|
|
|
|
|
|
@@ -139,7 +169,7 @@ const StyledValuesForm = styled.div`
|
|
|
height: 100%;
|
|
height: 100%;
|
|
|
background: #ffffff11;
|
|
background: #ffffff11;
|
|
|
color: #ffffff;
|
|
color: #ffffff;
|
|
|
- padding: 0px 35px;
|
|
|
|
|
|
|
+ padding: 0px 35px 30px;
|
|
|
position: relative;
|
|
position: relative;
|
|
|
border-radius: 5px;
|
|
border-radius: 5px;
|
|
|
font-size: 13px;
|
|
font-size: 13px;
|