summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/markdown/suggestion_diff_header.vue
blob: c5a2aa1f2af492fa72daba0f51741e7f42ecd081 (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
<script>
import Icon from '~/vue_shared/components/icon.vue';

export default {
  components: { Icon },
  props: {
    canApply: {
      type: Boolean,
      required: false,
      default: false,
    },
    isApplied: {
      type: Boolean,
      required: true,
      default: false,
    },
    helpPagePath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      isAppliedSuccessfully: false,
      isApplying: false,
    };
  },
  methods: {
    applySuggestion() {
      if (!this.canApply) return;
      this.isApplying = true;
      this.$emit('apply', this.applySuggestionCallback);
    },
    applySuggestionCallback() {
      this.isApplying = false;
    },
  },
};
</script>

<template>
  <div class="md-suggestion-header border-bottom-0 mt-2">
    <div class="qa-suggestion-diff-header font-weight-bold">
      {{ __('Suggested change') }}
      <a v-if="helpPagePath" :href="helpPagePath" :aria-label="__('Help')" class="js-help-btn">
        <icon name="question-o" css-classes="link-highlight" />
      </a>
    </div>
    <span v-if="isApplied" class="badge badge-success">{{ __('Applied') }}</span>
    <button
      v-if="canApply"
      type="button"
      class="btn qa-apply-btn"
      :disabled="isApplying"
      @click="applySuggestion"
    >
      {{ __('Apply suggestion') }}
    </button>
  </div>
</template>