Merge pull request #2512 from Human-Connection/refactor_content_menu

Refactor: content menu
This commit is contained in:
mattwr18 2019-12-16 16:13:45 +01:00 committed by GitHub
commit c2bb406502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 25 deletions

View File

@ -22,10 +22,6 @@ describe('ContentMenu.vue', () => {
locale: () => 'en',
},
$router: {
resolve: jest.fn(obj => {
obj.href = '/post/edit/d23a4265-f5f7-4e17-9f86-85f714b4b9f8'
return obj
}),
push: jest.fn(),
},
}
@ -76,7 +72,7 @@ describe('ContentMenu.vue', () => {
.at(0)
.find('span.ds-menu-item-link')
.attributes('to'),
).toBe('/post/edit/d23a4265-f5f7-4e17-9f86-85f714b4b9f8')
).toBe('/post-edit-id')
})
it('can delete the contribution', () => {

View File

@ -17,7 +17,7 @@
@click.stop.prevent="openItem(item.route, toggleMenu)"
>
<base-icon :name="item.route.icon" />
{{ item.route.name }}
{{ item.route.label }}
</ds-menu-item>
</ds-menu>
</div>
@ -58,17 +58,15 @@ export default {
if (this.resourceType === 'contribution') {
if (this.isOwner) {
routes.push({
name: this.$t(`post.menu.edit`),
path: this.$router.resolve({
name: 'post-edit-id',
params: {
id: this.resource.id,
},
}).href,
label: this.$t(`post.menu.edit`),
name: 'post-edit-id',
params: {
id: this.resource.id,
},
icon: 'edit',
})
routes.push({
name: this.$t(`post.menu.delete`),
label: this.$t(`post.menu.delete`),
callback: () => {
this.openModal('confirm', 'delete')
},
@ -79,7 +77,7 @@ export default {
if (this.isAdmin) {
if (!this.resource.pinnedBy) {
routes.push({
name: this.$t(`post.menu.pin`),
label: this.$t(`post.menu.pin`),
callback: () => {
this.$emit('pinPost', this.resource)
},
@ -87,7 +85,7 @@ export default {
})
} else {
routes.push({
name: this.$t(`post.menu.unpin`),
label: this.$t(`post.menu.unpin`),
callback: () => {
this.$emit('unpinPost', this.resource)
},
@ -99,14 +97,14 @@ export default {
if (this.isOwner && this.resourceType === 'comment') {
routes.push({
name: this.$t(`comment.menu.edit`),
label: this.$t(`comment.menu.edit`),
callback: () => {
this.$emit('showEditCommentMenu', true)
},
icon: 'edit',
})
routes.push({
name: this.$t(`comment.menu.delete`),
label: this.$t(`comment.menu.delete`),
callback: () => {
this.openModal('confirm', 'delete')
},
@ -116,7 +114,7 @@ export default {
if (!this.isOwner) {
routes.push({
name: this.$t(`report.${this.resourceType}.title`),
label: this.$t(`report.${this.resourceType}.title`),
callback: () => {
this.openModal('report')
},
@ -127,7 +125,7 @@ export default {
if (!this.isOwner && this.isModerator) {
if (!this.resource.disabled) {
routes.push({
name: this.$t(`disable.${this.resourceType}.title`),
label: this.$t(`disable.${this.resourceType}.title`),
callback: () => {
this.openModal('disable')
},
@ -135,7 +133,7 @@ export default {
})
} else {
routes.push({
name: this.$t(`release.${this.resourceType}.title`),
label: this.$t(`release.${this.resourceType}.title`),
callback: () => {
this.openModal('release')
},
@ -147,14 +145,14 @@ export default {
if (this.resourceType === 'user') {
if (this.isOwner) {
routes.push({
name: this.$t(`settings.name`),
label: this.$t(`settings.name`),
path: '/settings',
icon: 'edit',
})
} else {
if (this.resource.isBlocked) {
routes.push({
name: this.$t(`settings.blocked-users.unblock`),
label: this.$t(`settings.blocked-users.unblock`),
callback: () => {
this.$emit('unblock', this.resource)
},
@ -162,7 +160,7 @@ export default {
})
} else {
routes.push({
name: this.$t(`settings.blocked-users.block`),
label: this.$t(`settings.blocked-users.block`),
callback: () => {
this.$emit('block', this.resource)
},
@ -186,7 +184,7 @@ export default {
if (route.callback) {
route.callback()
} else {
this.$router.push(route.path)
this.$router.push(route)
}
toggleMenu()
},