fix(my-joy-beta): when no cns services, remove tag

This commit is contained in:
Sérgio Ramos 2018-02-05 12:54:53 +00:00
parent bae3e8145f
commit 72d5c8b18f

View File

@ -22,6 +22,7 @@ import {
import Description from '@components/description'; import Description from '@components/description';
import Cns, { Footer, AddServiceForm } from '@components/cns'; import Cns, { Footer, AddServiceForm } from '@components/cns';
import GetAccount from '@graphql/get-account.gql'; import GetAccount from '@graphql/get-account.gql';
import DeleteTag from '@graphql/delete-tag.gql';
import UpdateTags from '@graphql/update-tags.gql'; import UpdateTags from '@graphql/update-tags.gql';
import GetTags from '@graphql/list-tags.gql'; import GetTags from '@graphql/list-tags.gql';
import parseError from '@state/parse-error'; import parseError from '@state/parse-error';
@ -121,6 +122,7 @@ class CnsClass extends PureComponent {
export default compose( export default compose(
graphql(UpdateTags, { name: 'updateTags' }), graphql(UpdateTags, { name: 'updateTags' }),
graphql(DeleteTag, { name: 'deleteTag' }),
graphql(GetAccount, { graphql(GetAccount, {
props: ({ data }) => { props: ({ data }) => {
const { account = {} } = data; const { account = {} } = data;
@ -166,17 +168,19 @@ export default compose(
const toggling = get(values, `cns-${instance.id}-toggling`, false); const toggling = get(values, `cns-${instance.id}-toggling`, false);
const removing = get(values, `cns-${instance.id}-removing`, false); const removing = get(values, `cns-${instance.id}-removing`, false);
const enabled = get(values, `cns-${instance.id}-enabled`, undefined); const enabled = get(values, `cns-${instance.id}-enabled`, undefined);
const svcs = get(values, `cns-${instance.id}-svcs`, undefined);
const togglingError = get( const togglingError = get(
values, values,
`cns-${instance.id}-toggling-error`, `cns-${instance.id}-toggling-error`,
null null
); );
const removingError = get( const removingError = get(
values, values,
`cns-${instance.id}-removing-error`, `cns-${instance.id}-removing-error`,
null null
); );
const svcs = get(values, `cns-${instance.id}-svcs`, undefined);
if (isBoolean(enabled)) { if (isBoolean(enabled)) {
disabled = !enabled; disabled = !enabled;
@ -232,7 +236,7 @@ export default compose(
mutationError: togglingError || removingError mutationError: togglingError || removingError
}; };
}, },
(dispatch, { instance = {}, refetch, updateTags }) => ({ (dispatch, { instance = {}, refetch, updateTags, deleteTag }) => ({
reset: () => { reset: () => {
dispatch([ dispatch([
destroyValue({ name: `cns-${instance.id}-removing` }), destroyValue({ name: `cns-${instance.id}-removing` }),
@ -253,19 +257,27 @@ export default compose(
set({ name: `cns-${instance.id}-svcs`, value }) set({ name: `cns-${instance.id}-svcs`, value })
]); ]);
const [err] = await intercept( const newValue = value.join(',');
updateTags({ const mutation = !newValue.length
variables: { ? deleteTag({
id: instance.id, variables: {
tags: [ id: instance.id,
{ name: 'triton.cns.services'
name: 'triton.cns.services', }
value: value.join(',') })
} : updateTags({
] variables: {
} id: instance.id,
}) tags: [
); {
name: 'triton.cns.services',
value: value.join(',')
}
]
}
});
const [err] = await intercept(mutation);
const setLoadingFalse = set({ const setLoadingFalse = set({
name: `cns-${instance.id}-removing`, name: `cns-${instance.id}-removing`,