import React, { Fragment } from 'react'; import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; import remcalc from 'remcalc'; import styled from 'styled-components'; import titleCase from 'title-case'; import { Link } from 'react-router-dom'; import { Field } from 'redux-form'; import Flex from 'styled-flex-component'; import queryString from 'query-string'; import { Padding } from 'styled-components-spacing'; import { Anchor, FormGroup, Checkbox, Table, TableThead, TableTr, TableTh, TableTd, TableTbody, PaginationTableFoot, PaginationItem, StatusLoader, Popover, PopoverContainer, PopoverTarget, PopoverItem as BasePopoverItem, PopoverDivider as BasePopoverDivider, DotIcon, ActionsIcon } from 'joyent-ui-toolkit'; import GLOBAL, { Global } from '@state/global'; const stateColor = { PROVISIONING: 'primary', RUNNING: 'green', STOPPING: 'grey', STOPPED: 'grey', DELETED: 'secondaryActive', FAILED: 'red' }; const A = styled(Anchor)` color: ${props => props.theme.text}; text-decoration: none; font-weight: ${props => props.theme.font.weight.semibold}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: block; `; const ItemAnchor = styled(Anchor)` color: ${props => props.theme.text}; -webkit-text-fill-color: currentcolor; text-decoration: none; `; const MarginalPaginationItem = styled(PaginationItem)` margin: 0 ${remcalc(3)}; `; const Actions = styled(Flex)` height: 100%; `; const PopoverItem = styled(BasePopoverItem)` padding-bottom: ${remcalc(11)}; `; const PopoverDivider = styled(BasePopoverDivider)` margin-left: ${remcalc(-18)}; `; export const FetchingItem = () => ( ); export const Item = ({ id = '', name, state = 'RUNNING', created, allowedActions = {}, mutating = false, onCreateImage, onStart, onStop, onReboot, onRemove, onClick }) => ( {name} {mutating ? ( ) : ( {' '} {titleCase(state)} )} {distanceInWordsToNow(created)} {id.substring(0, 7)} {mutating ? ( ) : ( Start Stop Restart Delete Create Image )} ); export default ({ sortBy = 'name', sortOrder = 'desc', submitting = false, allSelected = false, toggleSelectAll = () => null, onSortBy = () => null, children, noInstances, limit = 0, offset = 0, total = 0 }) => { const numPages = Math.ceil(total / limit); const currPage = Math.ceil((offset + limit) / limit); const isLast = currPage === numPages; const isFirst = currPage === 1; return (
onSortBy('name')} sortOrder={sortOrder} showSort={sortBy === 'name'} left middle actionable > Name onSortBy('state')} sortOrder={sortOrder} showSort={sortBy === 'state'} left middle actionable > Status onSortBy('created')} sortOrder={sortOrder} showSort={sortBy === 'created'} left middle actionable > Created onSortBy('id')} sortOrder={sortOrder} showSort={sortBy === 'id'} left middle actionable > Short ID {children} {noInstances ? null : ( Prev {currPage - 2 > 0 ? ( {currPage - 2 > 1 ? ( 1 ) : null} ... ) : null} {currPage > 1 ? ( {currPage - 1} ) : null} {currPage} {numPages > currPage ? ( {currPage + 1} ) : null} {currPage + 2 <= numPages ? ( ... {numPages - currPage > 2 ? ( {numPages} ) : null} ) : null} Next )}
); };