Commit 24250d31 authored by Mark Florian's avatar Mark Florian

Merge branch '207100-description-diffs-system-notes-shows-only-latest-change' into 'master'

Allow multiple descriptionVersions

See merge request gitlab-org/gitlab!26316
parents d97e5550 698e4bb7
...@@ -515,7 +515,7 @@ export const removeConvertedDiscussion = ({ commit }, noteId) => ...@@ -515,7 +515,7 @@ export const removeConvertedDiscussion = ({ commit }, noteId) =>
export const setCurrentDiscussionId = ({ commit }, discussionId) => export const setCurrentDiscussionId = ({ commit }, discussionId) =>
commit(types.SET_CURRENT_DISCUSSION_ID, discussionId); commit(types.SET_CURRENT_DISCUSSION_ID, discussionId);
export const fetchDescriptionVersion = ({ dispatch }, { endpoint, startingVersion }) => { export const fetchDescriptionVersion = ({ dispatch }, { endpoint, startingVersion, versionId }) => {
let requestUrl = endpoint; let requestUrl = endpoint;
if (startingVersion) { if (startingVersion) {
...@@ -526,7 +526,7 @@ export const fetchDescriptionVersion = ({ dispatch }, { endpoint, startingVersio ...@@ -526,7 +526,7 @@ export const fetchDescriptionVersion = ({ dispatch }, { endpoint, startingVersio
return axios return axios
.get(requestUrl) .get(requestUrl)
.then(res => { .then(res => {
dispatch('receiveDescriptionVersion', res.data); dispatch('receiveDescriptionVersion', { descriptionVersion: res.data, versionId });
}) })
.catch(error => { .catch(error => {
dispatch('receiveDescriptionVersionError', error); dispatch('receiveDescriptionVersionError', error);
...@@ -544,7 +544,10 @@ export const receiveDescriptionVersionError = ({ commit }, error) => { ...@@ -544,7 +544,10 @@ export const receiveDescriptionVersionError = ({ commit }, error) => {
commit(types.RECEIVE_DESCRIPTION_VERSION_ERROR, error); commit(types.RECEIVE_DESCRIPTION_VERSION_ERROR, error);
}; };
export const softDeleteDescriptionVersion = ({ dispatch }, { endpoint, startingVersion }) => { export const softDeleteDescriptionVersion = (
{ dispatch },
{ endpoint, startingVersion, versionId },
) => {
let requestUrl = endpoint; let requestUrl = endpoint;
if (startingVersion) { if (startingVersion) {
...@@ -555,7 +558,7 @@ export const softDeleteDescriptionVersion = ({ dispatch }, { endpoint, startingV ...@@ -555,7 +558,7 @@ export const softDeleteDescriptionVersion = ({ dispatch }, { endpoint, startingV
return axios return axios
.delete(requestUrl) .delete(requestUrl)
.then(() => { .then(() => {
dispatch('receiveDeleteDescriptionVersion'); dispatch('receiveDeleteDescriptionVersion', versionId);
}) })
.catch(error => { .catch(error => {
dispatch('receiveDeleteDescriptionVersionError', error); dispatch('receiveDeleteDescriptionVersionError', error);
...@@ -566,8 +569,8 @@ export const softDeleteDescriptionVersion = ({ dispatch }, { endpoint, startingV ...@@ -566,8 +569,8 @@ export const softDeleteDescriptionVersion = ({ dispatch }, { endpoint, startingV
export const requestDeleteDescriptionVersion = ({ commit }) => { export const requestDeleteDescriptionVersion = ({ commit }) => {
commit(types.REQUEST_DELETE_DESCRIPTION_VERSION); commit(types.REQUEST_DELETE_DESCRIPTION_VERSION);
}; };
export const receiveDeleteDescriptionVersion = ({ commit }) => { export const receiveDeleteDescriptionVersion = ({ commit }, versionId) => {
commit(types.RECEIVE_DELETE_DESCRIPTION_VERSION, __('Deleted')); commit(types.RECEIVE_DELETE_DESCRIPTION_VERSION, { [versionId]: __('Deleted') });
}; };
export const receiveDeleteDescriptionVersionError = ({ commit }, error) => { export const receiveDeleteDescriptionVersionError = ({ commit }, error) => {
commit(types.RECEIVE_DELETE_DESCRIPTION_VERSION_ERROR, error); commit(types.RECEIVE_DELETE_DESCRIPTION_VERSION_ERROR, error);
......
...@@ -28,7 +28,7 @@ export const getUserData = state => state.userData || {}; ...@@ -28,7 +28,7 @@ export const getUserData = state => state.userData || {};
export const getUserDataByProp = state => prop => state.userData && state.userData[prop]; export const getUserDataByProp = state => prop => state.userData && state.userData[prop];
export const descriptionVersion = state => state.descriptionVersion; export const descriptionVersions = state => state.descriptionVersions;
export const notesById = state => export const notesById = state =>
state.discussions.reduce((acc, note) => { state.discussions.reduce((acc, note) => {
......
...@@ -28,7 +28,7 @@ export default () => ({ ...@@ -28,7 +28,7 @@ export default () => ({
commentsDisabled: false, commentsDisabled: false,
resolvableDiscussionsCount: 0, resolvableDiscussionsCount: 0,
unresolvedDiscussionsCount: 0, unresolvedDiscussionsCount: 0,
descriptionVersion: null, descriptionVersions: {},
}, },
actions, actions,
getters, getters,
......
...@@ -288,9 +288,9 @@ export default { ...@@ -288,9 +288,9 @@ export default {
[types.REQUEST_DESCRIPTION_VERSION](state) { [types.REQUEST_DESCRIPTION_VERSION](state) {
state.isLoadingDescriptionVersion = true; state.isLoadingDescriptionVersion = true;
}, },
[types.RECEIVE_DESCRIPTION_VERSION](state, descriptionVersion) { [types.RECEIVE_DESCRIPTION_VERSION](state, { descriptionVersion, versionId }) {
state.isLoadingDescriptionVersion = false; const descriptionVersions = { ...state.descriptionVersions, [versionId]: descriptionVersion };
state.descriptionVersion = descriptionVersion; Object.assign(state, { descriptionVersions, isLoadingDescriptionVersion: false });
}, },
[types.RECEIVE_DESCRIPTION_VERSION_ERROR](state) { [types.RECEIVE_DESCRIPTION_VERSION_ERROR](state) {
state.isLoadingDescriptionVersion = false; state.isLoadingDescriptionVersion = false;
...@@ -300,7 +300,7 @@ export default { ...@@ -300,7 +300,7 @@ export default {
}, },
[types.RECEIVE_DELETE_DESCRIPTION_VERSION](state, descriptionVersion) { [types.RECEIVE_DELETE_DESCRIPTION_VERSION](state, descriptionVersion) {
state.isLoadingDescriptionVersion = false; state.isLoadingDescriptionVersion = false;
state.descriptionVersion = descriptionVersion; Object.assign(state.descriptionVersions, descriptionVersion);
}, },
[types.RECEIVE_DELETE_DESCRIPTION_VERSION_ERROR](state) { [types.RECEIVE_DELETE_DESCRIPTION_VERSION_ERROR](state) {
state.isLoadingDescriptionVersion = false; state.isLoadingDescriptionVersion = false;
......
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(['targetNoteHash', 'descriptionVersion']), ...mapGetters(['targetNoteHash', 'descriptionVersions']),
...mapState(['isLoadingDescriptionVersion']), ...mapState(['isLoadingDescriptionVersion']),
noteAnchorId() { noteAnchorId() {
return `note_${this.note.id}`; return `note_${this.note.id}`;
...@@ -81,6 +81,9 @@ export default { ...@@ -81,6 +81,9 @@ export default {
.children().length > MAX_VISIBLE_COMMIT_LIST_COUNT .children().length > MAX_VISIBLE_COMMIT_LIST_COUNT
); );
}, },
descriptionVersion() {
return this.descriptionVersions[this.note.description_version_id];
},
}, },
mounted() { mounted() {
initMRPopovers(this.$el.querySelectorAll('.gfm-merge_request')); initMRPopovers(this.$el.querySelectorAll('.gfm-merge_request'));
......
...@@ -25,21 +25,23 @@ export default { ...@@ -25,21 +25,23 @@ export default {
methods: { methods: {
toggleDescriptionVersion() { toggleDescriptionVersion() {
this.isDescriptionVersionExpanded = !this.isDescriptionVersionExpanded; this.isDescriptionVersionExpanded = !this.isDescriptionVersionExpanded;
const versionId = this.note.description_version_id;
if (this.descriptionVersion) { if (this.descriptionVersions?.[versionId]) {
return false; return false;
} }
const endpoint = this.note.description_diff_path; const endpoint = this.note.description_diff_path;
const startingVersion = this.note.start_description_version_id; const startingVersion = this.note.start_description_version_id;
return this.fetchDescriptionVersion({ endpoint, startingVersion }); return this.fetchDescriptionVersion({ endpoint, startingVersion, versionId });
}, },
deleteDescriptionVersion() { deleteDescriptionVersion() {
const endpoint = this.note.delete_description_version_path; const endpoint = this.note.delete_description_version_path;
const startingVersion = this.note.start_description_version_id; const startingVersion = this.note.start_description_version_id;
const versionId = this.note.description_version_id;
return this.softDeleteDescriptionVersion({ endpoint, startingVersion }); return this.softDeleteDescriptionVersion({ endpoint, startingVersion, versionId });
}, },
}, },
}; };
...@@ -35,7 +35,7 @@ describe('Getters Notes Store', () => { ...@@ -35,7 +35,7 @@ describe('Getters Notes Store', () => {
notesData: notesDataMock, notesData: notesDataMock,
userData: userDataMock, userData: userDataMock,
noteableData: noteableDataMock, noteableData: noteableDataMock,
descriptionVersion: 'descriptionVersion', descriptionVersions: 'descriptionVersions',
}; };
}); });
...@@ -387,9 +387,9 @@ describe('Getters Notes Store', () => { ...@@ -387,9 +387,9 @@ describe('Getters Notes Store', () => {
}); });
}); });
describe('descriptionVersion', () => { describe('descriptionVersions', () => {
it('should return `descriptionVersion`', () => { it('should return `descriptionVersions`', () => {
expect(getters.descriptionVersion(state)).toEqual('descriptionVersion'); expect(getters.descriptionVersions(state)).toEqual('descriptionVersions');
}); });
}); });
}); });
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
userDataMock, userDataMock,
noteableDataMock, noteableDataMock,
individualNote, individualNote,
notesWithDescriptionChanges,
} from '../mock_data'; } from '../mock_data';
const RESOLVED_NOTE = { resolvable: true, resolved: true }; const RESOLVED_NOTE = { resolvable: true, resolved: true };
...@@ -579,4 +580,27 @@ describe('Notes Store mutations', () => { ...@@ -579,4 +580,27 @@ describe('Notes Store mutations', () => {
expect(state.convertedDisscussionIds).not.toContain(discussion.id); expect(state.convertedDisscussionIds).not.toContain(discussion.id);
}); });
}); });
describe('RECEIVE_DESCRIPTION_VERSION', () => {
const descriptionVersion = notesWithDescriptionChanges[0].notes[0].note;
const versionId = notesWithDescriptionChanges[0].notes[0].id;
const state = {};
it('adds a descriptionVersion', () => {
mutations.RECEIVE_DESCRIPTION_VERSION(state, { descriptionVersion, versionId });
expect(state.descriptionVersions[versionId]).toBe(descriptionVersion);
});
});
describe('RECEIVE_DELETE_DESCRIPTION_VERSION', () => {
const descriptionVersion = notesWithDescriptionChanges[0].notes[0].note;
const versionId = notesWithDescriptionChanges[0].notes[0].id;
const state = { descriptionVersions: { [versionId]: descriptionVersion } };
const deleted = 'Deleted';
it('updates descriptionVersion to "Deleted"', () => {
mutations.RECEIVE_DELETE_DESCRIPTION_VERSION(state, { [versionId]: deleted });
expect(state.descriptionVersions[versionId]).toBe(deleted);
});
});
}); });
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