From 14e067af392b92b683b3dea3c9f2628b296d8126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lu=C3=ADs?= Date: Thu, 19 Jul 2018 21:32:48 +0100 Subject: Stop using line_code and start using position.* for diff ordering of discussions --- app/assets/javascripts/notes/stores/getters.js | 12 +++++------ spec/javascripts/notes/mock_data.js | 28 ++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js index 4806699cb2c..36d8e0c1aa1 100644 --- a/app/assets/javascripts/notes/stores/getters.js +++ b/app/assets/javascripts/notes/stores/getters.js @@ -114,21 +114,21 @@ export const unresolvedDiscussionsIdsByDiff = (state, getters) => getters.allResolvableDiscussions .filter(d => !d.resolved) .sort((a, b) => { - if (!a.line_code || !b.line_code || !a.diff_file || !b.diff_file) { + if (!a.diff_file || !b.diff_file) { return 0; } - // Extract line numbers for comparison - const regexpExtractLineNumbers = /([0-9]*)_([0-9]*)$/; - const aLines = a.line_code.match(regexpExtractLineNumbers); - const bLines = b.line_code.match(regexpExtractLineNumbers); // Get file names comparison result const filenameComparison = a.diff_file.file_path.localeCompare(b.diff_file.file_path); + // Get the line numbers, to compare within the same file + const aLines = [a.position.formatter.new_line, a.position.formatter.old_line]; + const bLines = [b.position.formatter.new_line, b.position.formatter.old_line]; + return filenameComparison < 0 || (filenameComparison === 0 && // .max() because one of them might be zero (if removed/added) - Math.max(aLines[1], aLines[2]) < Math.max(bLines[1], bLines[2])) + Math.max(aLines[0], aLines[1]) < Math.max(bLines[0], bLines[1])) ? -1 : 1; }) diff --git a/spec/javascripts/notes/mock_data.js b/spec/javascripts/notes/mock_data.js index e77f2a9f7af..67f6a9629d9 100644 --- a/spec/javascripts/notes/mock_data.js +++ b/spec/javascripts/notes/mock_data.js @@ -1176,7 +1176,12 @@ export const discussion1 = { diff_file: { file_path: 'about.md', }, - line_code: 'abcdefghijkl_50_0', + position: { + formatter: { + new_line: 50, + old_line: null, + }, + }, notes: [ { created_at: '2018-07-04T16:25:41.749Z', @@ -1191,7 +1196,12 @@ export const resolvedDiscussion1 = { diff_file: { file_path: 'about.md', }, - line_code: 'abcdefghijkl_50_0', + position: { + formatter: { + new_line: 50, + old_line: null, + }, + }, notes: [ { created_at: '2018-07-04T16:25:41.749Z', @@ -1206,7 +1216,12 @@ export const discussion2 = { diff_file: { file_path: 'README.md', }, - line_code: 'abcdefghijkl_0_20', + position: { + formatter: { + new_line: null, + old_line: 20, + }, + }, notes: [ { created_at: '2018-07-04T12:05:41.749Z', @@ -1221,7 +1236,12 @@ export const discussion3 = { diff_file: { file_path: 'README.md', }, - line_code: 'abcdefghijkl_21_0', + position: { + formatter: { + new_line: 21, + old_line: null, + }, + }, notes: [ { created_at: '2018-07-05T17:25:41.749Z', -- cgit v1.2.1