summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/components/blob_button_group.vue
blob: 857795c71b0a7ab68798f595218c66757411e65e (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
145
146
147
148
149
150
151
152
153
<script>
import { GlButtonGroup, GlButton } from '@gitlab/ui';
import { uniqueId } from 'lodash';
import { sprintf, __ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import getRefMixin from '../mixins/get_ref';
import DeleteBlobModal from './delete_blob_modal.vue';
import UploadBlobModal from './upload_blob_modal.vue';

export default {
  i18n: {
    replace: __('Replace'),
    replacePrimaryBtnText: __('Replace file'),
    delete: __('Delete'),
  },
  components: {
    GlButtonGroup,
    GlButton,
    UploadBlobModal,
    DeleteBlobModal,
    LockButton: () => import('ee_component/repository/components/lock_button.vue'),
  },
  mixins: [getRefMixin, glFeatureFlagMixin()],
  inject: {
    targetBranch: {
      default: '',
    },
    originalBranch: {
      default: '',
    },
  },
  props: {
    name: {
      type: String,
      required: true,
    },
    path: {
      type: String,
      required: true,
    },
    replacePath: {
      type: String,
      required: true,
    },
    deletePath: {
      type: String,
      required: true,
    },
    canPushCode: {
      type: Boolean,
      required: true,
    },
    canPushToBranch: {
      type: Boolean,
      required: true,
    },
    emptyRepo: {
      type: Boolean,
      required: true,
    },
    projectPath: {
      type: String,
      required: true,
    },
    isLocked: {
      type: Boolean,
      required: true,
    },
    canLock: {
      type: Boolean,
      required: true,
    },
    showForkSuggestion: {
      type: Boolean,
      required: true,
    },
  },
  computed: {
    replaceModalId() {
      return uniqueId('replace-modal');
    },
    replaceModalTitle() {
      return sprintf(__('Replace %{name}'), { name: this.name });
    },
    deleteModalId() {
      return uniqueId('delete-modal');
    },
    deleteModalTitle() {
      return sprintf(__('Delete %{name}'), { name: this.name });
    },
    lockBtnQASelector() {
      return this.canLock ? 'lock_button' : 'disabled_lock_button';
    },
  },
  methods: {
    showModal(modalId) {
      if (this.showForkSuggestion) {
        this.$emit('fork');
        return;
      }

      this.$refs[modalId].show();
    },
  },
};
</script>

<template>
  <div class="gl-mr-3">
    <gl-button-group>
      <lock-button
        v-if="glFeatures.fileLocks"
        :name="name"
        :path="path"
        :project-path="projectPath"
        :is-locked="isLocked"
        :can-lock="canLock"
        data-testid="lock"
        :data-qa-selector="lockBtnQASelector"
      />
      <gl-button data-testid="replace" @click="showModal(replaceModalId)">
        {{ $options.i18n.replace }}
      </gl-button>
      <gl-button data-testid="delete" @click="showModal(deleteModalId)">
        {{ $options.i18n.delete }}
      </gl-button>
    </gl-button-group>
    <upload-blob-modal
      :ref="replaceModalId"
      :modal-id="replaceModalId"
      :modal-title="replaceModalTitle"
      :commit-message="replaceModalTitle"
      :target-branch="targetBranch || ref"
      :original-branch="originalBranch || ref"
      :can-push-code="canPushCode"
      :path="path"
      :replace-path="replacePath"
      :primary-btn-text="$options.i18n.replacePrimaryBtnText"
    />
    <delete-blob-modal
      :ref="deleteModalId"
      :modal-id="deleteModalId"
      :modal-title="deleteModalTitle"
      :delete-path="deletePath"
      :commit-message="deleteModalTitle"
      :target-branch="targetBranch || ref"
      :original-branch="originalBranch || ref"
      :can-push-code="canPushCode"
      :can-push-to-branch="canPushToBranch"
      :empty-repo="emptyRepo"
    />
  </div>
</template>