Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
80a689fa
Commit
80a689fa
authored
Oct 19, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Impove diff discussion data
Pre-request to
https://gitlab.com/gitlab-org/gitlab-ce/issues/48956
parent
0baa0c4b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
83 deletions
+80
-83
app/assets/javascripts/diffs/components/app.vue
app/assets/javascripts/diffs/components/app.vue
+11
-5
app/assets/javascripts/diffs/components/diff_file.vue
app/assets/javascripts/diffs/components/diff_file.vue
+2
-2
app/assets/javascripts/diffs/store/actions.js
app/assets/javascripts/diffs/store/actions.js
+27
-15
app/assets/javascripts/diffs/store/mutations.js
app/assets/javascripts/diffs/store/mutations.js
+35
-38
app/assets/javascripts/notes/stores/getters.js
app/assets/javascripts/notes/stores/getters.js
+0
-4
app/assets/javascripts/notes/stores/utils.js
app/assets/javascripts/notes/stores/utils.js
+0
-12
spec/javascripts/diffs/store/actions_spec.js
spec/javascripts/diffs/store/actions_spec.js
+3
-5
spec/javascripts/diffs/store/mutations_spec.js
spec/javascripts/diffs/store/mutations_spec.js
+2
-2
No files found.
app/assets/javascripts/diffs/components/app.vue
View file @
80a689fa
...
...
@@ -41,6 +41,11 @@ export default {
required
:
true
,
},
},
data
()
{
return
{
assignedDiscussions
:
false
,
};
},
computed
:
{
...
mapState
({
isLoading
:
state
=>
state
.
diffs
.
isLoading
,
...
...
@@ -60,7 +65,7 @@ export default {
}),
...
mapState
(
'
diffs
'
,
[
'
showTreeList
'
]),
...
mapGetters
(
'
diffs
'
,
[
'
isParallelView
'
]),
...
mapGetters
([
'
isNotesFetched
'
,
'
discussionsStructuredByLineCode
'
]),
...
mapGetters
([
'
isNotesFetched
'
,
'
getNoteableData
'
]),
targetBranch
()
{
return
{
branchName
:
this
.
targetBranchName
,
...
...
@@ -147,11 +152,12 @@ export default {
}
},
setDiscussions
()
{
if
(
this
.
isNotesFetched
)
{
if
(
this
.
isNotesFetched
&&
!
this
.
assignedDiscussions
)
{
requestIdleCallback
(
()
=>
{
this
.
assignDiscussionsToDiff
(
this
.
discussionsStructuredByLineCode
);
},
()
=>
this
.
assignDiscussionsToDiff
().
then
(()
=>
{
this
.
assignedDiscussions
=
true
;
}),
{
timeout
:
1000
},
);
}
...
...
app/assets/javascripts/diffs/components/diff_file.vue
View file @
80a689fa
...
...
@@ -29,7 +29,7 @@ export default {
},
computed
:
{
...
mapState
(
'
diffs
'
,
[
'
currentDiffFileId
'
]),
...
mapGetters
([
'
isNotesFetched
'
,
'
discussionsStructuredByLineCode
'
]),
...
mapGetters
([
'
isNotesFetched
'
]),
isCollapsed
()
{
return
this
.
file
.
collapsed
||
false
;
},
...
...
@@ -79,7 +79,7 @@ export default {
.
then
(()
=>
{
requestIdleCallback
(
()
=>
{
this
.
assignDiscussionsToDiff
(
this
.
discussionsStructuredByLineCode
);
this
.
assignDiscussionsToDiff
();
},
{
timeout
:
1000
},
);
...
...
app/assets/javascripts/diffs/store/actions.js
View file @
80a689fa
...
...
@@ -5,7 +5,6 @@ import createFlash from '~/flash';
import
{
s__
}
from
'
~/locale
'
;
import
{
handleLocationHash
,
historyPushState
}
from
'
~/lib/utils/common_utils
'
;
import
{
mergeUrlParams
,
getLocationHash
}
from
'
~/lib/utils/url_utility
'
;
import
{
reduceDiscussionsToLineCodes
}
from
'
../../notes/stores/utils
'
;
import
{
getDiffPositionByLineCode
,
getNoteFormData
}
from
'
./utils
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
{
...
...
@@ -36,18 +35,33 @@ export const fetchDiffFiles = ({ state, commit }) => {
// This is adding line discussions to the actual lines in the diff tree
// once for parallel and once for inline mode
export
const
assignDiscussionsToDiff
=
({
state
,
commit
},
allLineDiscussions
)
=>
{
export
const
assignDiscussionsToDiff
=
(
{
commit
,
state
,
rootState
},
discussionsToAssign
=
rootState
.
notes
.
discussions
,
)
=>
{
const
diffPositionByLineCode
=
getDiffPositionByLineCode
(
state
.
diffFiles
);
const
discussionsByDiffFile
=
discussionsToAssign
.
filter
(
discussion
=>
discussion
.
diff_discussion
)
.
reduce
((
acc
,
discussion
)
=>
{
const
discussions
=
(
acc
[
discussion
.
diff_file
.
file_hash
]
||
{
discussions
:
[]
}
).
discussions
.
concat
(
discussion
);
return
{
...
acc
,
[
discussion
.
diff_file
.
file_hash
]:
{
diffFile
:
state
.
diffFiles
.
find
(
file
=>
file
.
fileHash
===
discussion
.
diff_file
.
file_hash
),
discussions
,
},
};
},
{});
Object
.
values
(
allLineDiscussions
).
forEach
(
discussions
=>
{
if
(
discussions
.
length
>
0
)
{
const
{
fileHash
}
=
discussions
[
0
];
Object
.
values
(
discussionsByDiffFile
).
forEach
(({
discussions
,
diffFile
})
=>
{
commit
(
types
.
SET_LINE_DISCUSSIONS_FOR_FILE
,
{
fileHash
,
diffFile
,
discussions
,
diffPositionByLineCode
,
});
}
});
};
...
...
@@ -190,9 +204,7 @@ export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => {
return
dispatch
(
'
saveNote
'
,
postData
,
{
root
:
true
})
.
then
(
result
=>
dispatch
(
'
updateDiscussion
'
,
result
.
discussion
,
{
root
:
true
}))
.
then
(
discussion
=>
dispatch
(
'
assignDiscussionsToDiff
'
,
reduceDiscussionsToLineCodes
([
discussion
])),
)
.
then
(
discussion
=>
dispatch
(
'
assignDiscussionsToDiff
'
,
[
discussion
]))
.
catch
(()
=>
createFlash
(
s__
(
'
MergeRequests|Saving the comment failed
'
)));
};
...
...
app/assets/javascripts/diffs/store/mutations.js
View file @
80a689fa
...
...
@@ -90,53 +90,50 @@ export default {
}));
},
[
types
.
SET_LINE_DISCUSSIONS_FOR_FILE
](
state
,
{
fileHash
,
discussions
,
diffPositionByLineCode
})
{
const
selectedFile
=
state
.
diffFiles
.
find
(
f
=>
f
.
fileHash
===
fileHash
);
const
firstDiscussion
=
discussions
[
0
];
const
isDiffDiscussion
=
firstDiscussion
.
diff_discussion
;
const
hasLineCode
=
firstDiscussion
.
line_code
;
const
diffPosition
=
diffPositionByLineCode
[
firstDiscussion
.
line_code
];
if
(
selectedFile
&&
isDiffDiscussion
&&
hasLineCode
&&
diffPosition
&&
[
types
.
SET_LINE_DISCUSSIONS_FOR_FILE
](
state
,
{
diffFile
,
discussions
,
diffPositionByLineCode
})
{
const
{
latestDiff
}
=
state
;
discussions
.
forEach
(
discussion
=>
{
const
discussionLineCode
=
discussion
.
line_code
;
const
lineCheck
=
({
lineCode
})
=>
lineCode
===
discussionLineCode
&&
isDiscussionApplicableToLine
({
discussion
:
firstDiscussion
,
diffPosition
,
latestDiff
:
state
.
latestDiff
,
})
)
{
const
targetLine
=
selectedFile
.
parallelDiffLines
.
find
(
line
=>
(
line
.
left
&&
line
.
left
.
lineCode
===
firstDiscussion
.
line_code
)
||
(
line
.
right
&&
line
.
right
.
lineCode
===
firstDiscussion
.
line_code
),
);
if
(
targetLine
)
{
if
(
targetLine
.
left
&&
targetLine
.
left
.
lineCode
===
firstDiscussion
.
line_code
)
{
Object
.
assign
(
targetLine
.
left
,
{
discussions
,
discussion
,
diffPosition
:
diffPositionByLineCode
[
lineCode
],
latestDiff
,
});
}
else
{
Object
.
assign
(
targetLine
.
right
,
{
discussions
,
if
(
diffFile
.
highlightedDiffLines
)
{
const
line
=
diffFile
.
highlightedDiffLines
.
find
(
lineCheck
);
if
(
line
)
{
Object
.
assign
(
line
,
{
discussions
:
line
.
discussions
.
concat
(
discussion
),
});
}
}
if
(
selectedFile
.
highlightedDiffLines
)
{
const
targetInlineLine
=
selectedFile
.
highlightedDiffLines
.
find
(
line
=>
line
.
lineCode
===
firstDiscussion
.
line_code
,
if
(
diffFile
.
parallelDiffLines
)
{
const
{
left
,
right
}
=
diffFile
.
parallelDiffLines
.
find
(
parallelLine
=>
(
parallelLine
.
left
&&
lineCheck
(
parallelLine
.
left
))
||
(
parallelLine
.
right
&&
lineCheck
(
parallelLine
.
right
)),
);
const
line
=
left
&&
left
.
lineCode
===
discussionLineCode
?
left
:
right
;
if
(
targetInlineL
ine
)
{
Object
.
assign
(
targetInlineL
ine
,
{
discussions
,
if
(
l
ine
)
{
Object
.
assign
(
l
ine
,
{
discussions
:
line
.
discussions
.
concat
(
discussion
)
,
});
}
}
if
(
!
diffFile
.
parallelDiffLines
||
!
diffFile
.
highlightedDiffLines
)
{
Object
.
assign
(
diffFile
,
{
discussions
:
diffFile
.
discussions
.
concat
(
discussion
),
});
}
});
},
[
types
.
REMOVE_LINE_DISCUSSIONS_FOR_FILE
](
state
,
{
fileHash
,
lineCode
})
{
...
...
app/assets/javascripts/notes/stores/getters.js
View file @
80a689fa
import
_
from
'
underscore
'
;
import
*
as
constants
from
'
../constants
'
;
import
{
reduceDiscussionsToLineCodes
}
from
'
./utils
'
;
import
{
collapseSystemNotes
}
from
'
./collapse_utils
'
;
export
const
discussions
=
state
=>
collapseSystemNotes
(
state
.
discussions
);
...
...
@@ -31,9 +30,6 @@ export const notesById = state =>
return
acc
;
},
{});
export
const
discussionsStructuredByLineCode
=
state
=>
reduceDiscussionsToLineCodes
(
state
.
discussions
);
export
const
noteableType
=
state
=>
{
const
{
ISSUE_NOTEABLE_TYPE
,
MERGE_REQUEST_NOTEABLE_TYPE
,
EPIC_NOTEABLE_TYPE
}
=
constants
;
...
...
app/assets/javascripts/notes/stores/utils.js
View file @
80a689fa
...
...
@@ -25,18 +25,6 @@ export const getQuickActionText = note => {
return
text
;
};
export
const
reduceDiscussionsToLineCodes
=
selectedDiscussions
=>
selectedDiscussions
.
reduce
((
acc
,
note
)
=>
{
if
(
note
.
diff_discussion
&&
note
.
line_code
)
{
// For context about line notes: there might be multiple notes with the same line code
const
items
=
acc
[
note
.
line_code
]
||
[];
items
.
push
(
note
);
Object
.
assign
(
acc
,
{
[
note
.
line_code
]:
items
});
}
return
acc
;
},
{});
export
const
hasQuickActions
=
note
=>
REGEX_QUICK_ACTIONS
.
test
(
note
);
export
const
stripQuickActions
=
note
=>
note
.
replace
(
REGEX_QUICK_ACTIONS
,
''
).
trim
();
spec/javascripts/diffs/store/actions_spec.js
View file @
80a689fa
...
...
@@ -27,7 +27,6 @@ import actions, {
toggleShowTreeList
,
}
from
'
~/diffs/store/actions
'
;
import
*
as
types
from
'
~/diffs/store/mutation_types
'
;
import
{
reduceDiscussionsToLineCodes
}
from
'
~/notes/stores/utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
testAction
from
'
../../helpers/vuex_action_helper
'
;
...
...
@@ -152,7 +151,7 @@ describe('DiffsStoreActions', () => {
original_position
:
diffPosition
,
};
const
discussions
=
reduceDiscussionsToLineCodes
([
singleDiscussion
])
;
const
discussions
=
[
singleDiscussion
]
;
testAction
(
assignDiscussionsToDiff
,
...
...
@@ -162,7 +161,7 @@ describe('DiffsStoreActions', () => {
{
type
:
types
.
SET_LINE_DISCUSSIONS_FOR_FILE
,
payload
:
{
fileHash
:
'
ABC
'
,
diffFile
:
state
.
diffFiles
[
0
]
,
discussions
:
[
singleDiscussion
],
diffPositionByLineCode
:
{
ABC_1_1
:
{
...
...
@@ -581,7 +580,6 @@ describe('DiffsStoreActions', () => {
describe
(
'
saveDiffDiscussion
'
,
()
=>
{
beforeEach
(()
=>
{
spyOnDependency
(
actions
,
'
getNoteFormData
'
).
and
.
returnValue
(
'
testData
'
);
spyOnDependency
(
actions
,
'
reduceDiscussionsToLineCodes
'
).
and
.
returnValue
(
'
discussions
'
);
});
it
(
'
dispatches actions
'
,
done
=>
{
...
...
@@ -602,7 +600,7 @@ describe('DiffsStoreActions', () => {
.
then
(()
=>
{
expect
(
dispatch
.
calls
.
argsFor
(
0
)).
toEqual
([
'
saveNote
'
,
'
testData
'
,
{
root
:
true
}]);
expect
(
dispatch
.
calls
.
argsFor
(
1
)).
toEqual
([
'
updateDiscussion
'
,
'
test
'
,
{
root
:
true
}]);
expect
(
dispatch
.
calls
.
argsFor
(
2
)).
toEqual
([
'
assignDiscussionsToDiff
'
,
'
discussions
'
]);
expect
(
dispatch
.
calls
.
argsFor
(
2
)).
toEqual
([
'
assignDiscussionsToDiff
'
,
[
'
discussion
'
]
]);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
...
...
spec/javascripts/diffs/store/mutations_spec.js
View file @
80a689fa
...
...
@@ -222,7 +222,7 @@ describe('DiffsStoreMutations', () => {
};
mutations
[
types
.
SET_LINE_DISCUSSIONS_FOR_FILE
](
state
,
{
fileHash
:
'
ABC
'
,
diffFile
:
state
.
diffFiles
[
0
]
,
discussions
,
diffPositionByLineCode
,
});
...
...
@@ -292,7 +292,7 @@ describe('DiffsStoreMutations', () => {
};
mutations
[
types
.
SET_LINE_DISCUSSIONS_FOR_FILE
](
state
,
{
fileHash
:
'
ABC
'
,
diffFile
:
state
.
diffFiles
[
0
]
,
discussions
,
diffPositionByLineCode
,
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment