import React from 'react' import Form from 'react-formal' import { Alert, Button, Col, ControlLabel, Form as BsForm, FormControl, FormGroup as BsFormGroup, HelpBlock, } from 'react-bootstrap' import {APPS, APPS_BY_RELEASE} from './metadata' import schema, { serialize } from './schema'; import SelectApps from './SelectApps' const EMR_RELEASES = Object.keys(APPS_BY_RELEASE) function trimApplications(label, applications) { // If the release label has been cleared, don't do anything else if (label === '') { return applications } let nextAppIds = Object.keys(APPS_BY_RELEASE[label]) return applications.filter(appId => nextAppIds.indexOf(appId) !== -1) } function ReleaseSelect({ value, onChange, children }) { return ( {EMR_RELEASES.map(version => )} ); } // not necessary but takes advantage of the twbs error styling function FormGroup({ for: forFields, ...props }) { if (!forFields) return return ( {({ messages, ...triggerProps }) => } ); } let FormExample = React.createClass({ getInitialState() { return { value: schema.default(), errors: {} } }, handleChange(value) { // we could also adjust `errors` here to remove application errors // when releaseLabel is empty instead of the `alsoValidates` on the field this.setState({ value }) }, handleErrors(errors) { this.setState({ errors }) }, handleSubmit(cluster) { console.log(JSON.stringify(serialize(cluster), null, 2)) }, render() { let { errors, value } = this.state let releaseSelected = !!value.releaseLabel let isV4 = /^emr-4/.test(value.releaseLabel) return (
React Form Example Release Label: e.target.value, applications: e => trimApplications(e.target.value, value.applications) }} /> The identifier for the EMR release, which includes a set of software, to use with Amazon EC2 instances that are part of an Amazon EMR cluster. See About Amazon EMR Releases. Applications: {!releaseSelected && Select a Release Label to show available applications.} {releaseSelected &&
{errors.applications ? : Select applications to install on your cluster. }
}

) } }) export default FormExample