debian-mirror-gitlab/app/assets/javascripts/notes/stores/actions.js

656 lines
20 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import Vue from 'vue';
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import Visibility from 'visibilityjs';
2020-01-01 13:55:28 +05:30
import axios from '~/lib/utils/axios_utils';
2019-02-15 15:39:39 +05:30
import TaskList from '../../task_list';
2018-03-17 18:26:18 +05:30
import Flash from '../../flash';
import Poll from '../../lib/utils/poll';
import * as types from './mutation_types';
import * as utils from './utils';
import * as constants from '../constants';
import loadAwardsHandler from '../../awards_handler';
import sidebarTimeTrackingEventHub from '../../sidebar/event_hub';
2019-02-15 15:39:39 +05:30
import { isInViewport, scrollToElement, isInMRPage } from '../../lib/utils/common_utils';
2019-12-26 22:10:19 +05:30
import { mergeUrlParams } from '../../lib/utils/url_utility';
2018-12-05 23:21:45 +05:30
import mrWidgetEventHub from '../../vue_merge_request_widget/event_hub';
2020-01-01 13:55:28 +05:30
import { __, sprintf } from '~/locale';
2019-09-30 21:07:59 +05:30
import Api from '~/api';
2018-03-17 18:26:18 +05:30
let eTagPoll;
2019-02-15 15:39:39 +05:30
export const expandDiscussion = ({ commit, dispatch }, data) => {
if (data.discussionId) {
dispatch('diffs/renderFileForDiscussionId', data.discussionId, { root: true });
}
commit(types.EXPAND_DISCUSSION, data);
};
2018-11-08 19:23:39 +05:30
export const collapseDiscussion = ({ commit }, data) => commit(types.COLLAPSE_DISCUSSION, data);
export const setNotesData = ({ commit }, data) => commit(types.SET_NOTES_DATA, data);
export const setNoteableData = ({ commit }, data) => commit(types.SET_NOTEABLE_DATA, data);
export const setUserData = ({ commit }, data) => commit(types.SET_USER_DATA, data);
export const setLastFetchedAt = ({ commit }, data) => commit(types.SET_LAST_FETCHED_AT, data);
export const setInitialNotes = ({ commit }, discussions) =>
commit(types.SET_INITIAL_DISCUSSIONS, discussions);
export const setTargetNoteHash = ({ commit }, data) => commit(types.SET_TARGET_NOTE_HASH, data);
export const setNotesFetchedState = ({ commit }, state) =>
commit(types.SET_NOTES_FETCHED_STATE, state);
export const toggleDiscussion = ({ commit }, data) => commit(types.TOGGLE_DISCUSSION, data);
2020-04-22 19:07:51 +05:30
export const setExpandDiscussions = ({ commit }, { discussionIds, expanded }) => {
commit(types.SET_EXPAND_DISCUSSIONS, { discussionIds, expanded });
};
2020-04-08 14:13:33 +05:30
export const fetchDiscussions = ({ commit, dispatch }, { path, filter, persistFilter }) => {
const config =
filter !== undefined
? { params: { notes_filter: filter, persist_filter: persistFilter } }
: null;
return axios.get(path, config).then(({ data }) => {
2019-12-04 20:38:33 +05:30
commit(types.SET_INITIAL_DISCUSSIONS, data);
2020-04-22 19:07:51 +05:30
2019-12-04 20:38:33 +05:30
dispatch('updateResolvableDiscussionsCounts');
});
2020-04-08 14:13:33 +05:30
};
2018-11-08 19:23:39 +05:30
2018-12-05 23:21:45 +05:30
export const updateDiscussion = ({ commit, state }, discussion) => {
commit(types.UPDATE_DISCUSSION, discussion);
return utils.findNoteObjectById(state.discussions, discussion.id);
};
2018-03-17 18:26:18 +05:30
2020-04-22 19:07:51 +05:30
export const setDiscussionSortDirection = ({ commit }, direction) => {
commit(types.SET_DISCUSSIONS_SORT, direction);
};
2019-12-04 20:38:33 +05:30
export const removeNote = ({ commit, dispatch, state }, note) => {
const discussion = state.discussions.find(({ id }) => id === note.discussion_id);
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
commit(types.DELETE_NOTE, note);
2018-12-05 23:21:45 +05:30
2019-12-04 20:38:33 +05:30
dispatch('updateMergeRequestWidget');
dispatch('updateResolvableDiscussionsCounts');
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
if (isInMRPage()) {
dispatch('diffs/removeDiscussionsFromDiff', discussion);
}
};
export const deleteNote = ({ dispatch }, note) =>
axios.delete(note.path).then(() => {
dispatch('removeNote', note);
2018-03-17 18:26:18 +05:30
});
2019-02-15 15:39:39 +05:30
export const updateNote = ({ commit, dispatch }, { endpoint, note }) =>
2020-04-08 14:13:33 +05:30
axios.put(endpoint, note).then(({ data }) => {
2019-12-04 20:38:33 +05:30
commit(types.UPDATE_NOTE, data);
dispatch('startTaskList');
});
2018-03-17 18:26:18 +05:30
2019-07-07 11:18:12 +05:30
export const updateOrCreateNotes = ({ commit, state, getters, dispatch }, notes) => {
const { notesById } = getters;
notes.forEach(note => {
if (notesById[note.id]) {
commit(types.UPDATE_NOTE, note);
} else if (note.type === constants.DISCUSSION_NOTE || note.type === constants.DIFF_NOTE) {
const discussion = utils.findNoteObjectById(state.discussions, note.discussion_id);
if (discussion) {
commit(types.ADD_NEW_REPLY_TO_DISCUSSION, note);
} else if (note.type === constants.DIFF_NOTE) {
dispatch('fetchDiscussions', { path: state.notesData.discussionsPath });
} else {
commit(types.ADD_NEW_NOTE, note);
}
} else {
commit(types.ADD_NEW_NOTE, note);
}
});
};
2019-12-04 20:38:33 +05:30
export const replyToDiscussion = (
{ commit, state, getters, dispatch },
{ endpoint, data: reply },
) =>
2020-04-08 14:13:33 +05:30
axios.post(endpoint, reply).then(({ data }) => {
2019-12-04 20:38:33 +05:30
if (data.discussion) {
commit(types.UPDATE_DISCUSSION, data.discussion);
2019-07-07 11:18:12 +05:30
2019-12-04 20:38:33 +05:30
updateOrCreateNotes({ commit, state, getters, dispatch }, data.discussion.notes);
2019-07-07 11:18:12 +05:30
2019-12-04 20:38:33 +05:30
dispatch('updateMergeRequestWidget');
dispatch('startTaskList');
dispatch('updateResolvableDiscussionsCounts');
} else {
commit(types.ADD_NEW_REPLY_TO_DISCUSSION, data);
}
2018-03-17 18:26:18 +05:30
2019-12-04 20:38:33 +05:30
return data;
});
2018-03-17 18:26:18 +05:30
2019-12-04 20:38:33 +05:30
export const createNewNote = ({ commit, dispatch }, { endpoint, data: reply }) =>
2020-04-08 14:13:33 +05:30
axios.post(endpoint, reply).then(({ data }) => {
2019-12-04 20:38:33 +05:30
if (!data.errors) {
commit(types.ADD_NEW_NOTE, data);
dispatch('updateMergeRequestWidget');
dispatch('startTaskList');
dispatch('updateResolvableDiscussionsCounts');
}
return data;
});
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
export const removePlaceholderNotes = ({ commit }) => commit(types.REMOVE_PLACEHOLDER_NOTES);
2018-03-17 18:26:18 +05:30
2019-07-31 22:56:46 +05:30
export const resolveDiscussion = ({ state, dispatch, getters }, { discussionId }) => {
const discussion = utils.findNoteObjectById(state.discussions, discussionId);
const isResolved = getters.isDiscussionResolved(discussionId);
if (!discussion) {
return Promise.reject();
} else if (isResolved) {
return Promise.resolve();
}
return dispatch('toggleResolveNote', {
endpoint: discussion.resolve_path,
isResolved,
discussion: true,
});
};
2020-04-08 14:13:33 +05:30
export const toggleResolveNote = ({ commit, dispatch }, { endpoint, isResolved, discussion }) => {
const method = isResolved
? constants.UNRESOLVE_NOTE_METHOD_NAME
: constants.RESOLVE_NOTE_METHOD_NAME;
const mutationType = discussion ? types.UPDATE_DISCUSSION : types.UPDATE_NOTE;
2018-03-27 19:54:05 +05:30
2020-04-08 14:13:33 +05:30
return axios[method](endpoint).then(({ data }) => {
2019-12-04 20:38:33 +05:30
commit(mutationType, data);
2018-12-05 23:21:45 +05:30
2019-12-04 20:38:33 +05:30
dispatch('updateResolvableDiscussionsCounts');
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
dispatch('updateMergeRequestWidget');
});
2020-04-08 14:13:33 +05:30
};
2018-03-27 19:54:05 +05:30
2020-05-24 23:13:21 +05:30
export const toggleBlockedIssueWarning = ({ commit }, value) => {
commit(types.TOGGLE_BLOCKED_ISSUE_WARNING, value);
// Hides Close issue button at the top of issue page
const closeDropdown = document.querySelector('.js-issuable-close-dropdown');
if (closeDropdown) {
closeDropdown.classList.toggle('d-none');
} else {
const closeButton = document.querySelector(
'.detail-page-header-actions .btn-close.btn-grouped',
);
closeButton.classList.toggle('d-md-block');
}
};
2018-03-27 19:54:05 +05:30
export const closeIssue = ({ commit, dispatch, state }) => {
dispatch('toggleStateButtonLoading', true);
2020-04-08 14:13:33 +05:30
return axios.put(state.notesData.closePath).then(({ data }) => {
2019-12-04 20:38:33 +05:30
commit(types.CLOSE_ISSUE);
dispatch('emitStateChangedEvent', data);
dispatch('toggleStateButtonLoading', false);
2020-05-24 23:13:21 +05:30
dispatch('toggleBlockedIssueWarning', false);
2019-12-04 20:38:33 +05:30
});
2018-03-27 19:54:05 +05:30
};
export const reopenIssue = ({ commit, dispatch, state }) => {
dispatch('toggleStateButtonLoading', true);
2020-04-08 14:13:33 +05:30
return axios.put(state.notesData.reopenPath).then(({ data }) => {
2019-12-04 20:38:33 +05:30
commit(types.REOPEN_ISSUE);
dispatch('emitStateChangedEvent', data);
dispatch('toggleStateButtonLoading', false);
});
2018-03-27 19:54:05 +05:30
};
export const toggleStateButtonLoading = ({ commit }, value) =>
commit(types.TOGGLE_STATE_BUTTON_LOADING, value);
2018-11-08 19:23:39 +05:30
export const emitStateChangedEvent = ({ getters }, data) => {
2018-05-09 12:01:36 +05:30
const event = new CustomEvent('issuable_vue_app:change', {
detail: {
data,
isClosed: getters.openState === constants.CLOSED,
},
});
2018-03-27 19:54:05 +05:30
document.dispatchEvent(event);
};
export const toggleIssueLocalState = ({ commit }, newState) => {
if (newState === constants.CLOSED) {
commit(types.CLOSE_ISSUE);
} else if (newState === constants.REOPENED) {
commit(types.REOPEN_ISSUE);
}
};
2018-03-17 18:26:18 +05:30
export const saveNote = ({ commit, dispatch }, noteData) => {
2018-11-08 19:23:39 +05:30
// For MR discussuions we need to post as `note[note]` and issue we use `note.note`.
2018-12-05 23:21:45 +05:30
// For batch comments, we use draft_note
const note = noteData.data.draft_note || noteData.data['note[note]'] || noteData.data.note.note;
2018-03-17 18:26:18 +05:30
let placeholderText = note;
const hasQuickActions = utils.hasQuickActions(placeholderText);
const replyId = noteData.data.in_reply_to_discussion_id;
2018-12-05 23:21:45 +05:30
let methodToDispatch;
2020-05-24 23:13:21 +05:30
const postData = { ...noteData };
2018-12-05 23:21:45 +05:30
if (postData.isDraft === true) {
methodToDispatch = replyId
? 'batchComments/addDraftToDiscussion'
: 'batchComments/createNewDraft';
if (!postData.draft_note && noteData.note) {
postData.draft_note = postData.note;
delete postData.note;
}
} else {
methodToDispatch = replyId ? 'replyToDiscussion' : 'createNewNote';
}
2018-03-17 18:26:18 +05:30
$('.notes-form .flash-container').hide(); // hide previous flash notification
2018-11-20 20:47:30 +05:30
commit(types.REMOVE_PLACEHOLDER_NOTES); // remove previous placeholders
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
if (replyId) {
if (hasQuickActions) {
placeholderText = utils.stripQuickActions(placeholderText);
}
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
if (placeholderText.length) {
commit(types.SHOW_PLACEHOLDER_NOTE, {
noteBody: placeholderText,
replyId,
});
}
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
if (hasQuickActions) {
commit(types.SHOW_PLACEHOLDER_NOTE, {
isSystemNote: true,
noteBody: utils.getQuickActionText(note),
replyId,
});
}
2018-03-17 18:26:18 +05:30
}
2020-01-01 13:55:28 +05:30
const processQuickActions = res => {
const { errors: { commands_only: message } = { commands_only: null } } = res;
2019-12-21 20:55:43 +05:30
/*
The following reply means that quick actions have been successfully applied:
2018-03-17 18:26:18 +05:30
2019-12-21 20:55:43 +05:30
{"commands_changes":{},"valid":false,"errors":{"commands_only":["Commands applied"]}}
*/
2020-01-01 13:55:28 +05:30
if (hasQuickActions && message) {
2019-12-21 20:55:43 +05:30
eTagPoll.makeRequest();
2019-09-04 21:01:54 +05:30
2019-12-21 20:55:43 +05:30
$('.js-gfm-input').trigger('clear-commands-cache.atwho');
Flash(message || __('Commands applied'), 'notice', noteData.flashContainer);
2018-05-09 12:01:36 +05:30
}
2018-03-17 18:26:18 +05:30
2020-01-01 13:55:28 +05:30
return res;
2019-12-21 20:55:43 +05:30
};
2018-03-17 18:26:18 +05:30
2019-12-21 20:55:43 +05:30
const processEmojiAward = res => {
const { commands_changes: commandsChanges } = res;
const { emoji_award: emojiAward } = commandsChanges || {};
if (!emojiAward) {
return res;
2018-05-09 12:01:36 +05:30
}
2018-03-17 18:26:18 +05:30
2019-12-21 20:55:43 +05:30
const votesBlock = $('.js-awards-block').eq(0);
return loadAwardsHandler()
.then(awardsHandler => {
awardsHandler.addAwardToEmojiBar(votesBlock, emojiAward);
awardsHandler.scrollToAwards();
})
.catch(() => {
Flash(
__('Something went wrong while adding your award. Please try again.'),
'alert',
noteData.flashContainer,
);
})
.then(() => res);
};
const processTimeTracking = res => {
const { commands_changes: commandsChanges } = res;
const { spend_time: spendTime, time_estimate: timeEstimate } = commandsChanges || {};
if (spendTime != null || timeEstimate != null) {
sidebarTimeTrackingEventHub.$emit('timeTrackingUpdated', {
commands_changes: commandsChanges,
});
2018-05-09 12:01:36 +05:30
}
2019-12-21 20:55:43 +05:30
return res;
};
const removePlaceholder = res => {
2018-11-20 20:47:30 +05:30
if (replyId) {
commit(types.REMOVE_PLACEHOLDER_NOTES);
}
2018-05-09 12:01:36 +05:30
return res;
2019-12-21 20:55:43 +05:30
};
2020-01-01 13:55:28 +05:30
const processErrors = error => {
if (error.response) {
const {
response: { data = {} },
} = error;
const { errors = {} } = data;
const { base = [] } = errors;
// we handle only errors.base for now
if (base.length > 0) {
const errorMsg = sprintf(__('Your comment could not be submitted because %{error}'), {
error: base[0].toLowerCase(),
});
Flash(errorMsg, 'alert', noteData.flashContainer);
return { ...data, hasFlash: true };
}
}
throw error;
};
2019-12-21 20:55:43 +05:30
return dispatch(methodToDispatch, postData, { root: true })
2020-01-01 13:55:28 +05:30
.then(processQuickActions)
2019-12-21 20:55:43 +05:30
.then(processEmojiAward)
.then(processTimeTracking)
2020-01-01 13:55:28 +05:30
.then(removePlaceholder)
.catch(processErrors);
2018-03-17 18:26:18 +05:30
};
2018-11-08 19:23:39 +05:30
const pollSuccessCallBack = (resp, commit, state, getters, dispatch) => {
2018-03-17 18:26:18 +05:30
if (resp.notes && resp.notes.length) {
2019-07-07 11:18:12 +05:30
updateOrCreateNotes({ commit, state, getters, dispatch }, resp.notes);
2019-02-15 15:39:39 +05:30
dispatch('startTaskList');
2018-03-17 18:26:18 +05:30
}
2018-03-27 19:54:05 +05:30
commit(types.SET_LAST_FETCHED_AT, resp.last_fetched_at);
2018-03-17 18:26:18 +05:30
return resp;
};
2020-04-08 14:13:33 +05:30
const getFetchDataParams = state => {
const endpoint = state.notesData.notesPath;
const options = {
headers: {
'X-Last-Fetched-At': state.lastFetchedAt ? `${state.lastFetchedAt}` : undefined,
},
};
return { endpoint, options };
};
export const fetchData = ({ commit, state, getters }) => {
const { endpoint, options } = getFetchDataParams(state);
axios
.get(endpoint, options)
.then(({ data }) => pollSuccessCallBack(data, commit, state, getters))
.catch(() => Flash(__('Something went wrong while fetching latest comments.')));
};
2018-11-08 19:23:39 +05:30
export const poll = ({ commit, state, getters, dispatch }) => {
2018-03-17 18:26:18 +05:30
eTagPoll = new Poll({
2020-04-08 14:13:33 +05:30
resource: {
poll: () => {
const { endpoint, options } = getFetchDataParams(state);
return axios.get(endpoint, options);
},
},
2018-03-17 18:26:18 +05:30
method: 'poll',
2019-12-04 20:38:33 +05:30
successCallback: ({ data }) => pollSuccessCallBack(data, commit, state, getters, dispatch),
2019-07-31 22:56:46 +05:30
errorCallback: () => Flash(__('Something went wrong while fetching latest comments.')),
2018-03-17 18:26:18 +05:30
});
if (!Visibility.hidden()) {
eTagPoll.makeRequest();
} else {
2020-04-08 14:13:33 +05:30
fetchData({ commit, state, getters });
2018-03-17 18:26:18 +05:30
}
Visibility.change(() => {
if (!Visibility.hidden()) {
eTagPoll.restart();
} else {
eTagPoll.stop();
}
});
};
export const stopPolling = () => {
2019-09-30 21:07:59 +05:30
if (eTagPoll) eTagPoll.stop();
2018-03-17 18:26:18 +05:30
};
export const restartPolling = () => {
2019-09-30 21:07:59 +05:30
if (eTagPoll) eTagPoll.restart();
2018-03-17 18:26:18 +05:30
};
2018-11-08 19:23:39 +05:30
export const toggleAward = ({ commit, getters }, { awardName, noteId }) => {
2018-03-17 18:26:18 +05:30
commit(types.TOGGLE_AWARD, { awardName, note: getters.notesById[noteId] });
};
2018-11-08 19:23:39 +05:30
export const toggleAwardRequest = ({ dispatch }, data) => {
2018-03-17 18:26:18 +05:30
const { endpoint, awardName } = data;
2019-09-30 21:07:59 +05:30
return axios.post(endpoint, { name: awardName }).then(() => {
dispatch('toggleAward', data);
});
2018-03-17 18:26:18 +05:30
};
export const scrollToNoteIfNeeded = (context, el) => {
if (!isInViewport(el[0])) {
scrollToElement(el);
}
};
2018-10-15 14:42:47 +05:30
2018-11-08 19:23:39 +05:30
export const fetchDiscussionDiffLines = ({ commit }, discussion) =>
2019-02-15 15:39:39 +05:30
axios.get(discussion.truncated_diff_lines_path).then(({ data }) => {
2018-11-08 19:23:39 +05:30
commit(types.SET_DISCUSSION_DIFF_LINES, {
discussionId: discussion.id,
diffLines: data.truncated_diff_lines,
});
});
2018-12-05 23:21:45 +05:30
export const updateMergeRequestWidget = () => {
mrWidgetEventHub.$emit('mr.discussion.updated');
};
2018-12-13 13:39:08 +05:30
export const setLoadingState = ({ commit }, data) => {
commit(types.SET_NOTES_LOADING_STATE, data);
};
2019-10-12 21:52:04 +05:30
export const filterDiscussion = ({ dispatch }, { path, filter, persistFilter }) => {
2018-12-13 13:39:08 +05:30
dispatch('setLoadingState', true);
2019-10-12 21:52:04 +05:30
dispatch('fetchDiscussions', { path, filter, persistFilter })
2018-12-13 13:39:08 +05:30
.then(() => {
dispatch('setLoadingState', false);
dispatch('setNotesFetchedState', true);
})
.catch(() => {
dispatch('setLoadingState', false);
dispatch('setNotesFetchedState', true);
Flash(__('Something went wrong while fetching comments. Please try again.'));
});
};
export const setCommentsDisabled = ({ commit }, data) => {
commit(types.DISABLE_COMMENTS, data);
};
2019-02-15 15:39:39 +05:30
export const startTaskList = ({ dispatch }) =>
Vue.nextTick(
() =>
new TaskList({
dataType: 'note',
fieldName: 'note',
selector: '.notes .is-editable',
onSuccess: () => dispatch('startTaskList'),
}),
);
2019-09-30 21:07:59 +05:30
export const updateResolvableDiscussionsCounts = ({ commit }) =>
2019-02-15 15:39:39 +05:30
commit(types.UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS);
export const submitSuggestion = (
2019-07-31 22:56:46 +05:30
{ commit, dispatch },
{ discussionId, noteId, suggestionId, flashContainer },
2019-12-21 20:55:43 +05:30
) => {
const dispatchResolveDiscussion = () =>
dispatch('resolveDiscussion', { discussionId }).catch(() => {});
return Api.applySuggestion(suggestionId)
2019-07-31 22:56:46 +05:30
.then(() => commit(types.APPLY_SUGGESTION, { discussionId, noteId, suggestionId }))
2019-12-21 20:55:43 +05:30
.then(dispatchResolveDiscussion)
2019-02-15 15:39:39 +05:30
.catch(err => {
const defaultMessage = __(
'Something went wrong while applying the suggestion. Please try again.',
);
2020-06-23 00:09:42 +05:30
const errorMessage = err.response.data?.message;
const flashMessage = errorMessage || defaultMessage;
2019-02-15 15:39:39 +05:30
Flash(__(flashMessage), 'alert', flashContainer);
});
2019-12-21 20:55:43 +05:30
};
2019-02-15 15:39:39 +05:30
2020-06-23 00:09:42 +05:30
export const submitSuggestionBatch = ({ commit, dispatch, state }, { flashContainer }) => {
const suggestionIds = state.batchSuggestionsInfo.map(({ suggestionId }) => suggestionId);
const applyAllSuggestions = () =>
state.batchSuggestionsInfo.map(suggestionInfo =>
commit(types.APPLY_SUGGESTION, suggestionInfo),
);
const resolveAllDiscussions = () =>
state.batchSuggestionsInfo.map(suggestionInfo => {
const { discussionId } = suggestionInfo;
return dispatch('resolveDiscussion', { discussionId }).catch(() => {});
});
commit(types.SET_APPLYING_BATCH_STATE, true);
return Api.applySuggestionBatch(suggestionIds)
.then(() => Promise.all(applyAllSuggestions()))
.then(() => Promise.all(resolveAllDiscussions()))
.then(() => commit(types.CLEAR_SUGGESTION_BATCH))
.catch(err => {
const defaultMessage = __(
'Something went wrong while applying the batch of suggestions. Please try again.',
);
const errorMessage = err.response.data?.message;
const flashMessage = errorMessage || defaultMessage;
Flash(__(flashMessage), 'alert', flashContainer);
})
.finally(() => commit(types.SET_APPLYING_BATCH_STATE, false));
};
export const addSuggestionInfoToBatch = ({ commit }, { suggestionId, noteId, discussionId }) =>
commit(types.ADD_SUGGESTION_TO_BATCH, { suggestionId, noteId, discussionId });
export const removeSuggestionInfoFromBatch = ({ commit }, suggestionId) =>
commit(types.REMOVE_SUGGESTION_FROM_BATCH, suggestionId);
2019-03-02 22:35:43 +05:30
export const convertToDiscussion = ({ commit }, noteId) =>
commit(types.CONVERT_TO_DISCUSSION, noteId);
2019-07-07 11:18:12 +05:30
export const removeConvertedDiscussion = ({ commit }, noteId) =>
commit(types.REMOVE_CONVERTED_DISCUSSION, noteId);
2020-03-13 15:44:24 +05:30
export const setCurrentDiscussionId = ({ commit }, discussionId) =>
commit(types.SET_CURRENT_DISCUSSION_ID, discussionId);
2020-04-08 14:13:33 +05:30
export const fetchDescriptionVersion = ({ dispatch }, { endpoint, startingVersion, versionId }) => {
2019-12-26 22:10:19 +05:30
let requestUrl = endpoint;
if (startingVersion) {
requestUrl = mergeUrlParams({ start_version_id: startingVersion }, requestUrl);
}
2020-03-13 15:44:24 +05:30
dispatch('requestDescriptionVersion');
2019-12-26 22:10:19 +05:30
return axios
.get(requestUrl)
2020-03-13 15:44:24 +05:30
.then(res => {
2020-04-08 14:13:33 +05:30
dispatch('receiveDescriptionVersion', { descriptionVersion: res.data, versionId });
2020-03-13 15:44:24 +05:30
})
.catch(error => {
dispatch('receiveDescriptionVersionError', error);
2019-12-26 22:10:19 +05:30
Flash(__('Something went wrong while fetching description changes. Please try again.'));
});
};
2020-03-13 15:44:24 +05:30
export const requestDescriptionVersion = ({ commit }) => {
commit(types.REQUEST_DESCRIPTION_VERSION);
};
export const receiveDescriptionVersion = ({ commit }, descriptionVersion) => {
commit(types.RECEIVE_DESCRIPTION_VERSION, descriptionVersion);
};
export const receiveDescriptionVersionError = ({ commit }, error) => {
commit(types.RECEIVE_DESCRIPTION_VERSION_ERROR, error);
};
2020-04-08 14:13:33 +05:30
export const softDeleteDescriptionVersion = (
{ dispatch },
{ endpoint, startingVersion, versionId },
) => {
2020-03-13 15:44:24 +05:30
let requestUrl = endpoint;
if (startingVersion) {
requestUrl = mergeUrlParams({ start_version_id: startingVersion }, requestUrl);
}
dispatch('requestDeleteDescriptionVersion');
return axios
.delete(requestUrl)
.then(() => {
2020-04-08 14:13:33 +05:30
dispatch('receiveDeleteDescriptionVersion', versionId);
2020-03-13 15:44:24 +05:30
})
.catch(error => {
dispatch('receiveDeleteDescriptionVersionError', error);
Flash(__('Something went wrong while deleting description changes. Please try again.'));
2020-06-23 00:09:42 +05:30
// Throw an error here because a component like SystemNote -
// needs to know if the request failed to reset its internal state.
throw new Error();
2020-03-13 15:44:24 +05:30
});
};
export const requestDeleteDescriptionVersion = ({ commit }) => {
commit(types.REQUEST_DELETE_DESCRIPTION_VERSION);
};
2020-04-08 14:13:33 +05:30
export const receiveDeleteDescriptionVersion = ({ commit }, versionId) => {
commit(types.RECEIVE_DELETE_DESCRIPTION_VERSION, { [versionId]: __('Deleted') });
2020-03-13 15:44:24 +05:30
};
export const receiveDeleteDescriptionVersionError = ({ commit }, error) => {
commit(types.RECEIVE_DELETE_DESCRIPTION_VERSION_ERROR, error);
};
2020-06-23 00:09:42 +05:30
export const updateAssignees = ({ commit }, assignees) => {
commit(types.UPDATE_ASSIGNEES, assignees);
};
2018-10-15 14:42:47 +05:30
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};