Commit bcbbd05c authored by Kushal Pandya's avatar Kushal Pandya

Add methods to show modal dialog on Toggle or Remove actions

parent 3ae93c72
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import loadingIcon from '~/vue_shared/components/loading_icon.vue'; import loadingIcon from '~/vue_shared/components/loading_icon.vue';
import { NODE_ACTION_BASE_PATH, NODE_ACTIONS } from '../constants'; import eventHub from '../event_hub';
import { NODE_ACTIONS } from '../constants';
export default { export default {
components: { components: {
...@@ -22,11 +24,6 @@ ...@@ -22,11 +24,6 @@
required: true, required: true,
}, },
}, },
data() {
return {
isNodeToggleInProgress: false,
};
},
computed: { computed: {
isToggleAllowed() { isToggleAllowed() {
return !this.node.primary && this.nodeEditAllowed; return !this.node.primary && this.nodeEditAllowed;
...@@ -34,20 +31,27 @@ ...@@ -34,20 +31,27 @@
nodeToggleLabel() { nodeToggleLabel() {
return this.node.enabled ? __('Disable') : __('Enable'); return this.node.enabled ? __('Disable') : __('Enable');
}, },
nodeDisableMessage() {
return this.node.enabled ? s__('GeoNodes|Disabling a node stops the sync process. Are you sure?') : '';
}, },
nodePath() { methods: {
return `${NODE_ACTION_BASE_PATH}${this.node.id}`; onToggleNode() {
eventHub.$emit('showNodeActionModal', {
actionType: NODE_ACTIONS.TOGGLE,
node: this.node,
modalMessage: s__('GeoNodes|Disabling a node stops the sync process. Are you sure?'),
modalActionLabel: this.nodeToggleLabel,
});
}, },
nodeRepairAuthPath() { onRemoveNode() {
return `${this.nodePath}${NODE_ACTIONS.REPAIR}`; eventHub.$emit('showNodeActionModal', {
actionType: NODE_ACTIONS.REMOVE,
node: this.node,
modalKind: 'danger',
modalMessage: s__('GeoNodes|Removing a node stops the sync process. Are you sure?'),
modalActionLabel: __('Remove'),
});
}, },
nodeTogglePath() { onRepairNode() {
return `${this.nodePath}${NODE_ACTIONS.TOGGLE}`; eventHub.$emit('repairNode', this.node);
},
nodeEditPath() {
return `${this.nodePath}${NODE_ACTIONS.EDIT}`;
}, },
}, },
}; };
...@@ -59,30 +63,29 @@ ...@@ -59,30 +63,29 @@
v-if="nodeMissingOauth" v-if="nodeMissingOauth"
class="node-action-container" class="node-action-container"
> >
<a <button
type="button"
class="btn btn-default btn-sm btn-node-action" class="btn btn-default btn-sm btn-node-action"
data-method="post" @click="onRepairNode"
:href="nodeRepairAuthPath"
> >
{{ s__('Repair authentication') }} {{ s__('Repair authentication') }}
</a> </button>
</div> </div>
<div <div
v-if="isToggleAllowed" v-if="isToggleAllowed"
class="node-action-container" class="node-action-container"
> >
<a <button
type="button"
class="btn btn-sm btn-node-action" class="btn btn-sm btn-node-action"
data-method="post"
:href="nodeTogglePath"
:data-confirm="nodeDisableMessage"
:class="{ :class="{
'btn-warning': node.enabled, 'btn-warning': node.enabled,
'btn-success': !node.enabled 'btn-success': !node.enabled
}" }"
@click="onToggleNode"
> >
{{ nodeToggleLabel }} {{ nodeToggleLabel }}
</a> </button>
</div> </div>
<div <div
v-if="nodeEditAllowed" v-if="nodeEditAllowed"
...@@ -90,19 +93,19 @@ ...@@ -90,19 +93,19 @@
> >
<a <a
class="btn btn-sm btn-node-action" class="btn btn-sm btn-node-action"
:href="nodeEditPath" :href="node.editPath"
> >
{{ __('Edit') }} {{ __('Edit') }}
</a> </a>
</div> </div>
<div class="node-action-container"> <div class="node-action-container">
<a <button
type="button"
class="btn btn-sm btn-node-action btn-danger" class="btn btn-sm btn-node-action btn-danger"
data-method="delete" @click="onRemoveNode"
:href="nodePath"
> >
{{ __('Remove') }} {{ __('Remove') }}
</a> </button>
</div> </div>
</div> </div>
</template> </template>
...@@ -2,6 +2,8 @@ import Vue from 'vue'; ...@@ -2,6 +2,8 @@ import Vue from 'vue';
import geoNodeActionsComponent from 'ee/geo_nodes/components/geo_node_actions.vue'; import geoNodeActionsComponent from 'ee/geo_nodes/components/geo_node_actions.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
import eventHub from 'ee/geo_nodes/event_hub';
import { NODE_ACTIONS } from 'ee/geo_nodes/constants';
import { mockNodes } from '../mock_data'; import { mockNodes } from '../mock_data';
const createComponent = (node = mockNodes[0], nodeEditAllowed = true, nodeMissingOauth = false) => { const createComponent = (node = mockNodes[0], nodeEditAllowed = true, nodeMissingOauth = false) => {
...@@ -25,14 +27,6 @@ describe('GeoNodeActionsComponent', () => { ...@@ -25,14 +27,6 @@ describe('GeoNodeActionsComponent', () => {
vm.$destroy(); vm.$destroy();
}); });
describe('data', () => {
it('returns default data props', () => {
const vmX = createComponent();
expect(vmX.isNodeToggleInProgress).toBeFalsy();
vmX.$destroy();
});
});
describe('computed', () => { describe('computed', () => {
describe('isToggleAllowed', () => { describe('isToggleAllowed', () => {
it('returns boolean value representing if toggle on node can be allowed', () => { it('returns boolean value representing if toggle on node can be allowed', () => {
...@@ -59,49 +53,48 @@ describe('GeoNodeActionsComponent', () => { ...@@ -59,49 +53,48 @@ describe('GeoNodeActionsComponent', () => {
vmX.$destroy(); vmX.$destroy();
}); });
}); });
describe('nodeDisableMessage', () => {
it('returns node toggle message', () => {
let mockNode = Object.assign({}, mockNodes[1]);
let vmX = createComponent(mockNode);
expect(vmX.nodeDisableMessage).toBe('Disabling a node stops the sync process. Are you sure?');
vmX.$destroy();
mockNode = Object.assign({}, mockNodes[1], { enabled: false });
vmX = createComponent(mockNode);
expect(vmX.nodeDisableMessage).toBe('');
vmX.$destroy();
});
}); });
describe('nodePath', () => { describe('methods', () => {
it('returns node path', () => { describe('onToggleNode', () => {
expect(vm.nodePath).toBe('/admin/geo_nodes/1'); it('emits showNodeActionModal with actionType `toggle`, node reference, modalMessage and modalActionLabel', () => {
}); spyOn(eventHub, '$emit');
vm.onToggleNode();
expect(eventHub.$emit).toHaveBeenCalledWith('showNodeActionModal', {
actionType: NODE_ACTIONS.TOGGLE,
node: vm.node,
modalMessage: 'Disabling a node stops the sync process. Are you sure?',
modalActionLabel: vm.nodeToggleLabel,
}); });
describe('nodeRepairAuthPath', () => {
it('returns node repair authentication path', () => {
expect(vm.nodeRepairAuthPath).toBe('/admin/geo_nodes/1/repair');
}); });
}); });
describe('nodeTogglePath', () => { describe('onRemoveNode', () => {
it('returns node toggle path', () => { it('emits showNodeActionModal with actionType `remove`, node reference, modalKind, modalMessage and modalActionLabel', () => {
expect(vm.nodeTogglePath).toBe('/admin/geo_nodes/1/toggle'); spyOn(eventHub, '$emit');
vm.onRemoveNode();
expect(eventHub.$emit).toHaveBeenCalledWith('showNodeActionModal', {
actionType: NODE_ACTIONS.REMOVE,
node: vm.node,
modalKind: 'danger',
modalMessage: 'Removing a node stops the sync process. Are you sure?',
modalActionLabel: 'Remove',
});
}); });
}); });
describe('nodeEditPath', () => { describe('onRepairNode', () => {
it('returns node edit path', () => { it('emits `repairNode` event with node reference', () => {
expect(vm.nodeEditPath).toBe('/admin/geo_nodes/1/edit'); spyOn(eventHub, '$emit');
vm.onRepairNode();
expect(eventHub.$emit).toHaveBeenCalledWith('repairNode', vm.node);
}); });
}); });
}); });
describe('template', () => { describe('template', () => {
it('renders container elements correctly', () => { it('renders container elements correctly', () => {
expect(vm.$el.classList.contains('geo-node-actions')).toBeTruthy(); expect(vm.$el.classList.contains('geo-node-actions')).toBe(true);
expect(vm.$el.querySelectorAll('.node-action-container').length).not.toBe(0); expect(vm.$el.querySelectorAll('.node-action-container').length).not.toBe(0);
expect(vm.$el.querySelectorAll('.btn-node-action').length).not.toBe(0); expect(vm.$el.querySelectorAll('.btn-node-action').length).not.toBe(0);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment