diff options
author | Steve Azzopardi <sazzopardi@gitlab.com> | 2018-10-12 20:13:41 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-10-12 20:13:41 +0300 |
commit | 464655edb2bc1f78952fb86969405d3c19e35e6b (patch) | |
tree | 184780d5d1220221061b8179914d8c70ac4dd01b /app/assets/javascripts/jobs/store | |
parent | 982aaa04be85b53e686a3a5b6299389a98e5c0a2 (diff) |
Add stage name in job.json response
Diffstat (limited to 'app/assets/javascripts/jobs/store')
-rw-r--r-- | app/assets/javascripts/jobs/store/actions.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/jobs/store/mutations.js | 13 | ||||
-rw-r--r-- | app/assets/javascripts/jobs/store/state.js | 4 |
3 files changed, 21 insertions, 5 deletions
diff --git a/app/assets/javascripts/jobs/store/actions.js b/app/assets/javascripts/jobs/store/actions.js index c8e1090bcc5..d0040161dc3 100644 --- a/app/assets/javascripts/jobs/store/actions.js +++ b/app/assets/javascripts/jobs/store/actions.js @@ -141,8 +141,10 @@ export const fetchStages = ({ state, dispatch }) => { axios .get(`${state.job.pipeline.path}.json`) .then(({ data }) => { + // Set selected stage dispatch('receiveStagesSuccess', data.details.stages); - dispatch('fetchJobsForStage', data.details.stages[0]); + const selectedStage = data.details.stages.find(stage => stage.name === state.selectedStage); + dispatch('fetchJobsForStage', selectedStage); }) .catch(() => dispatch('receiveStagesError')); }; @@ -156,11 +158,12 @@ export const receiveStagesError = ({ commit }) => { /** * Jobs list on sidebar - depend on stages dropdown */ -export const requestJobsForStage = ({ commit }) => commit(types.REQUEST_JOBS_FOR_STAGE); +export const requestJobsForStage = ({ commit }, stage) => + commit(types.REQUEST_JOBS_FOR_STAGE, stage); // On stage click, set selected stage + fetch job export const fetchJobsForStage = ({ dispatch }, stage) => { - dispatch('requestJobsForStage'); + dispatch('requestJobsForStage', stage); axios .get(stage.dropdown_path, { diff --git a/app/assets/javascripts/jobs/store/mutations.js b/app/assets/javascripts/jobs/store/mutations.js index c3f2359fa4d..f00e06e1a6c 100644 --- a/app/assets/javascripts/jobs/store/mutations.js +++ b/app/assets/javascripts/jobs/store/mutations.js @@ -53,6 +53,16 @@ export default { state.isLoading = false; state.hasError = false; state.job = job; + + /** + * We only update it on the first request + * The dropdown can be changed by the user + * after the first request, + * and we do not want to hijack that + */ + if (state.selectedStage === 'More' && job.stage) { + state.selectedStage = job.stage; + } }, [types.RECEIVE_JOB_ERROR](state) { state.isLoading = false; @@ -81,8 +91,9 @@ export default { state.stages = []; }, - [types.REQUEST_JOBS_FOR_STAGE](state) { + [types.REQUEST_JOBS_FOR_STAGE](state, stage) { state.isLoadingJobs = true; + state.selectedStage = stage.name; }, [types.RECEIVE_JOBS_FOR_STAGE_SUCCESS](state, jobs) { state.isLoadingJobs = false; diff --git a/app/assets/javascripts/jobs/store/state.js b/app/assets/javascripts/jobs/store/state.js index 509cb69a5d3..afbc959bb71 100644 --- a/app/assets/javascripts/jobs/store/state.js +++ b/app/assets/javascripts/jobs/store/state.js @@ -1,3 +1,5 @@ +import { __ } from '~/locale'; + export default () => ({ jobEndpoint: null, traceEndpoint: null, @@ -34,7 +36,7 @@ export default () => ({ // sidebar dropdown isLoadingStages: false, isLoadingJobs: false, - selectedStage: null, + selectedStage: __('More'), stages: [], jobs: [], }); |