diff options
author | Jose <jivanvl@hotmail.com> | 2018-05-07 12:18:26 -0500 |
---|---|---|
committer | Jose <jivanvl@hotmail.com> | 2018-05-07 12:18:26 -0500 |
commit | 75434a33a6647c156ed2e3ec144779979854525f (patch) | |
tree | 1cf1c86d6fa763b00174aea1371a9766423cf101 | |
parent | 62078e6e2cb4f5658a6589bb27a688abab9eec6e (diff) | |
download | gitlab-ce-jivl-fix-close-merge-request-button-text.tar.gz |
Fix close merge request button textjivl-fix-close-merge-request-button-text
-rw-r--r-- | app/assets/javascripts/lib/utils/text_utility.js | 13 | ||||
-rw-r--r-- | app/assets/javascripts/notes/components/comment_form.vue | 4 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/text_utility_spec.js | 6 |
3 files changed, 21 insertions, 2 deletions
diff --git a/app/assets/javascripts/lib/utils/text_utility.js b/app/assets/javascripts/lib/utils/text_utility.js index 787874878bb..f9a4453fb15 100644 --- a/app/assets/javascripts/lib/utils/text_utility.js +++ b/app/assets/javascripts/lib/utils/text_utility.js @@ -102,3 +102,16 @@ export const convertToSentenceCase = string => { return splitWord.join(' '); }; + +/** + * Splits camelCase or PascalCase words + * e.g. HelloWorld => Hello World + * + * @param {*} string +*/ +export const splitCamelCase = string => ( + string + .replace(/([A-Z]+)([A-Z][a-z])/g, ' $1 $2') + .replace(/([a-z\d])([A-Z])/g, '$1 $2') + .trim() +); diff --git a/app/assets/javascripts/notes/components/comment_form.vue b/app/assets/javascripts/notes/components/comment_form.vue index 466570fc456..e0fdc0f1c22 100644 --- a/app/assets/javascripts/notes/components/comment_form.vue +++ b/app/assets/javascripts/notes/components/comment_form.vue @@ -7,7 +7,7 @@ import { __, sprintf } from '~/locale'; import Flash from '../../flash'; import Autosave from '../../autosave'; import TaskList from '../../task_list'; -import { capitalizeFirstCharacter, convertToCamelCase } from '../../lib/utils/text_utility'; +import { capitalizeFirstCharacter, convertToCamelCase, splitCamelCase } from '../../lib/utils/text_utility'; import * as constants from '../constants'; import eventHub from '../event_hub'; import issueWarning from '../../vue_shared/components/issue/issue_warning.vue'; @@ -53,7 +53,7 @@ export default { ]), ...mapState(['isToggleStateButtonLoading']), noteableDisplayName() { - return this.noteableType.replace(/_/g, ' '); + return splitCamelCase(this.noteableType).toLowerCase(); }, isLoggedIn() { return this.getUserData.id; diff --git a/spec/javascripts/lib/utils/text_utility_spec.js b/spec/javascripts/lib/utils/text_utility_spec.js index 09604448c53..5eeb5e2a0be 100644 --- a/spec/javascripts/lib/utils/text_utility_spec.js +++ b/spec/javascripts/lib/utils/text_utility_spec.js @@ -98,4 +98,10 @@ describe('text_utility', () => { expect(textUtils.truncateSha('shortsha')).toBe('shortsha'); }); }); + + describe('splitCamelCase', () => { + it('separates a PascalCase word to two', () => { + expect(textUtils.splitCamelCase('HelloWorld')).toBe('Hello World'); + }); + }); }); |