import React from 'react'; import { Row, Col } from 'react-styled-flexboxgrid'; import forceArray from 'force-array'; import find from 'lodash.find'; import { FormGroup, Input, FormLabel, ViewContainer, StatusLoader, Select, Message, MessageTitle, MessageDescription, Button, QueryBreakpoints } from 'joyent-ui-toolkit'; import Item from './snapshot'; const { SmallOnly, Medium } = QueryBreakpoints; export default ({ snapshots = [], selected = [], loading, error, handleChange = () => null, onAction = () => null, handleSubmit, submitting = false, pristine = true, ...rest }) => { const allowedActions = { delete: selected.length > 0, start: selected.length === 1 }; const handleActions = ev => { ev.stopPropagation(); ev.preventDefault(); onAction({ name: ev.target.value, items: selected }); }; const _snapshots = forceArray(snapshots); const _loading = !_snapshots.length && loading && ( ); const items = _snapshots.map((snapshot, i, all) => { const { name } = snapshot; const isSelected = Boolean(find(selected, ['name', name])); const isSubmitting = isSelected && submitting; return ( ); }); const _error = error && !submitting && ( Ooops! {error} ); return (
handleSubmit(ctx => handleChange(ctx))} onSubmit={handleSubmit} > Filter snapshots Sort {_loading} {_error} {items}
); };