summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-12-11 11:58:32 +0100
committerRémy Coutable <remy@rymai.me>2017-12-18 11:57:17 +0100
commitd9885761727c606e55728276e658ebb34c10aa2f (patch)
treeaaf55967365a1278f13f799fca46033bfa7bc63a
parent60c63c5bffabff911b0f314562ae45c6559e28d8 (diff)
downloadgitlab-ce-nurmuhammadsirat/gitlab-ce-27801-new-branch-slash-command.tar.gz
Improve the JS for notes and quick actionsnurmuhammadsirat/gitlab-ce-27801-new-branch-slash-command
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--app/assets/javascripts/notes.js46
-rw-r--r--app/assets/javascripts/notes/stores/actions.js117
-rw-r--r--spec/features/issues/user_uses_slash_commands_spec.rb4
3 files changed, 73 insertions, 94 deletions
diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js
index 33d869caefc..877e873af7b 100644
--- a/app/assets/javascripts/notes.js
+++ b/app/assets/javascripts/notes.js
@@ -59,6 +59,7 @@ export default class Notes {
this.postComment = this.postComment.bind(this);
this.clearFlashWrapper = this.clearFlash.bind(this);
this.onHashChange = this.onHashChange.bind(this);
+ this.handleQuickActionsCommands = this.handleQuickActionsCommands.bind(this);
this.notes_url = notes_url;
this.note_ids = note_ids;
@@ -338,6 +339,20 @@ export default class Notes {
$note.toggleClass('target', addTargetClass);
}
+ handleQuickActionsCommands(noteEntity, $notesList) {
+ const quickActionsCommands = noteEntity.quick_actions_commands;
+ const hasQuickActionsCommands = !_.isEmpty(quickActionsCommands);
+
+ if (hasQuickActionsCommands) {
+ $notesList.find('.system-note.being-posted').remove();
+ this.addFlash('Commands applied', 'notice', this.parentTimeline.get(0));
+
+ if (!noteEntity.valid) {
+ this.refresh();
+ }
+ }
+ }
+
/**
* Render note in main comments area.
*
@@ -348,38 +363,9 @@ export default class Notes {
return this.renderDiscussionNote(noteEntity, $form);
}
- const quickActionsCommands = noteEntity.quick_actions_commands;
- const hasQuickActionsCommands = quickActionsCommands && Object.keys(quickActionsCommands).length;
- let quickActionsMessage = null;
- let quickActionsMessageType = 'notice';
+ this.handleQuickActionsCommands(noteEntity, $notesList);
- // If the note is invalid with quickActionsCommands, that means it only contained quick actions
if (!noteEntity.valid) {
- if (hasQuickActionsCommands) {
- quickActionsMessage = 'Commands applied';
- }
-
- const quickActionsResults = noteEntity.quick_actions_results;
-
- if (quickActionsResults && quickActionsResults.create_branch) {
- const createBranchResult = quickActionsResults.create_branch;
-
- if (createBranchResult.status === 'error') {
- if (quickActionsMessage) {
- quickActionsMessage = `Commands applied, but the branch '${createBranchResult.branch_name}' could not be created.`;
- } else {
- quickActionsMessage = `The branch '${createBranchResult.branch_name}' could not be created!`;
- quickActionsMessageType = 'alert';
- }
- }
- }
-
- if (quickActionsMessage) {
- this.addFlash(quickActionsMessage, quickActionsMessageType, this.parentTimeline.get(0));
- this.refresh();
- $notesList.find('.system-note.being-posted').remove();
- }
-
return;
}
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js
index 7d012a78854..82278e76a66 100644
--- a/app/assets/javascripts/notes/stores/actions.js
+++ b/app/assets/javascripts/notes/stores/actions.js
@@ -61,6 +61,60 @@ export const createNewNote = ({ commit }, { endpoint, data }) => service
export const removePlaceholderNotes = ({ commit }) =>
commit(types.REMOVE_PLACEHOLDER_NOTES);
+const handleQuickActionsCommands = (noteEntity, noteData) => {
+ const quickActionsCommands = noteEntity.quick_actions_commands;
+ const hasQuickActionsCommands = !_.isEmpty(quickActionsCommands);
+ const quickActionsResults = noteEntity.quick_actions_results;
+ const hasQuickActionsResults = !_.isEmpty(quickActionsResults);
+ let quickActionsMessage = null;
+ let quickActionsMessageType = 'notice';
+
+ if (hasQuickActionsCommands || hasQuickActionsResults) {
+ quickActionsMessage = 'Commands applied';
+ eTagPoll.makeRequest();
+ $('.js-gfm-input').trigger('clear-commands-cache.atwho');
+
+ if (quickActionsCommands.emoji_award) {
+ const votesBlock = $('.js-awards-block').eq(0);
+
+ loadAwardsHandler()
+ .then((awardsHandler) => {
+ awardsHandler.addAwardToEmojiBar(votesBlock, quickActionsCommands.emoji_award);
+ awardsHandler.scrollToAwards();
+ })
+ .catch(() => {
+ Flash(
+ 'Something went wrong while adding your award. Please try again.',
+ 'alert',
+ noteData.flashContainer,
+ );
+ });
+ }
+
+ if (quickActionsCommands.spend_time != null
+ || quickActionsCommands.time_estimate != null) {
+ sidebarTimeTrackingEventHub.$emit('timeTrackingUpdated', noteEntity);
+ }
+ }
+
+ if (quickActionsResults && quickActionsResults.create_branch) {
+ const createBranchResult = quickActionsResults.create_branch;
+
+ if (createBranchResult.status === 'error') {
+ if (hasQuickActionsCommands) {
+ quickActionsMessage = quickActionsMessage.concat(`, but the branch '${createBranchResult.branch_name}' could not be created.`);
+ } else {
+ quickActionsMessage = `The branch '${createBranchResult.branch_name}' could not be created.`;
+ quickActionsMessageType = 'alert';
+ }
+ }
+ }
+
+ if (quickActionsMessage) {
+ Flash(quickActionsMessage, quickActionsMessageType, noteData.flashContainer);
+ }
+};
+
export const saveNote = ({ commit, dispatch }, noteData) => {
const { note } = noteData.data.note;
let placeholderText = note;
@@ -92,68 +146,7 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
return dispatch(methodToDispatch, noteData)
.then((res) => {
- const quickActionsCommands = res.quick_actions_commands;
- const hasQuickActionsCommands = quickActionsCommands
- && Object.keys(quickActionsCommands).length;
- let quickActionsMessage = null;
- let quickActionsMessageType = 'notice';
-
- // If the note is invalid with quickActionsCommands, that means it only
- // contained quick actions
- if (!res.valid) {
- if (hasQuickActionsCommands) {
- quickActionsMessage = 'Commands applied';
- }
-
- const quickActionsResults = res.quick_actions_results;
-
- if (quickActionsResults && quickActionsResults.create_branch) {
- const createBranchResult = quickActionsResults.create_branch;
-
- if (createBranchResult.status === 'error') {
- if (quickActionsMessage) {
- quickActionsMessage = `Commands applied, but the branch '${createBranchResult.branch_name}' could not be created.`;
- } else {
- quickActionsMessage = `The branch '${createBranchResult.branch_name}' could not be created!`;
- quickActionsMessageType = 'alert';
- }
- } else {
- quickActionsMessage = 'Commands applied';
- }
- }
-
- if (quickActionsMessage) {
- Flash(quickActionsMessage, quickActionsMessageType, noteData.flashContainer);
-
- if (quickActionsCommands.emoji_award) {
- const votesBlock = $('.js-awards-block').eq(0);
-
- loadAwardsHandler()
- .then((awardsHandler) => {
- awardsHandler.addAwardToEmojiBar(votesBlock, quickActionsCommands.emoji_award);
- awardsHandler.scrollToAwards();
- })
- .catch(() => {
- Flash(
- 'Something went wrong while adding your award. Please try again.',
- 'alert',
- noteData.flashContainer,
- );
- });
- }
-
- if (quickActionsCommands.spend_time != null
- || quickActionsCommands.time_estimate != null) {
- sidebarTimeTrackingEventHub.$emit('timeTrackingUpdated', res);
- }
- }
- }
-
- if (hasQuickActionsCommands) {
- eTagPoll.makeRequest();
-
- $('.js-gfm-input').trigger('clear-commands-cache.atwho');
- }
+ handleQuickActionsCommands(res, noteData);
commit(types.REMOVE_PLACEHOLDER_NOTES);
diff --git a/spec/features/issues/user_uses_slash_commands_spec.rb b/spec/features/issues/user_uses_slash_commands_spec.rb
index 761ef12609e..a316fef3425 100644
--- a/spec/features/issues/user_uses_slash_commands_spec.rb
+++ b/spec/features/issues/user_uses_slash_commands_spec.rb
@@ -284,7 +284,7 @@ feature 'Issues > User uses quick actions', :js do
write_note("/create_branch A New Feature")
expect(page).not_to have_content '/create_branch'
- expect(page).to have_content "The branch 'A New Feature' could not be created!"
+ expect(page).to have_content "The branch 'A New Feature' could not be created."
end
end
@@ -293,7 +293,7 @@ feature 'Issues > User uses quick actions', :js do
before do
project.add_guest(guest)
- sign_out(user)
+ gitlab_sign_out
sign_in(guest)
visit project_issue_path(project, issue)
end