Skip to content

Commit

Permalink
fix: comment delete not working (#8714)
Browse files Browse the repository at this point in the history
* fix: missing ui acl

* fix: remove unwanted ref fix: wrap condition in template
  • Loading branch information
DarkPhoenix2704 committed Jun 13, 2024
1 parent 7dc4319 commit 88278a7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
53 changes: 40 additions & 13 deletions packages/nc-gui/components/smartsheet/expanded-form/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const route = useRoute()
const { dashboardUrl } = useDashboard()
const editRef = ref<any>()
const { user, appInfo } = useGlobal()
const isExpandedFormLoading = computed(() => props.loading)
Expand Down Expand Up @@ -108,6 +106,9 @@ onKeyStroke('Enter', (event) => {
function editComments(comment: CommentType) {
editComment.value = comment
isEditing.value = true
nextTick(() => {
scrollToComment(comment.id)
})
}
const value = computed({
Expand Down Expand Up @@ -225,6 +226,21 @@ const createdBy = (
return 'Shared source'
}
}
const getUserRole = (email: string) => {
const user = baseUsers.value.find((user) => user.email === email)
if (!user) return ProjectRoles.NO_ACCESS
return user.roles || ProjectRoles.NO_ACCESS
}
const editedAt = (comment: CommentType) => {
if (comment.updated_at !== comment.created_at && comment.updated_at) {
const str = timeAgo(comment.updated_at).replace(' ', '_')
return `[(edited)](a~~~###~~~Edited_${str}) `
}
return ''
}
</script>

<template>
Expand Down Expand Up @@ -286,10 +302,8 @@ const createdBy = (
</div>
<div class="flex items-center gap-2">
<NcDropdown
v-if="(comment.created_by_email === user!.email && !editComment )"
:class="{
'opacity-0 group-hover:opacity-100': comment.created_by_email === user!.email && !editComment,
}"
v-if="!editCommentValue"
class="!hidden !group-hover:block"
overlay-class-name="!min-w-[160px]"
placement="bottomRight"
>
Expand All @@ -299,6 +313,7 @@ const createdBy = (
<template #overlay>
<NcMenu>
<NcMenuItem
v-if="user && comment.created_by_email === user.email"
v-e="['c:comment-expand:comment:edit']"
class="text-gray-700"
@click="editComments(comment)"
Expand All @@ -309,15 +324,28 @@ const createdBy = (
</div>
</NcMenuItem>
<NcMenuItem
v-e="['c:row-expand:comment:delete']"
class="!text-red-500 !hover:bg-red-50"
@click="deleteComment(comment.id!)"
v-e="['c:comment-expand:comment:copy']"
class="text-gray-700"
@click="copyComment(comment)"
>
<div class="flex gap-2 items-center">
<component :is="iconMap.delete" class="cursor-pointer" />
{{ $t('general.delete') }}
<component :is="iconMap.copy" class="cursor-pointer" />
{{ $t('general.copy') }} URL
</div>
</NcMenuItem>
<template v-if="user && comment.created_by_email === user.email">
<NcDivider />
<NcMenuItem
v-e="['c:row-expand:comment:delete']"
class="!text-red-500 !hover:bg-red-50"
@click="deleteComment(comment.id!)"
>
<div class="flex gap-2 items-center">
<component :is="iconMap.delete" class="cursor-pointer" />
{{ $t('general.delete') }}
</div>
</NcMenuItem>
</template>
</NcMenu>
</template>
</NcDropdown>
Expand Down Expand Up @@ -352,8 +380,7 @@ const createdBy = (
</div>
<div class="flex-1 flex flex-col gap-1 mt-1 max-w-[calc(100%)]">
<SmartsheetExpandedFormRichComment
v-if="comment.id === editComment?.id"
ref="editRef"
v-if="comment.id === editCommentValue?.id"
v-model:value="value"
autofocus
:hide-options="false"
Expand Down
1 change: 1 addition & 0 deletions packages/nc-gui/composables/useExpandedFormStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
}

const resolveComment = async (commentId: string) => {
if (!isUIAllowed('commentResolve')) return
const tempC = comments.value.find((c) => c.id === commentId)

try {
Expand Down
2 changes: 2 additions & 0 deletions packages/nc-gui/lib/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const rolePermissions = {
},
[ProjectRoles.COMMENTER]: {
include: {
commentDelete: true,
commentResolve: true,
commentEdit: true,
commentList: true,
commentCount: true,
Expand Down

0 comments on commit 88278a7

Please sign in to comment.