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'; ...@@ -4,8 +4,11 @@ import Icon from '~/vue_shared/components/icon.vue';
import UserAvatarImage from '../user_avatar/user_avatar_image.vue'; import UserAvatarImage from '../user_avatar/user_avatar_image.vue';
import { glEmojiTag } from '../../../emoji'; import { glEmojiTag } from '../../../emoji';
const MAX_SKELETON_LINES = 4;
export default { export default {
name: 'UserPopover', name: 'UserPopover',
maxSkeletonLines: MAX_SKELETON_LINES,
components: { components: {
Icon, Icon,
GlPopover, GlPopover,
...@@ -22,11 +25,6 @@ export default { ...@@ -22,11 +25,6 @@ export default {
required: true, required: true,
default: null, default: null,
}, },
loaded: {
type: Boolean,
required: false,
default: false,
},
}, },
computed: { computed: {
statusHtml() { statusHtml() {
...@@ -42,14 +40,8 @@ export default { ...@@ -42,14 +40,8 @@ export default {
return ''; return '';
}, },
nameIsLoading() { userIsLoading() {
return !this.user.name; return !this.user?.loaded;
},
workInformationIsLoading() {
return !this.user.loaded && this.user.workInformation === null;
},
locationIsLoading() {
return !this.user.loaded && this.user.location === null;
}, },
}, },
}; };
...@@ -63,49 +55,43 @@ export default { ...@@ -63,49 +55,43 @@ export default {
<user-avatar-image :img-src="user.avatarUrl" :size="60" css-classes="mr-2" /> <user-avatar-image :img-src="user.avatarUrl" :size="60" css-classes="mr-2" />
</div> </div>
<div class="p-1 w-100"> <div class="p-1 w-100">
<h5 class="m-0"> <template v-if="userIsLoading">
<span v-if="user.name">{{ user.name }}</span> <!-- `gl-skeleton-loading` does not support equal length lines -->
<gl-skeleton-loading v-else :lines="1" class="animation-container-small mb-1" /> <!-- This can be migrated to `gl-skeleton-loader` when https://gitlab.com/gitlab-org/gitlab-ui/-/issues/872 is completed -->
</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" />
</div>
<div class="text-secondary">
<div v-if="user.bio" class="d-flex mb-1">
<icon name="profile" class="category-icon flex-shrink-0" />
<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"
/>
<span ref="workInformation" class="ml-1">{{ user.workInformation }}</span>
</div>
<gl-skeleton-loading <gl-skeleton-loading
v-if="workInformationIsLoading" v-for="n in $options.maxSkeletonLines"
:key="n"
:lines="1" :lines="1"
class="animation-container-small mb-1" class="animation-container-small mb-1"
/> />
</div> </template>
<div class="js-location text-secondary d-flex"> <template v-else>
<icon <div class="mb-2">
v-show="!locationIsLoading && user.location" <h5 class="m-0">
name="location" {{ user.name }}
class="category-icon flex-shrink-0" </h5>
/> <span class="text-secondary">@{{ user.username }}</span>
<span v-if="user.location" class="ml-1">{{ user.location }}</span> </div>
<gl-skeleton-loading <div class="text-secondary">
v-if="locationIsLoading" <div v-if="user.bio" class="d-flex mb-1">
:lines="1" <icon name="profile" class="category-icon flex-shrink-0" />
class="animation-container-small mb-1" <span ref="bio" class="ml-1">{{ user.bio }}</span>
/> </div>
</div> <div v-if="user.workInformation" class="d-flex mb-1">
<div v-if="statusHtml" class="js-user-status mt-2"> <icon name="work" class="category-icon flex-shrink-0" />
<span v-html="statusHtml"></span> <span ref="workInformation" class="ml-1">{{ user.workInformation }}</span>
</div> </div>
</div>
<div class="js-location text-secondary d-flex">
<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>
</div> </div>
</gl-popover> </gl-popover>
......
...@@ -4,7 +4,6 @@ import UserPopover from '~/vue_shared/components/user_popover/user_popover.vue'; ...@@ -4,7 +4,6 @@ import UserPopover from '~/vue_shared/components/user_popover/user_popover.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
const DEFAULT_PROPS = { const DEFAULT_PROPS = {
loaded: true,
user: { user: {
username: 'root', username: 'root',
name: 'Administrator', name: 'Administrator',
...@@ -12,6 +11,7 @@ const DEFAULT_PROPS = { ...@@ -12,6 +11,7 @@ const DEFAULT_PROPS = {
bio: null, bio: null,
workInformation: null, workInformation: null,
status: null, status: null,
loaded: true,
}, },
}; };
...@@ -46,28 +46,21 @@ describe('User Popover Component', () => { ...@@ -46,28 +46,21 @@ describe('User Popover Component', () => {
}); });
}; };
describe('Empty', () => { describe('when user is loading', () => {
beforeEach(() => { it('displays skeleton loaders', () => {
createWrapper( createWrapper({
{}, user: {
{ name: null,
propsData: { username: null,
target: findTarget(), location: null,
user: { bio: null,
name: null, workInformation: null,
username: null, status: null,
location: null, loaded: false,
bio: null,
workInformation: null,
status: null,
},
},
}, },
); });
});
it('should return skeleton loaders', () => { expect(wrapper.findAll(GlSkeletonLoading)).toHaveLength(4);
expect(wrapper.find(GlSkeletonLoading).exists()).toBe(true);
}); });
}); });
......
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