summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Luís <aluis@gitlab.com>2018-07-19 21:32:48 +0100
committerAndré Luís <aluis@gitlab.com>2018-07-19 21:32:51 +0100
commit14e067af392b92b683b3dea3c9f2628b296d8126 (patch)
treeed4f7ca05cbcfe8a0a6bda740a5963a4ae4e5587
parent97f9329fed5b66199402cf4f75697490800068ff (diff)
downloadgitlab-ce-48817-fix-mr-changes-discussion-navigation.tar.gz
Stop using line_code and start using position.*48817-fix-mr-changes-discussion-navigation
for diff ordering of discussions
-rw-r--r--app/assets/javascripts/notes/stores/getters.js12
-rw-r--r--spec/javascripts/notes/mock_data.js28
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',