Commit f0e3674c authored by Paul Slaughter's avatar Paul Slaughter

Add tooltip for diffs edit file dropdown

- Also renames the "Edit file" to
"Edit in single-file editor"
parent 888559be
<script> <script>
import { uniqueId } from 'lodash';
import { import {
GlTooltipDirective, GlTooltipDirective,
GlIcon, GlIcon,
...@@ -37,13 +38,16 @@ export default { ...@@ -37,13 +38,16 @@ export default {
default: false, default: false,
}, },
}, },
data() {
return { tooltipId: uniqueId('edit_button_tooltip_') };
},
computed: { computed: {
tooltipTitle() { tooltipTitle() {
if (this.isDisabled) { if (this.isDisabled) {
return __("Can't edit as source branch was deleted"); return __("Can't edit as source branch was deleted");
} }
return ''; return __('Edit file in...');
}, },
isDisabled() { isDisabled() {
return !this.editPath; return !this.editPath;
...@@ -51,6 +55,10 @@ export default { ...@@ -51,6 +55,10 @@ export default {
}, },
methods: { methods: {
handleShow(evt) { handleShow(evt) {
// We must hide the tooltip because it is redundant and doesn't close itself
// when dropdown opens because we are still "focused".
this.$root.$emit('bv::hide::tooltip', this.tooltipId);
if (this.canCurrentUserFork && !this.canModifyBlob) { if (this.canCurrentUserFork && !this.canModifyBlob) {
evt.preventDefault(); evt.preventDefault();
this.$emit('showForkMessage'); this.$emit('showForkMessage');
...@@ -66,7 +74,7 @@ export default { ...@@ -66,7 +74,7 @@ export default {
</script> </script>
<template> <template>
<div v-gl-tooltip.top="tooltipTitle" class="gl-display-flex"> <div v-gl-tooltip.top="{ title: tooltipTitle, id: tooltipId }" class="gl-display-flex">
<gl-dropdown <gl-dropdown
toggle-class="rounded-0" toggle-class="rounded-0"
:disabled="isDisabled" :disabled="isDisabled"
...@@ -80,7 +88,9 @@ export default { ...@@ -80,7 +88,9 @@ export default {
<span class="gl-dropdown-toggle-text"><gl-icon name="pencil"/></span> <span class="gl-dropdown-toggle-text"><gl-icon name="pencil"/></span>
<gl-icon class="gl-dropdown-caret" name="chevron-down" aria-hidden="true" /> <gl-icon class="gl-dropdown-caret" name="chevron-down" aria-hidden="true" />
</template> </template>
<gl-dropdown-item v-if="editPath" :href="editPath">{{ __('Edit file') }}</gl-dropdown-item> <gl-dropdown-item v-if="editPath" :href="editPath">{{
__('Edit in single-file editor')
}}</gl-dropdown-item>
<gl-dropdown-item v-if="ideEditPath" :href="ideEditPath">{{ <gl-dropdown-item v-if="ideEditPath" :href="ideEditPath">{{
__('Edit in Web IDE') __('Edit in Web IDE')
}}</gl-dropdown-item> }}</gl-dropdown-item>
......
...@@ -9243,7 +9243,7 @@ msgstr "" ...@@ -9243,7 +9243,7 @@ msgstr ""
msgid "Edit environment" msgid "Edit environment"
msgstr "" msgstr ""
msgid "Edit file" msgid "Edit file in..."
msgstr "" msgstr ""
msgid "Edit files in the editor and commit changes here" msgid "Edit files in the editor and commit changes here"
...@@ -9258,6 +9258,9 @@ msgstr "" ...@@ -9258,6 +9258,9 @@ msgstr ""
msgid "Edit in Web IDE" msgid "Edit in Web IDE"
msgstr "" msgstr ""
msgid "Edit in single-file editor"
msgstr ""
msgid "Edit issues" msgid "Edit issues"
msgstr "" msgstr ""
......
...@@ -28,7 +28,7 @@ RSpec.describe 'a maintainer edits files on a source-branch of an MR from a fork ...@@ -28,7 +28,7 @@ RSpec.describe 'a maintainer edits files on a source-branch of an MR from a fork
wait_for_requests wait_for_requests
within first('.js-file-title') do within first('.js-file-title') do
find('[data-testid="edit_file"]').click find('[data-testid="edit_file"]').click
click_link 'Edit file' click_link 'Edit in single-file editor'
end end
wait_for_requests wait_for_requests
end end
......
...@@ -30,7 +30,7 @@ RSpec.describe 'Editing file blob', :js do ...@@ -30,7 +30,7 @@ RSpec.describe 'Editing file blob', :js do
def mr_edit_and_commit(commit_changes: true) def mr_edit_and_commit(commit_changes: true)
wait_for_requests wait_for_requests
find('[data-testid="edit_file"]').click find('[data-testid="edit_file"]').click
click_link 'Edit file' click_link 'Edit in single-file editor'
fill_and_commit(commit_changes) fill_and_commit(commit_changes)
end end
......
...@@ -3,9 +3,12 @@ import { GlDeprecatedDropdown, GlDeprecatedDropdownItem, GlIcon } from '@gitlab/ ...@@ -3,9 +3,12 @@ import { GlDeprecatedDropdown, GlDeprecatedDropdownItem, GlIcon } from '@gitlab/
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import EditButton from '~/diffs/components/edit_button.vue'; import EditButton from '~/diffs/components/edit_button.vue';
jest.mock('lodash/uniqueId', () => (str = '') => `${str}fake`);
const TOOLTIP_ID = 'edit_button_tooltip_fake';
const EDIT_ITEM = { const EDIT_ITEM = {
href: 'test-path', href: 'test-path',
text: 'Edit file', text: 'Edit in single-file editor',
}; };
const IDE_EDIT_ITEM = { const IDE_EDIT_ITEM = {
href: 'ide-test-path', href: 'ide-test-path',
...@@ -66,7 +69,7 @@ describe('EditButton', () => { ...@@ -66,7 +69,7 @@ describe('EditButton', () => {
}); });
it('does not have tooltip', () => { it('does not have tooltip', () => {
expect(getTooltip()).toBe(''); expect(getTooltip()).toEqual({ id: TOOLTIP_ID, title: 'Edit file in...' });
}); });
it('shows pencil dropdown', () => { it('shows pencil dropdown', () => {
...@@ -74,16 +77,26 @@ describe('EditButton', () => { ...@@ -74,16 +77,26 @@ describe('EditButton', () => {
expect(wrapper.find('.gl-dropdown-caret').exists()).toBe(true); expect(wrapper.find('.gl-dropdown-caret').exists()).toBe(true);
}); });
it.each` describe.each`
event | expectedEmit event | expectedEmit | expectedRootEmit
${'show'} | ${'open'} ${'show'} | ${'open'} | ${[['bv::hide::tooltip', TOOLTIP_ID]]}
${'hide'} | ${'close'} ${'hide'} | ${'close'} | ${[]}
`('when dropdown emits $event, emits $expectedEmit', ({ event, expectedEmit }) => { `('when dropdown emits $event', ({ event, expectedEmit, expectedRootEmit }) => {
expect(wrapper.emitted(expectedEmit)).toBeUndefined(); let rootEmitSpy;
beforeEach(() => {
rootEmitSpy = jest.spyOn(wrapper.vm.$root, '$emit');
findDropdown().vm.$emit(event); findDropdown().vm.$emit(event);
});
expect(wrapper.emitted(expectedEmit)).toEqual([[]]); it(`emits ${expectedEmit}`, () => {
expect(wrapper.emitted(expectedEmit)).toEqual([[]]);
});
it(`emits root = ${JSON.stringify(expectedRootEmit)}`, () => {
expect(rootEmitSpy.mock.calls).toEqual(expectedRootEmit);
});
}); });
}); });
...@@ -118,7 +131,10 @@ describe('EditButton', () => { ...@@ -118,7 +131,10 @@ describe('EditButton', () => {
}); });
it('should have tooltip', () => { it('should have tooltip', () => {
expect(getTooltip()).toBe("Can't edit as source branch was deleted"); expect(getTooltip()).toEqual({
id: TOOLTIP_ID,
title: "Can't edit as source branch was deleted",
});
}); });
}); });
}); });
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