repo_tab.vue 2.31 KB
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1
<script>
2
import { __, sprintf } from '~/locale';
Phil Hughes's avatar
Phil Hughes committed
3
import { mapActions } from 'vuex';
Phil Hughes's avatar
Phil Hughes committed
4

5 6
import FileIcon from '~/vue_shared/components/file_icon.vue';
import Icon from '~/vue_shared/components/icon.vue';
7
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
8
import FileStatusIcon from './repo_file_status_icon.vue';
Phil Hughes's avatar
Phil Hughes committed
9

Phil Hughes's avatar
Phil Hughes committed
10 11
export default {
  components: {
12 13 14 15
    FileStatusIcon,
    FileIcon,
    Icon,
    ChangedFileIcon,
Phil Hughes's avatar
Phil Hughes committed
16 17 18 19 20
  },
  props: {
    tab: {
      type: Object,
      required: true,
Phil Hughes's avatar
Phil Hughes committed
21
    },
Phil Hughes's avatar
Phil Hughes committed
22 23 24 25 26 27 28 29 30
  },
  data() {
    return {
      tabMouseOver: false,
    };
  },
  computed: {
    closeLabel() {
      if (this.fileHasChanged) {
31
        return sprintf(__(`%{tabname} changed`), { tabname: this.tab.name });
Phil Hughes's avatar
Phil Hughes committed
32
      }
33
      return sprintf(__(`Close %{tabname}`, { tabname: this.tab.name }));
Phil Hughes's avatar
Phil Hughes committed
34
    },
Phil Hughes's avatar
Phil Hughes committed
35
    showChangedIcon() {
36 37
      if (this.tab.pending) return true;

Phil Hughes's avatar
Phil Hughes committed
38
      return this.fileHasChanged ? !this.tabMouseOver : false;
Phil Hughes's avatar
Phil Hughes committed
39
    },
Phil Hughes's avatar
Phil Hughes committed
40
    fileHasChanged() {
41
      return this.tab.changed || this.tab.tempFile || this.tab.staged || this.tab.deleted;
Phil Hughes's avatar
Phil Hughes committed
42
    },
Phil Hughes's avatar
Phil Hughes committed
43
  },
Phil Hughes's avatar
Phil Hughes committed
44

Phil Hughes's avatar
Phil Hughes committed
45
  methods: {
46
    ...mapActions(['closeFile', 'updateDelayViewerUpdated', 'openPendingTab']),
Phil Hughes's avatar
Phil Hughes committed
47
    clickFile(tab) {
48 49
      if (tab.active) return;

50 51 52
      this.updateDelayViewerUpdated(true);

      if (tab.pending) {
53
        this.openPendingTab({ file: tab, keyPrefix: tab.staged ? 'staged' : 'unstaged' });
54 55 56
      } else {
        this.$router.push(`/project${tab.url}`);
      }
Phil Hughes's avatar
Phil Hughes committed
57
    },
Phil Hughes's avatar
Phil Hughes committed
58 59 60 61 62 63 64 65 66 67 68 69
    mouseOverTab() {
      if (this.fileHasChanged) {
        this.tabMouseOver = true;
      }
    },
    mouseOutTab() {
      if (this.fileHasChanged) {
        this.tabMouseOver = false;
      }
    },
  },
};
Phil Hughes's avatar
Phil Hughes committed
70 71 72 73
</script>

<template>
  <li
Phil Hughes's avatar
Phil Hughes committed
74
    :class="{
75
      active: tab.active,
Mike Greiling's avatar
Mike Greiling committed
76
      disabled: tab.pending,
Phil Hughes's avatar
Phil Hughes committed
77
    }"
78
    @click="clickFile(tab)"
Phil Hughes's avatar
Phil Hughes committed
79 80 81
    @mouseover="mouseOverTab"
    @mouseout="mouseOutTab"
  >
Mike Greiling's avatar
Mike Greiling committed
82 83
    <div :title="tab.url" class="multi-file-tab">
      <file-icon :file-name="tab.name" :size="16" />
Phil Hughes's avatar
Phil Hughes committed
84
      {{ tab.name }}
Mike Greiling's avatar
Mike Greiling committed
85
      <file-status-icon :file="tab" />
Phil Hughes's avatar
Phil Hughes committed
86
    </div>
Phil Hughes's avatar
Phil Hughes committed
87
    <button
88 89
      :aria-label="closeLabel"
      :disabled="tab.pending"
Phil Hughes's avatar
Phil Hughes committed
90 91
      type="button"
      class="multi-file-tab-close"
92
      @click.stop.prevent="closeFile(tab)"
Phil Hughes's avatar
Phil Hughes committed
93
    >
Mike Greiling's avatar
Mike Greiling committed
94 95
      <icon v-if="!showChangedIcon" :size="12" name="close" />
      <changed-file-icon v-else :file="tab" />
Phil Hughes's avatar
Phil Hughes committed
96 97 98
    </button>
  </li>
</template>