summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/log/log.vue
blob: f0bdbde0602a06a763c1bd52cbb7a8a14b237179 (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
<script>
import { mapState, mapActions } from 'vuex';
import CollpasibleLogSection from './collapsible_section.vue';
import LogLine from './line.vue';

export default {
  components: {
    CollpasibleLogSection,
    LogLine,
  },
  computed: {
    ...mapState([
      'traceEndpoint',
      'trace',
      'isTraceComplete',
      'isScrolledToBottomBeforeReceivingTrace',
    ]),
  },
  updated() {
    this.$nextTick(() => {
      this.handleScrollDown();
    });
  },
  mounted() {
    this.$nextTick(() => {
      this.handleScrollDown();
    });
  },
  methods: {
    ...mapActions(['toggleCollapsibleLine', 'scrollBottom']),
    handleOnClickCollapsibleLine(section) {
      this.toggleCollapsibleLine(section);
    },
    /**
     * The job log is sent in HTML, which means we need to use `v-html` to render it
     * Using the updated hook with $nextTick is not enough to wait for the DOM to be updated
     * in this case because it runs before `v-html` has finished running, since there's no
     * Vue binding.
     * In order to scroll the page down after `v-html` has finished, we need to use setTimeout
     */
    handleScrollDown() {
      if (this.isScrolledToBottomBeforeReceivingTrace) {
        setTimeout(() => {
          this.scrollBottom();
        }, 0);
      }
    },
  },
};
</script>
<template>
  <code class="job-log d-block" data-qa-selector="job_log_content">
    <template v-for="(section, index) in trace">
      <collpasible-log-section
        v-if="section.isHeader"
        :key="`collapsible-${index}`"
        :section="section"
        :trace-endpoint="traceEndpoint"
        @onClickCollapsibleLine="handleOnClickCollapsibleLine"
      />
      <log-line v-else :key="section.offset" :line="section" :path="traceEndpoint" />
    </template>

    <div v-if="!isTraceComplete" class="js-log-animation loader-animation pt-3 pl-3">
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
    </div>
  </code>
</template>