2018-02-01 12:38:12 +02:00
|
|
|
import React, { Fragment } from 'react';
|
2017-11-23 14:18:38 +02:00
|
|
|
import { Field } from 'redux-form';
|
2018-01-05 17:42:09 +02:00
|
|
|
import titleCase from 'title-case';
|
2018-01-05 18:35:26 +02:00
|
|
|
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
2018-01-05 17:42:09 +02:00
|
|
|
import remcalc from 'remcalc';
|
2018-03-28 15:51:34 +03:00
|
|
|
import { Margin } from 'styled-components-spacing';
|
2017-10-13 22:56:08 +03:00
|
|
|
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
StatusLoader,
|
2017-10-31 12:29:15 +02:00
|
|
|
Table,
|
|
|
|
TableThead,
|
|
|
|
TableTr,
|
|
|
|
TableTh,
|
|
|
|
TableTbody,
|
|
|
|
TableTd,
|
|
|
|
Checkbox,
|
2018-02-05 17:12:47 +02:00
|
|
|
KeyValue,
|
2018-01-05 17:42:09 +02:00
|
|
|
Popover,
|
|
|
|
PopoverContainer,
|
|
|
|
PopoverTarget,
|
|
|
|
PopoverItem,
|
|
|
|
ActionsIcon,
|
|
|
|
DotIcon
|
2017-10-13 22:56:08 +03:00
|
|
|
} from 'joyent-ui-toolkit';
|
|
|
|
|
2018-04-12 12:53:00 +03:00
|
|
|
import { Empty } from 'joyent-ui-resource-widgets';
|
2018-01-23 14:20:36 +02:00
|
|
|
|
2018-01-05 17:42:09 +02:00
|
|
|
const stateColor = {
|
|
|
|
QUEUED: 'primary',
|
|
|
|
CREATED: 'green'
|
|
|
|
};
|
2017-10-13 22:56:08 +03:00
|
|
|
|
2018-02-26 19:48:59 +02:00
|
|
|
const loadingState = {
|
|
|
|
start: 'Starting...',
|
|
|
|
remove: 'Removing...'
|
|
|
|
};
|
|
|
|
|
2018-02-27 15:24:36 +02:00
|
|
|
export const Item = ({ name, state, created, onStart, onRemove, mutating }) => (
|
2017-10-31 12:29:15 +02:00
|
|
|
<TableTr>
|
2018-01-05 17:42:09 +02:00
|
|
|
{!mutating ? (
|
2018-02-01 12:38:12 +02:00
|
|
|
<Fragment>
|
2018-01-05 17:42:09 +02:00
|
|
|
<TableTd padding="0" paddingLeft={remcalc(12)} middle left>
|
|
|
|
<FormGroup paddingTop={remcalc(4)} name={name} field={Field}>
|
|
|
|
<Checkbox noMargin />
|
|
|
|
</FormGroup>
|
2018-02-01 17:33:58 +02:00
|
|
|
</TableTd>
|
2018-01-05 17:42:09 +02:00
|
|
|
<TableTd middle left>
|
|
|
|
{name}
|
2018-02-01 17:33:58 +02:00
|
|
|
</TableTd>
|
2018-01-05 17:42:09 +02:00
|
|
|
<TableTd middle left>
|
2018-02-01 17:33:58 +02:00
|
|
|
<DotIcon size={remcalc(12)} color={stateColor[state]} />{' '}
|
|
|
|
{titleCase(state)}
|
|
|
|
</TableTd>
|
2018-01-05 17:42:09 +02:00
|
|
|
<TableTd xs="0" sm="160" middle left>
|
2018-01-05 18:35:26 +02:00
|
|
|
{distanceInWordsToNow(created)}
|
2018-02-01 17:33:58 +02:00
|
|
|
</TableTd>
|
2018-01-05 17:42:09 +02:00
|
|
|
<PopoverContainer clickable>
|
|
|
|
<TableTd padding="0" hasBorder="left">
|
|
|
|
<PopoverTarget box>
|
|
|
|
<ActionsIcon />
|
|
|
|
</PopoverTarget>
|
|
|
|
<Popover placement="top">
|
2018-03-28 15:51:34 +03:00
|
|
|
<Margin vertical={2} horizontal={3}>
|
|
|
|
<PopoverItem onClick={onStart}>Start</PopoverItem>
|
|
|
|
</Margin>
|
|
|
|
<Margin vertical={2} horizontal={3}>
|
|
|
|
<PopoverItem onClick={onRemove}>Remove</PopoverItem>
|
|
|
|
</Margin>
|
2018-01-05 17:42:09 +02:00
|
|
|
</Popover>
|
|
|
|
</TableTd>
|
|
|
|
</PopoverContainer>
|
2018-02-01 12:38:12 +02:00
|
|
|
</Fragment>
|
2018-01-05 17:42:09 +02:00
|
|
|
) : (
|
2018-02-26 19:48:59 +02:00
|
|
|
<TableTd colSpan="5">
|
|
|
|
<StatusLoader msg={loadingState[mutating]} />
|
2018-01-05 17:42:09 +02:00
|
|
|
</TableTd>
|
|
|
|
)}
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTr>
|
|
|
|
);
|
|
|
|
|
2018-01-05 17:42:09 +02:00
|
|
|
export const AddForm = props => (
|
2018-02-01 17:33:58 +02:00
|
|
|
<KeyValue
|
|
|
|
{...props}
|
|
|
|
method="create"
|
|
|
|
input="input"
|
|
|
|
type="snapshot"
|
2018-02-22 02:01:07 +02:00
|
|
|
typeLabel="name"
|
2018-02-01 17:33:58 +02:00
|
|
|
expanded
|
|
|
|
onlyName
|
|
|
|
noRemove
|
|
|
|
/>
|
2018-01-05 17:42:09 +02:00
|
|
|
);
|
|
|
|
|
2017-10-13 22:56:08 +03:00
|
|
|
export default ({
|
|
|
|
snapshots = [],
|
|
|
|
selected = [],
|
|
|
|
error,
|
|
|
|
handleChange = () => null,
|
|
|
|
onAction = () => null,
|
|
|
|
submitting = false,
|
2018-01-05 17:42:09 +02:00
|
|
|
sortBy = 'name',
|
|
|
|
sortOrder = 'desc',
|
|
|
|
onSortBy = () => null,
|
|
|
|
allSelected = false,
|
|
|
|
toggleSelectAll = () => null,
|
|
|
|
onStart,
|
|
|
|
onRemove,
|
2017-10-13 22:56:08 +03:00
|
|
|
...rest
|
2018-02-01 12:38:12 +02:00
|
|
|
}) => (
|
|
|
|
<Fragment>
|
2017-10-31 12:29:15 +02:00
|
|
|
<Table>
|
|
|
|
<TableThead>
|
|
|
|
<TableTr>
|
2018-01-05 17:42:09 +02:00
|
|
|
<TableTh xs="32" padding="0" paddingLeft={remcalc(12)} middle left>
|
|
|
|
<FormGroup paddingTop={remcalc(4)}>
|
|
|
|
<Checkbox
|
|
|
|
checked={allSelected}
|
|
|
|
disabled={submitting}
|
|
|
|
onChange={toggleSelectAll}
|
|
|
|
noMargin
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</TableTh>
|
|
|
|
<TableTh
|
|
|
|
onClick={() => onSortBy('name', sortOrder)}
|
|
|
|
sortOrder={sortOrder}
|
|
|
|
showSort={sortBy === 'name'}
|
|
|
|
left
|
|
|
|
middle
|
2018-02-01 17:33:58 +02:00
|
|
|
actionable
|
|
|
|
>
|
2018-01-05 17:42:09 +02:00
|
|
|
<span>Name </span>
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTh>
|
2018-01-05 17:42:09 +02:00
|
|
|
<TableTh
|
|
|
|
xs="150"
|
|
|
|
onClick={() => onSortBy('state', sortOrder)}
|
|
|
|
sortOrder={sortOrder}
|
|
|
|
showSort={sortBy === 'state'}
|
|
|
|
left
|
|
|
|
middle
|
2018-02-01 17:33:58 +02:00
|
|
|
actionable
|
|
|
|
>
|
2018-01-05 17:42:09 +02:00
|
|
|
<span>Status </span>
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTh>
|
2018-01-05 17:42:09 +02:00
|
|
|
<TableTh
|
|
|
|
xs="0"
|
|
|
|
sm="160"
|
|
|
|
onClick={() => onSortBy('created', sortOrder)}
|
|
|
|
sortOrder={sortOrder}
|
|
|
|
showSort={sortBy === 'created'}
|
|
|
|
left
|
|
|
|
middle
|
2018-02-01 17:33:58 +02:00
|
|
|
actionable
|
|
|
|
>
|
2018-01-05 17:42:09 +02:00
|
|
|
<span>Created </span>
|
|
|
|
</TableTh>
|
|
|
|
<TableTh xs="60" padding="0" />
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTr>
|
|
|
|
</TableThead>
|
2017-11-02 15:33:43 +02:00
|
|
|
<TableTbody>
|
2018-02-01 12:38:12 +02:00
|
|
|
{snapshots.length
|
|
|
|
? snapshots.map(snapshot => (
|
|
|
|
<Item
|
|
|
|
onStart={() => onStart(snapshot)}
|
|
|
|
onRemove={() => onRemove(snapshot)}
|
|
|
|
key={snapshot.id}
|
|
|
|
{...snapshot}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
: null}
|
2017-11-02 15:33:43 +02:00
|
|
|
</TableTbody>
|
2017-10-31 12:29:15 +02:00
|
|
|
</Table>
|
2018-02-26 15:47:37 +02:00
|
|
|
{!snapshots.length ? <Empty borderTop>You have no Snapshots</Empty> : null}
|
2018-02-01 12:38:12 +02:00
|
|
|
</Fragment>
|
|
|
|
);
|