import React, { Component } from 'react'; import { Field } from 'redux-form'; import styled from 'styled-components'; import { Row, Col } from 'react-styled-flexboxgrid'; import Bundle from 'react-bundle'; import remcalc from 'remcalc'; import forceArray from 'force-array'; import is from 'styled-is'; import { Loader } from '@components/messaging'; import { FormGroup, FormMeta, Input, Button, Card, Progressbar, ProgressbarItem, ProgressbarButton, H3, P, typography, Divider, Chevron } from 'joyent-ui-toolkit'; const EnvironmentChevron = styled(Chevron)` float: right; `; const EnvironmentDivider = Divider.extend` margin-top: ${remcalc(34)}; `; const ServiceDivider = Divider.extend` margin: ${remcalc(13)} ${remcalc(-20)} 0 ${remcalc(-20)}; `; const Dl = styled.dl` margin: 0; `; const ServiceName = H3.extend` margin-top: 0; margin-bottom: ${remcalc(5)}; line-height: 1.6; font-size: ${remcalc(18)}; `; const ImageTitle = H3.extend` display: inline-block; margin: 0; `; const Image = styled.span` ${typography.fontFamily}; font-size: ${remcalc(15)}; `; const ServiceEnvironmentTitle = P.extend` margin: ${remcalc(13)} 0 0 0; ${is('expanded')` margin-bottom: ${remcalc(13)}; `}; `; const ButtonsRow = Row.extend` margin: ${remcalc(29)} 0 ${remcalc(60)} 0; `; const FilenameContainer = styled.span` display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: space-between; align-content: stretch; align-items: stretch; `; const FilenameInput = styled(Input)` order: 0; flex: 1 1 auto; align-self: stretch; margin: 0 0 ${remcalc(13)} 0; `; const FilenameRemove = Button.extend` order: 0; flex: 0 1 auto; align-self: auto; margin: 0 0 0 ${remcalc(8)}; height: ${remcalc(48)}; `; const FileCard = Card.extend` padding: ${remcalc(24)} ${remcalc(19)}; `; const ServiceCard = Card.extend` padding: ${remcalc(13)} ${remcalc(19)}; min-height: initial; `; const Subtitle = H3.extend` margin-top: ${remcalc(34)}; margin-bottom: ${remcalc(3)}; `; const Description = P.extend` margin-top: ${remcalc(3)}; margin-bottom: ${remcalc(20)}; `; class ManifestEditorBundle extends Component { constructor() { super(); this.state = {}; this.handleRender = this.handleRender.bind(this); } handleRender(ManifestEditor) { if (ManifestEditor) { setTimeout(() => { this.setState({ ManifestEditor }); }, 80); } return ; } render() { if (!this.state.ManifestEditor) { return ( import('joyent-manifest-editor')}> {this.handleRender} ); } const { ManifestEditor } = this.state; const { children, ...rest } = this.props; return {children}; } } const MEditor = ({ input, defaultValue, readOnly }) => ( ); const EEditor = ({ input, defaultValue, readOnly }) => ( ); export const Name = ({ handleSubmit, onCancel, dirty }) => (
); export const Manifest = ({ handleSubmit, onCancel, dirty, defaultValue = '', loading }) => (
); const File = ({ id, name, value, onRemoveFile, readOnly }) => { const removeButton = !readOnly ? ( Remove ) : null; const fileEditor = !readOnly ? ( ) : ( ); const input = !readOnly ? ( ) : ( ); return ( {input} {removeButton} {fileEditor} ); }; const Files = ({ files, onAddFile, onRemoveFile, readOnly }) => { const footer = !readOnly ? ( ) : null; return (
{files.map(({ id, ...rest }) => ( onRemoveFile(id)} readOnly={readOnly} {...rest} /> ))} {footer}
); }; export const Environment = ({ handleSubmit, onCancel, onAddFile, onRemoveFile, dirty, defaultValue = '', files = [], readOnly = false, loading }) => { const envEditor = !readOnly ? ( ) : ( ); const footerDivider = !readOnly ? : null; const footer = !readOnly ? ( ) : null; return (
Global variables These variables are going to be availabe for interpolation in the manifest {envEditor} Enviroment files The variables from this files will be applied to the services that require them {footerDivider} {footer} ); }; const EnvironmentReview = ({ environment }) => { const value = environment .map(({ name, value }) => `${name}=${value}`) .join('\n'); return ; }; export const Review = ({ handleSubmit, onEnvironmentToggle = () => null, onCancel, dirty, loading, environmentToggles, ...state }) => { const serviceList = forceArray(state.services).map(({ name, config }) => ( {name}
Image: {config.image}
{config.environment && config.environment.length ? ( ) : null} {config.environment && config.environment.length ? ( onEnvironmentToggle(name)} > Environment variables{' '} ) : null} {config.environment && config.environment.length && environmentToggles[name] ? ( ) : null}
)); return (
{serviceList}
); }; export const Progress = ({ stage, create, edit }) => { const _nameCompleted = stage !== 'name'; const _nameActive = stage === 'name'; const _name = !create ? null : ( Name the group ); const _manifestCompleted = ['environment', 'review'].indexOf(stage) >= 0; const _manifestActive = create ? stage === 'manifest' : stage === 'edit'; const _manifest = ( Define Services ); const _environmentCompleted = stage === 'review'; const _environmentActive = stage === 'environment'; const _environment = ( Define Environment ); const _reviewActive = stage === 'review'; const _review = ( Review and deploy ); return ( {_name} {_manifest} {_environment} {_review} ); };