From 55811372fbcb76a93fb32c8515cfaf7f7995fad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Fri, 13 Oct 2017 20:51:18 +0100 Subject: [PATCH] feat(my-joy-beta): add loading and error to instance list actions --- .../src/components/instances/item.js | 49 +++++++---- .../src/components/instances/list.js | 86 ++++++++++++++----- .../src/containers/instances/list.js | 82 ++++++++++++------ .../src/containers/instances/summary.js | 12 +-- 4 files changed, 161 insertions(+), 68 deletions(-) diff --git a/packages/my-joy-beta/src/components/instances/item.js b/packages/my-joy-beta/src/components/instances/item.js index 050105ee..abf6f5a7 100644 --- a/packages/my-joy-beta/src/components/instances/item.js +++ b/packages/my-joy-beta/src/components/instances/item.js @@ -10,7 +10,8 @@ import { CardView, Checkbox, FormGroup, - QueryBreakpoints + QueryBreakpoints, + StatusLoader } from 'joyent-ui-toolkit'; const { SmallOnly, Small } = QueryBreakpoints; @@ -24,7 +25,8 @@ const stateColor = { FAILED: 'red' }; -export default ({ name, state, primary_ip, last, first }) => ( +// eslint-disable-next-line camelcase +export default ({ name, state, primary_ip, loading, last, first }) => ( @@ -34,23 +36,34 @@ export default ({ name, state, primary_ip, last, first }) => ( {name} - - {primary_ip} - - - - {titleCase(state)} + {loading && ( + + - - - - + )} + {!loading && ( + + {primary_ip} + + )} + {!loading && ( + + + {titleCase(state)} + + + )} + {!loading && ( + + + + )} diff --git a/packages/my-joy-beta/src/components/instances/list.js b/packages/my-joy-beta/src/components/instances/list.js index 9278ebe8..834b7dd1 100644 --- a/packages/my-joy-beta/src/components/instances/list.js +++ b/packages/my-joy-beta/src/components/instances/list.js @@ -1,7 +1,7 @@ import React from 'react'; import { Row, Col } from 'react-styled-flexboxgrid'; import forceArray from 'force-array'; -import get from 'lodash.get'; +import find from 'lodash.find'; import { FormGroup, @@ -9,18 +9,28 @@ import { FormLabel, ViewContainer, StatusLoader, - Select + 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 = { @@ -29,30 +39,44 @@ export default ({ 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: true, + createSnap: selected.length === 1, startSnap: selected.length === 1 && selected.every(({ snapshots = [] }) => snapshots.length) }; - const handleActions = ({ target }) => + const handleActions = ev => { + ev.stopPropagation(); + ev.preventDefault(); + onAction({ - name: target.value, + name: ev.target.value, items: selected }); + }; const _instances = forceArray(instances); - const items = _instances.map((instance, i, all) => ( - - )); + 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 ? ( @@ -61,19 +85,25 @@ export default ({ ) : null; + const _error = error && + !submitting && ( + + Ooops! + {error} + + ); + return ( -
handleSubmit(ctx => handleChange(ctx))} - onSubmit={handleSubmit} - > + - + Filter instances @@ -98,9 +128,9 @@ export default ({ - + - +