feat(my-joy-beta): confirm some mutations

This commit is contained in:
Sérgio Ramos 2018-02-21 22:24:39 +00:00
parent 929fcf0ab4
commit 4593980883
8 changed files with 74 additions and 17 deletions

View File

@ -158,7 +158,7 @@ export default compose(
proceeded: proceeded || affinityRules.length, proceeded: proceeded || affinityRules.length,
addOpen, addOpen,
affinityRules, affinityRules,
rule, rule
}; };
}), }),
connect(null, (dispatch, { affinityRules = [], history }) => ({ connect(null, (dispatch, { affinityRules = [], history }) => ({

View File

@ -138,12 +138,11 @@ export default compose(
const pkg = get(form, 'create-instance-package.values.package', ''); const pkg = get(form, 'create-instance-package.values.package', '');
const networks = get(form, 'CREATE-INSTANCE-NETWORKS.values', {}); const networks = get(form, 'CREATE-INSTANCE-NETWORKS.values', {});
const enabled = ( const enabled =
name.length && name.length &&
image.length && image.length &&
pkg.length && pkg.length &&
Values(networks).filter(Boolean).length Values(networks).filter(Boolean).length;
);
if (!enabled) { if (!enabled) {
return { return {
@ -160,7 +159,11 @@ export default compose(
const userScript = get(values, 'create-instance-user-script', {}); const userScript = get(values, 'create-instance-user-script', {});
const tags = receivedTags.map(a => omit(a, 'expanded')); 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({ tags.push({
name: 'triton.cns.disable', name: 'triton.cns.disable',

View File

@ -127,12 +127,19 @@ export default compose(
({ values, form }, { networks }) => { ({ values, form }, { networks }) => {
const selected = get(form, `${FORM_NAME}.values`, {}); const selected = get(form, `${FORM_NAME}.values`, {});
const empty = id => !includes(Object.keys(selected), id); 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 _public = find(networks, ['name', 'Joyent-SDC-Public']);
const initialValues = _public ? { const proceeded = get(
[_public.id]: true values,
} : {}; 'create-instance-networks-proceeded',
false
);
const initialValues = _public
? {
[_public.id]: true
}
: {};
const _networks = networks.map(({ id, name, ...network }) => { const _networks = networks.map(({ id, name, ...network }) => {
if (empty(id) && name === 'Joyent-SDC-Public') { if (empty(id) && name === 'Joyent-SDC-Public') {

View File

@ -11,6 +11,7 @@ import intercept from 'apr-intercept';
import find from 'lodash.find'; import find from 'lodash.find';
import reverse from 'lodash.reverse'; import reverse from 'lodash.reverse';
import sort from 'lodash.sortby'; import sort from 'lodash.sortby';
import includes from 'lodash.includes';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
import { import {
@ -30,6 +31,7 @@ import RemoveInstance from '@graphql/remove-instance.gql';
import ToolbarForm from '@components/instances/toolbar'; import ToolbarForm from '@components/instances/toolbar';
import Index from '@state/gen-index'; import Index from '@state/gen-index';
import parseError from '@state/parse-error'; import parseError from '@state/parse-error';
import Confirm from '@state/confirm';
import { import {
default as InstanceList, default as InstanceList,
@ -312,6 +314,19 @@ export default compose(
} }
}, },
handleAction: async ({ selected, name }) => { 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 action = ownProps[name];
const gerund = `${name}ing`; const gerund = `${name}ing`;

View File

@ -26,6 +26,7 @@ import UpdateMetadata from '@graphql/update-metadata.gql';
import DeleteMetadata from '@graphql/delete-metadata.gql'; import DeleteMetadata from '@graphql/delete-metadata.gql';
import parseError from '@state/parse-error'; import parseError from '@state/parse-error';
import ToolbarForm from '@components/instances/toolbar'; import ToolbarForm from '@components/instances/toolbar';
import Confirm from '@state/confirm';
import { import {
AddForm as MetadataAddForm, AddForm as MetadataAddForm,
@ -275,6 +276,15 @@ export default compose(
return refetch(); return refetch();
}, },
handleRemove: async form => { handleRemove: async form => {
const name = get(
find(metadata, ['form', form]),
'initialValues.name'
);
if (!await Confirm(`Do you want to remove "${name}"?`)) {
return;
}
dispatch([ dispatch([
set({ name: `${form}-removing`, value: true }), set({ name: `${form}-removing`, value: true }),
startSubmit(form) startSubmit(form)
@ -285,20 +295,17 @@ export default compose(
deleteMetadata({ deleteMetadata({
variables: { variables: {
id: instance.id, id: instance.id,
name: get(find(metadata, ['form', form]), 'initialValues.name') name
} }
}) })
); );
if (err) { const flipSubmitFalse = stopSubmit(form, {
// show mutation error _error: err && parseError(err)
throw new SubmissionError({ });
_error: parseError(err)
});
}
dispatch([ dispatch([
stopSubmit(form), flipSubmitFalse,
set({ name: `${form}-removing`, value: false }) set({ name: `${form}-removing`, value: false })
]); ]);

View File

@ -33,6 +33,7 @@ import ToolbarForm from '@components/instances/toolbar';
import SnapshotsListActions from '@components/instances/footer'; import SnapshotsListActions from '@components/instances/footer';
import parseError from '@state/parse-error'; import parseError from '@state/parse-error';
import GenIndex from '@state/gen-index'; import GenIndex from '@state/gen-index';
import Confirm from '@state/confirm';
const MENU_FORM_NAME = 'snapshot-list-menu'; const MENU_FORM_NAME = 'snapshot-list-menu';
const TABLE_FORM_NAME = 'snapshot-list-table'; const TABLE_FORM_NAME = 'snapshot-list-table';
@ -322,6 +323,19 @@ export default compose(
}, },
handleAction: async ({ name, selected = [] }) => { 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 action = ownProps[name];
const gerund = `${name}ing`; const gerund = `${name}ing`;

View File

@ -31,6 +31,7 @@ import UpdateTags from '@graphql/update-tags.gql';
import DeleteTag from '@graphql/delete-tag.gql'; import DeleteTag from '@graphql/delete-tag.gql';
import Index from '@state/gen-index'; import Index from '@state/gen-index';
import parseError from '@state/parse-error'; import parseError from '@state/parse-error';
import Confirm from '@state/confirm';
const MENU_FORM_NAME = 'instance-tags-list-menu'; const MENU_FORM_NAME = 'instance-tags-list-menu';
const ADD_FORM_NAME = 'instance-tags-add-new'; const ADD_FORM_NAME = 'instance-tags-add-new';
@ -253,6 +254,11 @@ export default compose(
return refetch(); return refetch();
}, },
handleRemove: async (form, { name }) => { 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; const { instance, deleteTag, refetch } = ownProps;
dispatch([ dispatch([

View File

@ -0,0 +1,5 @@
export default msg =>
new Promise(resolve => {
// eslint-disable-next-line no-alert
resolve(window.confirm(msg));
});