diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-07-25 20:01:53 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-07-25 20:01:53 +0100 |
commit | cf5cc6a9cc0ac1a8fe2ae9dff260fd66e316e483 (patch) | |
tree | 1d9f8e8ed576763a45253302fa8ccdead4b4c455 /app/assets/javascripts/notes/stores/utils.js | |
parent | fbdc02adc1682fe40c68e850496d94b89491a6f9 (diff) | |
download | gitlab-ce-cf5cc6a9cc0ac1a8fe2ae9dff260fd66e316e483.tar.gz |
Follow vuex docs to divide store into: actions, getters and mutations
Use constants for mutation types as per vuex docs
Diffstat (limited to 'app/assets/javascripts/notes/stores/utils.js')
-rw-r--r-- | app/assets/javascripts/notes/stores/utils.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/assets/javascripts/notes/stores/utils.js b/app/assets/javascripts/notes/stores/utils.js new file mode 100644 index 00000000000..6074115e855 --- /dev/null +++ b/app/assets/javascripts/notes/stores/utils.js @@ -0,0 +1,31 @@ +import AjaxCache from '~/lib/utils/ajax_cache'; + +const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm; + +export const findNoteObjectById = (notes, id) => notes.filter(n => n.id === id)[0]; + +export const getQuickActionText = (note) => { + let text = 'Applying command'; + const quickActions = AjaxCache.get(gl.GfmAutoComplete.dataSources.commands) || []; + + const executedCommands = quickActions.filter((command) => { + 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; +}; + +export const hasQuickActions = note => REGEX_QUICK_ACTIONS.test(note); + +export const stripQuickActions = note => note.replace(REGEX_QUICK_ACTIONS, '').trim(); + |