summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/user_popover/user_popover.vue
blob: 37bde089de8f6c358b83726e92e6f00f76249417 (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
76
77
78
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<script>
/* eslint-disable vue/no-v-html */
import {
  GlPopover,
  GlLink,
  GlDeprecatedSkeletonLoading as GlSkeletonLoading,
  GlIcon,
} from '@gitlab/ui';
import UserNameWithStatus from '~/sidebar/components/assignees/user_name_with_status.vue';
import { glEmojiTag } from '../../../emoji';
import UserAvatarImage from '../user_avatar/user_avatar_image.vue';

const MAX_SKELETON_LINES = 4;

const SECURITY_BOT_USER_DATA = {
  username: 'GitLab-Security-Bot',
  name: 'GitLab Security Bot',
};

export default {
  name: 'UserPopover',
  maxSkeletonLines: MAX_SKELETON_LINES,
  components: {
    GlIcon,
    GlLink,
    GlPopover,
    GlSkeletonLoading,
    UserAvatarImage,
    UserNameWithStatus,
  },
  props: {
    target: {
      type: HTMLAnchorElement,
      required: true,
    },
    user: {
      type: Object,
      required: true,
      default: null,
    },
  },
  computed: {
    statusHtml() {
      if (!this.user.status) {
        return '';
      }

      if (this.user.status.emoji && this.user.status.message_html) {
        return `${glEmojiTag(this.user.status.emoji)} ${this.user.status.message_html}`;
      } else if (this.user.status.message_html) {
        return this.user.status.message_html;
      }

      return '';
    },
    userIsLoading() {
      return !this.user?.loaded;
    },
    isSecurityBot() {
      const { username, name, websiteUrl = '' } = this.user;
      return (
        gon.features?.securityAutoFix &&
        username === SECURITY_BOT_USER_DATA.username &&
        name === SECURITY_BOT_USER_DATA.name &&
        websiteUrl.length
      );
    },
    availabilityStatus() {
      return this.user?.status?.availability || '';
    },
  },
};
</script>

<template>
  <!-- 200ms delay so not every mouseover triggers Popover -->
  <gl-popover :target="target" :delay="200" boundary="viewport" triggers="hover" placement="top">
    <div class="gl-p-3 gl-line-height-normal gl-display-flex" data-testid="user-popover">
      <div class="gl-p-2 flex-shrink-1">
        <user-avatar-image :img-src="user.avatarUrl" :size="60" css-classes="gl-mr-3!" />
      </div>
      <div class="gl-p-2 gl-w-full">
        <template v-if="userIsLoading">
          <!-- `gl-skeleton-loading` does not support equal length lines -->
          <!-- This can be migrated to `gl-skeleton-loader` when https://gitlab.com/gitlab-org/gitlab-ui/-/issues/872 is completed -->
          <gl-skeleton-loading
            v-for="n in $options.maxSkeletonLines"
            :key="n"
            :lines="1"
            class="animation-container-small gl-mb-2"
          />
        </template>
        <template v-else>
          <div class="gl-mb-3">
            <h5 class="gl-m-0">
              <user-name-with-status :name="user.name" :availability="availabilityStatus" />
            </h5>
            <span class="gl-text-gray-500">@{{ user.username }}</span>
          </div>
          <div class="gl-text-gray-500">
            <div v-if="user.bio" class="gl-display-flex gl-mb-2">
              <gl-icon name="profile" class="gl-text-gray-400 gl-flex-shrink-0" />
              <span ref="bio" class="gl-ml-2" v-html="user.bioHtml"></span>
            </div>
            <div v-if="user.workInformation" class="gl-display-flex gl-mb-2">
              <gl-icon name="work" class="gl-text-gray-400 gl-flex-shrink-0" />
              <span ref="workInformation" class="gl-ml-2">{{ user.workInformation }}</span>
            </div>
          </div>
          <div v-if="user.location" class="js-location gl-text-gray-500 gl-display-flex">
            <gl-icon name="location" class="gl-text-gray-400 flex-shrink-0" />
            <span class="gl-ml-2">{{ user.location }}</span>
          </div>
          <div v-if="statusHtml" class="js-user-status gl-mt-3">
            <span v-html="statusHtml"></span>
          </div>
          <div v-if="isSecurityBot" class="gl-text-blue-500">
            <gl-icon name="question" />
            <gl-link data-testid="user-popover-bot-docs-link" :href="user.websiteUrl">
              {{ sprintf(__('Learn more about %{username}'), { username: user.name }) }}
            </gl-link>
          </div>
        </template>
      </div>
    </div>
  </gl-popover>
</template>