2017-09-20 12:30:53 +03:00
|
|
|
import React from 'react';
|
2017-11-23 14:18:38 +02:00
|
|
|
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
|
|
|
import remcalc from 'remcalc';
|
2017-10-31 12:29:15 +02:00
|
|
|
import titleCase from 'title-case';
|
2017-11-23 14:18:38 +02:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import { Field } from 'redux-form';
|
2017-09-20 12:30:53 +03:00
|
|
|
|
2017-09-27 17:44:57 +03:00
|
|
|
import {
|
2017-11-23 14:18:38 +02:00
|
|
|
Row,
|
|
|
|
Col,
|
|
|
|
Anchor,
|
2017-09-27 17:44:57 +03:00
|
|
|
FormGroup,
|
2017-11-23 14:18:38 +02:00
|
|
|
Checkbox,
|
2017-10-13 22:51:18 +03:00
|
|
|
Button,
|
2017-10-31 12:29:15 +02:00
|
|
|
Table,
|
|
|
|
TableThead,
|
|
|
|
TableTr,
|
|
|
|
TableTh,
|
|
|
|
TableTd,
|
2017-11-23 14:18:38 +02:00
|
|
|
TableTbody,
|
|
|
|
Footer,
|
|
|
|
StatusLoader,
|
|
|
|
Popover,
|
2017-10-31 12:29:15 +02:00
|
|
|
PopoverContainer,
|
|
|
|
PopoverTarget,
|
|
|
|
PopoverItem,
|
|
|
|
PopoverDivider,
|
2017-11-23 14:18:38 +02:00
|
|
|
QueryBreakpoints,
|
|
|
|
DotIcon,
|
|
|
|
StartIcon,
|
|
|
|
StopIcon,
|
|
|
|
ResetIcon,
|
|
|
|
DeleteIcon,
|
|
|
|
ActionsIcon
|
2017-09-27 17:44:57 +03:00
|
|
|
} from 'joyent-ui-toolkit';
|
|
|
|
|
2017-11-02 15:33:43 +02:00
|
|
|
const { SmallOnly, Medium } = QueryBreakpoints;
|
2017-09-20 12:30:53 +03:00
|
|
|
|
2017-10-31 12:29:15 +02:00
|
|
|
const stateColor = {
|
|
|
|
PROVISIONING: 'primary',
|
|
|
|
RUNNING: 'green',
|
|
|
|
STOPPING: 'grey',
|
|
|
|
STOPPED: 'grey',
|
|
|
|
DELETED: 'secondaryActive',
|
|
|
|
FAILED: 'red'
|
|
|
|
};
|
|
|
|
|
2017-11-23 14:18:38 +02:00
|
|
|
export const Actions = ({
|
|
|
|
submitting = false,
|
2017-12-21 02:12:42 +02:00
|
|
|
statuses = {},
|
2017-11-23 14:18:38 +02:00
|
|
|
allowedActions = {},
|
|
|
|
onStart = () => null,
|
|
|
|
onStop = () => null,
|
|
|
|
onReboot = () => null,
|
|
|
|
onDelete = () => null
|
|
|
|
}) => (
|
|
|
|
<Footer fixed bottom>
|
|
|
|
<Row between="xs" middle="xs">
|
|
|
|
<Col xs={7}>
|
2017-12-21 02:12:42 +02:00
|
|
|
<SmallOnly key="small-only">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onStart}
|
|
|
|
disabled={submitting || !allowedActions.start}
|
|
|
|
loading={submitting && statuses.starting}
|
|
|
|
secondary
|
|
|
|
small
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<StartIcon disabled={submitting || !allowedActions.start} />
|
|
|
|
</Button>
|
|
|
|
</SmallOnly>
|
|
|
|
<Medium key="medium">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onStart}
|
|
|
|
disabled={submitting || !allowedActions.start}
|
|
|
|
loading={submitting && statuses.starting}
|
|
|
|
secondary
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<StartIcon disabled={submitting || !allowedActions.start} />
|
|
|
|
<span>Start</span>
|
|
|
|
</Button>
|
|
|
|
</Medium>
|
|
|
|
<SmallOnly key="small-only">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onStop}
|
|
|
|
disabled={submitting || !allowedActions.stop}
|
|
|
|
loading={submitting && statuses.stopping}
|
|
|
|
secondary
|
|
|
|
small
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<StopIcon disabled={submitting || !allowedActions.stop} />
|
|
|
|
</Button>
|
|
|
|
</SmallOnly>
|
|
|
|
<Medium key="medium">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onStop}
|
|
|
|
disabled={submitting || !allowedActions.stop}
|
|
|
|
loading={submitting && statuses.stopping}
|
|
|
|
secondary
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<StopIcon disabled={submitting || !allowedActions.stop} />
|
|
|
|
<span>Stop</span>
|
|
|
|
</Button>
|
|
|
|
</Medium>
|
|
|
|
<SmallOnly key="small-only">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onReboot}
|
|
|
|
disabled={submitting || !allowedActions.reboot}
|
|
|
|
loading={submitting && statuses.restarting}
|
|
|
|
secondary
|
|
|
|
small
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<ResetIcon disabled={submitting || !allowedActions.reboot} />
|
|
|
|
</Button>
|
|
|
|
</SmallOnly>
|
|
|
|
<Medium key="medium">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onReboot}
|
|
|
|
disabled={submitting || !allowedActions.reboot}
|
|
|
|
loading={submitting && statuses.restarting}
|
|
|
|
secondary
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<ResetIcon disabled={submitting || !allowedActions.reboot} />
|
|
|
|
<span>Reboot</span>
|
|
|
|
</Button>
|
|
|
|
</Medium>
|
2017-11-23 14:18:38 +02:00
|
|
|
</Col>
|
|
|
|
<Col xs={5}>
|
2017-12-21 02:12:42 +02:00
|
|
|
<SmallOnly key="small-only">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onDelete}
|
|
|
|
disabled={submitting}
|
|
|
|
loading={submitting && statuses.deleting}
|
|
|
|
secondary
|
|
|
|
right
|
|
|
|
small
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<DeleteIcon disabled={submitting} />
|
|
|
|
</Button>
|
|
|
|
</SmallOnly>
|
|
|
|
<Medium key="medium">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={onDelete}
|
|
|
|
disabled={submitting}
|
|
|
|
loading={submitting && statuses.deleting}
|
|
|
|
secondary
|
|
|
|
right
|
|
|
|
icon
|
|
|
|
>
|
|
|
|
<DeleteIcon disabled={submitting} />
|
|
|
|
<span>Delete</span>
|
|
|
|
</Button>
|
|
|
|
</Medium>
|
2017-11-23 14:18:38 +02:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Footer>
|
|
|
|
);
|
|
|
|
|
|
|
|
export const Item = ({
|
|
|
|
id = '',
|
2017-10-31 12:29:15 +02:00
|
|
|
name,
|
2017-12-21 02:12:42 +02:00
|
|
|
state = 'RUNNING',
|
2017-11-23 14:18:38 +02:00
|
|
|
created,
|
|
|
|
allowedActions = {},
|
2017-12-21 02:12:42 +02:00
|
|
|
mutating = false,
|
2017-10-31 12:29:15 +02:00
|
|
|
onStart,
|
2017-11-23 14:18:38 +02:00
|
|
|
onStop,
|
2017-10-31 12:29:15 +02:00
|
|
|
onReboot,
|
2017-11-23 14:18:38 +02:00
|
|
|
onDelete
|
2017-10-31 12:29:15 +02:00
|
|
|
}) => (
|
|
|
|
<TableTr>
|
2017-11-23 14:18:38 +02:00
|
|
|
<TableTd padding="0" paddingLeft={remcalc(12)} middle left>
|
2017-11-23 14:18:38 +02:00
|
|
|
<FormGroup name={id} paddingTop={remcalc(4)} field={Field}>
|
|
|
|
<Checkbox noMargin />
|
2017-10-31 12:29:15 +02:00
|
|
|
</FormGroup>
|
|
|
|
</TableTd>
|
2017-11-23 14:18:38 +02:00
|
|
|
<TableTd middle left>
|
2017-11-23 14:18:38 +02:00
|
|
|
<Anchor to={`/instances/${name}`} component={Link}>
|
|
|
|
{name}
|
|
|
|
</Anchor>
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTd>
|
2017-11-23 14:18:38 +02:00
|
|
|
<TableTd middle left>
|
2017-12-21 02:12:42 +02:00
|
|
|
{mutating ? (
|
|
|
|
<StatusLoader small />
|
|
|
|
) : (
|
|
|
|
<span>
|
|
|
|
<DotIcon
|
|
|
|
width={remcalc(11)}
|
|
|
|
height={remcalc(11)}
|
|
|
|
borderRadius={remcalc(11)}
|
|
|
|
color={stateColor[state]}
|
|
|
|
/>{' '}
|
|
|
|
{titleCase(state)}
|
|
|
|
</span>
|
|
|
|
)}
|
2017-11-23 14:18:38 +02:00
|
|
|
</TableTd>
|
2017-12-04 20:24:24 +02:00
|
|
|
<TableTd xs="0" sm="160" middle left>
|
2017-11-23 14:18:38 +02:00
|
|
|
{distanceInWordsToNow(created)}
|
|
|
|
</TableTd>
|
2017-12-06 12:34:15 +02:00
|
|
|
<TableTd xs="0" sm="130" middle left>
|
2017-11-23 14:18:38 +02:00
|
|
|
<code>{id.substring(0, 7)}</code>
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTd>
|
2017-12-21 02:12:42 +02:00
|
|
|
{!mutating ? (
|
|
|
|
<PopoverContainer clickable>
|
|
|
|
<TableTd padding="0" hasBorder="left">
|
|
|
|
<PopoverTarget box>
|
|
|
|
<ActionsIcon />
|
|
|
|
</PopoverTarget>
|
|
|
|
<Popover placement="bottom">
|
|
|
|
<PopoverItem disabled={!allowedActions.start} onClick={onStart}>
|
|
|
|
Start
|
|
|
|
</PopoverItem>
|
|
|
|
<PopoverItem disabled={!allowedActions.stop} onClick={onStop}>
|
|
|
|
Stop
|
|
|
|
</PopoverItem>
|
|
|
|
<PopoverItem onClick={onReboot}>Reboot</PopoverItem>
|
|
|
|
<PopoverDivider />
|
|
|
|
<PopoverItem onClick={onDelete}>Delete</PopoverItem>
|
|
|
|
</Popover>
|
|
|
|
</TableTd>
|
|
|
|
</PopoverContainer>
|
|
|
|
) : (
|
|
|
|
<TableTd padding="0" hasBorder="left" center middle>
|
|
|
|
<ActionsIcon disabled />
|
2017-11-23 14:18:38 +02:00
|
|
|
</TableTd>
|
2017-12-21 02:12:42 +02:00
|
|
|
)}
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTr>
|
|
|
|
);
|
2017-10-13 22:51:18 +03:00
|
|
|
|
2017-09-27 17:44:57 +03:00
|
|
|
export default ({
|
2017-11-23 14:18:38 +02:00
|
|
|
sortBy = 'name',
|
|
|
|
sortOrder = 'desc',
|
2017-10-13 22:51:18 +03:00
|
|
|
submitting = false,
|
2017-11-23 14:18:38 +02:00
|
|
|
allSelected = false,
|
|
|
|
toggleSelectAll = () => null,
|
2017-12-21 02:12:42 +02:00
|
|
|
onSortBy = () => null,
|
|
|
|
children
|
2017-11-23 14:18:38 +02:00
|
|
|
}) => (
|
|
|
|
<form>
|
2017-10-31 12:29:15 +02:00
|
|
|
<Table>
|
|
|
|
<TableThead>
|
|
|
|
<TableTr>
|
2017-11-23 14:18:38 +02:00
|
|
|
<TableTh xs="32" padding="0" paddingLeft={remcalc(12)} middle left>
|
|
|
|
<FormGroup paddingTop={remcalc(4)}>
|
|
|
|
<Checkbox
|
|
|
|
checked={allSelected}
|
|
|
|
disabled={submitting}
|
|
|
|
onChange={toggleSelectAll}
|
2017-11-23 14:18:38 +02:00
|
|
|
noMargin
|
2017-11-23 14:18:38 +02:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTh>
|
2017-12-06 12:34:15 +02:00
|
|
|
<TableTh
|
|
|
|
onClick={() => onSortBy('name')}
|
|
|
|
sortOrder={sortOrder}
|
|
|
|
showSort={sortBy === 'name'}
|
|
|
|
left
|
|
|
|
middle
|
|
|
|
actionable
|
|
|
|
>
|
2017-11-23 14:18:38 +02:00
|
|
|
<span>Name </span>
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTh>
|
2017-11-23 14:18:38 +02:00
|
|
|
<TableTh
|
2017-12-04 20:24:24 +02:00
|
|
|
xs="150"
|
2017-11-23 14:18:38 +02:00
|
|
|
onClick={() => onSortBy('state')}
|
2017-12-06 12:34:15 +02:00
|
|
|
sortOrder={sortOrder}
|
|
|
|
showSort={sortBy === 'state'}
|
2017-11-23 14:18:38 +02:00
|
|
|
left
|
|
|
|
middle
|
|
|
|
actionable
|
|
|
|
>
|
|
|
|
<span>Status </span>
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTh>
|
2017-11-23 14:18:38 +02:00
|
|
|
<TableTh
|
|
|
|
xs="0"
|
2017-12-04 20:24:24 +02:00
|
|
|
sm="160"
|
2017-11-23 14:18:38 +02:00
|
|
|
onClick={() => onSortBy('created')}
|
2017-12-06 12:34:15 +02:00
|
|
|
sortOrder={sortOrder}
|
|
|
|
showSort={sortBy === 'created'}
|
2017-11-23 14:18:38 +02:00
|
|
|
left
|
|
|
|
middle
|
|
|
|
actionable
|
|
|
|
>
|
|
|
|
<span>Created </span>
|
|
|
|
</TableTh>
|
|
|
|
<TableTh
|
|
|
|
xs="0"
|
2017-12-06 12:34:15 +02:00
|
|
|
sm="130"
|
2017-11-23 14:18:38 +02:00
|
|
|
onClick={() => onSortBy('id')}
|
2017-12-06 12:34:15 +02:00
|
|
|
sortOrder={sortOrder}
|
|
|
|
showSort={sortBy === 'id'}
|
2017-11-23 14:18:38 +02:00
|
|
|
left
|
|
|
|
middle
|
|
|
|
actionable
|
|
|
|
>
|
|
|
|
<span>Short ID </span>
|
|
|
|
</TableTh>
|
2017-12-04 20:24:24 +02:00
|
|
|
<TableTh xs="60" padding="0" />
|
2017-10-31 12:29:15 +02:00
|
|
|
</TableTr>
|
|
|
|
</TableThead>
|
2017-12-21 02:12:42 +02:00
|
|
|
<TableTbody>{children}</TableTbody>
|
2017-10-31 12:29:15 +02:00
|
|
|
</Table>
|
2017-11-23 14:18:38 +02:00
|
|
|
</form>
|
|
|
|
);
|