diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-12 18:13:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-12 18:13:54 +0300 |
commit | 462b603802e45891ac5152aea8cbc9298d7d4a53 (patch) | |
tree | de7e03460744491c0d7dcc6e3340272f833fb3b7 /app/assets/javascripts/sidebar | |
parent | da646aac6c559584f63d1fc06132d7351abcfac6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/sidebar')
-rw-r--r-- | app/assets/javascripts/sidebar/mount_sidebar.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/sidebar/sidebar_mediator.js | 52 | ||||
-rw-r--r-- | app/assets/javascripts/sidebar/stores/sidebar_store.js | 4 |
3 files changed, 50 insertions, 13 deletions
diff --git a/app/assets/javascripts/sidebar/mount_sidebar.js b/app/assets/javascripts/sidebar/mount_sidebar.js index cbe40d0bfbe..6363422259e 100644 --- a/app/assets/javascripts/sidebar/mount_sidebar.js +++ b/app/assets/javascripts/sidebar/mount_sidebar.js @@ -26,6 +26,7 @@ import trackShowInviteMemberLink from '~/sidebar/track_invite_members'; import { DropdownVariant } from '~/vue_shared/components/sidebar/labels_select_vue/constants'; import LabelsSelectWidget from '~/vue_shared/components/sidebar/labels_select_widget/labels_select_root.vue'; import { LabelType } from '~/vue_shared/components/sidebar/labels_select_widget/constants'; +import eventHub from '~/sidebar/event_hub'; import Translate from '../vue_shared/translate'; import SidebarAssignees from './components/assignees/sidebar_assignees.vue'; import CopyEmailToClipboard from './components/copy_email_to_clipboard.vue'; @@ -600,6 +601,12 @@ export function mountSidebar(mediator, store) { mountTimeTrackingComponent(); mountSeverityComponent(); + + if (window.gon?.features?.mrAttentionRequests) { + eventHub.$on('removeCurrentUserAttentionRequested', () => + mediator.removeCurrentUserAttentionRequested(), + ); + } } export { getSidebarOptions }; diff --git a/app/assets/javascripts/sidebar/sidebar_mediator.js b/app/assets/javascripts/sidebar/sidebar_mediator.js index a49ddac8c89..25468d4a697 100644 --- a/app/assets/javascripts/sidebar/sidebar_mediator.js +++ b/app/assets/javascripts/sidebar/sidebar_mediator.js @@ -30,7 +30,7 @@ export default class SidebarMediator { this.store.addAssignee(this.store.currentUser); } - saveAssignees(field) { + async saveAssignees(field) { const selected = this.store.assignees.map((u) => u.id); // If there are no ids, that means we have to unassign (which is id = 0) @@ -38,10 +38,22 @@ export default class SidebarMediator { const assignees = selected.length === 0 ? [0] : selected; const data = { assignee_ids: assignees }; - return this.service.update(field, data); + try { + const res = await this.service.update(field, data); + + this.store.overwrite('assignees', res.data.assignees); + + if (res.data.reviewers) { + this.store.overwrite('reviewers', res.data.reviewers); + } + + return Promise.resolve(res); + } catch (e) { + return Promise.reject(e); + } } - saveReviewers(field) { + async saveReviewers(field) { const selected = this.store.reviewers.map((u) => u.id); // If there are no ids, that means we have to unassign (which is id = 0) @@ -49,7 +61,16 @@ export default class SidebarMediator { const reviewers = selected.length === 0 ? [0] : selected; const data = { reviewer_ids: reviewers }; - return this.service.update(field, data); + try { + const res = await this.service.update(field, data); + + this.store.overwrite('reviewers', res.data.reviewers); + this.store.overwrite('assignees', res.data.assignees); + + return Promise.resolve(res); + } catch (e) { + return Promise.reject(); + } } requestReview({ userId, callback }) { @@ -63,6 +84,19 @@ export default class SidebarMediator { .catch(() => callback(userId, false)); } + removeCurrentUserAttentionRequested() { + const currentUserId = gon.current_user_id; + + const currentUserReviewer = this.store.findReviewer({ id: currentUserId }); + const currentUserAssignee = this.store.findAssignee({ id: currentUserId }); + + if (currentUserReviewer?.attention_requested || currentUserAssignee?.attention_requested) { + // Update current users attention_requested state + this.store.updateReviewer(currentUserId, 'attention_requested'); + this.store.updateAssignee(currentUserId, 'attention_requested'); + } + } + async toggleAttentionRequested(type, { user, callback }) { try { const isReviewer = type === 'reviewer'; @@ -82,15 +116,7 @@ export default class SidebarMediator { const currentUserId = gon.current_user_id; if (currentUserId !== user.id) { - const currentUserReviewerOrAssignee = isReviewer - ? this.store.findReviewer({ id: currentUserId }) - : this.store.findAssignee({ id: currentUserId }); - - if (currentUserReviewerOrAssignee?.attention_requested) { - // Update current users attention_requested state - this.store.updateReviewer(currentUserId, 'attention_requested'); - this.store.updateAssignee(currentUserId, 'attention_requested'); - } + this.removeCurrentUserAttentionRequested(); } toast(sprintf(__('Requested attention from @%{username}'), { username: user.username })); diff --git a/app/assets/javascripts/sidebar/stores/sidebar_store.js b/app/assets/javascripts/sidebar/stores/sidebar_store.js index 5376791469e..2caa6f4f0a0 100644 --- a/app/assets/javascripts/sidebar/stores/sidebar_store.js +++ b/app/assets/javascripts/sidebar/stores/sidebar_store.js @@ -98,6 +98,10 @@ export default class SidebarStore { } } + overwrite(key, newData) { + this[key] = newData; + } + findAssignee(findAssignee) { return this.assignees.find(({ id }) => id === findAssignee.id); } |