2
2
import { GlSafeHtmlDirective as SafeHtml } from ' @gitlab/ui' ;
3
3
import { mapGetters , mapState , mapActions } from ' vuex' ;
4
4
import { IdState } from ' vendor/vue-virtual-scroller' ;
5
+ import glFeatureFlagsMixin from ' ~/vue_shared/mixins/gl_feature_flags_mixin' ;
5
6
import DraftNote from ' ~/batch_comments/components/draft_note.vue' ;
6
7
import draftCommentsMixin from ' ~/diffs/mixins/draft_comments' ;
7
8
import { getCommentedLines } from ' ~/notes/components/multiline_comment_utils' ;
8
9
import { hide } from ' ~/tooltips' ;
9
10
import { pickDirection } from ' ../utils/diff_line' ;
10
11
import DiffCommentCell from ' ./diff_comment_cell.vue' ;
12
+ import DiffCodeQuality from ' ./diff_code_quality.vue' ;
11
13
import DiffExpansionCell from ' ./diff_expansion_cell.vue' ;
12
14
import DiffRow from ' ./diff_row.vue' ;
13
15
import { isHighlighted } from ' ./diff_row_utils' ;
@@ -17,12 +19,17 @@ export default {
17
19
DiffExpansionCell,
18
20
DiffRow,
19
21
DiffCommentCell,
22
+ DiffCodeQuality,
20
23
DraftNote,
21
24
},
22
25
directives: {
23
26
SafeHtml,
24
27
},
25
- mixins: [draftCommentsMixin, IdState ({ idProp : (vm ) => vm .diffFile .file_hash })],
28
+ mixins: [
29
+ draftCommentsMixin,
30
+ IdState ({ idProp : (vm ) => vm .diffFile .file_hash }),
31
+ glFeatureFlagsMixin (),
32
+ ],
26
33
props: {
27
34
diffFile: {
28
35
type: Object ,
@@ -43,6 +50,11 @@ export default {
43
50
default: false ,
44
51
},
45
52
},
53
+ data () {
54
+ return {
55
+ codeQualityExpandedLines: [],
56
+ };
57
+ },
46
58
idState () {
47
59
return {
48
60
dragStart: null ,
@@ -84,6 +96,23 @@ export default {
84
96
}
85
97
this .idState .dragStart = line;
86
98
},
99
+ parseCodeQuality (line ) {
100
+ return line .left ? .codequality ?? line .right .codequality ;
101
+ },
102
+
103
+ hideCodeQualityFindings (line ) {
104
+ const index = this .codeQualityExpandedLines .indexOf (line);
105
+ if (index > - 1 ) {
106
+ this .codeQualityExpandedLines .splice (index, 1 );
107
+ }
108
+ },
109
+ toggleCodeQualityFindings (line ) {
110
+ if (! this .codeQualityExpandedLines .includes (line)) {
111
+ this .codeQualityExpandedLines .push (line);
112
+ } else {
113
+ this .hideCodeQualityFindings (line);
114
+ }
115
+ },
87
116
onDragOver (line ) {
88
117
if (line .chunk !== this .idState .dragStart .chunk ) return ;
89
118
@@ -125,15 +154,16 @@ export default {
125
154
},
126
155
handleParallelLineMouseDown (e ) {
127
156
const line = e .target .closest (' .diff-td' );
128
- const table = line . closest ( ' .diff-table ' );
129
-
130
- table .classList .remove (' left-side-selected' , ' right-side-selected' );
131
- const [lineClass ] = [' left-side' , ' right-side' ].filter ((name ) =>
132
- line .classList .contains (name),
133
- );
157
+ if (line) {
158
+ const table = line . closest ( ' .diff-table ' );
159
+ table .classList .remove (' left-side-selected' , ' right-side-selected' );
160
+ const [lineClass ] = [' left-side' , ' right-side' ].filter ((name ) =>
161
+ line .classList .contains (name),
162
+ );
134
163
135
- if (lineClass) {
136
- table .classList .add (` ${ lineClass} -selected` );
164
+ if (lineClass) {
165
+ table .classList .add (` ${ lineClass} -selected` );
166
+ }
137
167
}
138
168
},
139
169
getCountBetweenIndex (index ) {
@@ -148,6 +178,9 @@ export default {
148
178
Number (this .diffLines [index - 1 ].left .new_line )
149
179
);
150
180
},
181
+ getCodeQualityLine (line ) {
182
+ return this .parseCodeQuality (line)? .[0 ]? .line ;
183
+ },
151
184
},
152
185
userColorScheme: window .gon .user_color_scheme ,
153
186
};
@@ -190,6 +223,7 @@ export default {
190
223
: coverage- loaded= " coverageLoaded"
191
224
@showCommentForm= " (code) => singleLineComment(code, line)"
192
225
@setHighlightedRow= " setHighlightedRow"
226
+ @toggleCodeQualityFindings= " toggleCodeQualityFindings"
193
227
@toggleLineDiscussions= "
194
228
({ lineCode, expanded }) =>
195
229
toggleLineDiscussions({ lineCode, fileHash: diffFile.file_hash, expanded })
@@ -198,6 +232,17 @@ export default {
198
232
@startdragging= " onStartDragging"
199
233
@stopdragging= " onStopDragging"
200
234
/ >
235
+
236
+ < diff- code- quality
237
+ v- if = "
238
+ glFeatures.refactorCodeQualityInlineFindings &&
239
+ codeQualityExpandedLines.includes(getCodeQualityLine(line))
240
+ "
241
+ : key= " line.line_code"
242
+ : line= " getCodeQualityLine(line)"
243
+ : code- quality= " parseCodeQuality(line)"
244
+ @hideCodeQualityFindings= " hideCodeQualityFindings"
245
+ / >
201
246
< div
202
247
v- if = " line.renderCommentRow"
203
248
: key= " `dcr-${line.line_code || index}`"
0 commit comments