Commit 09060d19 authored by peterhegman's avatar peterhegman

Simplify user popover loading logic

There were a number of computed properties that did the same thing
parent 8dd8e6ad
...@@ -22,11 +22,6 @@ export default { ...@@ -22,11 +22,6 @@ export default {
required: true, required: true,
default: null, default: null,
}, },
loaded: {
type: Boolean,
required: false,
default: false,
},
}, },
computed: { computed: {
statusHtml() { statusHtml() {
...@@ -42,14 +37,8 @@ export default { ...@@ -42,14 +37,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 +52,41 @@ export default { ...@@ -63,49 +52,41 @@ 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 v-else :lines="1" class="animation-container-small mb-1" />
</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
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 <gl-skeleton-loading
v-if="locationIsLoading" v-for="n in 4"
:key="n"
:lines="1" :lines="1"
class="animation-container-small mb-1" class="animation-container-small mb-1"
/> />
</div> </template>
<div v-if="statusHtml" class="js-user-status mt-2"> <template v-else>
<span v-html="statusHtml"></span> <div class="mb-2">
</div> <h5 class="m-0">
{{ user.name }}
</h5>
<span class="text-secondary">@{{ user.username }}</span>
</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 name="work" class="category-icon flex-shrink-0" />
<span ref="workInformation" class="ml-1">{{ user.workInformation }}</span>
</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