From d90bdf35cf975b47c3c4a37c5c7691365e1e39fa Mon Sep 17 00:00:00 2001 From: jboyson Date: Thu, 11 Jun 2020 15:33:35 -0500 Subject: [PATCH 01/10] Highlight commented rows --- .../components/inline_diff_table_row.vue | 10 +++++++++- .../diffs/components/inline_diff_view.vue | 20 +++++++++++++++++++ .../components/parallel_diff_table_row.vue | 7 +++++++ .../diffs/components/parallel_diff_view.vue | 20 +++++++++++++++++++ .../notes/components/noteable_note.vue | 3 +++ .../javascripts/notes/stores/actions.js | 4 ++++ .../javascripts/notes/stores/getters.js | 2 ++ .../javascripts/notes/stores/modules/index.js | 1 + .../notes/stores/mutation_types.js | 1 + .../javascripts/notes/stores/mutations.js | 4 ++++ .../jdb-highlight-commented-rows.yml | 5 +++++ 11 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/jdb-highlight-commented-rows.yml diff --git a/app/assets/javascripts/diffs/components/inline_diff_table_row.vue b/app/assets/javascripts/diffs/components/inline_diff_table_row.vue index 4e228577666f28..168e8c6c14e30b 100644 --- a/app/assets/javascripts/diffs/components/inline_diff_table_row.vue +++ b/app/assets/javascripts/diffs/components/inline_diff_table_row.vue @@ -37,6 +37,11 @@ export default { required: false, default: false, }, + isCommented: { + type: Boolean, + required: false, + default: false, + }, }, data() { return { @@ -47,7 +52,10 @@ export default { ...mapGetters('diffs', ['fileLineCoverage']), ...mapState({ isHighlighted(state) { - return this.line.line_code !== null && this.line.line_code === state.diffs.highlightedRow; + if (this.isCommented) return true; + + const lineCode = this.line.line_code; + return lineCode ? lineCode === state.diffs.highlightedRow : false; }, }), isContextLine() { diff --git a/app/assets/javascripts/diffs/components/inline_diff_view.vue b/app/assets/javascripts/diffs/components/inline_diff_view.vue index babf48f41f3563..67f478be2b40f1 100644 --- a/app/assets/javascripts/diffs/components/inline_diff_view.vue +++ b/app/assets/javascripts/diffs/components/inline_diff_view.vue @@ -31,9 +31,28 @@ export default { }, computed: { ...mapGetters('diffs', ['commitId']), + ...mapGetters(['selectedCommentPosition']), diffLinesLength() { return this.diffLines.length; }, + commentedLines() { + if (!this.selectedCommentPosition) return { startLine: Infinity, endLine: -Infinity }; + + if (this.selectedCommentPosition.line_range) { + const { start, end } = this.selectedCommentPosition.line_range; + const startLine = this.diffLines.findIndex(l => l.line_code === start.line_code); + const endLine = this.diffLines.findIndex(l => l.line_code === end.line_code); + + return { startLine, endLine }; + } + + const start = this.selectedCommentPosition.start_line_code; + const end = this.selectedCommentPosition.end_line_code; + const startLine = this.diffLines.findIndex(l => l.line_code === start); + const endLine = this.diffLines.findIndex(l => l.line_code === end); + + return { startLine, endLine }; + }, }, userColorScheme: window.gon.user_color_scheme, }; @@ -67,6 +86,7 @@ export default { :file-path="diffFile.file_path" :line="line" :is-bottom="index + 1 === diffLinesLength" + :is-commented="index >= commentedLines.startLine && index <= commentedLines.endLine" /> l.line_code === start.line_code); + const endLine = this.diffLines.findIndex(l => l.line_code === end.line_code); + + return { startLine, endLine }; + } + + const start = this.selectedCommentPosition.start_line_code; + const end = this.selectedCommentPosition.end_line_code; + const startLine = this.diffLines.findIndex(l => l.line_code === start); + const endLine = this.diffLines.findIndex(l => l.line_code === end); + + return { startLine, endLine }; + }, }, userColorScheme: window.gon.user_color_scheme, }; @@ -69,6 +88,7 @@ export default { :file-path="diffFile.file_path" :line="line" :is-bottom="index + 1 === diffLinesLength" + :is-commented="index >= commentedLines.startLine && index <= commentedLines.endLine" />
{ commit(types.SET_DISCUSSIONS_SORT, direction); }; +export const setSelectedCommentPostision = ({ commit }, position) => { + commit(types.SET_SELECTED_COMMENT_POSTISION, position); +}; + export const removeNote = ({ commit, dispatch, state }, note) => { const discussion = state.discussions.find(({ id }) => id === note.discussion_id); diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js index 85997b44bccf48..44f6723b71b257 100644 --- a/app/assets/javascripts/notes/stores/getters.js +++ b/app/assets/javascripts/notes/stores/getters.js @@ -230,5 +230,7 @@ export const getDiscussion = state => discussionId => export const commentsDisabled = state => state.commentsDisabled; +export const selectedCommentPosition = state => state.selectedCommentPosition; + // prevent babel-plugin-rewire from generating an invalid default during karma tests export default () => {}; diff --git a/app/assets/javascripts/notes/stores/modules/index.js b/app/assets/javascripts/notes/stores/modules/index.js index c71e62cb551fff..397def915142f9 100644 --- a/app/assets/javascripts/notes/stores/modules/index.js +++ b/app/assets/javascripts/notes/stores/modules/index.js @@ -12,6 +12,7 @@ export default () => ({ lastFetchedAt: null, currentDiscussionId: null, batchSuggestionsInfo: [], + selectedCommentPosition: null, // View layer isToggleStateButtonLoading: false, diff --git a/app/assets/javascripts/notes/stores/mutation_types.js b/app/assets/javascripts/notes/stores/mutation_types.js index efb24479f7c0bf..78561630413214 100644 --- a/app/assets/javascripts/notes/stores/mutation_types.js +++ b/app/assets/javascripts/notes/stores/mutation_types.js @@ -33,6 +33,7 @@ export const SET_EXPAND_DISCUSSIONS = 'SET_EXPAND_DISCUSSIONS'; export const UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS = 'UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS'; export const SET_CURRENT_DISCUSSION_ID = 'SET_CURRENT_DISCUSSION_ID'; export const SET_DISCUSSIONS_SORT = 'SET_DISCUSSIONS_SORT'; +export const SET_SELECTED_COMMENT_POSTISION = 'SET_SELECTED_COMMENT_POSITION'; // Issue export const CLOSE_ISSUE = 'CLOSE_ISSUE'; diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js index 7ed0dd84b655f4..7a0149b6d8a3f7 100644 --- a/app/assets/javascripts/notes/stores/mutations.js +++ b/app/assets/javascripts/notes/stores/mutations.js @@ -308,6 +308,10 @@ export default { state.discussionSortOrder = sort; }, + [types.SET_SELECTED_COMMENT_POSTISION](state, position) { + state.selectedCommentPosition = position; + }, + [types.DISABLE_COMMENTS](state, value) { state.commentsDisabled = value; }, diff --git a/changelogs/unreleased/jdb-highlight-commented-rows.yml b/changelogs/unreleased/jdb-highlight-commented-rows.yml new file mode 100644 index 00000000000000..a4aa76ca6848e8 --- /dev/null +++ b/changelogs/unreleased/jdb-highlight-commented-rows.yml @@ -0,0 +1,5 @@ +--- +title: Highlight commented rows +merge_request: 34432 +author: +type: added -- GitLab From 7be0e264c3bea1f22f611777bfbaff067c4585b7 Mon Sep 17 00:00:00 2001 From: jboyson Date: Tue, 16 Jun 2020 09:52:27 -0500 Subject: [PATCH 02/10] Code review changes --- .../diffs/components/inline_diff_view.vue | 22 ++++--------------- .../diffs/components/parallel_diff_view.vue | 22 ++++--------------- .../components/multiline_comment_utils.js | 19 ++++++++++++++++ .../javascripts/notes/stores/getters.js | 2 -- 4 files changed, 27 insertions(+), 38 deletions(-) diff --git a/app/assets/javascripts/diffs/components/inline_diff_view.vue b/app/assets/javascripts/diffs/components/inline_diff_view.vue index 67f478be2b40f1..866efca77109bd 100644 --- a/app/assets/javascripts/diffs/components/inline_diff_view.vue +++ b/app/assets/javascripts/diffs/components/inline_diff_view.vue @@ -1,10 +1,11 @@