commits_header.vue 2.7 KB
Newer Older
1
<script>
2
/* eslint-disable vue/no-v-html */
3
import { GlDeprecatedButton, GlIcon } from '@gitlab/ui';
4
import { escape } from 'lodash';
5 6 7 8
import { __, n__, sprintf, s__ } from '~/locale';

export default {
  components: {
9
    GlIcon,
10
    GlDeprecatedButton,
11 12 13 14 15 16
  },
  props: {
    isSquashEnabled: {
      type: Boolean,
      required: true,
    },
N
Natalia Tepluhina 已提交
17 18 19 20
    isFastForwardEnabled: {
      type: Boolean,
      required: true,
    },
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    commitsCount: {
      type: Number,
      required: false,
      default: 0,
    },
    targetBranch: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      expanded: false,
    };
  },
  computed: {
    collapseIcon() {
      return this.expanded ? 'chevron-down' : 'chevron-right';
    },
    commitsCountMessage() {
      return n__(__('%d commit'), __('%d commits'), this.isSquashEnabled ? 1 : this.commitsCount);
    },
    modifyLinkMessage() {
N
Natalia Tepluhina 已提交
44 45 46
      if (this.isFastForwardEnabled) return __('Modify commit message');
      else if (this.isSquashEnabled) return __('Modify commit messages');
      return __('Modify merge commit');
47 48 49 50 51
    },
    ariaLabel() {
      return this.expanded ? __('Collapse') : __('Expand');
    },
    message() {
N
Natalia Tepluhina 已提交
52 53 54 55 56 57
      const message = this.isFastForwardEnabled
        ? s__('mrWidgetCommitsAdded|%{commitCount} will be added to %{targetBranch}.')
        : s__(
            'mrWidgetCommitsAdded|%{commitCount} and %{mergeCommitCount} will be added to %{targetBranch}.',
          );

58
      return sprintf(
N
Natalia Tepluhina 已提交
59
        message,
60 61 62
        {
          commitCount: `<strong class="commits-count-message">${this.commitsCountMessage}</strong>`,
          mergeCommitCount: `<strong>${s__('mrWidgetCommitsAdded|1 merge commit')}</strong>`,
63
          targetBranch: `<span class="label-branch">${escape(this.targetBranch)}</span>`,
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
        },
        false,
      );
    },
  },
  methods: {
    toggle() {
      this.expanded = !this.expanded;
    },
  },
};
</script>

<template>
  <div>
    <div
      class="js-mr-widget-commits-count mr-widget-extension clickable d-flex align-items-center px-3 py-2"
      @click="toggle()"
    >
83
      <gl-deprecated-button
84 85
        :aria-label="ariaLabel"
        variant="blank"
86
        class="commit-edit-toggle square s24 gl-mr-3"
87 88
        @click.stop="toggle()"
      >
89
        <gl-icon :name="collapseIcon" :size="16" />
90
      </gl-deprecated-button>
91 92
      <span v-if="expanded">{{ __('Collapse') }}</span>
      <span v-else>
N
Natalia Tepluhina 已提交
93
        <span class="vertical-align-middle" v-html="message"></span>
94
        <gl-deprecated-button variant="link" class="modify-message-button">
95
          {{ modifyLinkMessage }}
96
        </gl-deprecated-button>
97 98 99 100 101
      </span>
    </div>
    <div v-show="expanded"><slot></slot></div>
  </div>
</template>