2018-03-17 18:26:18 +05:30
|
|
|
import _ from 'underscore';
|
|
|
|
|
|
|
|
export const notes = state => state.notes;
|
|
|
|
export const targetNoteHash = state => state.targetNoteHash;
|
|
|
|
|
|
|
|
export const getNotesData = state => state.notesData;
|
|
|
|
export const getNotesDataByProp = state => prop => state.notesData[prop];
|
|
|
|
|
|
|
|
export const getNoteableData = state => state.noteableData;
|
|
|
|
export const getNoteableDataByProp = state => prop => state.noteableData[prop];
|
2018-03-27 19:54:05 +05:30
|
|
|
export const openState = state => state.noteableData.state;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
export const getUserData = state => state.userData || {};
|
2018-05-09 12:01:36 +05:30
|
|
|
export const getUserDataByProp = state => prop =>
|
|
|
|
state.userData && state.userData[prop];
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export const notesById = state =>
|
|
|
|
state.notes.reduce((acc, note) => {
|
|
|
|
note.notes.every(n => Object.assign(acc, { [n.id]: n }));
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
const reverseNotes = array => array.slice(0).reverse();
|
2018-05-09 12:01:36 +05:30
|
|
|
const isLastNote = (note, state) =>
|
|
|
|
!note.system &&
|
|
|
|
state.userData &&
|
|
|
|
note.author &&
|
2018-03-17 18:26:18 +05:30
|
|
|
note.author.id === state.userData.id;
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export const getCurrentUserLastNote = state =>
|
|
|
|
_.flatten(
|
|
|
|
reverseNotes(state.notes).map(note => reverseNotes(note.notes)),
|
2018-03-17 18:26:18 +05:30
|
|
|
).find(el => isLastNote(el, state));
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export const getDiscussionLastNote = state => discussion =>
|
|
|
|
reverseNotes(discussion.notes).find(el => isLastNote(el, state));
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export const discussionCount = state => {
|
2018-03-27 19:54:05 +05:30
|
|
|
const discussions = state.notes.filter(n => !n.individual_note);
|
|
|
|
|
|
|
|
return discussions.length;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const unresolvedDiscussions = (state, getters) => {
|
|
|
|
const resolvedMap = getters.resolvedDiscussionsById;
|
|
|
|
|
|
|
|
return state.notes.filter(n => !n.individual_note && !resolvedMap[n.id]);
|
|
|
|
};
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export const resolvedDiscussionsById = state => {
|
2018-03-27 19:54:05 +05:30
|
|
|
const map = {};
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
state.notes.forEach(n => {
|
2018-03-27 19:54:05 +05:30
|
|
|
if (n.notes) {
|
|
|
|
const resolved = n.notes.every(note => note.resolved && !note.system);
|
|
|
|
|
|
|
|
if (resolved) {
|
|
|
|
map[n.id] = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return map;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const resolvedDiscussionCount = (state, getters) => {
|
|
|
|
const resolvedMap = getters.resolvedDiscussionsById;
|
|
|
|
|
|
|
|
return Object.keys(resolvedMap).length;
|
|
|
|
};
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
// prevent babel-plugin-rewire from generating an invalid default during karma tests
|
|
|
|
export default () => {};
|