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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
4164c616
Commit
4164c616
authored
Aug 13, 2018
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loading Discussions later on Diffs
parent
18c7a213
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
160 additions
and
66 deletions
+160
-66
app/assets/javascripts/diffs/components/app.vue
app/assets/javascripts/diffs/components/app.vue
+22
-3
app/assets/javascripts/diffs/components/parallel_diff_comment_row.vue
...avascripts/diffs/components/parallel_diff_comment_row.vue
+21
-25
app/assets/javascripts/diffs/components/parallel_diff_view.vue
...ssets/javascripts/diffs/components/parallel_diff_view.vue
+5
-8
app/assets/javascripts/diffs/store/actions.js
app/assets/javascripts/diffs/store/actions.js
+53
-14
app/assets/javascripts/diffs/store/getters.js
app/assets/javascripts/diffs/store/getters.js
+52
-15
app/assets/javascripts/diffs/store/utils.js
app/assets/javascripts/diffs/store/utils.js
+1
-0
app/assets/javascripts/notes/stores/getters.js
app/assets/javascripts/notes/stores/getters.js
+6
-1
No files found.
app/assets/javascripts/diffs/components/app.vue
View file @
4164c616
...
@@ -59,7 +59,7 @@ export default {
...
@@ -59,7 +59,7 @@ export default {
emailPatchPath
:
state
=>
state
.
diffs
.
emailPatchPath
,
emailPatchPath
:
state
=>
state
.
diffs
.
emailPatchPath
,
}),
}),
...
mapGetters
(
'
diffs
'
,
[
'
isParallelView
'
]),
...
mapGetters
(
'
diffs
'
,
[
'
isParallelView
'
]),
...
mapGetters
([
'
isNotesFetched
'
]),
...
mapGetters
([
'
isNotesFetched
'
,
'
discussionsStructuredByLineCode
'
]),
targetBranch
()
{
targetBranch
()
{
return
{
return
{
branchName
:
this
.
targetBranchName
,
branchName
:
this
.
targetBranchName
,
...
@@ -112,13 +112,32 @@ export default {
...
@@ -112,13 +112,32 @@ export default {
},
},
created
()
{
created
()
{
this
.
adjustView
();
this
.
adjustView
();
eventHub
.
$once
(
'
renderedFiles
'
,
this
.
assignDiscussionsToDiff
);
},
},
methods
:
{
methods
:
{
...
mapActions
(
'
diffs
'
,
[
'
setBaseConfig
'
,
'
fetchDiffFiles
'
,
'
startRenderDiffsQueue
'
]),
...
mapActions
(
'
diffs
'
,
[
'
setBaseConfig
'
,
'
fetchDiffFiles
'
,
'
startRenderDiffsQueue
'
,
'
assignDiscussionsToDiff
'
,
]),
fetchData
()
{
fetchData
()
{
this
.
fetchDiffFiles
()
this
.
fetchDiffFiles
()
.
then
(()
=>
{
.
then
(()
=>
{
requestIdleCallback
(
this
.
startRenderDiffsQueue
,
{
timeout
:
1000
});
requestIdleCallback
(
()
=>
{
this
.
startRenderDiffsQueue
()
.
then
(()
=>
{
console
.
log
(
'
Done rendering Que
'
);
this
.
assignDiscussionsToDiff
(
this
.
discussionsStructuredByLineCode
);
})
.
catch
(()
=>
{
createFlash
(
__
(
'
Something went wrong on our end. Please try again!
'
));
});
},
{
timeout
:
1000
},
);
})
})
.
catch
(()
=>
{
.
catch
(()
=>
{
createFlash
(
__
(
'
Something went wrong on our end. Please try again!
'
));
createFlash
(
__
(
'
Something went wrong on our end. Please try again!
'
));
...
...
app/assets/javascripts/diffs/components/parallel_diff_comment_row.vue
View file @
4164c616
...
@@ -21,51 +21,47 @@ export default {
...
@@ -21,51 +21,47 @@ export default {
type
:
Number
,
type
:
Number
,
required
:
true
,
required
:
true
,
},
},
leftDiscussions
:
{
type
:
Array
,
required
:
false
,
default
:
()
=>
[],
},
rightDiscussions
:
{
type
:
Array
,
required
:
false
,
default
:
()
=>
[],
},
},
},
computed
:
{
computed
:
{
...
mapState
({
...
mapState
({
diffLineCommentForms
:
state
=>
state
.
diffs
.
diffLineCommentForms
,
diffLineCommentForms
:
state
=>
state
.
diffs
.
diffLineCommentForms
,
}),
}),
leftLineCode
()
{
leftLineCode
()
{
return
this
.
line
.
left
.
lineCode
;
return
this
.
line
.
left
&&
this
.
line
.
left
.
lineCode
;
},
},
rightLineCode
()
{
rightLineCode
()
{
return
this
.
line
.
right
.
lineCode
;
return
this
.
line
.
right
&&
this
.
line
.
right
.
lineCode
;
},
},
hasExpandedDiscussionOnLeft
()
{
hasExpandedDiscussionOnLeft
()
{
const
discussions
=
this
.
leftDiscussions
;
return
this
.
line
.
left
&&
this
.
line
.
left
.
discussions
?
this
.
line
.
left
.
discussions
.
every
(
discussion
=>
discussion
.
expanded
)
return
discussions
?
discussions
.
every
(
discussion
=>
discussion
.
expanded
)
:
false
;
:
false
;
},
},
hasExpandedDiscussionOnRight
()
{
hasExpandedDiscussionOnRight
()
{
const
discussions
=
this
.
rightDiscussions
;
return
this
.
line
.
right
&&
this
.
line
.
right
.
discussions
?
this
.
line
.
right
.
discussions
.
every
(
discussion
=>
discussion
.
expanded
)
return
discussions
?
discussions
.
every
(
discussion
=>
discussion
.
expanded
)
:
false
;
:
false
;
},
},
hasAnyExpandedDiscussion
()
{
hasAnyExpandedDiscussion
()
{
return
this
.
hasExpandedDiscussionOnLeft
||
this
.
hasExpandedDiscussionOnRight
;
return
this
.
hasExpandedDiscussionOnLeft
||
this
.
hasExpandedDiscussionOnRight
;
},
},
shouldRenderDiscussionsOnLeft
()
{
shouldRenderDiscussionsOnLeft
()
{
return
this
.
l
eftD
iscussions
&&
this
.
hasExpandedDiscussionOnLeft
;
return
this
.
l
ine
.
left
&&
this
.
line
.
left
.
d
iscussions
&&
this
.
hasExpandedDiscussionOnLeft
;
},
},
shouldRenderDiscussionsOnRight
()
{
shouldRenderDiscussionsOnRight
()
{
return
this
.
rightDiscussions
&&
this
.
hasExpandedDiscussionOnRight
&&
this
.
line
.
right
.
type
;
return
(
this
.
line
.
right
&&
this
.
line
.
right
.
discussions
&&
this
.
hasExpandedDiscussionOnRight
&&
this
.
line
.
right
.
type
);
},
},
showRightSideCommentForm
()
{
showRightSideCommentForm
()
{
return
this
.
line
.
right
.
type
&&
this
.
diffLineCommentForms
[
this
.
rightLineCode
];
return
this
.
line
.
right
.
type
&&
this
.
diffLineCommentForms
[
this
.
rightLineCode
];
},
},
className
()
{
className
()
{
return
this
.
leftDiscussions
.
length
>
0
||
this
.
rightDiscussions
.
length
>
0
return
(
this
.
left
&&
this
.
line
.
left
.
discussions
.
length
>
0
)
||
(
this
.
right
&&
this
.
line
.
right
.
discussions
.
length
>
0
)
?
''
?
''
:
'
js-temp-notes-holder
'
;
:
'
js-temp-notes-holder
'
;
},
},
...
@@ -85,8 +81,8 @@ export default {
...
@@ -85,8 +81,8 @@ export default {
class=
"content"
class=
"content"
>
>
<diff-discussions
<diff-discussions
v-if=
"l
eftD
iscussions.length"
v-if=
"l
ine.left.d
iscussions.length"
:discussions=
"l
eftD
iscussions"
:discussions=
"l
ine.left.d
iscussions"
/>
/>
</div>
</div>
<diff-line-note-form
<diff-line-note-form
...
@@ -104,8 +100,8 @@ export default {
...
@@ -104,8 +100,8 @@ export default {
class=
"content"
class=
"content"
>
>
<diff-discussions
<diff-discussions
v-if=
"
rightD
iscussions.length"
v-if=
"
line.right.d
iscussions.length"
:discussions=
"
rightD
iscussions"
:discussions=
"
line.right.d
iscussions"
/>
/>
</div>
</div>
<diff-line-note-form
<diff-line-note-form
...
...
app/assets/javascripts/diffs/components/parallel_diff_view.vue
View file @
4164c616
...
@@ -32,8 +32,9 @@ export default {
...
@@ -32,8 +32,9 @@ export default {
},
},
methods
:
{
methods
:
{
discussionsByLine
(
line
,
leftOrRight
)
{
discussionsByLine
(
line
,
leftOrRight
)
{
return
line
[
leftOrRight
]
&&
line
[
leftOrRight
].
lineCode
!==
undefined
?
return
line
[
leftOrRight
]
&&
line
[
leftOrRight
].
lineCode
!==
undefined
this
.
singleDiscussionByLineCode
(
line
[
leftOrRight
].
lineCode
)
:
[];
?
this
.
singleDiscussionByLineCode
(
line
[
leftOrRight
].
lineCode
)
:
[];
},
},
},
},
};
};
...
@@ -56,18 +57,14 @@ export default {
...
@@ -56,18 +57,14 @@ export default {
:line=
"line"
:line=
"line"
:is-bottom=
"index + 1 === diffLinesLength"
:is-bottom=
"index + 1 === diffLinesLength"
:key=
"index"
:key=
"index"
:left-discussions=
"discussionsByLine(line, 'left')"
:right-discussions=
"discussionsByLine(line, 'right')"
/>
/>
<
!--
<
parallel-diff-comment-row
<parallel-diff-comment-row
v-if=
"shouldRenderParallelCommentRow(line)"
v-if=
"shouldRenderParallelCommentRow(line)"
:key=
"`dcr-$
{index}`"
:key=
"`dcr-$
{index}`"
:line="line"
:line="line"
:diff-file-hash="diffFile.fileHash"
:diff-file-hash="diffFile.fileHash"
:line-index="index"
:line-index="index"
:left-discussions="discussionsByLine(line, 'left')"
/>
:right-discussions="discussionsByLine(line, 'right')"
/>-->
</
template
>
</
template
>
</tbody>
</tbody>
</table>
</table>
...
...
app/assets/javascripts/diffs/store/actions.js
View file @
4164c616
...
@@ -29,25 +29,64 @@ export const fetchDiffFiles = ({ state, commit }) => {
...
@@ -29,25 +29,64 @@ export const fetchDiffFiles = ({ state, commit }) => {
.
then
(
handleLocationHash
);
.
then
(
handleLocationHash
);
};
};
export
const
assignDiscussionsToDiff
=
({
state
,
commit
},
allLineDiscussions
)
=>
{
console
.
log
(
'
DIFF :
'
,
state
.
diffFiles
);
console
.
log
(
'
STATE :
'
,
allLineDiscussions
);
Object
.
values
(
allLineDiscussions
).
forEach
(
discussions
=>
{
if
(
discussions
.
length
>
0
)
{
console
.
log
(
'
KE :
'
,
discussions
);
const
fileHash
=
discussions
[
0
].
fileHash
;
const
selectedFile
=
state
.
diffFiles
.
find
(
file
=>
file
.
fileHash
===
fileHash
);
console
.
log
(
'
FILE :
'
,
selectedFile
);
if
(
selectedFile
)
{
const
targetLine
=
selectedFile
.
parallelDiffLines
.
find
(
line
=>
{
return
(
(
line
.
left
&&
line
.
left
.
lineCode
===
discussions
[
0
].
line_code
)
||
(
line
.
right
&&
line
.
right
.
lineCode
===
discussions
[
0
].
line_code
)
);
});
if
(
targetLine
)
{
console
.
log
(
'
TARGET LINE :
'
,
targetLine
);
Object
.
assign
(
targetLine
.
right
,
{
discussions
});
}
}
}
});
};
export
const
startRenderDiffsQueue
=
({
state
,
commit
})
=>
{
export
const
startRenderDiffsQueue
=
({
state
,
commit
})
=>
{
const
checkItem
=
()
=>
{
const
checkItem
=
()
=>
{
const
nextFile
=
state
.
diffFiles
.
find
(
return
new
Promise
(
resolve
=>
{
file
=>
!
file
.
renderIt
&&
(
!
file
.
collapsed
||
!
file
.
text
),
const
nextFile
=
state
.
diffFiles
.
find
(
);
file
=>
!
file
.
renderIt
&&
(
!
file
.
collapsed
||
!
file
.
text
),
if
(
nextFile
)
{
requestAnimationFrame
(()
=>
{
commit
(
types
.
RENDER_FILE
,
nextFile
);
});
requestIdleCallback
(
()
=>
{
checkItem
();
},
{
timeout
:
1000
},
);
);
}
if
(
nextFile
)
{
requestAnimationFrame
(()
=>
{
commit
(
types
.
RENDER_FILE
,
nextFile
);
});
requestIdleCallback
(
()
=>
{
checkItem
()
.
then
(
resolve
)
.
catch
(()
=>
{});
},
{
timeout
:
1000
},
);
}
else
{
console
.
log
(
'
No more items found -> Done
'
);
resolve
();
}
});
};
};
checkItem
();
return
new
Promise
(
resolve
=>
{
checkItem
()
.
then
(
resolve
)
.
catch
(()
=>
{});
});
};
};
export
const
setInlineDiffViewType
=
({
commit
})
=>
{
export
const
setInlineDiffViewType
=
({
commit
})
=>
{
...
...
app/assets/javascripts/diffs/store/getters.js
View file @
4164c616
...
@@ -75,26 +75,63 @@ export const singleDiscussionByLineCodeOld = (
...
@@ -75,26 +75,63 @@ export const singleDiscussionByLineCodeOld = (
return
discussions
[
lineCode
]
||
[];
return
discussions
[
lineCode
]
||
[];
};
};
export
const
shouldRenderParallelCommentRowOld
=
(
state
,
getters
)
=>
line
=>
{
/**
const
leftLineCode
=
line
.
left
.
lineCode
;
* Returns an Object with discussions by their diff line code
const
rightLineCode
=
line
.
right
.
lineCode
;
* To avoid rendering outdated discussions on the Changes tab we should do a bunch of SHA
const
leftDiscussions
=
getters
.
singleDiscussionByLineCode
(
leftLineCode
);
* comparisions. `note.position.formatter` have the current version diff refs but
const
rightDiscussions
=
getters
.
singleDiscussionByLineCode
(
rightLineCode
);
* `note.original_position.formatter` will have the first version's diff refs.
const
hasDiscussion
=
leftDiscussions
.
length
||
rightDiscussions
.
length
;
* If line diff refs matches with one of them, we should render it as a discussion on Changes tab.
*
const
hasExpandedDiscussionOnLeft
=
leftDiscussions
.
length
* @param {Object} diff
?
leftDiscussions
.
every
(
discussion
=>
discussion
.
expanded
)
* @returns {Array}
:
false
;
*/
const
hasExpandedDiscussionOnRight
=
rightDiscussions
.
length
export
const
discussionsByLineCode
=
(
state
,
getters
,
rootState
,
rootGetters
)
=>
{
?
rightDiscussions
.
every
(
discussion
=>
discussion
.
expanded
)
const
diffRefsByLineCode
=
getDiffRefsByLineCode
(
state
.
diffFiles
);
:
false
;
return
rootGetters
.
discussions
.
reduce
((
acc
,
note
)
=>
{
const
isDiffDiscussion
=
note
.
diff_discussion
;
const
hasLineCode
=
note
.
line_code
;
const
isResolvable
=
note
.
resolvable
;
const
diffRefs
=
diffRefsByLineCode
[
note
.
line_code
];
if
(
isDiffDiscussion
&&
hasLineCode
&&
isResolvable
&&
diffRefs
)
{
const
refs
=
convertObjectPropsToCamelCase
(
note
.
position
.
formatter
);
const
originalRefs
=
convertObjectPropsToCamelCase
(
note
.
original_position
.
formatter
);
if
(
_
.
isEqual
(
refs
,
diffRefs
)
||
_
.
isEqual
(
originalRefs
,
diffRefs
))
{
const
lineCode
=
note
.
line_code
;
if
(
acc
[
lineCode
])
{
acc
[
lineCode
].
push
(
note
);
}
else
{
acc
[
lineCode
]
=
[
note
];
}
}
}
return
acc
;
},
{});
};
export
const
shouldRenderParallelCommentRow
=
(
state
,
getters
)
=>
line
=>
{
const
hasDiscussion
=
(
line
.
left
&&
line
.
left
.
discussions
.
length
)
||
(
line
.
right
&&
line
.
right
.
discussions
.
length
);
const
hasExpandedDiscussionOnLeft
=
line
.
left
&&
line
.
left
.
discussions
.
length
?
line
.
left
.
discussions
.
every
(
discussion
=>
discussion
.
expanded
)
:
false
;
const
hasExpandedDiscussionOnRight
=
line
.
right
&&
line
.
right
.
discussions
.
length
?
line
.
right
.
discussions
.
every
(
discussion
=>
discussion
.
expanded
)
:
false
;
if
(
hasDiscussion
&&
(
hasExpandedDiscussionOnLeft
||
hasExpandedDiscussionOnRight
))
{
if
(
hasDiscussion
&&
(
hasExpandedDiscussionOnLeft
||
hasExpandedDiscussionOnRight
))
{
return
true
;
return
true
;
}
}
const
hasCommentFormOnLeft
=
state
.
diffLineCommentForms
[
leftL
ineCode
];
const
hasCommentFormOnLeft
=
line
.
left
&&
state
.
diffLineCommentForms
[
line
.
left
.
l
ineCode
];
const
hasCommentFormOnRight
=
state
.
diffLineCommentForms
[
rightL
ineCode
];
const
hasCommentFormOnRight
=
line
.
right
&&
state
.
diffLineCommentForms
[
line
.
right
.
l
ineCode
];
return
hasCommentFormOnLeft
||
hasCommentFormOnRight
;
return
hasCommentFormOnLeft
||
hasCommentFormOnRight
;
};
};
...
...
app/assets/javascripts/diffs/store/utils.js
View file @
4164c616
...
@@ -162,6 +162,7 @@ export function addContextLines(options) {
...
@@ -162,6 +162,7 @@ export function addContextLines(options) {
*/
*/
export
function
trimFirstCharOfLineContent
(
line
=
{})
{
export
function
trimFirstCharOfLineContent
(
line
=
{})
{
delete
line
.
text
;
delete
line
.
text
;
line
.
discussions
=
[];
const
parsedLine
=
Object
.
assign
({},
line
);
const
parsedLine
=
Object
.
assign
({},
line
);
...
...
app/assets/javascripts/notes/stores/getters.js
View file @
4164c616
...
@@ -28,11 +28,16 @@ export const notesById = state =>
...
@@ -28,11 +28,16 @@ export const notesById = state =>
return
acc
;
return
acc
;
},
{});
},
{});
export
const
discussionsByLineCode
=
state
=>
export
const
discussions
Structured
ByLineCode
=
state
=>
state
.
discussions
.
reduce
((
acc
,
note
)
=>
{
state
.
discussions
.
reduce
((
acc
,
note
)
=>
{
if
(
note
.
diff_discussion
&&
note
.
line_code
&&
note
.
resolvable
)
{
if
(
note
.
diff_discussion
&&
note
.
line_code
&&
note
.
resolvable
)
{
// For context about line notes: there might be multiple notes with the same line code
// For context about line notes: there might be multiple notes with the same line code
const
items
=
acc
[
note
.
line_code
]
||
[];
const
items
=
acc
[
note
.
line_code
]
||
[];
if
(
note
.
diff_file
)
{
Object
.
assign
(
note
,
{
fileHash
:
note
.
diff_file
.
file_hash
});
// delete note.diff_file;
}
items
.
push
(
note
);
items
.
push
(
note
);
Object
.
assign
(
acc
,
{
[
note
.
line_code
]:
items
});
Object
.
assign
(
acc
,
{
[
note
.
line_code
]:
items
});
...
...
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