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 './item'; const { SmallOnly, Medium } = QueryBreakpoints; export default ({ instances = [], selected = [], loading, error, handleChange = () => null, onAction = () => null, handleSubmit, submitting = false, pristine = true, ...rest }) => { const allowedActions = { stop: selected.some(({ state }) => state === 'RUNNING'), start: selected.some(({ state }) => state !== 'RUNNING'), reboot: true, resize: selected.length === 1 && selected.every(({ brand }) => brand === 'KVM'), // eslint-disable-next-line camelcase enableFw: selected.some(({ firewall_enabled }) => !firewall_enabled), // eslint-disable-next-line camelcase disableFw: selected.some(({ firewall_enabled }) => firewall_enabled), createSnap: selected.length === 1, startSnap: selected.length === 1 && selected.every(({ snapshots = [] }) => snapshots.length) }; const handleActions = ev => { ev.stopPropagation(); ev.preventDefault(); onAction({ name: ev.target.value, items: selected }); }; const _instances = forceArray(instances); const items = _instances.map((instance, i, all) => { const { id } = instance; const isSelected = Boolean(find(selected, ['id', id])); const isSubmitting = isSelected && submitting; return ( ); }); const _loading = !items.length && loading ? ( ) : null; const _error = error && !submitting && ( Ooops! {error} ); return (
Filter instances Sort {_loading} {_error} {items}
); };