diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /app/assets/javascripts/vue_shared/components/filtered_search_bar | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/filtered_search_bar')
5 files changed, 313 insertions, 0 deletions
diff --git a/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/actions.js b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/actions.js new file mode 100644 index 00000000000..443cb28cf10 --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/actions.js @@ -0,0 +1,121 @@ +import { deprecatedCreateFlash as createFlash } from '~/flash'; +import axios from '~/lib/utils/axios_utils'; +import { __ } from '~/locale'; +import Api from '~/api'; +import * as types from './mutation_types'; + +export const setEndpoints = ({ commit }, params) => { + const { milestonesEndpoint, labelsEndpoint, groupEndpoint, projectEndpoint } = params; + commit(types.SET_MILESTONES_ENDPOINT, milestonesEndpoint); + commit(types.SET_LABELS_ENDPOINT, labelsEndpoint); + commit(types.SET_GROUP_ENDPOINT, groupEndpoint); + commit(types.SET_PROJECT_ENDPOINT, projectEndpoint); +}; + +export function fetchBranches({ commit, state }, search = '') { + const { projectEndpoint } = state; + commit(types.REQUEST_BRANCHES); + + return Api.branches(projectEndpoint, search) + .then(response => { + commit(types.RECEIVE_BRANCHES_SUCCESS, response.data); + return response; + }) + .catch(({ response }) => { + const { status } = response; + commit(types.RECEIVE_BRANCHES_ERROR, status); + createFlash(__('Failed to load branches. Please try again.')); + }); +} + +export const fetchMilestones = ({ commit, state }, search_title = '') => { + commit(types.REQUEST_MILESTONES); + const { milestonesEndpoint } = state; + + return axios + .get(milestonesEndpoint, { params: { search_title } }) + .then(response => { + commit(types.RECEIVE_MILESTONES_SUCCESS, response.data); + return response; + }) + .catch(({ response }) => { + const { status } = response; + commit(types.RECEIVE_MILESTONES_ERROR, status); + createFlash(__('Failed to load milestones. Please try again.')); + }); +}; + +export const fetchLabels = ({ commit, state }, search = '') => { + commit(types.REQUEST_LABELS); + + return axios + .get(state.labelsEndpoint, { params: { search } }) + .then(response => { + commit(types.RECEIVE_LABELS_SUCCESS, response.data); + return response; + }) + .catch(({ response }) => { + const { status } = response; + commit(types.RECEIVE_LABELS_ERROR, status); + createFlash(__('Failed to load labels. Please try again.')); + }); +}; + +function fetchUser(options = {}) { + const { commit, projectEndpoint, groupEndpoint, query, action, errorMessage } = options; + commit(`REQUEST_${action}`); + + let fetchUserPromise; + if (projectEndpoint) { + fetchUserPromise = Api.projectUsers(projectEndpoint, query).then(data => ({ data })); + } else { + fetchUserPromise = Api.groupMembers(groupEndpoint, { query }); + } + + return fetchUserPromise + .then(response => { + commit(`RECEIVE_${action}_SUCCESS`, response.data); + return response; + }) + .catch(({ response }) => { + const { status } = response; + commit(`RECEIVE_${action}_ERROR`, status); + createFlash(errorMessage); + }); +} + +export const fetchAuthors = ({ commit, state }, query = '') => { + const { projectEndpoint, groupEndpoint } = state; + + return fetchUser({ + commit, + query, + projectEndpoint, + groupEndpoint, + action: 'AUTHORS', + errorMessage: __('Failed to load authors. Please try again.'), + }); +}; + +export const fetchAssignees = ({ commit, state }, query = '') => { + const { projectEndpoint, groupEndpoint } = state; + + return fetchUser({ + commit, + query, + projectEndpoint, + groupEndpoint, + action: 'ASSIGNEES', + errorMessage: __('Failed to load assignees. Please try again.'), + }); +}; + +export const setFilters = ({ commit, dispatch }, filters) => { + commit(types.SET_SELECTED_FILTERS, filters); + + return dispatch('setFilters', filters, { root: true }); +}; + +export const initialize = ({ commit }, initialFilters) => { + commit(types.SET_SELECTED_FILTERS, initialFilters); +}; diff --git a/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/index.js b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/index.js new file mode 100644 index 00000000000..665bb29a17e --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/index.js @@ -0,0 +1,10 @@ +import state from './state'; +import * as actions from './actions'; +import mutations from './mutations'; + +export default { + namespaced: true, + actions, + mutations, + state: state(), +}; diff --git a/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/mutation_types.js b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/mutation_types.js new file mode 100644 index 00000000000..07163550524 --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/mutation_types.js @@ -0,0 +1,26 @@ +export const SET_MILESTONES_ENDPOINT = 'SET_MILESTONES_ENDPOINT'; +export const SET_LABELS_ENDPOINT = 'SET_LABELS_ENDPOINT'; +export const SET_GROUP_ENDPOINT = 'SET_GROUP_ENDPOINT'; +export const SET_PROJECT_ENDPOINT = 'SET_PROJECT_ENDPOINT'; + +export const REQUEST_BRANCHES = 'REQUEST_BRANCHES'; +export const RECEIVE_BRANCHES_SUCCESS = 'RECEIVE_BRANCHES_SUCCESS'; +export const RECEIVE_BRANCHES_ERROR = 'RECEIVE_BRANCHES_ERROR'; + +export const REQUEST_MILESTONES = 'REQUEST_MILESTONES'; +export const RECEIVE_MILESTONES_SUCCESS = 'RECEIVE_MILESTONES_SUCCESS'; +export const RECEIVE_MILESTONES_ERROR = 'RECEIVE_MILESTONES_ERROR'; + +export const REQUEST_LABELS = 'REQUEST_LABELS'; +export const RECEIVE_LABELS_SUCCESS = 'RECEIVE_LABELS_SUCCESS'; +export const RECEIVE_LABELS_ERROR = 'RECEIVE_LABELS_ERROR'; + +export const REQUEST_AUTHORS = 'REQUEST_AUTHORS'; +export const RECEIVE_AUTHORS_SUCCESS = 'RECEIVE_AUTHORS_SUCCESS'; +export const RECEIVE_AUTHORS_ERROR = 'RECEIVE_AUTHORS_ERROR'; + +export const REQUEST_ASSIGNEES = 'REQUEST_ASSIGNEES'; +export const RECEIVE_ASSIGNEES_SUCCESS = 'RECEIVE_ASSIGNEES_SUCCESS'; +export const RECEIVE_ASSIGNEES_ERROR = 'RECEIVE_ASSIGNEES_ERROR'; + +export const SET_SELECTED_FILTERS = 'SET_SELECTED_FILTERS'; diff --git a/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/mutations.js b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/mutations.js new file mode 100644 index 00000000000..056b1c6310f --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/mutations.js @@ -0,0 +1,109 @@ +import * as types from './mutation_types'; + +export default { + [types.SET_SELECTED_FILTERS](state, params) { + const { + selectedSourceBranch = null, + selectedSourceBranchList = [], + selectedTargetBranch = null, + selectedTargetBranchList = [], + selectedAuthor = null, + selectedAuthorList = [], + selectedMilestone = null, + selectedMilestoneList = [], + selectedAssignee = null, + selectedAssigneeList = [], + selectedLabel = null, + selectedLabelList = [], + } = params; + state.branches.source.selected = selectedSourceBranch; + state.branches.source.selectedList = selectedSourceBranchList; + state.branches.target.selected = selectedTargetBranch; + state.branches.target.selectedList = selectedTargetBranchList; + state.authors.selected = selectedAuthor; + state.authors.selectedList = selectedAuthorList; + state.assignees.selected = selectedAssignee; + state.assignees.selectedList = selectedAssigneeList; + state.milestones.selected = selectedMilestone; + state.milestones.selectedList = selectedMilestoneList; + state.labels.selected = selectedLabel; + state.labels.selectedList = selectedLabelList; + }, + [types.SET_MILESTONES_ENDPOINT](state, milestonesEndpoint) { + state.milestonesEndpoint = milestonesEndpoint; + }, + [types.SET_LABELS_ENDPOINT](state, labelsEndpoint) { + state.labelsEndpoint = labelsEndpoint; + }, + [types.SET_GROUP_ENDPOINT](state, groupEndpoint) { + state.groupEndpoint = groupEndpoint; + }, + [types.SET_PROJECT_ENDPOINT](state, projectEndpoint) { + state.projectEndpoint = projectEndpoint; + }, + [types.REQUEST_MILESTONES](state) { + state.milestones.isLoading = true; + }, + [types.RECEIVE_MILESTONES_SUCCESS](state, data) { + state.milestones.isLoading = false; + state.milestones.data = data; + state.milestones.errorCode = null; + }, + [types.RECEIVE_MILESTONES_ERROR](state, errorCode) { + state.milestones.isLoading = false; + state.milestones.errorCode = errorCode; + state.milestones.data = []; + }, + [types.REQUEST_LABELS](state) { + state.labels.isLoading = true; + }, + [types.RECEIVE_LABELS_SUCCESS](state, data) { + state.labels.isLoading = false; + state.labels.data = data; + state.labels.errorCode = null; + }, + [types.RECEIVE_LABELS_ERROR](state, errorCode) { + state.labels.isLoading = false; + state.labels.errorCode = errorCode; + state.labels.data = []; + }, + [types.REQUEST_AUTHORS](state) { + state.authors.isLoading = true; + }, + [types.RECEIVE_AUTHORS_SUCCESS](state, data) { + state.authors.isLoading = false; + state.authors.data = data; + state.authors.errorCode = null; + }, + [types.RECEIVE_AUTHORS_ERROR](state, errorCode) { + state.authors.isLoading = false; + state.authors.errorCode = errorCode; + state.authors.data = []; + }, + [types.REQUEST_ASSIGNEES](state) { + state.assignees.isLoading = true; + }, + [types.RECEIVE_ASSIGNEES_SUCCESS](state, data) { + state.assignees.isLoading = false; + state.assignees.data = data; + state.assignees.errorCode = null; + }, + [types.RECEIVE_ASSIGNEES_ERROR](state, errorCode) { + state.assignees.isLoading = false; + state.assignees.errorCode = errorCode; + state.assignees.data = []; + }, + [types.REQUEST_BRANCHES](state) { + state.branches.isLoading = true; + }, + [types.RECEIVE_BRANCHES_SUCCESS](state, data) { + state.branches.isLoading = false; + state.branches.data = data; + state.branches.errorCode = null; + }, + [types.RECEIVE_BRANCHES_ERROR](state, errorCode) { + state.branches.isLoading = false; + state.branches.errorCode = errorCode; + state.branches.data = []; + }, +}; diff --git a/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/state.js b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/state.js new file mode 100644 index 00000000000..f89f5efc341 --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/filtered_search_bar/store/modules/filters/state.js @@ -0,0 +1,47 @@ +export default () => ({ + milestonesEndpoint: '', + labelsEndpoint: '', + groupEndpoint: '', + projectEndpoint: '', + branches: { + isLoading: false, + errorCode: null, + data: [], + source: { + selected: null, + selectedList: [], + }, + target: { + selected: null, + selectedList: [], + }, + }, + milestones: { + isLoading: false, + errorCode: null, + data: [], + selected: null, + selectedList: [], + }, + labels: { + isLoading: false, + errorCode: null, + data: [], + selected: null, + selectedList: [], + }, + authors: { + isLoading: false, + errorCode: null, + data: [], + selected: null, + selectedList: [], + }, + assignees: { + isLoading: false, + errorCode: null, + data: [], + selected: null, + selectedList: [], + }, +}); |