Commit 6293786e authored by Phil Hughes's avatar Phil Hughes

Merge branch '57123-revert-single-comments-to-initial-state-after-cancelling-reply' into 'master'

Resolve "Revert single comments to initial state after cancelling reply"

Closes #57123

See merge request gitlab-org/gitlab-ce!25339
parents f1b73619 5e137b58
......@@ -253,6 +253,7 @@ export default {
'removePlaceholderNotes',
'toggleResolveNote',
'expandDiscussion',
'removeConvertedDiscussion',
]),
truncateSha,
componentName(note) {
......@@ -292,6 +293,10 @@ export default {
}
}
if (this.convertedDisscussionIds.includes(this.discussion.id)) {
this.removeConvertedDiscussion(this.discussion.id);
}
this.isReplying = false;
this.resetAutoSave();
},
......
......@@ -443,5 +443,8 @@ export const submitSuggestion = (
export const convertToDiscussion = ({ commit }, noteId) =>
commit(types.CONVERT_TO_DISCUSSION, noteId);
export const removeConvertedDiscussion = ({ commit }, noteId) =>
commit(types.REMOVE_CONVERTED_DISCUSSION, noteId);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
......@@ -18,6 +18,7 @@ export const SET_NOTES_LOADING_STATE = 'SET_NOTES_LOADING_STATE';
export const DISABLE_COMMENTS = 'DISABLE_COMMENTS';
export const APPLY_SUGGESTION = 'APPLY_SUGGESTION';
export const CONVERT_TO_DISCUSSION = 'CONVERT_TO_DISCUSSION';
export const REMOVE_CONVERTED_DISCUSSION = 'REMOVE_CONVERTED_DISCUSSION';
// DISCUSSION
export const COLLAPSE_DISCUSSION = 'COLLAPSE_DISCUSSION';
......
......@@ -269,4 +269,11 @@ export default {
const convertedDisscussionIds = [...state.convertedDisscussionIds, discussionId];
Object.assign(state, { convertedDisscussionIds });
},
[types.REMOVE_CONVERTED_DISCUSSION](state, discussionId) {
const convertedDisscussionIds = [...state.convertedDisscussionIds];
convertedDisscussionIds.splice(convertedDisscussionIds.indexOf(discussionId), 1);
Object.assign(state, { convertedDisscussionIds });
},
};
......@@ -737,4 +737,18 @@ describe('Actions Notes Store', () => {
);
});
});
describe('removeConvertedDiscussion', () => {
it('commits CONVERT_TO_DISCUSSION with noteId', done => {
const noteId = 'dummy-id';
testAction(
actions.removeConvertedDiscussion,
noteId,
{},
[{ type: 'REMOVE_CONVERTED_DISCUSSION', payload: noteId }],
[],
done,
);
});
});
});
......@@ -536,4 +536,23 @@ describe('Notes Store mutations', () => {
expect(state.convertedDisscussionIds).toContain(discussion.id);
});
});
describe('REMOVE_CONVERTED_DISCUSSION', () => {
let discussion;
let state;
beforeEach(() => {
discussion = {
id: 42,
individual_note: true,
};
state = { convertedDisscussionIds: [41, 42] };
});
it('removes a disucssion from convertedDisscussionIds', () => {
mutations.REMOVE_CONVERTED_DISCUSSION(state, discussion.id);
expect(state.convertedDisscussionIds).not.toContain(discussion.id);
});
});
});
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