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,
addOpen,
affinityRules,
rule,
rule
};
}),
connect(null, (dispatch, { affinityRules = [], history }) => ({

View File

@ -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',

View File

@ -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 ? {
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') {

View File

@ -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`;

View File

@ -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 })
]);

View File

@ -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`;

View File

@ -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([

View File

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