stacktrace_entry.vue 3.8 KB
Newer Older
1
<script>
2
import { GlTooltip, GlSprintf } from '@gitlab/ui';
3 4 5 6 7 8 9 10 11
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import Icon from '~/vue_shared/components/icon.vue';

export default {
  components: {
    ClipboardButton,
    FileIcon,
    Icon,
12
    GlSprintf,
13 14 15 16 17 18 19 20 21 22 23 24 25
  },
  directives: {
    GlTooltip,
  },
  props: {
    lines: {
      type: Array,
      required: true,
    },
    filePath: {
      type: String,
      required: true,
    },
26 27 28 29 30
    errorFn: {
      type: String,
      required: false,
      default: '',
    },
31 32
    errorLine: {
      type: Number,
33 34 35 36 37 38 39
      required: false,
      default: 0,
    },
    errorColumn: {
      type: Number,
      required: false,
      default: 0,
40 41 42 43 44 45 46 47 48 49 50 51 52
    },
    expanded: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      isExpanded: this.expanded,
    };
  },
  computed: {
53 54
    hasCode() {
      return Boolean(this.lines.length);
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
    },
    collapseIcon() {
      return this.isExpanded ? 'chevron-down' : 'chevron-right';
    },
  },
  methods: {
    isHighlighted(lineNum) {
      return lineNum === this.errorLine;
    },
    toggle() {
      this.isExpanded = !this.isExpanded;
    },
    lineNum(line) {
      return line[0];
    },
    lineCode(line) {
      return line[1];
    },
  },
  userColorScheme: window.gon.user_color_scheme,
};
</script>

<template>
  <div class="file-holder">
    <div ref="header" class="file-title file-title-flex-parent">
81 82
      <div class="file-header-content d-flex align-content-center">
        <div v-if="hasCode" class="d-inline-block cursor-pointer" @click="toggle()">
83 84
          <icon :name="collapseIcon" :size="16" aria-hidden="true" class="append-right-5" />
        </div>
85 86 87 88 89 90 91 92 93
        <file-icon
          :file-name="filePath"
          :size="18"
          aria-hidden="true"
          css-classes="append-right-5"
        />
        <strong
          v-gl-tooltip
          :title="filePath"
94
          class="file-title-name d-inline-block overflow-hidden text-truncate limited-width"
95 96 97 98
          data-container="body"
        >
          {{ filePath }}
        </strong>
99 100 101
        <clipboard-button
          :title="__('Copy file path')"
          :text="filePath"
102
          css-class="btn-default btn-transparent btn-clipboard position-static"
103
        />
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

        <gl-sprintf v-if="errorFn" :message="__('%{spanStart}in%{spanEnd} %{errorFn}')">
          <template #span="{content}">
            <span class="gl-text-gray-400">{{ content }}&nbsp;</span>
          </template>
          <template #errorFn>
            <strong>{{ errorFn }}&nbsp;</strong>
          </template>
        </gl-sprintf>

        <gl-sprintf :message="__('%{spanStart}at line%{spanEnd} %{errorLine}%{errorColumn}')">
          <template #span="{content}">
            <span class="gl-text-gray-400">{{ content }}&nbsp;</span>
          </template>
          <template #errorLine>
            <strong>{{ errorLine }}</strong>
          </template>
          <template #errorColumn>
            <strong v-if="errorColumn">:{{ errorColumn }}</strong>
          </template>
        </gl-sprintf>
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
      </div>
    </div>

    <table v-if="isExpanded" :class="$options.userColorScheme" class="code js-syntax-highlight">
      <tbody>
        <template v-for="(line, index) in lines">
          <tr :key="`stacktrace-line-${index}`" class="line_holder">
            <td class="diff-line-num" :class="{ old: isHighlighted(lineNum(line)) }">
              {{ lineNum(line) }}
            </td>
            <td
              class="line_content"
              :class="{ old: isHighlighted(lineNum(line)) }"
              v-html="lineCode(line)"
            ></td>
          </tr>
        </template>
      </tbody>
    </table>
  </div>
</template>