Fix behavior around MRs that need legacy diff notes
This commit is contained in:
parent
5a8f727fd5
commit
71e4175f65
1 changed files with 28 additions and 21 deletions
|
@ -25,14 +25,15 @@ module NotesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def diff_view_data
|
def diff_view_data
|
||||||
return {} unless defined?(@comments_target) && @comments_target.any?
|
return {} unless @comments_target
|
||||||
|
|
||||||
@comments_target.slice(:noteable_id, :noteable_type, :commit_id)
|
@comments_target.slice(:noteable_id, :noteable_type, :commit_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def use_legacy_diff_notes?(line_code)
|
def diff_view_line_data(line_code, position, line_type)
|
||||||
return @use_legacy_diff_notes if defined?(@use_legacy_diff_notes)
|
return if @diff_notes_disabled
|
||||||
|
|
||||||
|
use_legacy_diff_note = @use_legacy_diff_notes
|
||||||
# If the controller doesn't force the use of legacy diff notes, we
|
# If the controller doesn't force the use of legacy diff notes, we
|
||||||
# determine this on a line-by-line basis by seeing if there already exist
|
# determine this on a line-by-line basis by seeing if there already exist
|
||||||
# active legacy diff notes at this line, in which case newly created notes
|
# active legacy diff notes at this line, in which case newly created notes
|
||||||
|
@ -42,36 +43,42 @@ module NotesHelper
|
||||||
# are incompatible.
|
# are incompatible.
|
||||||
# If we didn't, diff notes that would show for the same line on the changes
|
# If we didn't, diff notes that would show for the same line on the changes
|
||||||
# tab, would show in different discussions on the discussion tab.
|
# tab, would show in different discussions on the discussion tab.
|
||||||
|
use_legacy_diff_note ||= begin
|
||||||
line_diff_notes = @grouped_diff_notes[line_code]
|
line_diff_notes = @grouped_diff_notes[line_code]
|
||||||
@use_legacy_diff_notes = line_diff_notes && line_diff_notes.any?(&:legacy_diff_note?)
|
@use_legacy_diff_notes = line_diff_notes && line_diff_notes.any?(&:legacy_diff_note?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def diff_view_line_data(line_code, position, line_type)
|
data = {
|
||||||
return if @diff_notes_disabled
|
|
||||||
|
|
||||||
{
|
|
||||||
line_code: line_code,
|
line_code: line_code,
|
||||||
position: position.to_json,
|
|
||||||
line_type: line_type,
|
line_type: line_type,
|
||||||
note_type: (use_legacy_diff_notes?(line_code) ? LegacyDiffNote.name : DiffNote.name),
|
|
||||||
discussion_id: discussion_id(line_code, position)
|
|
||||||
}
|
}
|
||||||
end
|
|
||||||
|
|
||||||
def discussion_id(line_code, position)
|
if use_legacy_diff_note
|
||||||
if use_legacy_diff_notes?(line_code)
|
discussion_id = LegacyDiffNote.build_discussion_id(
|
||||||
LegacyDiffNote.build_discussion_id(
|
|
||||||
@comments_target[:noteable_type],
|
@comments_target[:noteable_type],
|
||||||
@comments_target[:noteable_id] || @comments_target[:commit_id],
|
@comments_target[:noteable_id] || @comments_target[:commit_id],
|
||||||
line_code
|
line_code
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data.merge!(
|
||||||
|
note_type: LegacyDiffNote.name,
|
||||||
|
discussion_id: discussion_id
|
||||||
|
)
|
||||||
else
|
else
|
||||||
discussion_id = DiffNote.build_discussion_id(
|
discussion_id = DiffNote.build_discussion_id(
|
||||||
@comments_target[:noteable_type],
|
@comments_target[:noteable_type],
|
||||||
@comments_target[:noteable_id] || @comments_target[:commit_id],
|
@comments_target[:noteable_id] || @comments_target[:commit_id],
|
||||||
position
|
position
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data.merge!(
|
||||||
|
position: position.to_json,
|
||||||
|
note_type: DiffNote.name,
|
||||||
|
discussion_id: discussion_id
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_reply_discussion(note, line_type = nil)
|
def link_to_reply_discussion(note, line_type = nil)
|
||||||
|
|
Loading…
Reference in a new issue