summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/store/mutations.js
blob: d5d5cebb0579ae9552bb02a434a59f3715fd5539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import Vue from 'vue';
import * as types from './mutation_types';
import { logLinesParser, updateIncrementalTrace } from './utils';

//todo remove
import oldLog from '../mock_data/trace';
import newLog from '../mock_data/trace_incremental';

export default {
  [types.SET_JOB_ENDPOINT](state, endpoint) {
    state.jobEndpoint = endpoint;
  },

  [types.SET_TRACE_OPTIONS](state, options = {}) {
    state.traceEndpoint = options.pagePath;
    state.traceState = options.logState;
  },

  [types.HIDE_SIDEBAR](state) {
    state.isSidebarOpen = false;
  },
  [types.SHOW_SIDEBAR](state) {
    state.isSidebarOpen = true;
  },

  [types.RECEIVE_TRACE_SUCCESS](state, log) {
    if (log.state) {
      state.traceState = log.state;
    }

    if (log.append) {
      // state.originalTrace = state.originalTrace.concat(log.trace);
      // state.trace = updateIncrementalTrace(state.originalTrace, state.trace, log.lines)
      state.traceSize += log.size;
    } else {
      // When the job still does not have a trace
      // the trace response will not have a defined
      // html or size. We keep the old value otherwise these
      // will be set to `undefined`
      // state.originalTrace = log.lines || state.trace;
      // state.trace = logLinesParser(log.lines) || state.trace;
      state.traceSize = log.size || state.traceSize;
    }

    state.originalTrace = oldLog.lines;
    state.trace = logLinesParser(oldLog.lines);

    if (state.traceSize < log.total) {
      state.isTraceSizeVisible = true;
    } else {
      state.isTraceSizeVisible = false;
    }

    state.isTraceComplete = log.complete || state.isTraceComplete;
  },

  /**
   * Will remove loading animation
   */
  [types.STOP_POLLING_TRACE](state) {
    state.isTraceComplete = true;
  },

  /**
   * Will remove loading animation
   */
  [types.RECEIVE_TRACE_ERROR](state) {
    state.isTraceComplete = true;
  },

  /**
   * 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);
  },

  [types.REQUEST_JOB](state) {
    state.isLoading = true;
  },
  [types.RECEIVE_JOB_SUCCESS](state, job) {
    state.hasError = false;
    state.isLoading = false;
    state.job = job;

    state.stages =
      job.pipeline && job.pipeline.details && job.pipeline.details.stages
        ? job.pipeline.details.stages
        : [];

    /**
     * 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;
    }
  },
  [types.RECEIVE_JOB_ERROR](state) {
    state.isLoading = false;
    state.job = {};
    state.hasError = true;
  },

  [types.ENABLE_SCROLL_TOP](state) {
    state.isScrollTopDisabled = false;
  },
  [types.DISABLE_SCROLL_TOP](state) {
    state.isScrollTopDisabled = true;
  },
  [types.ENABLE_SCROLL_BOTTOM](state) {
    state.isScrollBottomDisabled = false;
  },
  [types.DISABLE_SCROLL_BOTTOM](state) {
    state.isScrollBottomDisabled = true;
  },
  [types.TOGGLE_SCROLL_ANIMATION](state, toggle) {
    state.isScrollingDown = toggle;
  },

  [types.TOGGLE_IS_SCROLL_IN_BOTTOM_BEFORE_UPDATING_TRACE](state, toggle) {
    state.isScrolledToBottomBeforeReceivingTrace = toggle;
  },

  [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;
    state.jobs = jobs;
  },
  [types.RECEIVE_JOBS_FOR_STAGE_ERROR](state) {
    state.isLoadingJobs = false;
    state.jobs = [];
  },
};