Browse Source

feat: audit log

pull/6464/head
DarkPhoenix2704 1 year ago
parent
commit
c4f52bbb10
  1. 100
      packages/nc-gui/components/smartsheet/expanded-form/Comments.vue
  2. 14
      packages/nc-gui/components/smartsheet/expanded-form/index.vue
  3. 2
      packages/nc-gui/composables/useExpandedFormStore.ts

100
packages/nc-gui/components/smartsheet/expanded-form/Comments.vue

@ -4,8 +4,7 @@ import type { AuditType } from 'nocodb-sdk'
import { Icon } from '@iconify/vue' import { Icon } from '@iconify/vue'
import { ref, timeAgo, useExpandedFormStoreOrThrow, useGlobal, useRoles, watch } from '#imports' import { ref, timeAgo, useExpandedFormStoreOrThrow, useGlobal, useRoles, watch } from '#imports'
const { loadCommentsAndLogs, commentsAndLogs, isCommentsLoading, saveComment, comment, updateComment } = const { loadCommentsAndLogs, commentsAndLogs, isYou, saveComment, comment, updateComment } = useExpandedFormStoreOrThrow()
useExpandedFormStoreOrThrow()
const commentsWrapperEl = ref<HTMLDivElement>() const commentsWrapperEl = ref<HTMLDivElement>()
@ -60,6 +59,7 @@ function onCancel() {
} }
function onStopEdit() { function onStopEdit() {
loadCommentsAndLogs()
isEditing.value = false isEditing.value = false
editLog.value = undefined editLog.value = undefined
} }
@ -71,6 +71,7 @@ onKeyStroke('Enter', (event) => {
}) })
const comments = computed(() => commentsAndLogs.value.filter((log) => log.op_type === 'COMMENT')) const comments = computed(() => commentsAndLogs.value.filter((log) => log.op_type === 'COMMENT'))
const audits = computed(() => commentsAndLogs.value.filter((log) => log.op_type !== 'COMMENT'))
function editComment(log: AuditType) { function editComment(log: AuditType) {
editLog.value = log editLog.value = log
@ -128,16 +129,12 @@ watch(
ref="commentsWrapperEl" ref="commentsWrapperEl"
class="flex flex-col m-1 p-1 !h-[calc(100vh-300px)] overflow-y-scroll nc-scrollbar-md space-y-2" class="flex flex-col m-1 p-1 !h-[calc(100vh-300px)] overflow-y-scroll nc-scrollbar-md space-y-2"
> >
<a-skeleton v-if="isCommentsLoading" type="list-item-avatar-two-line@8" /> <template v-if="commentsAndLogs.length === 0">
<template v-else-if="commentsAndLogs.length === 0">
<div class="flex flex-col text-center justify-center h-full"> <div class="flex flex-col text-center justify-center h-full">
<div class="text-center text-3xl text-gray-300"> <div class="text-center text-3xl text-gray-300">
<MdiChatProcessingOutline /> <MdiChatProcessingOutline />
</div> </div>
<div class="font-bold text-center my-1 text-gray-400">Start a conversation</div> <div class="font-bold text-center my-1 text-gray-400">Start a conversation</div>
<div class="text-gray-400">
NocoDB allows you to inquire, monitor progress updates, and collaborate with your team members.
</div>
</div> </div>
</template> </template>
<template v-else> <template v-else>
@ -146,7 +143,8 @@ watch(
<div class="flex flex-col p-4 gap-3"> <div class="flex flex-col p-4 gap-3">
<div class="flex justify-between"> <div class="flex justify-between">
<div class="flex font-bold items-center gap-2"> <div class="flex font-bold items-center gap-2">
<MdiAccountCircleOutline class="row-span-2 h-8 w-8" /> <GeneralUserIcon v-if="isYou(log.user)" />
<MdiAccountCircleOutline v-else class="h-6 w-6" />
<span class="truncate max-w-42"> <span class="truncate max-w-42">
{{ log.user ?? 'Shared base' }} {{ log.user ?? 'Shared base' }}
</span> </span>
@ -181,76 +179,32 @@ watch(
</div> </div>
</div> </div>
</div> </div>
<!-- <a-dropdown :trigger="['contextmenu']" :overlay-class-name="`nc-dropdown-comment-context-menu-${idx}`"> </div>
<div class="flex gap-1 text-xs"> </template>
<component </div>
:is="iconMap.accountCircle" <div v-else class="flex flex-col m-1 p-1 !h-[calc(100vh-239px)] overflow-y-scroll nc-scrollbar-md space-y-2">
class="row-span-2" <div v-for="(log, idx) of audits" :key="log.id">
:class="isYou(log.user) ? 'text-pink-600' : 'text-blue-600 '" <div class="bg-white rounded-xl border-1 gap-3 border-gray-200">
/> <div class="flex flex-col p-4 gap-3">
<div class="flex justify-between">
<div class="flex-1"> <div class="flex font-bold items-end gap-2">
<p class="mb-1 caption edited-text text-[10px] text-gray-500"> <GeneralUserIcon v-if="isYou(log.user)" />
{{ log.op_type === 'COMMENT' ? 'commented' : log.op_sub_type === 'INSERT' ? 'created' : 'edited' }} <MdiAccountCircleOutline v-else class="row-span-2 h-6 w-6" />
</p> <span class="truncate max-w-50">
{{ log.user ?? 'Shared base' }}
<div v-if="log.op_type === 'COMMENT'"> </span>
<a-input </div>
v-if="log.id === editLog?.id" </div>
:ref="focusInput" <div class="text-sm text-gray-700">
v-model:value="editLog.description" {{ log.description }}
@blur="onCancel"
@keydown.stop="onKeyDown($event)"
/>
<p
v-else
class="block caption my-2 nc-chip w-full min-h-20px p-2 rounded"
:style="{ backgroundColor: enumColor.light[2] }"
>
retrieve the comment part from the audit description
`The following comment has been created: foo` -> `foo`
{{ log.description.substring(log.description.indexOf(':') + 1) }}
</p>
</div> </div>
<div v-if="log.id !== editLog?.id" class="text-xs text-gray-500">
<p v-else-if="log.details" v-dompurify-html="log.details" class="caption my-3" style="word-break: break-all" /> {{ timeAgo(log.created_at) }}
<p v-else>{{ log.description }}</p>
<p class="time text-right text-[10px] mb-0 mt-1 text-gray-500">
{{ timeAgo(log.created_at) }}
</p>
</div> </div>
</div> </div>
<template #overlay>
<a-menu v-if="log.op_type === 'COMMENT'" @click="contextMenu = false">
<a-menu-item key="copy-comment" @click="copyComment(log.description)">
<div v-e="['a:comment:copy']" class="nc-project-menu-item">
{{ t('general.copy') }}
</div>
</a-menu-item>
<a-menu-item v-if="log.user === user.email " key="edit-comment" ">
<div v-e="['a:comment:edit']" class="nc-project-menu-item">
{{ t('general.edit') }}
</div>
</a-menu-item>
</a-menu>
</template>
</a-dropdown> -->
</div> </div>
</template> </div>
</div> </div>
<!-- <div class="flex justify-center">
<a-checkbox v-model:checked="commentsOnly" v-e="['c:row-expand:comment-only']" @change="loadCommentsAndLogs">
{{ $t('labels.commentsOnly') }}
<span class="text-[11px] text-gray-500" />
</a-checkbox>
</div> -->
<div v-if="hasEditPermission && tab === 'comments'" class="shrink mt-2 p-2 rounded-b-xl border-t-1 bg-white gap-1 flex"> <div v-if="hasEditPermission && tab === 'comments'" class="shrink mt-2 p-2 rounded-b-xl border-t-1 bg-white gap-1 flex">
<a-input <a-input
v-model:value="comment" v-model:value="comment"

14
packages/nc-gui/components/smartsheet/expanded-form/index.vue

@ -344,12 +344,14 @@ export default {
> >
<div class="flex w-full items-center relative pb-2 justify-between"> <div class="flex w-full items-center relative pb-2 justify-between">
<div class="flex gap-3"> <div class="flex gap-3">
<NcButton v-if="props.showNextPrevIcons" type="secondary" size="small" class="nc-prev-arrow" @click="$emit('prev')"> <div class="flex gap-1">
<MdiChevronUp class="text-md text-gray-700" /> <NcButton v-if="props.showNextPrevIcons" type="secondary" size="small" class="nc-prev-arrow" @click="$emit('prev')">
</NcButton> <MdiChevronUp class="text-md text-gray-700" />
<NcButton v-if="!props.lastRow" type="secondary" size="small" class="nc-next-arrow" @click="onNext"> </NcButton>
<MdiChevronDown class="text-md text-gray-700" /> <NcButton v-if="!props.lastRow" type="secondary" size="small" class="nc-next-arrow" @click="onNext">
</NcButton> <MdiChevronDown class="text-md text-gray-700" />
</NcButton>
</div>
<div v-if="displayValue" class="flex items-center font-bold text-gray-800 text-xl"> <div v-if="displayValue" class="flex items-center font-bold text-gray-800 text-xl">
{{ displayValue }} {{ displayValue }}
</div> </div>

2
packages/nc-gui/composables/useExpandedFormStore.ts

@ -31,7 +31,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
const { t } = useI18n() const { t } = useI18n()
const commentsOnly = ref(true) const commentsOnly = ref(false)
const commentsAndLogs = ref<any[]>([]) const commentsAndLogs = ref<any[]>([])

Loading…
Cancel
Save