debian-mirror-gitlab/app/assets/javascripts/jobs/store/mutations.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

157 lines
4.4 KiB
JavaScript
Raw Normal View History

2019-12-04 20:38:33 +05:30
import Vue from 'vue';
2021-09-30 23:02:18 +05:30
import { INFINITELY_NESTED_COLLAPSIBLE_SECTIONS_FF } from '../constants';
2018-11-20 20:47:30 +05:30
import * as types from './mutation_types';
2021-11-18 22:05:49 +05:30
import { logLinesParser, logLinesParserLegacy, updateIncrementalJobLog } from './utils';
2018-11-20 20:47:30 +05:30
export default {
2018-12-05 23:21:45 +05:30
[types.SET_JOB_ENDPOINT](state, endpoint) {
state.jobEndpoint = endpoint;
},
2018-12-13 13:39:08 +05:30
2021-11-18 22:05:49 +05:30
[types.SET_JOB_LOG_OPTIONS](state, options = {}) {
state.jobLogEndpoint = options.pagePath;
state.jobLogState = options.logState;
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
[types.HIDE_SIDEBAR](state) {
state.isSidebarOpen = false;
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
[types.SHOW_SIDEBAR](state) {
state.isSidebarOpen = true;
2018-11-20 20:47:30 +05:30
},
2021-11-18 22:05:49 +05:30
[types.RECEIVE_JOB_LOG_SUCCESS](state, log = {}) {
2021-09-30 23:02:18 +05:30
const infinitelyCollapsibleSectionsFlag =
gon.features?.[INFINITELY_NESTED_COLLAPSIBLE_SECTIONS_FF];
2018-11-20 20:47:30 +05:30
if (log.state) {
2021-11-18 22:05:49 +05:30
state.jobLogState = log.state;
2018-11-20 20:47:30 +05:30
}
if (log.append) {
2021-09-30 23:02:18 +05:30
if (infinitelyCollapsibleSectionsFlag) {
if (log.lines) {
const parsedResult = logLinesParser(
log.lines,
2021-11-18 22:05:49 +05:30
state.auxiliaryPartialJobLogHelpers,
state.jobLog,
2021-09-30 23:02:18 +05:30
);
2021-11-18 22:05:49 +05:30
state.jobLog = parsedResult.parsedLines;
state.auxiliaryPartialJobLogHelpers = parsedResult.auxiliaryPartialJobLogHelpers;
2021-09-30 23:02:18 +05:30
}
} else {
2021-11-18 22:05:49 +05:30
state.jobLog = log.lines ? updateIncrementalJobLog(log.lines, state.jobLog) : state.jobLog;
2021-09-30 23:02:18 +05:30
}
2020-07-28 23:09:34 +05:30
2021-11-18 22:05:49 +05:30
state.jobLogSize += log.size;
2018-11-20 20:47:30 +05:30
} else {
2021-11-18 22:05:49 +05:30
// When the job still does not have a log
// the job log response will not have a defined
2018-12-13 13:39:08 +05:30
// html or size. We keep the old value otherwise these
2019-12-21 20:55:43 +05:30
// will be set to `null`
2021-09-30 23:02:18 +05:30
if (infinitelyCollapsibleSectionsFlag) {
const parsedResult = logLinesParser(log.lines);
2021-11-18 22:05:49 +05:30
state.jobLog = parsedResult.parsedLines;
state.auxiliaryPartialJobLogHelpers = parsedResult.auxiliaryPartialJobLogHelpers;
2021-09-30 23:02:18 +05:30
} else {
2021-11-18 22:05:49 +05:30
state.jobLog = log.lines ? logLinesParserLegacy(log.lines) : state.jobLog;
2021-09-30 23:02:18 +05:30
}
2020-07-28 23:09:34 +05:30
2021-11-18 22:05:49 +05:30
state.jobLogSize = log.size || state.jobLogSize;
2018-11-20 20:47:30 +05:30
}
2021-11-18 22:05:49 +05:30
if (state.jobLogSize < log.total) {
state.isJobLogSizeVisible = true;
2018-11-20 20:47:30 +05:30
} else {
2021-11-18 22:05:49 +05:30
state.isJobLogSizeVisible = false;
2018-11-20 20:47:30 +05:30
}
2021-11-18 22:05:49 +05:30
state.isJobLogComplete = log.complete || state.isJobLogComplete;
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
2021-11-18 22:05:49 +05:30
[types.SET_JOB_LOG_TIMEOUT](state, id) {
state.jobLogTimeout = id;
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
/**
* Will remove loading animation
*/
2021-11-18 22:05:49 +05:30
[types.STOP_POLLING_JOB_LOG](state) {
state.isJobLogComplete = true;
2018-11-20 20:47:30 +05:30
},
2019-12-04 20:38:33 +05:30
/**
* Instead of filtering the array of lines to find the one that must be updated
* we use Vue.set to make this process more performant
*
* https://vuex.vuejs.org/guide/mutations.html#mutations-follow-vue-s-reactivity-rules
* @param {Object} state
* @param {Object} section
*/
[types.TOGGLE_COLLAPSIBLE_LINE](state, section) {
Vue.set(section, 'isClosed', !section.isClosed);
},
2018-11-20 20:47:30 +05:30
[types.REQUEST_JOB](state) {
state.isLoading = true;
},
[types.RECEIVE_JOB_SUCCESS](state, job) {
state.hasError = false;
2018-12-13 13:39:08 +05:30
state.isLoading = false;
2018-11-20 20:47:30 +05:30
state.job = job;
2018-12-05 23:21:45 +05:30
2019-09-04 21:01:54 +05:30
state.stages =
job.pipeline && job.pipeline.details && job.pipeline.details.stages
? job.pipeline.details.stages
: [];
2018-12-05 23:21:45 +05:30
/**
* 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 === '' && job.stage) {
state.selectedStage = job.stage;
}
2018-11-20 20:47:30 +05:30
},
[types.RECEIVE_JOB_ERROR](state) {
state.isLoading = false;
state.job = {};
2018-12-13 13:39:08 +05:30
state.hasError = true;
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
[types.ENABLE_SCROLL_TOP](state) {
state.isScrollTopDisabled = false;
},
[types.DISABLE_SCROLL_TOP](state) {
state.isScrollTopDisabled = true;
},
[types.ENABLE_SCROLL_BOTTOM](state) {
state.isScrollBottomDisabled = false;
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
[types.DISABLE_SCROLL_BOTTOM](state) {
state.isScrollBottomDisabled = true;
},
[types.TOGGLE_SCROLL_ANIMATION](state, toggle) {
state.isScrollingDown = toggle;
},
2021-11-18 22:05:49 +05:30
[types.TOGGLE_IS_SCROLL_IN_BOTTOM_BEFORE_UPDATING_JOB_LOG](state, toggle) {
state.isScrolledToBottomBeforeReceivingJobLog = toggle;
2018-11-20 20:47:30 +05:30
},
2019-09-04 21:01:54 +05:30
[types.REQUEST_JOBS_FOR_STAGE](state, stage = {}) {
2018-11-20 20:47:30 +05:30
state.isLoadingJobs = true;
2018-12-05 23:21:45 +05:30
state.selectedStage = stage.name;
2018-11-20 20:47:30 +05:30
},
[types.RECEIVE_JOBS_FOR_STAGE_SUCCESS](state, jobs) {
state.isLoadingJobs = false;
state.jobs = jobs;
},
[types.RECEIVE_JOBS_FOR_STAGE_ERROR](state) {
state.isLoadingJobs = false;
state.jobs = [];
},
};