2018-01-09 20:14:20 +02:00
|
|
|
import React, { Fragment } from 'react';
|
2018-01-29 20:09:18 +02:00
|
|
|
import styled from 'styled-components';
|
2018-01-09 20:14:20 +02:00
|
|
|
import { Field } from 'redux-form';
|
2018-01-30 18:04:03 +02:00
|
|
|
import { Row, Col } from 'joyent-react-styled-flexboxgrid';
|
2018-01-09 20:14:20 +02:00
|
|
|
import { Margin } from 'styled-components-spacing';
|
2018-02-05 17:12:47 +02:00
|
|
|
import pascalCase from 'pascal-case';
|
2018-01-09 20:14:20 +02:00
|
|
|
import titleCase from 'title-case';
|
2018-02-05 17:12:47 +02:00
|
|
|
import remcalc from 'remcalc';
|
2018-02-26 15:47:52 +02:00
|
|
|
|
|
|
|
import * as Assets from 'joyent-logo-assets';
|
2018-01-09 20:14:20 +02:00
|
|
|
|
2018-01-30 13:37:13 +02:00
|
|
|
import {
|
|
|
|
H3,
|
|
|
|
P,
|
|
|
|
FormGroup,
|
2018-02-26 15:47:52 +02:00
|
|
|
SectionList,
|
|
|
|
SectionListItem,
|
|
|
|
SectionListAnchor,
|
2018-01-30 13:37:13 +02:00
|
|
|
H4,
|
|
|
|
Select,
|
|
|
|
Card
|
|
|
|
} from 'joyent-ui-toolkit';
|
2018-01-09 20:14:20 +02:00
|
|
|
|
|
|
|
const Version = styled(Select)`
|
|
|
|
min-width: 100%;
|
|
|
|
width: ${remcalc(144)};
|
|
|
|
|
|
|
|
select {
|
|
|
|
margin: 0;
|
|
|
|
border-bottom-width: 0;
|
2018-01-18 15:42:55 +02:00
|
|
|
border-top-left-radius: 0;
|
|
|
|
border-top-right-radius: 0;
|
2018-01-09 20:14:20 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-01-30 01:20:22 +02:00
|
|
|
export const Preview = ({ name, version, isVm }) => (
|
2018-01-18 16:46:49 +02:00
|
|
|
<Fragment>
|
|
|
|
<Margin bottom={2} top={3}>
|
2018-02-23 17:59:12 +02:00
|
|
|
<H3>
|
2018-01-30 01:20:22 +02:00
|
|
|
{name} - {version}
|
2018-01-18 16:46:49 +02:00
|
|
|
</H3>
|
2018-01-30 01:20:22 +02:00
|
|
|
<P>{isVm ? 'Hardware Virtual Machine' : 'Infrastructure Container'} </P>
|
2018-01-18 16:46:49 +02:00
|
|
|
</Margin>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
|
2018-01-30 01:20:22 +02:00
|
|
|
const Image = ({ onClick, active, ...image }) => {
|
|
|
|
const { imageName = '', versions = [] } = image;
|
|
|
|
|
2018-02-22 04:08:18 +02:00
|
|
|
const id = `image-card-${imageName}`;
|
2018-02-05 17:12:47 +02:00
|
|
|
|
2018-02-22 04:08:18 +02:00
|
|
|
const handleCardClick = ev => {
|
|
|
|
return ev.target.id === id ? onClick(image) : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleLogoClick = ev => {
|
|
|
|
return onClick(image);
|
|
|
|
};
|
2018-01-30 01:20:22 +02:00
|
|
|
|
2018-02-05 17:12:47 +02:00
|
|
|
const Logo = Assets[pascalCase(imageName)] || Assets.Placeholder;
|
|
|
|
|
2018-01-30 01:20:22 +02:00
|
|
|
return (
|
|
|
|
<Col md={2} sm={3}>
|
2018-01-30 18:04:03 +02:00
|
|
|
<Margin bottom={3}>
|
2018-02-22 04:08:18 +02:00
|
|
|
<Card id={id} onClick={handleCardClick} active={active} preview>
|
|
|
|
<Logo onClick={handleLogoClick} width="42" height="42" />
|
2018-01-30 18:04:03 +02:00
|
|
|
<H4>{titleCase(imageName)}</H4>
|
|
|
|
<FormGroup name="image" field={Field}>
|
|
|
|
<Version onBlur={null}>
|
|
|
|
<option selected>Version</option>
|
|
|
|
{versions.map(({ name, version, id }) => (
|
|
|
|
<option
|
|
|
|
key={`${name} - ${version}`}
|
|
|
|
value={id}
|
|
|
|
>{`${name} - ${version}`}</option>
|
|
|
|
))}
|
|
|
|
</Version>
|
|
|
|
</FormGroup>
|
|
|
|
</Card>
|
|
|
|
</Margin>
|
2018-01-30 01:20:22 +02:00
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-02-26 15:47:52 +02:00
|
|
|
export const ImageType = ({ setImageType, vms }) => (
|
|
|
|
<Margin bottom={4}>
|
|
|
|
<SectionList>
|
|
|
|
<SectionListItem>
|
2018-02-27 17:23:29 +02:00
|
|
|
<SectionListAnchor active={vms} onClick={() => setImageType(true)}>
|
2018-02-26 15:47:52 +02:00
|
|
|
Hardware virtual machine
|
|
|
|
</SectionListAnchor>
|
|
|
|
</SectionListItem>
|
|
|
|
<SectionListItem>
|
2018-02-27 17:23:29 +02:00
|
|
|
<SectionListAnchor active={!vms} onClick={() => setImageType(false)}>
|
2018-02-26 15:47:52 +02:00
|
|
|
Infrastructure container
|
|
|
|
</SectionListAnchor>
|
|
|
|
</SectionListItem>
|
|
|
|
</SectionList>
|
|
|
|
</Margin>
|
2018-01-30 01:20:22 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
export default ({ images = [], onSelectLatest }) => (
|
|
|
|
<form>
|
2018-01-18 16:46:49 +02:00
|
|
|
<Row>
|
2018-01-30 01:20:22 +02:00
|
|
|
{images.map(({ imageName, ...image }) => (
|
|
|
|
<Image
|
|
|
|
{...image}
|
|
|
|
key={imageName}
|
|
|
|
imageName={imageName}
|
|
|
|
onClick={onSelectLatest}
|
|
|
|
/>
|
|
|
|
))}
|
2018-01-18 16:46:49 +02:00
|
|
|
</Row>
|
2018-01-09 20:14:20 +02:00
|
|
|
</form>
|
|
|
|
);
|