Commit 915bfa4f authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/345498/actionOnClickHandler' into 'master'

Added support for click handlers in widget extension action buttons

See merge request gitlab-org/gitlab!74401
parents 84c244c3 07469e10
...@@ -24,6 +24,13 @@ export default { ...@@ -24,6 +24,13 @@ export default {
return sprintf(__('%{widget} options'), { widget: this.widget }); return sprintf(__('%{widget} options'), { widget: this.widget });
}, },
}, },
methods: {
onClickAction(action) {
if (action.onClick) {
action.onClick();
}
},
},
}; };
</script> </script>
...@@ -47,6 +54,7 @@ export default { ...@@ -47,6 +54,7 @@ export default {
:key="index" :key="index"
:href="btn.href" :href="btn.href"
:target="btn.target" :target="btn.target"
@click="onClickAction(btn)"
> >
{{ btn.text }} {{ btn.text }}
</gl-dropdown-item> </gl-dropdown-item>
...@@ -57,11 +65,12 @@ export default { ...@@ -57,11 +65,12 @@ export default {
:key="index" :key="index"
:href="btn.href" :href="btn.href"
:target="btn.target" :target="btn.target"
:class="{ 'gl-mr-3': index > 1 }" :class="{ 'gl-mr-3': index !== tertiaryButtons.length - 1 }"
category="tertiary" category="tertiary"
variant="confirm" variant="confirm"
size="small" size="small"
class="gl-display-none gl-md-display-block" class="gl-display-none gl-md-display-block gl-float-left"
@click="onClickAction(btn)"
> >
{{ btn.text }} {{ btn.text }}
</gl-button> </gl-button>
......
...@@ -30,7 +30,15 @@ export default { ...@@ -30,7 +30,15 @@ export default {
// Tertiary action buttons that will take the user elsewhere // Tertiary action buttons that will take the user elsewhere
// in the GitLab app // in the GitLab app
tertiaryButtons() { tertiaryButtons() {
return [{ text: 'Full report', href: this.conflictsDocsPath, target: '_blank' }]; return [
{
text: 'Click me',
onClick() {
console.log('Hello world');
},
},
{ text: 'Full report', href: this.conflictsDocsPath, target: '_blank' },
];
}, },
}, },
methods: { methods: {
......
...@@ -24,6 +24,18 @@ describe('MR widget extension actions', () => { ...@@ -24,6 +24,18 @@ describe('MR widget extension actions', () => {
expect(wrapper.findAllComponents(GlButton)).toHaveLength(1); expect(wrapper.findAllComponents(GlButton)).toHaveLength(1);
}); });
it('calls action click handler', async () => {
const onClick = jest.fn();
factory({
tertiaryButtons: [{ text: 'hello world', onClick }],
});
await wrapper.findComponent(GlButton).vm.$emit('click');
expect(onClick).toHaveBeenCalled();
});
it('renders tertiary actions in dropdown', () => { it('renders tertiary actions in dropdown', () => {
factory({ factory({
tertiaryButtons: [{ text: 'hello world', href: 'https://gitlab.com', target: '_blank' }], tertiaryButtons: [{ text: 'hello world', href: 'https://gitlab.com', target: '_blank' }],
......
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