diff options
Diffstat (limited to 'app/assets/javascripts/notes/stores')
4 files changed, 56 insertions, 16 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js index 5b2ab255557..f6069b509e8 100644 --- a/app/assets/javascripts/notes/stores/actions.js +++ b/app/assets/javascripts/notes/stores/actions.js @@ -3,7 +3,7 @@ import $ from 'jquery'; import Visibility from 'visibilityjs'; import axios from '~/lib/utils/axios_utils'; import TaskList from '../../task_list'; -import Flash from '../../flash'; +import { deprecatedCreateFlash as Flash } from '../../flash'; import Poll from '../../lib/utils/poll'; import * as types from './mutation_types'; import * as utils from './utils'; @@ -13,32 +13,35 @@ import sidebarTimeTrackingEventHub from '../../sidebar/event_hub'; import { isInViewport, scrollToElement, isInMRPage } from '../../lib/utils/common_utils'; import { mergeUrlParams } from '../../lib/utils/url_utility'; import mrWidgetEventHub from '../../vue_merge_request_widget/event_hub'; -import updateIssueConfidentialMutation from '~/sidebar/components/confidential/queries/update_issue_confidential.mutation.graphql'; +import updateIssueConfidentialMutation from '~/sidebar/components/confidential/mutations/update_issue_confidential.mutation.graphql'; +import updateMergeRequestLockMutation from '~/sidebar/components/lock/mutations/update_merge_request_lock.mutation.graphql'; +import updateIssueLockMutation from '~/sidebar/components/lock/mutations/update_issue_lock.mutation.graphql'; import { __, sprintf } from '~/locale'; import Api from '~/api'; let eTagPoll; -export const updateConfidentialityOnIssue = ({ commit, getters }, { confidential, fullPath }) => { - const { iid } = getters.getNoteableData; +export const updateLockedAttribute = ({ commit, getters }, { locked, fullPath }) => { + const { iid, targetType } = getters.getNoteableData; return utils.gqClient .mutate({ - mutation: updateIssueConfidentialMutation, + mutation: targetType === 'issue' ? updateIssueLockMutation : updateMergeRequestLockMutation, variables: { input: { projectPath: fullPath, iid: String(iid), - confidential, + locked, }, }, }) .then(({ data }) => { - const { - issueSetConfidential: { issue }, - } = data; + const discussionLocked = + targetType === 'issue' + ? data.issueSetLocked.issue.discussionLocked + : data.mergeRequestSetLocked.mergeRequest.discussionLocked; - commit(types.SET_ISSUE_CONFIDENTIAL, issue.confidential); + commit(types.SET_ISSUABLE_LOCK, discussionLocked); }); }; @@ -683,5 +686,32 @@ export const updateAssignees = ({ commit }, assignees) => { commit(types.UPDATE_ASSIGNEES, assignees); }; -// prevent babel-plugin-rewire from generating an invalid default during karma tests -export default () => {}; +export const updateDiscussionPosition = ({ commit }, updatedPosition) => { + commit(types.UPDATE_DISCUSSION_POSITION, updatedPosition); +}; + +export const updateConfidentialityOnIssuable = ( + { getters, commit }, + { confidential, fullPath }, +) => { + const { iid } = getters.getNoteableData; + + return utils.gqClient + .mutate({ + mutation: updateIssueConfidentialMutation, + variables: { + input: { + projectPath: fullPath, + iid: String(iid), + confidential, + }, + }, + }) + .then(({ data }) => { + const { + issueSetConfidential: { issue }, + } = data; + + setConfidentiality({ commit }, issue.confidential); + }); +}; diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js index 85997b44bcc..7d60fbffb10 100644 --- a/app/assets/javascripts/notes/stores/getters.js +++ b/app/assets/javascripts/notes/stores/getters.js @@ -194,7 +194,9 @@ export const findUnresolvedDiscussionIdNeighbor = (state, getters) => ({ diffOrder, step, }) => { - const ids = getters.unresolvedDiscussionsIdsOrdered(diffOrder); + const diffIds = getters.unresolvedDiscussionsIdsOrdered(diffOrder); + const dateIds = getters.unresolvedDiscussionsIdsOrdered(false); + const ids = diffIds.length ? diffIds : dateIds; const index = ids.indexOf(discussionId) + step; if (index < 0 && step < 0) { @@ -229,6 +231,3 @@ export const getDiscussion = state => discussionId => state.discussions.find(discussion => discussion.id === discussionId); export const commentsDisabled = state => state.commentsDisabled; - -// prevent babel-plugin-rewire from generating an invalid default during karma tests -export default () => {}; diff --git a/app/assets/javascripts/notes/stores/mutation_types.js b/app/assets/javascripts/notes/stores/mutation_types.js index f2236b18beb..eb3447291bc 100644 --- a/app/assets/javascripts/notes/stores/mutation_types.js +++ b/app/assets/javascripts/notes/stores/mutation_types.js @@ -12,6 +12,7 @@ export const SHOW_PLACEHOLDER_NOTE = 'SHOW_PLACEHOLDER_NOTE'; export const TOGGLE_AWARD = 'TOGGLE_AWARD'; export const UPDATE_NOTE = 'UPDATE_NOTE'; export const UPDATE_DISCUSSION = 'UPDATE_DISCUSSION'; +export const UPDATE_DISCUSSION_POSITION = 'UPDATE_DISCUSSION_POSITION'; export const SET_DISCUSSION_DIFF_LINES = 'SET_DISCUSSION_DIFF_LINES'; export const SET_NOTES_FETCHED_STATE = 'SET_NOTES_FETCHED_STATE'; export const SET_NOTES_LOADING_STATE = 'SET_NOTES_LOADING_STATE'; @@ -42,6 +43,7 @@ export const REOPEN_ISSUE = 'REOPEN_ISSUE'; export const TOGGLE_STATE_BUTTON_LOADING = 'TOGGLE_STATE_BUTTON_LOADING'; export const TOGGLE_BLOCKED_ISSUE_WARNING = 'TOGGLE_BLOCKED_ISSUE_WARNING'; export const SET_ISSUE_CONFIDENTIAL = 'SET_ISSUE_CONFIDENTIAL'; +export const SET_ISSUABLE_LOCK = 'SET_ISSUABLE_LOCK'; // Description version export const REQUEST_DESCRIPTION_VERSION = 'REQUEST_DESCRIPTION_VERSION'; diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js index e5f1c11fb35..aa078f00569 100644 --- a/app/assets/javascripts/notes/stores/mutations.js +++ b/app/assets/javascripts/notes/stores/mutations.js @@ -99,6 +99,10 @@ export default { state.noteableData.confidential = data; }, + [types.SET_ISSUABLE_LOCK](state, locked) { + state.noteableData.discussion_locked = locked; + }, + [types.SET_USER_DATA](state, data) { Object.assign(state, { userData: data }); }, @@ -274,6 +278,11 @@ export default { Object.assign(selectedDiscussion, { ...note }); }, + [types.UPDATE_DISCUSSION_POSITION](state, { discussionId, position }) { + const selectedDiscussion = state.discussions.find(disc => disc.id === discussionId); + if (selectedDiscussion) Object.assign(selectedDiscussion.position, { ...position }); + }, + [types.CLOSE_ISSUE](state) { Object.assign(state.noteableData, { state: constants.CLOSED }); }, |