2018-02-06 12:32:47 +02:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
import { Field } from 'redux-form';
|
2018-05-08 18:55:18 +03:00
|
|
|
import Flex, { FlexItem } from 'styled-flex-component';
|
2018-02-13 22:03:57 +02:00
|
|
|
import { Padding, Margin } from 'styled-components-spacing';
|
2018-03-21 19:35:51 +02:00
|
|
|
import remcalc from 'remcalc';
|
2018-02-13 22:03:57 +02:00
|
|
|
|
2018-02-06 12:32:47 +02:00
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
Anchor,
|
|
|
|
CardHeader,
|
|
|
|
Divider,
|
|
|
|
ActionsIcon,
|
|
|
|
PopoverTarget,
|
|
|
|
Popover,
|
|
|
|
PopoverItem,
|
2018-04-12 12:53:00 +03:00
|
|
|
PopoverDivider as BasePopoverDivider,
|
2018-02-06 12:32:47 +02:00
|
|
|
PopoverContainer,
|
|
|
|
Radio,
|
|
|
|
FormLabel,
|
2018-02-14 21:36:31 +02:00
|
|
|
FormGroup,
|
|
|
|
StatusLoader
|
2018-02-06 12:32: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-06 12:32:47 +02:00
|
|
|
|
|
|
|
const A = styled(Anchor)`
|
|
|
|
color: ${props => props.theme.text};
|
|
|
|
text-decoration: none;
|
|
|
|
font-weight: ${props => props.theme.font.weight.semibold};
|
|
|
|
`;
|
|
|
|
|
2018-02-13 22:33:03 +02:00
|
|
|
const CardAnchor = styled(Anchor)`
|
|
|
|
color: ${props => props.theme.text};
|
|
|
|
text-decoration: none;
|
|
|
|
`;
|
|
|
|
|
2018-02-15 16:37:59 +02:00
|
|
|
const ItemAnchor = styled(Anchor)`
|
|
|
|
color: ${props => props.theme.text};
|
|
|
|
-webkit-text-fill-color: currentcolor;
|
|
|
|
text-decoration: none;
|
|
|
|
`;
|
|
|
|
|
2018-02-13 22:33:03 +02:00
|
|
|
const Type = styled(Margin)`
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Content = styled(Padding)`
|
2018-03-21 19:35:51 +02:00
|
|
|
max-width: calc(100% - ${remcalc(48)});
|
2018-02-13 22:33:03 +02:00
|
|
|
overflow: hidden;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Max = styled(Flex)`
|
|
|
|
max-width: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Actions = styled(Flex)`
|
2018-03-21 19:35:51 +02:00
|
|
|
width: ${remcalc(48)};
|
|
|
|
height: ${remcalc(48)};
|
|
|
|
min-width: ${remcalc(48)};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ActionsWrapper = styled(Flex)`
|
|
|
|
height: 100%;
|
2018-04-12 12:53:00 +03:00
|
|
|
width: 100%;
|
2018-03-21 19:35:51 +02:00
|
|
|
border-left: ${remcalc(1)} solid ${props => props.theme.grey};
|
2018-02-13 22:33:03 +02:00
|
|
|
`;
|
|
|
|
|
2018-04-12 12:53:00 +03:00
|
|
|
const PopoverDivider = styled(BasePopoverDivider)`
|
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
2018-02-15 16:37:59 +02:00
|
|
|
export const Image = ({
|
|
|
|
name,
|
2018-03-21 19:35:51 +02:00
|
|
|
id,
|
2018-02-15 16:37:59 +02:00
|
|
|
os,
|
|
|
|
version,
|
|
|
|
type,
|
|
|
|
removing,
|
|
|
|
onRemove,
|
|
|
|
onCreateInstance
|
|
|
|
}) => (
|
2018-02-06 12:32:47 +02:00
|
|
|
<Margin bottom={3}>
|
2018-03-21 19:35:51 +02:00
|
|
|
<CardAnchor to={`/images/${id}`} component={Link}>
|
2018-02-13 22:33:03 +02:00
|
|
|
<Card radius>
|
2018-02-14 21:36:31 +02:00
|
|
|
{removing ? (
|
|
|
|
<Padding all={2}>
|
|
|
|
<StatusLoader />
|
2018-02-13 22:33:03 +02:00
|
|
|
</Padding>
|
2018-02-14 21:36:31 +02:00
|
|
|
) : (
|
|
|
|
<Fragment>
|
|
|
|
<CardHeader white radius>
|
|
|
|
<Padding left={2} right={2}>
|
|
|
|
<Flex full alignCenter>
|
2018-05-08 18:55:18 +03:00
|
|
|
<FlexItem>
|
|
|
|
<Margin right={2}>
|
|
|
|
{React.createElement(OS[os], {
|
|
|
|
width: '24',
|
|
|
|
height: '24'
|
|
|
|
})}
|
|
|
|
</Margin>
|
|
|
|
</FlexItem>
|
|
|
|
<FlexItem>
|
|
|
|
<A to={`/images/${id}/summary`} component={Link}>
|
|
|
|
{name}
|
|
|
|
</A>
|
|
|
|
</FlexItem>
|
2018-02-14 21:36:31 +02:00
|
|
|
</Flex>
|
|
|
|
</Padding>
|
|
|
|
</CardHeader>
|
|
|
|
<Flex justifyBetween>
|
|
|
|
<Content left={2} top={2} bottom={2}>
|
|
|
|
<Max justifyBetween>
|
|
|
|
<Max alignCenter>
|
|
|
|
<Flex>{version}</Flex>
|
2018-04-12 12:53:00 +03:00
|
|
|
<Divider vertical />
|
|
|
|
<Type>{ImageType[type]}</Type>
|
2018-02-14 21:36:31 +02:00
|
|
|
</Max>
|
|
|
|
</Max>
|
|
|
|
</Content>
|
|
|
|
<PopoverContainer clickable>
|
|
|
|
<Actions>
|
2018-03-21 19:35:51 +02:00
|
|
|
<PopoverTarget box>
|
|
|
|
<ActionsWrapper alignCenter justifyCenter>
|
|
|
|
<ActionsIcon />
|
|
|
|
</ActionsWrapper>
|
2018-02-14 21:36:31 +02:00
|
|
|
</PopoverTarget>
|
2018-04-12 12:53:00 +03:00
|
|
|
<Popover noPadding placement="bottom">
|
|
|
|
<Padding horizontal={3} vertical={2}>
|
|
|
|
<PopoverItem disabled={false} onClick={onCreateInstance}>
|
|
|
|
<ItemAnchor
|
|
|
|
href={`${
|
|
|
|
GLOBAL.origin
|
|
|
|
}/instances/~create/?image=${name}`}
|
|
|
|
target="__blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
Create Instance
|
|
|
|
</ItemAnchor>
|
|
|
|
</PopoverItem>
|
|
|
|
</Padding>
|
2018-02-14 21:36:31 +02:00
|
|
|
<PopoverDivider />
|
2018-04-12 12:53:00 +03:00
|
|
|
<Padding horizontal={3} vertical={2}>
|
|
|
|
<PopoverItem disabled={removing} onClick={onRemove}>
|
|
|
|
Remove
|
|
|
|
</PopoverItem>
|
|
|
|
</Padding>
|
2018-02-14 21:36:31 +02:00
|
|
|
</Popover>
|
|
|
|
</Actions>
|
|
|
|
</PopoverContainer>
|
|
|
|
</Flex>
|
|
|
|
</Fragment>
|
|
|
|
)}
|
2018-02-13 22:33:03 +02:00
|
|
|
</Card>
|
|
|
|
</CardAnchor>
|
2018-02-06 12:32:47 +02:00
|
|
|
</Margin>
|
|
|
|
);
|
|
|
|
|
2018-02-13 22:33:03 +02:00
|
|
|
export const Filters = ({ selected }) => (
|
2018-02-06 12:32:47 +02:00
|
|
|
<Fragment>
|
|
|
|
<FormGroup name="image-type" value="all" field={Field} type="radio">
|
2018-04-12 12:53:00 +03:00
|
|
|
<Radio>
|
2018-02-06 12:32:47 +02:00
|
|
|
<Flex alignCenter>
|
2018-04-12 12:53:00 +03:00
|
|
|
<Margin horizontal={2}>
|
2018-02-13 22:33:03 +02:00
|
|
|
<FormLabel big normal={selected !== 'all'}>
|
|
|
|
All
|
|
|
|
</FormLabel>
|
2018-02-06 12:32:47 +02:00
|
|
|
</Margin>
|
|
|
|
</Flex>
|
|
|
|
</Radio>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
name="image-type"
|
|
|
|
value="hardware-virtual-machine"
|
|
|
|
field={Field}
|
|
|
|
type="radio"
|
|
|
|
>
|
|
|
|
<Radio noMargin>
|
|
|
|
<Flex alignCenter>
|
2018-04-12 12:53:00 +03:00
|
|
|
<Margin horizontal={2}>
|
2018-02-13 22:33:03 +02:00
|
|
|
<FormLabel big normal={selected !== 'hardware-virtual-machine'}>
|
|
|
|
Virtual machines
|
|
|
|
</FormLabel>
|
2018-02-06 12:32:47 +02:00
|
|
|
</Margin>
|
|
|
|
</Flex>
|
|
|
|
</Radio>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
name="image-type"
|
|
|
|
value="infrastructure-container"
|
|
|
|
field={Field}
|
|
|
|
type="radio"
|
|
|
|
>
|
|
|
|
<Radio noMargin>
|
|
|
|
<Flex alignCenter>
|
2018-04-12 12:53:00 +03:00
|
|
|
<Margin horizontal={2}>
|
2018-02-13 22:33:03 +02:00
|
|
|
<FormLabel big normal={selected !== 'infrastructure-container'}>
|
|
|
|
Infrastructure container
|
|
|
|
</FormLabel>
|
2018-02-06 12:32:47 +02:00
|
|
|
</Margin>
|
|
|
|
</Flex>
|
|
|
|
</Radio>
|
|
|
|
</FormGroup>
|
|
|
|
</Fragment>
|
|
|
|
);
|