import React, { Fragment } from 'react'; import styled, { keyframes } from 'styled-components'; import { Field } from 'redux-form'; import { Margin } from 'styled-components-spacing'; import Flex from 'styled-flex-component'; import remcalc from 'remcalc'; import { Row, Col } from 'react-styled-flexboxgrid'; import titleCase from 'title-case'; import is from 'styled-is'; import { H3, P, FormGroup, FormLabel, Button, Toggle, H4, Select } from 'joyent-ui-toolkit'; const fadeIn = keyframes` from { opacity: 0; } to { opacity: 1; } `; const Card = styled.div` width: ${remcalc(144)}; height: ${remcalc(144)}; background: ${props => props.theme.white}; border: ${remcalc(1)} solid ${props => props.theme.grey}; border-radius: ${remcalc(4)}; box-sizing: border-box; padding-top: ${remcalc(12)}; align-items: center; justify-content: space-between; flex-direction: column; display: flex; margin-bottom: ${remcalc(20)}; animation: ${fadeIn} 0.2s ease-in-out; ${is('selected')` border: 1px solid ${props => props.theme.primaryActive}; select { border-color: ${props => props.theme.primaryActive}; } `}; `; const Version = styled(Select)` min-width: 100%; width: ${remcalc(144)}; select { margin: 0; border-bottom-width: 0; border-top-left-radius: 0; border-top-right-radius: 0; } `; const getImage = name => { try { return { url: require(`@assets/${name}.svg`), size: 42, bottom: 0 }; } catch (e) { return { url: require('@assets/placeholder.svg'), size: 36, bottom: 6 }; } }; const getImageByID = (id, images) => { const image = images .map(image => ({ ...image, versions: (image.versions || []).filter(version => version.id === id) })) .filter(e => e.versions.length)[0]; return image ? { imageName: image.imageName, name: image.versions[0].name, version: image.versions[0].version } : {}; }; export const Preview = ({ imageID, images, isVmSelected, onEdit }) => (

{titleCase(getImageByID(imageID, images).name)} -{' '} {getImageByID(imageID, images).version}

{isVmSelected ? 'Hardware Virtual Machine' : 'Infrastructure Container'}{' '}

); export default ({ handleSubmit, pristine, imageID, images = [], isVmSelected }) => (
Infrastructure Container Hardware Virtual Machine {images && images.filter(i => i.isVm === isVmSelected).map(image => ( {image.imageName}

{titleCase(image.imageName)}

{image.versions && image.versions.map(version => ( ))}
))}
);