commit.vue 4.2 KB
Newer Older
1 2 3
<script>
  import commitIconSvg from 'icons/_icon_commit.svg';
  import userAvatarLink from './user_avatar/user_avatar_link.vue';
4
  import tooltip from '../directives/tooltip';
F
Filipa Lacerda 已提交
5
  import icon from '../../vue_shared/components/icon.vue';
6 7

  export default {
F
Filipa Lacerda 已提交
8 9 10 11 12 13 14
    directives: {
      tooltip,
    },
    components: {
      userAvatarLink,
      icon,
    },
15 16 17 18
    props: {
      /**
       * Indicates the existance of a tag.
       * Used to render the correct icon, if true will render `fa-tag` icon,
J
Jose Ivan Vargas 已提交
19
       * if false will render a svg sprite fork icon
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
       */
      tag: {
        type: Boolean,
        required: false,
        default: false,
      },
      /**
       * 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: '',
      },

      /**
       * 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: () => ({}),
      },
74 75 76 77 78
      showBranch: {
        type: Boolean,
        required: false,
        default: true,
      },
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
    },
    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;
      },
      /**
       * 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;
      },
      /**
       * 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;
      },
    },
113 114 115
    created() {
      this.commitIconSvg = commitIconSvg;
    },
116 117 118 119
  };
</script>
<template>
  <div class="branch-commit">
120
    <template v-if="hasCommitRef && showBranch">
121
      <div class="icon-container">
122 123 124
        <i
          v-if="tag"
          class="fa fa-tag"
F
Filipa Lacerda 已提交
125 126
          aria-hidden="true"
        >
127
        </i>
J
Jose Ivan Vargas 已提交
128
        <icon
129
          v-if="!tag"
F
Filipa Lacerda 已提交
130 131
          name="fork"
        />
132
      </div>
133

134
      <a
135
        class="ref-name"
136 137 138
        :href="commitRef.ref_url"
        v-tooltip
        data-container="body"
F
Filipa Lacerda 已提交
139 140 141
        :title="commitRef.name"
      >
        {{ commitRef.name }}
142 143
      </a>
    </template>
144 145
    <div
      v-html="commitIconSvg"
F
Filipa Lacerda 已提交
146 147
      class="commit-icon js-commit-icon"
    >
148 149 150 151
    </div>

    <a
      class="commit-sha"
F
Filipa Lacerda 已提交
152 153 154
      :href="commitUrl"
    >
      {{ shortSha }}
155 156 157 158 159
    </a>

    <div class="commit-title flex-truncate-parent">
      <span
        v-if="title"
F
Filipa Lacerda 已提交
160 161
        class="flex-truncate-child"
      >
162 163 164 165 166 167 168 169
        <user-avatar-link
          v-if="hasAuthor"
          class="avatar-image-container"
          :link-href="author.path"
          :img-src="author.avatar_url"
          :img-alt="userImageAltDescription"
          :tooltip-text="author.username"
        />
170 171
        <a
          class="commit-row-message"
F
Filipa Lacerda 已提交
172 173 174
          :href="commitUrl"
        >
          {{ title }}
175 176 177 178 179 180 181 182
        </a>
      </span>
      <span v-else>
        Cant find HEAD commit for this branch
      </span>
    </div>
  </div>
</template>