summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/edit_button.vue
blob: ff1af5569dcdb8055697ad5b55798aea7c874ed3 (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
<script>
import { GlTooltipDirective, GlDeprecatedButton, GlIcon } from '@gitlab/ui';
import { __ } from '~/locale';

export default {
  components: {
    GlDeprecatedButton,
    GlIcon,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    editPath: {
      type: String,
      required: false,
      default: '',
    },
    canCurrentUserFork: {
      type: Boolean,
      required: true,
    },
    canModifyBlob: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    tooltipTitle() {
      if (this.isDisabled) {
        return __("Can't edit as source branch was deleted");
      }

      return __('Edit file');
    },
    isDisabled() {
      return !this.editPath;
    },
  },
  methods: {
    handleEditClick(evt) {
      if (this.canCurrentUserFork && !this.canModifyBlob) {
        evt.preventDefault();
        this.$emit('showForkMessage');
      }
    },
  },
};
</script>

<template>
  <span v-gl-tooltip.top :title="tooltipTitle">
    <gl-deprecated-button
      :href="editPath"
      :disabled="isDisabled"
      :class="{ 'cursor-not-allowed': isDisabled }"
      class="rounded-0 js-edit-blob"
      @click.native="handleEditClick"
    >
      <gl-icon name="pencil" />
    </gl-deprecated-button>
  </span>
</template>