Commit 4d41405c authored by Clement Ho's avatar Clement Ho

[skip ci] add more computed props

parent 6ead98de
...@@ -18,6 +18,24 @@ export default { ...@@ -18,6 +18,24 @@ export default {
}, },
}, },
computed: { computed: {
firstUser() {
return this.users[0];
},
hasMoreThanTwoAssignees() {
return this.users.length > 2;
},
hasMoreThanOneAssignee() {
return this.users.length > 1;
},
hasAssignees() {
return this.users.length > 0;
},
hasNoUsers() {
return !this.users.length;
},
hasOneUser() {
return this.users.length === 1;
},
renderShowMoreSection() { renderShowMoreSection() {
return this.users.length > this.defaultRenderCount; return this.users.length > this.defaultRenderCount;
}, },
...@@ -27,6 +45,9 @@ export default { ...@@ -27,6 +45,9 @@ export default {
isHiddenAssignees() { isHiddenAssignees() {
return this.numberOfHiddenAssignees > 0; return this.numberOfHiddenAssignees > 0;
}, },
hiddenAssigneesLabel() {
return `+ ${this.numberOfHiddenAssignees} more`;
},
collapsedTooltipTitle() { collapsedTooltipTitle() {
const maxRender = Math.min(this.defaultRenderCount, this.users.length); const maxRender = Math.min(this.defaultRenderCount, this.users.length);
const renderUsers = this.users.slice(0, maxRender); const renderUsers = this.users.slice(0, maxRender);
...@@ -64,26 +85,32 @@ export default { ...@@ -64,26 +85,32 @@ export default {
assigneeAlt(user) { assigneeAlt(user) {
return `${user.name}'s avatar`; return `${user.name}'s avatar`;
}, },
assigneeUsername(user) {
return `@${user.username}`;
},
shouldRenderCollapsedAssignee(index) {
return index === 0 || this.users.length <= 2 && index <= 2
}
}, },
template: ` template: `
<div> <div>
<div <div
class="sidebar-collapsed-icon sidebar-collapsed-user" class="sidebar-collapsed-icon sidebar-collapsed-user"
:class="{ 'multiple-users': users.length > 1, 'has-tooltip': users.length > 0}" :class="{ 'multiple-users': hasMoreThanOneAssignee, 'has-tooltip': hasAssignees }"
data-container="body" data-container="body"
data-placement="left" data-placement="left"
:title="collapsedTooltipTitle" :title="collapsedTooltipTitle"
> >
<i <i
v-if="users.length === 0" v-if="hasNoUsers"
aria-hidden="true" aria-label="No Assignee"
class="fa fa-user" class="fa fa-user"
/> />
<button <button
type="button" type="button"
class="btn-link" class="btn-link"
v-for="(user, index) in users" v-for="(user, index) in users"
v-if="index === 0 || users.length <= 2 && index <= 2" v-if="shouldRenderCollapsedAssignee(index)"
> >
<img <img
width="24" width="24"
...@@ -91,22 +118,24 @@ export default { ...@@ -91,22 +118,24 @@ export default {
:alt="assigneeAlt(user)" :alt="assigneeAlt(user)"
:src="user.avatar_url" :src="user.avatar_url"
/> />
<span class="author">{{user.name}}</span> <span class="author">
{{ user.name }}
</span>
</button> </button>
<button <button
v-if="users.length > 2" v-if="hasMoreThanTwoAssignees"
class="btn-link" class="btn-link"
type="button" type="button"
> >
<span <span
class="avatar-counter sidebar-avatar-counter" class="avatar-counter sidebar-avatar-counter"
> >
{{sidebarAvatarCounter}} {{ sidebarAvatarCounter }}
</span> </span>
</button> </button>
</div> </div>
<div class="value hide-collapsed"> <div class="value hide-collapsed">
<template v-if="users.length === 0"> <template v-if="hasNoUsers">
<span class="assign-yourself no-value"> <span class="assign-yourself no-value">
No assignee - No assignee -
<button <button
...@@ -118,19 +147,23 @@ export default { ...@@ -118,19 +147,23 @@ export default {
</button> </button>
</span> </span>
</template> </template>
<template v-else-if="users.length === 1"> <template v-else-if="hasOneUser">
<a <a
class="author_link bold" class="author_link bold"
:href="assigneeUrl(users[0])" :href="assigneeUrl(firstUser)"
> >
<img <img
width="32" width="32"
class="avatar avatar-inline s32" class="avatar avatar-inline s32"
:alt="assigneeAlt(users[0])" :alt="assigneeAlt(firstUser)"
:src="users[0].avatar_url" :src="firstUser.avatar_url"
/> />
<span class="author">{{users[0].name}}</span> <span class="author">
<span class="username">@{{users[0].username}}</span> {{ firstUser.name }}
</span>
<span class="username">
{{ assigneeUsername(firstUser) }}
</span>
</a> </a>
</template> </template>
<template v-else> <template v-else>
...@@ -165,7 +198,7 @@ export default { ...@@ -165,7 +198,7 @@ export default {
@click="toggleShowLess" @click="toggleShowLess"
> >
<template v-if="showLess"> <template v-if="showLess">
+ {{numberOfHiddenAssignees}} more {{ hiddenAssigneesLabel }}
</template> </template>
<template v-else> <template v-else>
- show less - show less
......
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