diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /app/assets/javascripts/milestones | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'app/assets/javascripts/milestones')
7 files changed, 147 insertions, 1 deletions
diff --git a/app/assets/javascripts/milestones/project_milestone_combobox.vue b/app/assets/javascripts/milestones/project_milestone_combobox.vue index 5ee917573ce..0fa5585e858 100644 --- a/app/assets/javascripts/milestones/project_milestone_combobox.vue +++ b/app/assets/javascripts/milestones/project_milestone_combobox.vue @@ -205,7 +205,6 @@ export default { <gl-search-box-by-type ref="searchBox" v-model.trim="searchQuery" - class="gl-m-3" :placeholder="this.$options.translations.searchMilestones" @input="onSearchBoxInput" @keydown.enter.prevent="onSearchBoxEnter" diff --git a/app/assets/javascripts/milestones/stores/actions.js b/app/assets/javascripts/milestones/stores/actions.js new file mode 100644 index 00000000000..3859771aeba --- /dev/null +++ b/app/assets/javascripts/milestones/stores/actions.js @@ -0,0 +1,58 @@ +import Api from '~/api'; +import * as types from './mutation_types'; + +export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId); + +export const setSelectedMilestones = ({ commit }, selectedMilestones) => + commit(types.SET_SELECTED_MILESTONES, selectedMilestones); + +export const toggleMilestones = ({ commit, state }, selectedMilestone) => { + const removeMilestone = state.selectedMilestones.includes(selectedMilestone); + + if (removeMilestone) { + commit(types.REMOVE_SELECTED_MILESTONE, selectedMilestone); + } else { + commit(types.ADD_SELECTED_MILESTONE, selectedMilestone); + } +}; + +export const search = ({ dispatch, commit }, query) => { + commit(types.SET_QUERY, query); + + dispatch('searchMilestones'); +}; + +export const fetchMilestones = ({ commit, state }) => { + commit(types.REQUEST_START); + + Api.projectMilestones(state.projectId) + .then(response => { + commit(types.RECEIVE_PROJECT_MILESTONES_SUCCESS, response); + }) + .catch(error => { + commit(types.RECEIVE_PROJECT_MILESTONES_ERROR, error); + }) + .finally(() => { + commit(types.REQUEST_FINISH); + }); +}; + +export const searchMilestones = ({ commit, state }) => { + commit(types.REQUEST_START); + + const options = { + search: state.query, + scope: 'milestones', + }; + + Api.projectSearch(state.projectId, options) + .then(response => { + commit(types.RECEIVE_PROJECT_MILESTONES_SUCCESS, response); + }) + .catch(error => { + commit(types.RECEIVE_PROJECT_MILESTONES_ERROR, error); + }) + .finally(() => { + commit(types.REQUEST_FINISH); + }); +}; diff --git a/app/assets/javascripts/milestones/stores/getters.js b/app/assets/javascripts/milestones/stores/getters.js new file mode 100644 index 00000000000..d8a283403ec --- /dev/null +++ b/app/assets/javascripts/milestones/stores/getters.js @@ -0,0 +1,2 @@ +/** Returns `true` if there is at least one in-progress request */ +export const isLoading = ({ requestCount }) => requestCount > 0; diff --git a/app/assets/javascripts/milestones/stores/index.js b/app/assets/javascripts/milestones/stores/index.js new file mode 100644 index 00000000000..2bebffc19ab --- /dev/null +++ b/app/assets/javascripts/milestones/stores/index.js @@ -0,0 +1,16 @@ +import Vue from 'vue'; +import Vuex from 'vuex'; +import * as actions from './actions'; +import * as getters from './getters'; +import mutations from './mutations'; +import createState from './state'; + +Vue.use(Vuex); + +export default () => + new Vuex.Store({ + actions, + getters, + mutations, + state: createState(), + }); diff --git a/app/assets/javascripts/milestones/stores/mutation_types.js b/app/assets/javascripts/milestones/stores/mutation_types.js new file mode 100644 index 00000000000..370d386dba2 --- /dev/null +++ b/app/assets/javascripts/milestones/stores/mutation_types.js @@ -0,0 +1,13 @@ +export const SET_PROJECT_ID = 'SET_PROJECT_ID'; + +export const SET_SELECTED_MILESTONES = 'SET_SELECTED_MILESTONES'; +export const ADD_SELECTED_MILESTONE = 'ADD_SELECTED_MILESTONE'; +export const REMOVE_SELECTED_MILESTONE = 'REMOVE_SELECTED_MILESTONE'; + +export const SET_QUERY = 'SET_QUERY'; + +export const REQUEST_START = 'REQUEST_START'; +export const REQUEST_FINISH = 'REQUEST_FINISH'; + +export const RECEIVE_PROJECT_MILESTONES_SUCCESS = 'RECEIVE_PROJECT_MILESTONES_SUCCESS'; +export const RECEIVE_PROJECT_MILESTONES_ERROR = 'RECEIVE_PROJECT_MILESTONES_ERROR'; diff --git a/app/assets/javascripts/milestones/stores/mutations.js b/app/assets/javascripts/milestones/stores/mutations.js new file mode 100644 index 00000000000..7c75d09766c --- /dev/null +++ b/app/assets/javascripts/milestones/stores/mutations.js @@ -0,0 +1,44 @@ +import Vue from 'vue'; +import * as types from './mutation_types'; +import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; + +export default { + [types.SET_PROJECT_ID](state, projectId) { + state.projectId = projectId; + }, + [types.SET_SELECTED_MILESTONES](state, selectedMilestones) { + Vue.set(state, 'selectedMilestones', selectedMilestones); + }, + [types.ADD_SELECTED_MILESTONE](state, selectedMilestone) { + state.selectedMilestones.push(selectedMilestone); + }, + [types.REMOVE_SELECTED_MILESTONE](state, selectedMilestone) { + const filteredMilestones = state.selectedMilestones.filter( + milestone => milestone !== selectedMilestone, + ); + Vue.set(state, 'selectedMilestones', filteredMilestones); + }, + [types.SET_QUERY](state, query) { + state.query = query; + }, + [types.REQUEST_START](state) { + state.requestCount += 1; + }, + [types.REQUEST_FINISH](state) { + state.requestCount -= 1; + }, + [types.RECEIVE_PROJECT_MILESTONES_SUCCESS](state, response) { + state.matches.projectMilestones = { + list: convertObjectPropsToCamelCase(response.data).map(({ title }) => ({ title })), + totalCount: parseInt(response.headers['x-total'], 10), + error: null, + }; + }, + [types.RECEIVE_PROJECT_MILESTONES_ERROR](state, error) { + state.matches.projectMilestones = { + list: [], + totalCount: 0, + error, + }; + }, +}; diff --git a/app/assets/javascripts/milestones/stores/state.js b/app/assets/javascripts/milestones/stores/state.js new file mode 100644 index 00000000000..0944539f367 --- /dev/null +++ b/app/assets/javascripts/milestones/stores/state.js @@ -0,0 +1,14 @@ +export default () => ({ + projectId: null, + groupId: null, + query: '', + matches: { + projectMilestones: { + list: [], + totalCount: 0, + error: null, + }, + }, + selectedMilestones: [], + requestCount: 0, +}); |