debian-mirror-gitlab/app/assets/javascripts/notes/stores/utils.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import AjaxCache from '~/lib/utils/ajax_cache';
const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm;
2018-11-20 20:47:30 +05:30
export const findNoteObjectById = (notes, id) => notes.filter(n => n.id === id)[0];
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
export const getQuickActionText = note => {
2018-03-17 18:26:18 +05:30
let text = 'Applying command';
2018-11-20 20:47:30 +05:30
const quickActions = AjaxCache.get(gl.GfmAutoComplete.dataSources.commands) || [];
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
const executedCommands = quickActions.filter(command => {
2018-03-17 18:26:18 +05:30
const commandRegex = new RegExp(`/${command.name}`);
return commandRegex.test(note);
});
if (executedCommands && executedCommands.length) {
if (executedCommands.length > 1) {
text = 'Applying multiple commands';
} else {
const commandDescription = executedCommands[0].description.toLowerCase();
text = `Applying command to ${commandDescription}`;
}
}
return text;
};
2018-11-20 20:47:30 +05:30
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] || [];
items.push(note);
Object.assign(acc, { [note.line_code]: items });
}
return acc;
}, {});
2018-03-17 18:26:18 +05:30
export const hasQuickActions = note => REGEX_QUICK_ACTIONS.test(note);
2018-11-20 20:47:30 +05:30
export const stripQuickActions = note => note.replace(REGEX_QUICK_ACTIONS, '').trim();