summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/components/blob_replace.vue
blob: 91d7811eb6dbe22a6765e06d4312153b4e7f24ee (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
<script>
import { GlButton, GlModalDirective } from '@gitlab/ui';
import { uniqueId } from 'lodash';
import { sprintf, __ } from '~/locale';
import getRefMixin from '../mixins/get_ref';
import UploadBlobModal from './upload_blob_modal.vue';

export default {
  i18n: {
    replace: __('Replace'),
    replacePrimaryBtnText: __('Replace file'),
  },
  components: {
    GlButton,
    UploadBlobModal,
  },
  directives: {
    GlModal: GlModalDirective,
  },
  mixins: [getRefMixin],
  inject: {
    targetBranch: {
      default: '',
    },
    originalBranch: {
      default: '',
    },
  },
  props: {
    name: {
      type: String,
      required: true,
    },
    path: {
      type: String,
      required: true,
    },
    replacePath: {
      type: String,
      required: true,
    },
    canPushCode: {
      type: Boolean,
      required: true,
    },
  },
  computed: {
    replaceModalId() {
      return uniqueId('replace-modal');
    },
    title() {
      return sprintf(__('Replace %{name}'), { name: this.name });
    },
  },
};
</script>

<template>
  <div class="gl-mr-3">
    <gl-button v-gl-modal="replaceModalId">
      {{ $options.i18n.replace }}
    </gl-button>
    <upload-blob-modal
      :modal-id="replaceModalId"
      :modal-title="title"
      :commit-message="title"
      :target-branch="targetBranch || ref"
      :original-branch="originalBranch || ref"
      :can-push-code="canPushCode"
      :path="path"
      :replace-path="replacePath"
      :primary-btn-text="$options.i18n.replacePrimaryBtnText"
    />
  </div>
</template>