From 459398088376cd87c4e33e4b9833a5f65e3edc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Wed, 21 Feb 2018 22:24:39 +0000 Subject: [PATCH] feat(my-joy-beta): confirm some mutations --- .../containers/create-instance/affinity.js | 2 +- .../src/containers/create-instance/index.js | 11 +++++---- .../containers/create-instance/networks.js | 15 ++++++++---- .../src/containers/instances/list.js | 15 ++++++++++++ .../src/containers/instances/metadata.js | 23 ++++++++++++------- .../src/containers/instances/snapshots.js | 14 +++++++++++ .../src/containers/instances/tags.js | 6 +++++ packages/my-joy-beta/src/state/confirm.js | 5 ++++ 8 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 packages/my-joy-beta/src/state/confirm.js diff --git a/packages/my-joy-beta/src/containers/create-instance/affinity.js b/packages/my-joy-beta/src/containers/create-instance/affinity.js index dc46427e..b812a22e 100644 --- a/packages/my-joy-beta/src/containers/create-instance/affinity.js +++ b/packages/my-joy-beta/src/containers/create-instance/affinity.js @@ -158,7 +158,7 @@ export default compose( proceeded: proceeded || affinityRules.length, addOpen, affinityRules, - rule, + rule }; }), connect(null, (dispatch, { affinityRules = [], history }) => ({ diff --git a/packages/my-joy-beta/src/containers/create-instance/index.js b/packages/my-joy-beta/src/containers/create-instance/index.js index a5f2911f..6633a136 100644 --- a/packages/my-joy-beta/src/containers/create-instance/index.js +++ b/packages/my-joy-beta/src/containers/create-instance/index.js @@ -138,12 +138,11 @@ export default compose( const pkg = get(form, 'create-instance-package.values.package', ''); const networks = get(form, 'CREATE-INSTANCE-NETWORKS.values', {}); - const enabled = ( + const enabled = name.length && image.length && pkg.length && - Values(networks).filter(Boolean).length - ); + Values(networks).filter(Boolean).length; if (!enabled) { return { @@ -160,7 +159,11 @@ export default compose( const userScript = get(values, 'create-instance-user-script', {}); const tags = receivedTags.map(a => omit(a, 'expanded')); - const firewall_enabled = get(form, 'CREATE-INSTANCE-FIREWALL.values.enabled', false); + const firewall_enabled = get( + form, + 'CREATE-INSTANCE-FIREWALL.values.enabled', + false + ); tags.push({ name: 'triton.cns.disable', diff --git a/packages/my-joy-beta/src/containers/create-instance/networks.js b/packages/my-joy-beta/src/containers/create-instance/networks.js index b505afa9..85f52c66 100644 --- a/packages/my-joy-beta/src/containers/create-instance/networks.js +++ b/packages/my-joy-beta/src/containers/create-instance/networks.js @@ -127,12 +127,19 @@ export default compose( ({ values, form }, { networks }) => { const selected = get(form, `${FORM_NAME}.values`, {}); const empty = id => !includes(Object.keys(selected), id); - const proceeded = get(values, 'create-instance-networks-proceeded', false); const _public = find(networks, ['name', 'Joyent-SDC-Public']); - const initialValues = _public ? { - [_public.id]: true - } : {}; + const proceeded = get( + values, + 'create-instance-networks-proceeded', + false + ); + + const initialValues = _public + ? { + [_public.id]: true + } + : {}; const _networks = networks.map(({ id, name, ...network }) => { if (empty(id) && name === 'Joyent-SDC-Public') { diff --git a/packages/my-joy-beta/src/containers/instances/list.js b/packages/my-joy-beta/src/containers/instances/list.js index e6258321..d69dda21 100644 --- a/packages/my-joy-beta/src/containers/instances/list.js +++ b/packages/my-joy-beta/src/containers/instances/list.js @@ -11,6 +11,7 @@ import intercept from 'apr-intercept'; import find from 'lodash.find'; import reverse from 'lodash.reverse'; import sort from 'lodash.sortby'; +import includes from 'lodash.includes'; import remcalc from 'remcalc'; import { @@ -30,6 +31,7 @@ import RemoveInstance from '@graphql/remove-instance.gql'; import ToolbarForm from '@components/instances/toolbar'; import Index from '@state/gen-index'; import parseError from '@state/parse-error'; +import Confirm from '@state/confirm'; import { default as InstanceList, @@ -312,6 +314,19 @@ export default compose( } }, handleAction: async ({ selected, name }) => { + // eslint-disable-next-line no-alert + if ( + !await Confirm( + `Do you want to ${name} ${ + selected.length === 1 + ? `"${selected[0].name}"` + : `${selected.length} snapshots` + }` + ) + ) { + return; + } + const action = ownProps[name]; const gerund = `${name}ing`; diff --git a/packages/my-joy-beta/src/containers/instances/metadata.js b/packages/my-joy-beta/src/containers/instances/metadata.js index 9bac9263..d9052fc2 100644 --- a/packages/my-joy-beta/src/containers/instances/metadata.js +++ b/packages/my-joy-beta/src/containers/instances/metadata.js @@ -26,6 +26,7 @@ import UpdateMetadata from '@graphql/update-metadata.gql'; import DeleteMetadata from '@graphql/delete-metadata.gql'; import parseError from '@state/parse-error'; import ToolbarForm from '@components/instances/toolbar'; +import Confirm from '@state/confirm'; import { AddForm as MetadataAddForm, @@ -275,6 +276,15 @@ export default compose( return refetch(); }, handleRemove: async form => { + const name = get( + find(metadata, ['form', form]), + 'initialValues.name' + ); + + if (!await Confirm(`Do you want to remove "${name}"?`)) { + return; + } + dispatch([ set({ name: `${form}-removing`, value: true }), startSubmit(form) @@ -285,20 +295,17 @@ export default compose( deleteMetadata({ variables: { id: instance.id, - name: get(find(metadata, ['form', form]), 'initialValues.name') + name } }) ); - if (err) { - // show mutation error - throw new SubmissionError({ - _error: parseError(err) - }); - } + const flipSubmitFalse = stopSubmit(form, { + _error: err && parseError(err) + }); dispatch([ - stopSubmit(form), + flipSubmitFalse, set({ name: `${form}-removing`, value: false }) ]); diff --git a/packages/my-joy-beta/src/containers/instances/snapshots.js b/packages/my-joy-beta/src/containers/instances/snapshots.js index 7e132a54..c58e6eb0 100644 --- a/packages/my-joy-beta/src/containers/instances/snapshots.js +++ b/packages/my-joy-beta/src/containers/instances/snapshots.js @@ -33,6 +33,7 @@ import ToolbarForm from '@components/instances/toolbar'; import SnapshotsListActions from '@components/instances/footer'; import parseError from '@state/parse-error'; import GenIndex from '@state/gen-index'; +import Confirm from '@state/confirm'; const MENU_FORM_NAME = 'snapshot-list-menu'; const TABLE_FORM_NAME = 'snapshot-list-table'; @@ -322,6 +323,19 @@ export default compose( }, handleAction: async ({ name, selected = [] }) => { + // eslint-disable-next-line no-alert + if ( + !await Confirm( + `Do you want to ${name} ${ + selected.length === 1 + ? `"${selected[0].name}"` + : `${selected.length} snapshots` + }` + ) + ) { + return; + } + const action = ownProps[name]; const gerund = `${name}ing`; diff --git a/packages/my-joy-beta/src/containers/instances/tags.js b/packages/my-joy-beta/src/containers/instances/tags.js index 734a5057..e2f46e36 100644 --- a/packages/my-joy-beta/src/containers/instances/tags.js +++ b/packages/my-joy-beta/src/containers/instances/tags.js @@ -31,6 +31,7 @@ import UpdateTags from '@graphql/update-tags.gql'; import DeleteTag from '@graphql/delete-tag.gql'; import Index from '@state/gen-index'; import parseError from '@state/parse-error'; +import Confirm from '@state/confirm'; const MENU_FORM_NAME = 'instance-tags-list-menu'; const ADD_FORM_NAME = 'instance-tags-add-new'; @@ -253,6 +254,11 @@ export default compose( return refetch(); }, handleRemove: async (form, { name }) => { + // eslint-disable-next-line no-alert + if (!await Confirm(`Do you want to remove "${name}"?`)) { + return; + } + const { instance, deleteTag, refetch } = ownProps; dispatch([ diff --git a/packages/my-joy-beta/src/state/confirm.js b/packages/my-joy-beta/src/state/confirm.js new file mode 100644 index 00000000..fd585ce2 --- /dev/null +++ b/packages/my-joy-beta/src/state/confirm.js @@ -0,0 +1,5 @@ +export default msg => + new Promise(resolve => { + // eslint-disable-next-line no-alert + resolve(window.confirm(msg)); + });