joyent-portal/consoles/my-joy-images/src/components/summary.js

191 lines
5.0 KiB
JavaScript
Raw Normal View History

2018-02-05 17:12:47 +02:00
import React, { Fragment } from 'react';
import { Row, Col } from 'joyent-react-styled-flexboxgrid';
import { Margin, Padding } from 'styled-components-spacing';
2018-04-06 17:53:44 +03:00
import styled from 'styled-components';
2018-02-05 17:12:47 +02:00
import Flex, { FlexItem } from 'styled-flex-component';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import titleCase from 'title-case';
import remcalc from 'remcalc';
import { ValueBreakpoints as breakpoints } from 'joyent-ui-toolkit';
2018-02-05 17:12:47 +02:00
import {
Card,
CardOutlet,
H2,
P,
2018-05-17 13:05:28 +03:00
Label as BaseLabel,
2018-02-05 17:12:47 +02:00
Divider,
Button,
QueryBreakpoints,
CopiableField,
DuplicateIcon,
DeleteIcon,
DotIcon,
FormLabel,
Input
2018-02-05 17:12:47 +02:00
} from 'joyent-ui-toolkit';
2018-03-06 03:14:33 +02:00
import GLOBAL from '@state/global';
2018-02-13 22:03:57 +02:00
import { ImageType, OS } from '@root/constants';
2018-02-05 17:12:47 +02:00
const { SmallOnly, Medium } = QueryBreakpoints;
const VerticalDivider = styled.div`
width: ${remcalc(1)};
background: ${props => props.theme.grey};
height: ${remcalc(24)};
display: flex;
align-self: flex-end;
margin: 0 ${remcalc(18)};
@media (max-width: ${remcalc(breakpoints.small.upper)}) {
2018-02-05 17:12:47 +02:00
display: none;
}
`;
2018-05-17 13:05:28 +03:00
const Label = styled(BaseLabel)`
font-weight: 200;
`;
2018-02-05 17:12:47 +02:00
const GreyLabel = styled(Label)`
opacity: 0.5;
padding-right: ${remcalc(3)};
`;
const StateColor = {
ACTIVE: 'green',
UNACTIVATED: 'grey',
DISABLED: 'secondaryActive',
CREATING: 'primary',
FAILED: 'red'
};
2018-02-06 12:32:47 +02:00
// eslint-disable-next-line camelcase
2018-02-05 17:12:47 +02:00
export const Meta = ({ name, version, type, published_at, state, os }) => (
<Fragment>
<Flex alignCenter>
<FlexItem>
<Margin right="2">
{React.createElement(OS[os], {
width: '30',
height: '30'
})}
</Margin>
</FlexItem>
<FlexItem>
<H2 bold>{name}</H2>
</FlexItem>
</Flex>
2018-04-06 17:53:44 +03:00
<Margin top="2" bottom="3">
2018-02-05 17:12:47 +02:00
<Flex>
<Label>{version}</Label>
<VerticalDivider />
<Label>{ImageType[type]}</Label>
<VerticalDivider />
<Fragment>
<GreyLabel>Created:</GreyLabel>
<Label> {distanceInWordsToNow(published_at)} ago</Label>
</Fragment>
<VerticalDivider />
<Flex>
<FlexItem>
<DotIcon
right={remcalc(6)}
size={remcalc(15)}
color={StateColor[state]}
/>
</FlexItem>
<FlexItem>
<Label>{titleCase(state)}</Label>
</FlexItem>
</Flex>
</Flex>
</Margin>
</Fragment>
);
2018-04-06 17:53:44 +03:00
export default ({ theme = {}, onRemove, removing, ...image }) => (
2018-02-05 17:12:47 +02:00
<Row>
2018-05-23 19:29:04 +03:00
<Col xs="12" sm="12" md="9">
2018-02-05 17:12:47 +02:00
<Card>
<CardOutlet>
2018-05-23 19:29:04 +03:00
<Padding all="5">
2018-02-05 17:12:47 +02:00
<Meta {...image} />
<Row between="xs">
2018-05-23 19:29:04 +03:00
<Col xs="9">
2018-02-05 17:12:47 +02:00
<SmallOnly>
<Button type="button" small icon>
<DuplicateIcon light />
</Button>
</SmallOnly>
<Medium>
<Button
type="button"
2018-03-06 03:47:30 +02:00
href={`${GLOBAL.origin}/instances/~create/?image=${
image.id
2018-03-06 03:47:30 +02:00
}`}
target="__blank"
rel="noopener noreferrer"
bold
icon
>
2018-02-05 17:12:47 +02:00
<span>Create Instance</span>
</Button>
</Medium>
</Col>
2018-05-23 19:29:04 +03:00
<Col xs="3">
2018-02-05 17:12:47 +02:00
<SmallOnly>
<Button type="button" small icon error right>
2018-04-06 17:53:44 +03:00
<DeleteIcon fill="red" />
2018-02-05 17:12:47 +02:00
</Button>
</SmallOnly>
<Medium>
<Button
type="button"
loading={removing}
onClick={onRemove}
bold
icon
error
right
>
<Margin right="1">
2018-04-06 17:53:44 +03:00
<DeleteIcon fill="red" />
</Margin>
2018-05-17 13:05:28 +03:00
<span>Delete</span>
2018-02-05 17:12:47 +02:00
</Button>
</Medium>
</Col>
</Row>
<Margin bottom="4" top="4">
<Divider height={remcalc(1)} />
</Margin>
<Margin bottom="2">
<P>{image.description}</P>
</Margin>
2018-04-06 17:53:44 +03:00
<Margin bottom="3">
<CopiableField text={(image.id || '').split('-')[0]} label="ID" />
</Margin>
2018-04-06 17:53:44 +03:00
<Margin bottom="3">
<CopiableField text={image.id} label="UUID" />
</Margin>
<Row>
2018-05-23 19:29:04 +03:00
<Col xs="12" md="7">
2018-04-06 17:53:44 +03:00
<Margin bottom="3">
<FormLabel>Operating system</FormLabel>
<Input
monospace
onBlur={null}
fluid
value={titleCase(image.os)}
/>
</Margin>
</Col>
</Row>
2018-02-05 17:12:47 +02:00
</Padding>
</CardOutlet>
</Card>
</Col>
</Row>
2018-04-06 17:53:44 +03:00
);