diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js index 56bbb44df5396691f12f77b2b47b38139316f1c3..2ccd3e3de821bfb33dde8109bd7852679861d593 100644 --- a/app/assets/javascripts/notes/stores/getters.js +++ b/app/assets/javascripts/notes/stores/getters.js @@ -23,31 +23,37 @@ const getDraftComments = (state) => { }; const hideActivity = (filters, discussion) => { + if (filters.length === constants.MR_FILTER_OPTIONS) return false; + if (filters.length === 0) return true; + const firstNote = discussion.notes[0]; + const hidingFilters = constants.MR_FILTER_OPTIONS.filter(({ value }) => !filters.includes(value)); - return constants.MR_FILTER_OPTIONS.some((f) => { - if (filters.includes(f.value) || f.value === '*') return false; + for (let i = 0, len = hidingFilters.length; i < len; i += 1) { + const filter = hidingFilters[i]; if ( // For all of the below firstNote is the first note of a discussion, whether that be // the first in a discussion or a single note // If the filter option filters based on icon check against the first notes system note icon - f.systemNoteIcons?.includes(firstNote.system_note_icon_name) || + filter.systemNoteIcons?.includes(firstNote.system_note_icon_name) || // If the filter option filters based on note type use the first notes type - (f.noteType?.includes(firstNote.type) && !firstNote.author.bot) || + (filter.noteType?.includes(firstNote.type) && !firstNote.author?.bot) || // If the filter option filters based on the note text then check if it is sytem // and filter based on the text of the system note - (firstNote.system && f.noteText?.some((t) => firstNote.note.includes(t))) || + (firstNote.system && filter.noteText?.some((t) => firstNote.note.includes(t))) || // For individual notes we filter if the discussion is a single note and is not a sytem - (f.individualNote === discussion.individual_note && !firstNote.system) || + (filter.individualNote === discussion.individual_note && + !firstNote.system && + !firstNote.author?.bot) || // For bot comments we filter on the authors `bot` boolean attribute - (f.bot && firstNote.author.bot) + (filter.bot && firstNote.author?.bot) ) { return true; } + } - return false; - }); + return false; }; export const discussions = (state, getters, rootState) => { diff --git a/spec/frontend/notes/stores/getters_spec.js b/spec/frontend/notes/stores/getters_spec.js index 8eebfeff553b8ab393daf5bece824eaf4a1548fc..69b25701de429c7bb0afb782d60bca83a093fa00 100644 --- a/spec/frontend/notes/stores/getters_spec.js +++ b/spec/frontend/notes/stores/getters_spec.js @@ -89,14 +89,23 @@ describe('Getters Notes Store', () => { describe('merge request filters', () => { it('returns only bot comments', () => { + const normalDiscussion = JSON.parse(JSON.stringify(discussionMock)); const discussion = JSON.parse(JSON.stringify(discussionMock)); discussion.notes[0].author.bot = true; + const individualBotNote = JSON.parse(JSON.stringify(discussionMock)); + individualBotNote.notes[0].author.bot = true; + individualBotNote.individual_note = true; + state.noteableData = { targetType: 'merge_request' }; - state.discussions = [discussion]; + state.discussions = [discussion, normalDiscussion, individualBotNote]; state.mergeRequestFilters = ['bot_comments']; - expect(getDiscussions()).toContain(discussion); + const discussions = getDiscussions(); + + expect(discussions).toContain(discussion); + expect(discussions).not.toContain(normalDiscussion); + expect(discussions).toContain(individualBotNote); }); });