Commit f1de60f2 authored by Kristin Brooks's avatar Kristin Brooks

Convert quick_submit.js to GlTooltip

* Used on snippets note submit button, for example.
* Also adds support for 'add' to tooltips API.
parent 105dc62a
...@@ -2,6 +2,7 @@ import $ from 'jquery'; ...@@ -2,6 +2,7 @@ import $ from 'jquery';
import '../commons/bootstrap'; import '../commons/bootstrap';
import { isInIssuePage } from '../lib/utils/common_utils'; import { isInIssuePage } from '../lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { add, show, hide } from '~/tooltips';
// Quick Submit behavior // Quick Submit behavior
// //
...@@ -65,18 +66,17 @@ $(document).on( ...@@ -65,18 +66,17 @@ $(document).on(
return; return;
} }
const $this = $(this); const $el = $(this);
const title = isMac() const title = isMac()
? __('You can also press ⌘-Enter') ? __('You can also press \u{2318}-Enter')
: __('You can also press Ctrl-Enter'); : __('You can also press Ctrl-Enter');
$this.tooltip({ add($el, {
container: 'body', triggers: 'manual',
html: true, show: true,
placement: 'top',
title, title,
trigger: 'manual',
}); });
$this.tooltip('show').one('blur click', () => $this.tooltip('hide')); $el.one('blur click', () => hide($el));
show($el);
}, },
); );
...@@ -108,6 +108,7 @@ export default { ...@@ -108,6 +108,7 @@ export default {
:container="tooltip.container" :container="tooltip.container"
:boundary="tooltip.boundary" :boundary="tooltip.boundary"
:disabled="tooltip.disabled" :disabled="tooltip.disabled"
:show="tooltip.show"
> >
<span v-if="tooltip.html" v-safe-html="tooltip.title"></span> <span v-if="tooltip.html" v-safe-html="tooltip.title"></span>
<span v-else>{{ tooltip.title }}</span> <span v-else>{{ tooltip.title }}</span>
......
...@@ -96,6 +96,12 @@ export const initTooltips = (config = {}) => { ...@@ -96,6 +96,12 @@ export const initTooltips = (config = {}) => {
return invokeBootstrapApi(document.body, config); return invokeBootstrapApi(document.body, config);
}; };
export const add = (elements, config = {}) => {
if (isGlTooltipsEnabled()) {
return addTooltips(elements, config);
}
return invokeBootstrapApi(elements, config);
};
export const dispose = tooltipApiInvoker({ export const dispose = tooltipApiInvoker({
glHandler: element => tooltipsApp().dispose(element), glHandler: element => tooltipsApp().dispose(element),
bsHandler: elements => invokeBootstrapApi(elements, 'dispose'), bsHandler: elements => invokeBootstrapApi(elements, 'dispose'),
......
---
title: Replace quick_submit BSTooltip with GlTooltip
merge_request: 45638
author: Kristin Brooks @kristinbrooks
type: other
...@@ -30024,10 +30024,10 @@ msgstr "" ...@@ -30024,10 +30024,10 @@ msgstr ""
msgid "You can also create a project from the command line." msgid "You can also create a project from the command line."
msgstr "" msgstr ""
msgid "You can also press &#8984;-Enter" msgid "You can also press Ctrl-Enter"
msgstr "" msgstr ""
msgid "You can also press Ctrl-Enter" msgid "You can also press -Enter"
msgstr "" msgstr ""
msgid "You can also star a label to make it a priority label." msgid "You can also star a label to make it a priority label."
......
...@@ -18,7 +18,7 @@ jest.mock('@gitlab/ui/dist/directives/tooltip.js', () => ({ ...@@ -18,7 +18,7 @@ jest.mock('@gitlab/ui/dist/directives/tooltip.js', () => ({
})); }));
jest.mock('@gitlab/ui/dist/components/base/tooltip/tooltip.js', () => ({ jest.mock('@gitlab/ui/dist/components/base/tooltip/tooltip.js', () => ({
props: ['target', 'id', 'triggers', 'placement', 'container', 'boundary', 'disabled'], props: ['target', 'id', 'triggers', 'placement', 'container', 'boundary', 'disabled', 'show'],
render(h) { render(h) {
return h( return h(
'div', 'div',
......
...@@ -80,6 +80,14 @@ describe('tooltips/components/tooltips.vue', () => { ...@@ -80,6 +80,14 @@ describe('tooltips/components/tooltips.vue', () => {
expect(wrapper.find(GlTooltip).html()).toContain(target.getAttribute('title')); expect(wrapper.find(GlTooltip).html()).toContain(target.getAttribute('title'));
}); });
it('sets the configuration values passed in the config object', async () => {
const config = { show: true };
target = createTooltipTarget();
wrapper.vm.addTooltips([target], config);
await wrapper.vm.$nextTick();
expect(wrapper.find(GlTooltip).props()).toMatchObject(config);
});
it.each` it.each`
attribute | value | prop attribute | value | prop
${'data-placement'} | ${'bottom'} | ${'placement'} ${'data-placement'} | ${'bottom'} | ${'placement'}
......
import jQuery from 'jquery'; import jQuery from 'jquery';
import { initTooltips, dispose, destroy, hide, show, enable, disable, fixTitle } from '~/tooltips'; import {
add,
initTooltips,
dispose,
destroy,
hide,
show,
enable,
disable,
fixTitle,
} from '~/tooltips';
describe('tooltips/index.js', () => { describe('tooltips/index.js', () => {
let tooltipsApp; let tooltipsApp;
...@@ -67,6 +77,20 @@ describe('tooltips/index.js', () => { ...@@ -67,6 +77,20 @@ describe('tooltips/index.js', () => {
}); });
}); });
describe('add', () => {
it('adds a GlTooltip for the specified elements', async () => {
const target = createTooltipTarget();
buildTooltipsApp();
add([target], { title: 'custom title' });
await tooltipsApp.$nextTick();
expect(document.querySelector('.gl-tooltip')).not.toBe(null);
expect(document.querySelector('.gl-tooltip').innerHTML).toContain('custom title');
});
});
describe('dispose', () => { describe('dispose', () => {
it('removes tooltips that target the elements specified', async () => { it('removes tooltips that target the elements specified', async () => {
const target = createTooltipTarget(); const target = createTooltipTarget();
...@@ -136,12 +160,13 @@ describe('tooltips/index.js', () => { ...@@ -136,12 +160,13 @@ describe('tooltips/index.js', () => {
${disable} | ${'disable'} | ${'disable'} ${disable} | ${'disable'} | ${'disable'}
${hide} | ${'hide'} | ${'hide'} ${hide} | ${'hide'} | ${'hide'}
${show} | ${'show'} | ${'show'} ${show} | ${'show'} | ${'show'}
${add} | ${'init'} | ${{ title: 'the title' }}
`('delegates $methodName to bootstrap tooltip API', ({ method, bootstrapParams }) => { `('delegates $methodName to bootstrap tooltip API', ({ method, bootstrapParams }) => {
const elements = jQuery(createTooltipTarget()); const elements = jQuery(createTooltipTarget());
jest.spyOn(jQuery.fn, 'tooltip'); jest.spyOn(jQuery.fn, 'tooltip');
method(elements); method(elements, bootstrapParams);
expect(elements.tooltip).toHaveBeenCalledWith(bootstrapParams); expect(elements.tooltip).toHaveBeenCalledWith(bootstrapParams);
}); });
......
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