Commit 51f99aef authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '2526-popovers-instead-of-tooltips' into 'master'

Use popovers instead of tooltips in inline code quality

See merge request gitlab-org/gitlab!64371
parents 36c5d718 949b5ed4
...@@ -65,7 +65,7 @@ See also the Code Climate list of [Supported Languages for Maintainability](http ...@@ -65,7 +65,7 @@ See also the Code Climate list of [Supported Languages for Maintainability](http
Changes to files in merge requests can cause Code Quality to fall if merged. In these cases, Changes to files in merge requests can cause Code Quality to fall if merged. In these cases,
the merge request's diff view displays an indicator next to lines with new Code Quality violations. For example: the merge request's diff view displays an indicator next to lines with new Code Quality violations. For example:
![Code Quality MR diff report](img/code_quality_mr_diff_report_v14.png) ![Code Quality MR diff report](img/code_quality_mr_diff_report_v14_2.png)
## Example configuration ## Example configuration
......
<script> <script>
import { GlTooltipDirective, GlIcon, GlModalDirective, GlModal } from '@gitlab/ui'; import { GlPopover, GlIcon } from '@gitlab/ui';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility'; import { __, s__ } from '~/locale';
import { __, s__, sprintf } from '~/locale';
import CodequalityIssueBody from '~/reports/codequality_report/components/codequality_issue_body.vue'; import CodequalityIssueBody from '~/reports/codequality_report/components/codequality_issue_body.vue';
import { SEVERITY_CLASSES, SEVERITY_ICONS } from '~/reports/codequality_report/constants'; import { SEVERITY_CLASSES, SEVERITY_ICONS } from '~/reports/codequality_report/constants';
const i18n = {
tooltip: s__('CodeQuality|Code quality: %{severity} - %{description}'),
};
export default { export default {
components: { components: {
GlIcon, GlIcon,
GlModal, GlPopover,
CodequalityIssueBody, CodequalityIssueBody,
}, },
directives: {
GlTooltip: GlTooltipDirective,
GlModal: GlModalDirective,
},
modalCloseButton: { modalCloseButton: {
text: __('Close'), text: __('Close'),
attributes: [{ variant: 'info' }], attributes: [{ variant: 'info' }],
}, },
i18n: { i18n: {
modalTitle: s__('CodeQuality|New code quality degradations on this line'), popoverTitle: s__('CodeQuality|New code quality degradations on this line'),
}, },
props: { props: {
filePath: { filePath: {
...@@ -38,12 +29,6 @@ export default { ...@@ -38,12 +29,6 @@ export default {
}, },
}, },
computed: { computed: {
tooltipText() {
return sprintf(i18n.tooltip, {
severity: capitalizeFirstCharacter(this.severity),
description: this.codequality[0].description,
});
},
severity() { severity() {
return this.codequality[0].severity; return this.codequality[0].severity;
}, },
...@@ -61,8 +46,6 @@ export default { ...@@ -61,8 +46,6 @@ export default {
return { return {
name: degradation.description, name: degradation.description,
severity: degradation.severity, severity: degradation.severity,
path: this.filePath,
line: this.line,
}; };
}); });
}, },
...@@ -73,24 +56,24 @@ export default { ...@@ -73,24 +56,24 @@ export default {
<template> <template>
<div> <div>
<gl-icon <gl-icon
v-gl-modal="`codequality-${filePath}:${line}`" :id="`codequality-${filePath}:${line}`"
v-gl-tooltip.hover
:title="tooltipText"
:size="12" :size="12"
:name="severityIcon" :name="severityIcon"
:class="severityClass" :class="severityClass"
class="gl-hover-cursor-pointer codequality-severity-icon" class="gl-hover-cursor-pointer codequality-severity-icon"
/> />
<gl-modal <gl-popover
:modal-id="`codequality-${filePath}:${line}`" triggers="hover focus"
:title="$options.i18n.modalTitle" placement="topright"
:action-primary="$options.modalCloseButton" :css-classes="['gl-max-w-max-content', 'gl-w-half']"
:target="`codequality-${filePath}:${line}`"
:title="$options.i18n.popoverTitle"
> >
<codequality-issue-body <codequality-issue-body
v-for="(degradation, index) in degradations" v-for="(degradation, index) in degradations"
:key="index" :key="index"
:issue="degradation" :issue="degradation"
/> />
</gl-modal> </gl-popover>
</div> </div>
</template> </template>
import { GlIcon } from '@gitlab/ui'; import { GlIcon, GlPopover } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
...@@ -68,17 +68,17 @@ describe('EE CodeQualityGutterIcon', () => { ...@@ -68,17 +68,17 @@ describe('EE CodeQualityGutterIcon', () => {
}); });
}); });
describe('code quality modal', () => { describe('code quality gutter icon', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
}); });
it('opens a code quality modal on click', () => { it('shows a popover on hover', () => {
const modalId = 'codequality-index.js:3'; const popoverTarget = 'codequality-index.js:3';
const rootEmit = jest.spyOn(wrapper.vm.$root, '$emit');
wrapper.findComponent(GlIcon).trigger('click');
expect(rootEmit.mock.calls[0]).toContainEqual(modalId); wrapper.findComponent(GlIcon).trigger('mouseover');
expect(wrapper.find(GlPopover).props().target).toBe(popoverTarget);
}); });
it('passes the issue data into the issue components correctly', () => { it('passes the issue data into the issue components correctly', () => {
...@@ -89,19 +89,15 @@ describe('EE CodeQualityGutterIcon', () => { ...@@ -89,19 +89,15 @@ describe('EE CodeQualityGutterIcon', () => {
expect(issueProps).toEqual([ expect(issueProps).toEqual([
{ {
issue: { issue: {
path: defaultProps.filePath,
severity: defaultProps.codequality[0].severity, severity: defaultProps.codequality[0].severity,
name: defaultProps.codequality[0].description, name: defaultProps.codequality[0].description,
line: defaultProps.codequality[0].line,
}, },
status: 'neutral', status: 'neutral',
}, },
{ {
issue: { issue: {
path: defaultProps.filePath,
severity: defaultProps.codequality[1].severity, severity: defaultProps.codequality[1].severity,
name: defaultProps.codequality[1].description, name: defaultProps.codequality[1].description,
line: defaultProps.codequality[1].line,
}, },
status: 'neutral', status: 'neutral',
}, },
......
...@@ -8009,9 +8009,6 @@ msgstr "" ...@@ -8009,9 +8009,6 @@ msgstr ""
msgid "CodeOwner|Pattern" msgid "CodeOwner|Pattern"
msgstr "" msgstr ""
msgid "CodeQuality|Code quality: %{severity} - %{description}"
msgstr ""
msgid "CodeQuality|New code quality degradations on this line" msgid "CodeQuality|New code quality degradations on this line"
msgstr "" msgstr ""
......
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