Commit 7892570f authored by Clement Ho's avatar Clement Ho

[skip ci] refactor and remove show more assignees

parent 098beb7d
import ShowMoreAssignees from './show_more_assignees';
export default { export default {
name: 'MultipleAssignees', name: 'MultipleAssignees',
data() { data() {
return { return {
showMore: false, showLess: true,
defaultRenderCount: 5,
}; };
}, },
props: { props: {
...@@ -14,41 +13,57 @@ export default { ...@@ -14,41 +13,57 @@ export default {
rootPath() { rootPath() {
return this.assignees.rootPath; return this.assignees.rootPath;
}, },
shouldShowMoreAssignees() { renderShowMoreSection() {
return this.assignees.users.length > 5; return this.assignees.users.length > this.defaultRenderCount;
}, },
numberOfHiddenAssignees() { numberOfHiddenAssignees() {
return this.showMore ? 0 : this.assignees.users.length - 5; return this.assignees.users.length - this.defaultRenderCount;
}, },
toggleShowMore() { isHiddenAssignees() {
return function toggleShowMore() { return this.numberOfHiddenAssignees > 0;
this.showMore = !this.showMore;
}.bind(this);
}, },
}, },
components: { methods: {
'show-more-assignees': ShowMoreAssignees, toggleShowLess() {
this.showLess = !this.showLess;
},
renderAssignee(index) {
return !this.showLess || (index < this.defaultRenderCount && this.showLess);
},
assigneeUrl(username) {
return `${this.rootPath}${username}`;
},
assigneeAlt(name) {
return `${name}'s avatar`;
},
}, },
template: ` template: `
<div class="hide-collapsed"> <div class="hide-collapsed">
<div class="hide-collapsed"> <div class="hide-collapsed">
<div class="user-list"> <div class="user-list">
<div class="user-item" v-for="(user, index) in assignees.users" <div class="user-item" v-for="(user, index) in assignees.users"
v-if="showMore || (index < 5 && !showMore)" > v-if="renderAssignee(index)" >
<a class="user-link has-tooltip" <a class="user-link has-tooltip"
data-placement="bottom" data-placement="bottom"
:href="rootPath + user.username" :href="assigneeUrl(user.username)"
:data-title="user.name" > :data-title="user.name" >
<img width="32" <img width="32"
class="avatar avatar-inline s32" class="avatar avatar-inline s32"
:alt="user.name + '\\'s avatar'" :alt="assigneeAlt(user.name)"
:src="user.avatarUrl" > :src="user.avatarUrl" >
</a> </a>
</div> </div>
</div> </div>
<show-more-assignees v-if="shouldShowMoreAssignees" <div class="user-list-more" v-if="renderShowMoreSection">
:hiddenAssignees="numberOfHiddenAssignees" <button type="button" class="btn-link" @click="toggleShowLess">
:toggle="toggleShowMore" /> <template v-if="showLess">
+ {{numberOfHiddenAssignees}} more
</template>
<template v-else>
- show less
</template>
</button>
</div>
</div> </div>
</div> </div>
`, `,
......
export default {
name: 'ShowMoreAssignees',
props: {
hiddenAssignees: { type: Number, required: true },
toggle: { type: Function, required: true },
},
computed: {
showMore() {
return this.hiddenAssignees > 0;
},
},
template: `
<div class="user-list-more">
<button type="button" class="btn-link" @click="toggle">
<template v-if="showMore">
+ {{hiddenAssignees}} more
</template>
<template v-else>
- show less
</template>
</button>
</div>
`,
};
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