Commit 53def4e2 authored by Tim Zallmann's avatar Tim Zallmann

Adding new threads to MR page

parent 6f46b274
...@@ -105,7 +105,7 @@ export default { ...@@ -105,7 +105,7 @@ export default {
methods: { methods: {
...mapActions('diffs', ['loadMoreLines', 'showCommentForm']), ...mapActions('diffs', ['loadMoreLines', 'showCommentForm']),
handleCommentButton() { handleCommentButton() {
this.showCommentForm({ lineCode: this.line.code }); this.showCommentForm({ lineCode: this.line.lineCode });
}, },
handleLoadMoreLines() { handleLoadMoreLines() {
if (this.isRequesting) { if (this.isRequesting) {
......
...@@ -6,6 +6,7 @@ import noteForm from '../../notes/components/note_form.vue'; ...@@ -6,6 +6,7 @@ import noteForm from '../../notes/components/note_form.vue';
import { getNoteFormData } from '../store/utils'; import { getNoteFormData } from '../store/utils';
import autosave from '../../notes/mixins/autosave'; import autosave from '../../notes/mixins/autosave';
import { DIFF_NOTE_TYPE } from '../constants'; import { DIFF_NOTE_TYPE } from '../constants';
import * as utils from '../../notes/stores/utils';
export default { export default {
components: { components: {
...@@ -52,7 +53,7 @@ export default { ...@@ -52,7 +53,7 @@ export default {
} }
}, },
methods: { methods: {
...mapActions('diffs', ['cancelCommentForm']), ...mapActions('diffs', ['cancelCommentForm', 'assignDiscussionsToDiff']),
...mapActions(['saveNote', 'refetchDiscussionById']), ...mapActions(['saveNote', 'refetchDiscussionById']),
handleCancelCommentForm(shouldConfirm, isDirty) { handleCancelCommentForm(shouldConfirm, isDirty) {
if (shouldConfirm && isDirty) { if (shouldConfirm && isDirty) {
...@@ -88,7 +89,13 @@ export default { ...@@ -88,7 +89,13 @@ export default {
const endpoint = this.getNotesDataByProp('discussionsPath'); const endpoint = this.getNotesDataByProp('discussionsPath');
this.refetchDiscussionById({ path: endpoint, discussionId: result.discussion_id }) this.refetchDiscussionById({ path: endpoint, discussionId: result.discussion_id })
.then(() => { .then(selectedDiscussion => {
//debugger;
console.log('SEL DISCUSSION: ', selectedDiscussion);
const lineCodeDiscussions = utils.reduceDiscussionsToLineCodes([selectedDiscussion]);
console.log('LINE CODE DISCUSSIONS: ', lineCodeDiscussions);
this.assignDiscussionsToDiff(lineCodeDiscussions);
this.handleCancelCommentForm(); this.handleCancelCommentForm();
}) })
.catch(() => { .catch(() => {
......
...@@ -29,7 +29,8 @@ export const fetchDiffFiles = ({ state, commit }) => { ...@@ -29,7 +29,8 @@ export const fetchDiffFiles = ({ state, commit }) => {
.then(handleLocationHash); .then(handleLocationHash);
}; };
export const assignDiscussionsToDiff = ({ state, commit }, allLineDiscussions) => { export const assignDiscussionsToDiff = ({ state }, allLineDiscussions) => {
console.log('ASSIGN DISCS : ');
console.log('DIFF : ', state.diffFiles); console.log('DIFF : ', state.diffFiles);
console.log('STATE : ', allLineDiscussions); console.log('STATE : ', allLineDiscussions);
......
...@@ -2,7 +2,6 @@ import Vue from 'vue'; ...@@ -2,7 +2,6 @@ import Vue from 'vue';
import _ from 'underscore'; import _ from 'underscore';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { findDiffFile, addLineReferences, removeMatchLine, addContextLines } from './utils'; import { findDiffFile, addLineReferences, removeMatchLine, addContextLines } from './utils';
import { LINES_TO_BE_RENDERED_DIRECTLY, MAX_LINES_TO_BE_RENDERED } from '../constants';
import { trimFirstCharOfLineContent } from '../store/utils'; import { trimFirstCharOfLineContent } from '../store/utils';
import { LINES_TO_BE_RENDERED_DIRECTLY, MAX_LINES_TO_BE_RENDERED } from '../constants'; import { LINES_TO_BE_RENDERED_DIRECTLY, MAX_LINES_TO_BE_RENDERED } from '../constants';
import * as types from './mutation_types'; import * as types from './mutation_types';
......
...@@ -43,14 +43,21 @@ export const fetchDiscussions = ({ commit }, path) => ...@@ -43,14 +43,21 @@ export const fetchDiscussions = ({ commit }, path) =>
commit(types.SET_INITIAL_DISCUSSIONS, discussions); commit(types.SET_INITIAL_DISCUSSIONS, discussions);
}); });
export const refetchDiscussionById = ({ commit }, { path, discussionId }) => export const refetchDiscussionById = ({ commit }, { path, discussionId }) => {
return new Promise(resolve => {
service service
.fetchDiscussions(path) .fetchDiscussions(path)
.then(res => res.json()) .then(res => res.json())
.then(discussions => { .then(discussions => {
const selectedDiscussion = discussions.find(discussion => discussion.id === discussionId); const selectedDiscussion = discussions.find(discussion => discussion.id === discussionId);
if (selectedDiscussion) commit(types.UPDATE_DISCUSSION, selectedDiscussion); if (selectedDiscussion) {
commit(types.UPDATE_DISCUSSION, selectedDiscussion);
resolve(selectedDiscussion);
}
})
.catch(() => {});
}); });
};
export const deleteNote = ({ commit }, note) => export const deleteNote = ({ commit }, note) =>
service.deleteNote(note.path).then(() => { service.deleteNote(note.path).then(() => {
...@@ -152,9 +159,10 @@ export const saveNote = ({ commit, dispatch }, noteData) => { ...@@ -152,9 +159,10 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
const replyId = noteData.data.in_reply_to_discussion_id; const replyId = noteData.data.in_reply_to_discussion_id;
const methodToDispatch = replyId ? 'replyToDiscussion' : 'createNewNote'; const methodToDispatch = replyId ? 'replyToDiscussion' : 'createNewNote';
commit(types.REMOVE_PLACEHOLDER_NOTES); // remove previous placeholders
$('.notes-form .flash-container').hide(); // hide previous flash notification $('.notes-form .flash-container').hide(); // hide previous flash notification
commit(types.REMOVE_PLACEHOLDER_NOTES); // remove previous placeholders
if (replyId) {
if (hasQuickActions) { if (hasQuickActions) {
placeholderText = utils.stripQuickActions(placeholderText); placeholderText = utils.stripQuickActions(placeholderText);
} }
...@@ -173,6 +181,7 @@ export const saveNote = ({ commit, dispatch }, noteData) => { ...@@ -173,6 +181,7 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
replyId, replyId,
}); });
} }
}
return dispatch(methodToDispatch, noteData).then(res => { return dispatch(methodToDispatch, noteData).then(res => {
const { errors } = res; const { errors } = res;
...@@ -211,7 +220,9 @@ export const saveNote = ({ commit, dispatch }, noteData) => { ...@@ -211,7 +220,9 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
if (errors && errors.commands_only) { if (errors && errors.commands_only) {
Flash(errors.commands_only, 'notice', noteData.flashContainer); Flash(errors.commands_only, 'notice', noteData.flashContainer);
} }
if (replyId) {
commit(types.REMOVE_PLACEHOLDER_NOTES); commit(types.REMOVE_PLACEHOLDER_NOTES);
}
return res; return res;
}); });
......
import _ from 'underscore'; import _ from 'underscore';
import * as constants from '../constants'; import * as constants from '../constants';
import { reduceDiscussionsToLineCodes } from './utils';
import { collapseSystemNotes } from './collapse_utils'; import { collapseSystemNotes } from './collapse_utils';
export const discussions = state => collapseSystemNotes(state.discussions); export const discussions = state => collapseSystemNotes(state.discussions);
...@@ -29,21 +30,7 @@ export const notesById = state => ...@@ -29,21 +30,7 @@ export const notesById = state =>
}, {}); }, {});
export const discussionsStructuredByLineCode = state => export const discussionsStructuredByLineCode = state =>
state.discussions.reduce((acc, note) => { reduceDiscussionsToLineCodes(state.discussions);
if (note.diff_discussion && note.line_code && note.resolvable) {
// For context about line notes: there might be multiple notes with the same 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);
Object.assign(acc, { [note.line_code]: items });
}
return acc;
}, {});
export const noteableType = state => { export const noteableType = state => {
const { ISSUE_NOTEABLE_TYPE, MERGE_REQUEST_NOTEABLE_TYPE, EPIC_NOTEABLE_TYPE } = constants; const { ISSUE_NOTEABLE_TYPE, MERGE_REQUEST_NOTEABLE_TYPE, EPIC_NOTEABLE_TYPE } = constants;
......
...@@ -2,13 +2,11 @@ import AjaxCache from '~/lib/utils/ajax_cache'; ...@@ -2,13 +2,11 @@ import AjaxCache from '~/lib/utils/ajax_cache';
const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm; const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm;
export const findNoteObjectById = (notes, id) => export const findNoteObjectById = (notes, id) => notes.filter(n => n.id === id)[0];
notes.filter(n => n.id === id)[0];
export const getQuickActionText = note => { export const getQuickActionText = note => {
let text = 'Applying command'; let text = 'Applying command';
const quickActions = const quickActions = AjaxCache.get(gl.GfmAutoComplete.dataSources.commands) || [];
AjaxCache.get(gl.GfmAutoComplete.dataSources.commands) || [];
const executedCommands = quickActions.filter(command => { const executedCommands = quickActions.filter(command => {
const commandRegex = new RegExp(`/${command.name}`); const commandRegex = new RegExp(`/${command.name}`);
...@@ -27,7 +25,23 @@ export const getQuickActionText = note => { ...@@ -27,7 +25,23 @@ export const getQuickActionText = note => {
return text; return text;
}; };
export const reduceDiscussionsToLineCodes = selectedDiscussions =>
selectedDiscussions.reduce((acc, note) => {
if (note.diff_discussion && note.line_code && note.resolvable) {
// For context about line notes: there might be multiple notes with the same 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);
Object.assign(acc, { [note.line_code]: items });
}
return acc;
}, {});
export const hasQuickActions = note => REGEX_QUICK_ACTIONS.test(note); export const hasQuickActions = note => REGEX_QUICK_ACTIONS.test(note);
export const stripQuickActions = note => export const stripQuickActions = note => note.replace(REGEX_QUICK_ACTIONS, '').trim();
note.replace(REGEX_QUICK_ACTIONS, '').trim();
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