commit.vue 3.8 KB
Newer Older
1
<script>
2 3 4
import UserAvatarLink from './user_avatar/user_avatar_link.vue';
import tooltip from '../directives/tooltip';
import Icon from '../../vue_shared/components/icon.vue';
5

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
export default {
  directives: {
    tooltip,
  },
  components: {
    UserAvatarLink,
    Icon,
  },
  props: {
    /**
     * Indicates the existance of a tag.
     * Used to render the correct icon, if true will render `fa-tag` icon,
     * if false will render a svg sprite fork icon
     */
    tag: {
      type: Boolean,
      required: false,
      default: false,
F
Filipa Lacerda 已提交
24
    },
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    /**
     * If provided is used to render the branch name and url.
     * Should contain the following properties:
     * name
     * ref_url
     */
    commitRef: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    /**
     * Used to link to the commit sha.
     */
    commitUrl: {
      type: String,
      required: false,
      default: '',
F
Filipa Lacerda 已提交
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
    /**
     * Used to show the commit short sha that links to the commit url.
     */
    shortSha: {
      type: String,
      required: false,
      default: '',
    },
    /**
     * If provided shows the commit tile.
     */
    title: {
      type: String,
      required: false,
      default: '',
    },
    /**
     * If provided renders information about the author of the commit.
     * When provided should include:
     * `avatar_url` to render the avatar icon
     * `web_url` to link to user profile
     * `username` to render alt and title tags
     */
    author: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    showBranch: {
      type: Boolean,
      required: false,
      default: true,
77
    },
78 79 80 81 82 83 84 85 86 87
  },
  computed: {
    /**
     * Used to verify if all the properties needed to render the commit
     * ref section were provided.
     *
     * @returns {Boolean}
     */
    hasCommitRef() {
      return this.commitRef && this.commitRef.name && this.commitRef.ref_url;
88
    },
89 90 91 92 93 94 95 96
    /**
     * Used to verify if all the properties needed to render the commit
     * author section were provided.
     *
     * @returns {Boolean}
     */
    hasAuthor() {
      return this.author && this.author.avatar_url && this.author.path && this.author.username;
97
    },
98 99 100 101 102 103 104 105 106 107 108
    /**
     * If information about the author is provided will return a string
     * to be rendered as the alt attribute of the img tag.
     *
     * @returns {String}
     */
    userImageAltDescription() {
      return this.author && this.author.username ? `${this.author.username}'s avatar` : null;
    },
  },
};
109 110 111
</script>
<template>
  <div class="branch-commit">
112
    <template v-if="hasCommitRef && showBranch">
113
      <div class="icon-container">
114 115 116
        <i
          v-if="tag"
          class="fa fa-tag"
F
Filipa Lacerda 已提交
117 118
          aria-hidden="true"
        >
119
        </i>
J
Jose Ivan Vargas 已提交
120
        <icon
121
          v-if="!tag"
F
Filipa Lacerda 已提交
122 123
          name="fork"
        />
124
      </div>
125

126 127
      <a
        v-tooltip
128
        :href="commitRef.ref_url"
F
Filipa Lacerda 已提交
129
        :title="commitRef.name"
130 131
        class="ref-name"
        data-container="body"
F
Filipa Lacerda 已提交
132 133
      >
        {{ commitRef.name }}
134 135
      </a>
    </template>
136 137
    <icon
      name="commit"
F
Filipa Lacerda 已提交
138
      class="commit-icon js-commit-icon"
139
    />
140 141

    <a
F
Filipa Lacerda 已提交
142
      :href="commitUrl"
143
      class="commit-sha"
F
Filipa Lacerda 已提交
144 145
    >
      {{ shortSha }}
146 147 148 149 150
    </a>

    <div class="commit-title flex-truncate-parent">
      <span
        v-if="title"
F
Filipa Lacerda 已提交
151 152
        class="flex-truncate-child"
      >
153 154 155 156 157 158
        <user-avatar-link
          v-if="hasAuthor"
          :link-href="author.path"
          :img-src="author.avatar_url"
          :img-alt="userImageAltDescription"
          :tooltip-text="author.username"
159
          class="avatar-image-container"
160
        />
161
        <a
F
Filipa Lacerda 已提交
162
          :href="commitUrl"
163
          class="commit-row-message"
F
Filipa Lacerda 已提交
164 165
        >
          {{ title }}
166 167
        </a>
      </span>
168
      <span v-else>
169
        Can't find HEAD commit for this branch
170 171 172 173
      </span>
    </div>
  </div>
</template>