summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/stores
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-07-28 19:59:31 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-07-28 19:59:42 +0100
commitf5a21c596b79c5f86c6b8034e1d0bf1d7078c593 (patch)
tree0ed02b93f530141b13c1ef04bde63c38cc627ffc /app/assets/javascripts/notes/stores
parent9b87e680ca9653f40897ab8fa916d44fcfd1f4d5 (diff)
downloadgitlab-ce-f5a21c596b79c5f86c6b8034e1d0bf1d7078c593.tar.gz
[ci skip] Fix shortcuts for preview
Diffstat (limited to 'app/assets/javascripts/notes/stores')
-rw-r--r--app/assets/javascripts/notes/stores/actions.js45
-rw-r--r--app/assets/javascripts/notes/stores/getters.js16
-rw-r--r--app/assets/javascripts/notes/stores/index.js1
3 files changed, 27 insertions, 35 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js
index e1e0aec8a83..d7059f462a4 100644
--- a/app/assets/javascripts/notes/stores/actions.js
+++ b/app/assets/javascripts/notes/stores/actions.js
@@ -131,32 +131,31 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
});
};
-export const poll = ({ commit, state, getters }) => {
- return service.poll(state.notesData.notesPath, state.lastFetchedAt)
- .then(res => res.json())
- .then((res) => {
- if (res.notes.length) {
- const { notesById } = getters;
-
- res.notes.forEach((note) => {
- if (notesById[note.id]) {
- commit(types.UPDATE_NOTE, note);
- } else if (note.type === constants.DISCUSSION_NOTE) {
- const discussion = utils.findNoteObjectById(state.notes, note.discussion_id);
-
- if (discussion) {
- commit(types.ADD_NEW_REPLY_TO_DISCUSSION, note);
- } else {
- commit(types.ADD_NEW_NOTE, note);
- }
+export const poll = ({ commit, state, getters }) => service
+ .poll(state.notesData.notesPath, state.lastFetchedAt)
+ .then(res => res.json())
+ .then((res) => {
+ if (res.notes.length) {
+ const { notesById } = getters;
+
+ res.notes.forEach((note) => {
+ if (notesById[note.id]) {
+ commit(types.UPDATE_NOTE, note);
+ } else if (note.type === constants.DISCUSSION_NOTE) {
+ const discussion = utils.findNoteObjectById(state.notes, note.discussion_id);
+
+ if (discussion) {
+ commit(types.ADD_NEW_REPLY_TO_DISCUSSION, note);
} else {
commit(types.ADD_NEW_NOTE, note);
}
- });
- }
- return res;
- });
-};
+ } else {
+ commit(types.ADD_NEW_NOTE, note);
+ }
+ });
+ }
+ return res;
+ });
export const toggleAward = ({ commit, getters, dispatch }, data) => {
const { endpoint, awardName, noteId, skipMutalityCheck } = data;
diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js
index 8dc24cd745e..fab2252eeb8 100644
--- a/app/assets/javascripts/notes/stores/getters.js
+++ b/app/assets/javascripts/notes/stores/getters.js
@@ -10,17 +10,10 @@ export const getIssueDataByProp = state => prop => state.issueData[prop];
export const getUserData = state => state.userData;
export const getUserDataByProp = state => prop => state.notesData[prop];
-export const notesById = (state) => {
- const notesByIdObject = {};
- // TODO: FILIPA: TRANSFORM INTO A REDUCE
- state.notes.forEach((note) => {
- note.notes.forEach((n) => {
- notesByIdObject[n.id] = n;
- });
- });
-
- return notesByIdObject;
-};
+export const notesById = state => state.notes.reduce((acc, note) => {
+ note.notes.every(n => Object.assign(acc, { [n.id]: n }));
+ return acc;
+}, {});
const reverseNotes = array => array.slice(0).reverse();
const isLastNote = (note, userId) => !note.system && note.author.id === userId;
@@ -31,6 +24,7 @@ export const getCurrentUserLastNote = state => userId => reverseNotes(state.note
return acc;
}, []).filter(el => el !== undefined)[0];
+// eslint-disable-next-line no-unused-vars
export const getDiscussionLastNote = state => (discussion, userId) => reverseNotes(discussion.notes)
.find(el => isLastNote(el, userId));
diff --git a/app/assets/javascripts/notes/stores/index.js b/app/assets/javascripts/notes/stores/index.js
index be4f509932f..8e0c8531bbc 100644
--- a/app/assets/javascripts/notes/stores/index.js
+++ b/app/assets/javascripts/notes/stores/index.js
@@ -16,7 +16,6 @@ export default new Vuex.Store({
notesData: {},
userData: {},
issueData: {},
- paths: {},
},
actions,
getters,