Add showGlTooltip and hideGlTooltip helpers for tooltip events
What does this MR do and why?
Moves the 27 places where components show or hide tooltips from code behind two small helpers, without changing any behavior. This is a prep MR for the upcoming GlTooltip in @gitlab/ui, which no longer uses bootstrap-vue: gitlab-org/gitlab-services/design.gitlab.com!6294 (merged).
Why
Today, 20 components emit bootstrap-vue's root events to control tooltips:
this.$root.$emit(BV_HIDE_TOOLTIP, id);The new GlTooltip doesn't listen to these events, so all 20 components (and 8 specs) would have to change in the same MR as the @gitlab/ui upgrade (!255018). Putting the events behind helpers first means that upgrade only has to change the helpers, in one file.
What changes
New ~/vue_shared/utils/tooltips.js:
showGlTooltip(this, id); // was: this.$root.$emit(BV_SHOW_TOOLTIP, id)
hideGlTooltip(this, id); // was: this.$root.$emit(BV_HIDE_TOOLTIP, id)For now, the helpers emit exactly the same events on the same $root as before, with the same arguments. Without an id, they still act on all tooltips of the app. The component is passed in because those root events only reach the tooltips of the Vue app they're emitted in.
- 20 components: each
this.$root.$emit(BV_…_TOOLTIP, …)becomesshowGlTooltip(this, …)/hideGlTooltip(this, …). Every change has the same shape. - 8 specs: they mock the helpers and assert their calls, instead of asserting the root events. That way they stay valid when the helpers change.
spec/frontend/vue_shared/utils/tooltips_spec.jscovers the helpers.
No behavior changes. The BV_SHOW_TOOLTIP / BV_HIDE_TOOLTIP constants stay; only the helpers use them now.
What happens next
- The
@gitlab/uiupgrade MR changes the helpers to call the newshowGlTooltip/hideGlTooltipfrom@gitlab/ui, and ignores the component argument. - A follow-up then drops the component argument at the call sites, removes this module, and deletes the two constants.
References
- GitLab UI MR (new
GlTooltip): gitlab-org/gitlab-services/design.gitlab.com!6294 (merged) - Integration MR: !255018
- Previous prep MRs: !262798 (merged), !262883 (merged)
- Related: !260229 (merged) also changes
clipboard_button.vue. Whichever merges second needs a small rebase.
How to set up and validate locally
Nothing visible should change. To check, try any of these tooltips before and after:
- Copy buttons (for example the commit SHA copy button): the "Copied" tooltip still appears and goes away.
- MR widget action buttons and the diffs file tree: tooltips still close on click or scroll.
- Pipeline graph: job and downstream pipeline tooltips still close when you open an action.
yarn jest spec/frontend/vue_shared/utils/tooltips_spec.js