Commit b26637c5 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Move inline fn to utils file.

parent db0b7fb3
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
import service from '../services/issue_notes_service'; import service from '../services/issue_notes_service';
import utils from './issue_notes_utils'; import utils from './issue_notes_utils';
const findNoteObjectById = (notes, id) => notes.filter(n => n.id === id)[0];
const state = { const state = {
notes: [], notes: [],
targetNoteHash: null, targetNoteHash: null,
...@@ -39,17 +37,17 @@ const mutations = { ...@@ -39,17 +37,17 @@ const mutations = {
storeState.targetNoteHash = hash; storeState.targetNoteHash = hash;
}, },
toggleDiscussion(storeState, { discussionId }) { toggleDiscussion(storeState, { discussionId }) {
const discussion = findNoteObjectById(storeState.notes, discussionId); const discussion = utils.findNoteObjectById(storeState.notes, discussionId);
discussion.expanded = !discussion.expanded; discussion.expanded = !discussion.expanded;
}, },
deleteNote(storeState, note) { deleteNote(storeState, note) {
const noteObj = findNoteObjectById(storeState.notes, note.discussion_id); const noteObj = utils.findNoteObjectById(storeState.notes, note.discussion_id);
if (noteObj.individual_note) { if (noteObj.individual_note) {
storeState.notes.splice(storeState.notes.indexOf(noteObj), 1); storeState.notes.splice(storeState.notes.indexOf(noteObj), 1);
} else { } else {
const comment = findNoteObjectById(noteObj.notes, note.id); const comment = utils.findNoteObjectById(noteObj.notes, note.id);
noteObj.notes.splice(noteObj.notes.indexOf(comment), 1); noteObj.notes.splice(noteObj.notes.indexOf(comment), 1);
if (!noteObj.notes.length) { if (!noteObj.notes.length) {
...@@ -58,19 +56,19 @@ const mutations = { ...@@ -58,19 +56,19 @@ const mutations = {
} }
}, },
addNewReplyToDiscussion(storeState, note) { addNewReplyToDiscussion(storeState, note) {
const noteObj = findNoteObjectById(storeState.notes, note.discussion_id); const noteObj = utils.findNoteObjectById(storeState.notes, note.discussion_id);
if (noteObj) { if (noteObj) {
noteObj.notes.push(note); noteObj.notes.push(note);
} }
}, },
updateNote(storeState, note) { updateNote(storeState, note) {
const noteObj = findNoteObjectById(storeState.notes, note.discussion_id); const noteObj = utils.findNoteObjectById(storeState.notes, note.discussion_id);
if (noteObj.individual_note) { if (noteObj.individual_note) {
noteObj.notes.splice(0, 1, note); noteObj.notes.splice(0, 1, note);
} else { } else {
const comment = findNoteObjectById(noteObj.notes, note.id); const comment = utils.findNoteObjectById(noteObj.notes, note.id);
noteObj.notes.splice(noteObj.notes.indexOf(comment), 1, note); noteObj.notes.splice(noteObj.notes.indexOf(comment), 1, note);
} }
}, },
...@@ -112,7 +110,7 @@ const mutations = { ...@@ -112,7 +110,7 @@ const mutations = {
showPlaceholderNote(storeState, data) { showPlaceholderNote(storeState, data) {
let notesArr = storeState.notes; let notesArr = storeState.notes;
if (data.replyId) { if (data.replyId) {
notesArr = findNoteObjectById(notesArr, data.replyId).notes; notesArr = utils.findNoteObjectById(notesArr, data.replyId).notes;
} }
notesArr.push({ notesArr.push({
...@@ -255,7 +253,7 @@ const actions = { ...@@ -255,7 +253,7 @@ const actions = {
if (notesById[note.id]) { if (notesById[note.id]) {
context.commit('updateNote', note); context.commit('updateNote', note);
} else if (note.type === 'DiscussionNote') { } else if (note.type === 'DiscussionNote') {
const discussion = findNoteObjectById(context.state.notes, note.discussion_id); const discussion = utils.findNoteObjectById(context.state.notes, note.discussion_id);
if (discussion) { if (discussion) {
context.commit('addNewReplyToDiscussion', note); context.commit('addNewReplyToDiscussion', note);
......
...@@ -3,6 +3,9 @@ import AjaxCache from '~/lib/utils/ajax_cache'; ...@@ -3,6 +3,9 @@ import AjaxCache from '~/lib/utils/ajax_cache';
const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm; const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm;
export default { export default {
findNoteObjectById(notes, id) {
return notes.filter(n => n.id === id)[0];
},
getQuickActionText(note) { getQuickActionText(note) {
let text = 'Applying command'; let text = 'Applying command';
const quickActions = AjaxCache.get(gl.GfmAutoComplete.dataSources.commands); const quickActions = AjaxCache.get(gl.GfmAutoComplete.dataSources.commands);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment