Commit 55b61773 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '214125-refactor-user_popover-vue-loading-logic' into 'master'

Simplify user popover loading logic

See merge request gitlab-org/gitlab!35903
parents 8d8fcd8c e5bccfee
......@@ -4,8 +4,11 @@ import Icon from '~/vue_shared/components/icon.vue';
import UserAvatarImage from '../user_avatar/user_avatar_image.vue';
import { glEmojiTag } from '../../../emoji';
const MAX_SKELETON_LINES = 4;
export default {
name: 'UserPopover',
maxSkeletonLines: MAX_SKELETON_LINES,
components: {
Icon,
GlPopover,
......@@ -22,11 +25,6 @@ export default {
required: true,
default: null,
},
loaded: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
statusHtml() {
......@@ -42,14 +40,8 @@ export default {
return '';
},
nameIsLoading() {
return !this.user.name;
},
workInformationIsLoading() {
return !this.user.loaded && this.user.workInformation === null;
},
locationIsLoading() {
return !this.user.loaded && this.user.location === null;
userIsLoading() {
return !this.user?.loaded;
},
},
};
......@@ -63,13 +55,22 @@ export default {
<user-avatar-image :img-src="user.avatarUrl" :size="60" css-classes="mr-2" />
</div>
<div class="p-1 w-100">
<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 mb-1"
/>
</template>
<template v-else>
<div class="mb-2">
<h5 class="m-0">
<span v-if="user.name">{{ user.name }}</span>
<gl-skeleton-loading v-else :lines="1" class="animation-container-small mb-1" />
{{ user.name }}
</h5>
<div class="text-secondary mb-2">
<span v-if="user.username">@{{ user.username }}</span>
<gl-skeleton-loading v-else :lines="1" class="animation-container-small mb-1" />
<span class="text-secondary">@{{ user.username }}</span>
</div>
<div class="text-secondary">
<div v-if="user.bio" class="d-flex mb-1">
......@@ -77,35 +78,20 @@ export default {
<span ref="bio" class="ml-1">{{ user.bio }}</span>
</div>
<div v-if="user.workInformation" class="d-flex mb-1">
<icon
v-show="!workInformationIsLoading"
name="work"
class="category-icon flex-shrink-0"
/>
<icon name="work" class="category-icon flex-shrink-0" />
<span ref="workInformation" class="ml-1">{{ user.workInformation }}</span>
</div>
<gl-skeleton-loading
v-if="workInformationIsLoading"
:lines="1"
class="animation-container-small mb-1"
/>
</div>
<div class="js-location text-secondary d-flex">
<icon
v-show="!locationIsLoading && user.location"
name="location"
class="category-icon flex-shrink-0"
/>
<span v-if="user.location" class="ml-1">{{ user.location }}</span>
<gl-skeleton-loading
v-if="locationIsLoading"
:lines="1"
class="animation-container-small mb-1"
/>
<div v-if="user.location">
<icon name="location" class="category-icon flex-shrink-0" />
<span class="ml-1">{{ user.location }}</span>
</div>
</div>
<div v-if="statusHtml" class="js-user-status mt-2">
<span v-html="statusHtml"></span>
</div>
</template>
</div>
</div>
</gl-popover>
......
......@@ -4,7 +4,6 @@ import UserPopover from '~/vue_shared/components/user_popover/user_popover.vue';
import Icon from '~/vue_shared/components/icon.vue';
const DEFAULT_PROPS = {
loaded: true,
user: {
username: 'root',
name: 'Administrator',
......@@ -12,6 +11,7 @@ const DEFAULT_PROPS = {
bio: null,
workInformation: null,
status: null,
loaded: true,
},
};
......@@ -46,13 +46,9 @@ describe('User Popover Component', () => {
});
};
describe('Empty', () => {
beforeEach(() => {
createWrapper(
{},
{
propsData: {
target: findTarget(),
describe('when user is loading', () => {
it('displays skeleton loaders', () => {
createWrapper({
user: {
name: null,
username: null,
......@@ -60,14 +56,11 @@ describe('User Popover Component', () => {
bio: null,
workInformation: null,
status: null,
loaded: false,
},
},
},
);
});
it('should return skeleton loaders', () => {
expect(wrapper.find(GlSkeletonLoading).exists()).toBe(true);
expect(wrapper.findAll(GlSkeletonLoading)).toHaveLength(4);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment