Browse Source

fix(nc-gui): add search option in dropdown

pull/8836/head
Ramesh Mane 5 months ago
parent
commit
46e8e59a74
  1. 6
      packages/nc-gui/assets/nc-icons/chevron-up-down.svg
  2. 387
      packages/nc-gui/components/workspace/AuditLogs.vue
  3. 2
      packages/nc-gui/utils/iconUtils.ts

6
packages/nc-gui/assets/nc-icons/chevron-up-down.svg

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" class="flex-none">
<path d="M12 6L8 2L4 6" stroke="currentColor" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"
class="up" />
<path d=" M4 10L8 14L12 10" stroke="currentColor" stroke-width="1.33333" stroke-linecap="round"
stroke-linejoin="round" class="down" />
</svg>

After

Width:  |  Height:  |  Size: 410 B

387
packages/nc-gui/components/workspace/AuditLogs.vue

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { Empty } from 'ant-design-vue' import { Empty } from 'ant-design-vue'
import type { VNodeRef } from '@vue/runtime-core'
import type { AuditType, WorkspaceUserType } from 'nocodb-sdk' import type { AuditType, WorkspaceUserType } from 'nocodb-sdk'
import { import {
AuditOperationSubTypes, AuditOperationSubTypes,
@ -68,6 +69,14 @@ const auditDropdowns = ref({
user: false, user: false,
}) })
const auditDropdownsSearch = ref({
type: '',
base: '',
user: '',
})
console.log('changing')
const auditTypeOptions = computed(() => { const auditTypeOptions = computed(() => {
return Object.values(AuditOperationTypes) return Object.values(AuditOperationTypes)
.filter((type) => allowedAuditOperationTypes.includes(type as AuditOperationTypes)) .filter((type) => allowedAuditOperationTypes.includes(type as AuditOperationTypes))
@ -154,6 +163,27 @@ onMounted(async () => {
await loadAudits(currentPage.value, currentLimit.value) await loadAudits(currentPage.value, currentLimit.value)
} }
}) })
watchEffect(() => {
console.log('auditDropdownsSearch', auditDropdownsSearch.value)
})
watch(
auditDropdownsSearch,
() => {
console.log('fdlsa', auditDropdownsSearch.value)
},
{ deep: true },
)
const focusUserSearchRef: VNodeRef = (el) => {
return el && auditDropdowns.value.user && el?.focus?.()
}
const focusBaseSearchRef: VNodeRef = (el) => {
return el && auditDropdowns.value.base && el?.focus?.()
}
const focusTypeSearchRef: VNodeRef = (el) => {
return el && auditDropdowns.value.type && el?.focus?.()
}
</script> </script>
<template> <template>
@ -187,133 +217,184 @@ onMounted(async () => {
@keydown.enter.exact="loadAudits" @keydown.enter.exact="loadAudits"
> >
<template #prefix> <template #prefix>
<GeneralIcon icon="search" class="mr-2 h-4 w-4 text-gray-500 group-hover:text-black" /> <GeneralIcon icon="search" class="mr-1 h-4 w-4 text-gray-500 group-hover:text-black" />
</template> </template>
<template #suffix> <template #suffix>
<GeneralIcon <GeneralIcon
v-if="auditLogsQuery.search && auditLogsQuery.search.length > 0" v-if="auditLogsQuery.search && auditLogsQuery.search.length > 0"
icon="close" icon="close"
class="ml-2 h-4 w-4 text-gray-500 group-hover:text-black" class="ml-1 h-4 w-4 text-gray-500 group-hover:text-black"
data-testid="nc-audit-logs-clear-search" data-testid="nc-audit-logs-clear-search"
@click="auditLogsQuery.search = undefined" @click="auditLogsQuery.search = undefined"
/> />
</template> </template>
</a-input> </a-input>
</form> </form>
<div class="flex items-stretch border-1 border-gray-200 rounded-lg overflow-hidden h-8"> <NcDropdown
<NcDropdown v-model:visible="auditDropdowns.type"> v-if="collaborators?.length"
<NcButton type="secondary" size="small" class="!border-none !rounded-none"> v-model:visible="auditDropdowns.user"
<div class="!w-[106px] flex items-center justify-between gap-2"> @update:visible="
(value) => {
if (value) {
auditDropdownsSearch.user = ''
}
}
"
>
<NcButton type="secondary" size="small">
<div class="flex items-center gap-2">
<div class="max-w-[120px] truncate text-sm !leading-5"> <div class="max-w-[120px] truncate text-sm !leading-5">
Type: {{ auditOperationTypeLabels[auditLogsQuery.type] || 'All' }} User:
<span :class="{ 'text-brand-500': auditLogsQuery.user }">
{{
(auditLogsQuery.user &&
(collaboratorsMap.get(auditLogsQuery.user)?.display_name ||
collaboratorsMap
.get(auditLogsQuery.user)
?.email?.slice(0, collaboratorsMap.get(auditLogsQuery.user)?.email.indexOf('@')))) ||
'All'
}}
</span>
</div> </div>
<GeneralIcon icon="arrowDown" class="flex-none h-4 w-4" /> <GeneralIcon icon="arrowDown" class="flex-none h-4 w-4" />
</div> </div>
</NcButton> </NcButton>
<template #overlay> <template #overlay>
<NcMenu <div class="w-[256px]">
class="w-[256px]" <div class="px-2 py-2" @click.stop>
@click=" <a-input
() => { v-model:value="auditDropdownsSearch.user"
auditDropdowns.type = false type="text"
:ref="focusUserSearchRef"
loadAudits() autocomplete="off"
} class="nc-input-sm nc-input-shadow"
" placeholder="Search"
> data-testid="nc-audit-dropdown-user-search-input"
<NcMenuItem class="!children:w-full" @click="auditLogsQuery.type = undefined">
<div class="w-full flex items-center justify-between gap-3">
<span class="flex-1"> All Types </span>
<GeneralIcon v-if="!auditLogsQuery.type" icon="check" class="flex-none text-primary w-4 h-4" />
</div>
</NcMenuItem>
<NcDivider />
<NcMenuItem
v-for="type in auditTypeOptions"
:key="type.value"
class="!children:w-full"
@click="
() => {
auditLogsQuery.type = type.value
auditLogsQuery.subType = undefined
}
"
> >
<div class="w-full flex items-center justify-between gap-3"> <template #prefix>
<div class="flex-1 flex items-center gap-2 max-w-[calc(100%_-_28px)]"> <GeneralIcon icon="search" class="mr-1 h-4 w-4 text-gray-500 group-hover:text-black" />
{{ type.label }}
</div>
<GeneralIcon v-if="auditLogsQuery.type === type.value" icon="check" class="flex-none text-primary w-4 h-4" />
</div>
</NcMenuItem>
</NcMenu>
</template> </template>
</NcDropdown> <template #suffix>
<NcDropdown v-model:visible="auditDropdowns.subType" placement="bottomRight"> <GeneralIcon
<NcButton type="secondary" size="small" class="!border-none !rounded-none"> v-if="auditDropdownsSearch.user.length > 0"
<div class="!w-[146px] flex items-center justify-between gap-2"> icon="close"
<div class="truncate text-sm !leading-5"> class="ml-1 h-4 w-4 text-gray-500 group-hover:text-black"
Sub-Type: data-testid="nc-audit-logs-clear-search"
{{ auditLogsQuery.subType ? auditOperationSubTypeLabels[auditLogsQuery.subType] : 'All' }} @click="auditDropdownsSearch.user = ''"
</div> />
<GeneralIcon icon="arrowDown" class="flex-none h-4 w-4" /> </template>
</a-input>
</div> </div>
</NcButton>
<template #overlay>
<NcMenu <NcMenu
class="w-[256px]" class="w-full max-h-[360px] nc-scrollbar-thin"
@click=" @click="
() => { () => {
auditDropdowns.subType = false auditDropdowns.user = false
loadAudits() loadAudits()
} }
" "
> >
<NcMenuItem class="!children:w-full" @click="auditLogsQuery.subType = undefined"> <NcMenuItem
class="!children:w-full ant-dropdown-menu-item ant-dropdown-menu-item-only-child sticky top-0"
@click="auditLogsQuery.user = undefined"
>
<div class="w-full flex items-center justify-between gap-3"> <div class="w-full flex items-center justify-between gap-3">
<span class="flex-1"> All SubTypes </span> <span class="flex-1 text-gray-800"> All Users </span>
<GeneralIcon v-if="!auditLogsQuery.subType" icon="check" class="flex-none text-primary w-4 h-4" /> <GeneralIcon v-if="!auditLogsQuery.user" icon="check" class="flex-none text-primary w-4 h-4" />
</div> </div>
</NcMenuItem> </NcMenuItem>
<NcDivider /> <NcDivider />
<template v-for="(coll, index) of collaborators" :key="index">
<NcMenuItem <NcMenuItem
v-for="subType in auditSubTypeOptions" v-if="
:key="subType.value" coll.email?.includes(auditDropdownsSearch.user.toLowerCase()) ||
class="!children:w-full" coll.display_name?.includes(auditDropdownsSearch.user.toLowerCase())
@click="auditLogsQuery.subType = subType.value" "
class="!children:w-full ant-dropdown-menu-item ant-dropdown-menu-item-only-child"
@click="auditLogsQuery.user = coll.email"
> >
<div class="w-full flex items-center justify-between gap-3"> <div class="w-full flex items-center justify-between gap-3">
<div class="flex-1 flex items-center gap-2 max-w-[calc(100%_-_28px)]"> <div v-if="coll?.email" class="w-full flex gap-3 items-center max-w-[calc(100%_-_28px)]">
{{ subType.label }} <GeneralUserIcon :email="coll?.email" size="base" class="flex-none" />
<div class="flex-1 flex flex-col max-w-[calc(100%_-_44px)]">
<div class="w-full flex gap-3">
<span class="text-sm text-gray-800 capitalize font-semibold truncate">
{{ coll?.display_name || coll?.email?.slice(0, coll?.email.indexOf('@')) }}
</span>
</div> </div>
<span class="text-xs text-gray-600 truncate">
{{ coll?.email }}
</span>
</div>
</div>
<template v-else>{{ coll.email }} </template>
<GeneralIcon <GeneralIcon
v-if="auditLogsQuery.subType === subType.value" v-if="auditLogsQuery.user === coll.email"
icon="check" icon="check"
class="flex-none text-primary w-4 h-4" class="flex-none text-primary w-4 h-4"
/> />
</div> </div>
</NcMenuItem> </NcMenuItem>
</template>
</NcMenu> </NcMenu>
</div>
</template> </template>
</NcDropdown> </NcDropdown>
</div> <NcDropdown
<NcDropdown v-if="basesList?.length" v-model:visible="auditDropdowns.base"> v-if="basesList?.length"
v-model:visible="auditDropdowns.base"
@update:visible="
(value) => {
if (value) {
auditDropdownsSearch.base = ''
}
}
"
>
<NcButton type="secondary" size="small"> <NcButton type="secondary" size="small">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<div class="max-w-[120px] truncate text-sm !leading-5"> <div class="max-w-[120px] truncate text-sm !leading-5">
Base: {{ (auditLogsQuery.base && bases.get(auditLogsQuery.base)?.title) || 'All' }} Base:
<span :class="{ 'text-brand-500': auditLogsQuery.base }">
{{ (auditLogsQuery.base && bases.get(auditLogsQuery.base)?.title) || 'All' }}
</span>
</div> </div>
<GeneralIcon icon="arrowDown" class="flex-none h-4 w-4" /> <GeneralIcon icon="arrowDown" class="flex-none h-4 w-4" />
</div> </div>
</NcButton> </NcButton>
<template #overlay> <template #overlay>
<div class="w-[256px]">
<div class="px-2 pt-2" @click.stop>
<a-input
v-model:value="auditDropdownsSearch.base"
type="text"
:ref="focusBaseSearchRef"
autocomplete="off"
class="nc-input-sm nc-input-shadow"
placeholder="Search"
data-testid="nc-audit-dropdown-base-search-input"
>
<template #prefix>
<GeneralIcon icon="search" class="mr-1 h-4 w-4 text-gray-500 group-hover:text-black" />
</template>
<template #suffix>
<GeneralIcon
v-if="auditDropdownsSearch.user.length > 0"
icon="close"
class="ml-1 h-4 w-4 text-gray-500 group-hover:text-black"
data-testid="nc-audit-logs-clear-search"
@click="auditDropdownsSearch.user = ''"
/>
</template>
</a-input>
</div>
<NcMenu <NcMenu
class="w-[256px]" class="w-full max-h-[360px] nc-scrollbar-thin"
@click=" @click="
() => { () => {
auditDropdowns.base = false auditDropdowns.base = false
@ -322,7 +403,7 @@ onMounted(async () => {
" "
> >
<NcMenuItem <NcMenuItem
class="!children:w-full" class="!children:w-full ant-dropdown-menu-item ant-dropdown-menu-item-only-child"
@click=" @click="
() => { () => {
auditLogsQuery.base = undefined auditLogsQuery.base = undefined
@ -331,15 +412,17 @@ onMounted(async () => {
" "
> >
<div class="w-full flex items-center justify-between gap-3"> <div class="w-full flex items-center justify-between gap-3">
<span class="flex-1"> All Bases </span> <span class="flex-1 text-gray-800"> All Bases </span>
<GeneralIcon v-if="!auditLogsQuery.base" icon="check" class="flex-none text-primary w-4 h-4" /> <GeneralIcon v-if="!auditLogsQuery.base" icon="check" class="flex-none text-primary w-4 h-4" />
</div> </div>
</NcMenuItem> </NcMenuItem>
<NcDivider /> <NcDivider />
<template v-for="(base, index) of basesList" :key="index"> <template v-for="(base, index) of basesList" :key="index">
<NcMenuItem <NcMenuItem
v-if="base?.sources?.[0]?.enabled" v-if="
class="!children:w-full" base?.sources?.[0]?.enabled && base.title?.toLowerCase()?.includes(auditDropdownsSearch.base.toLowerCase())
"
class="!children:w-full ant-dropdown-menu-item ant-dropdown-menu-item-only-child"
@click=" @click="
() => { () => {
auditLogsQuery.base = base.id auditLogsQuery.base = base.id
@ -355,7 +438,7 @@ onMounted(async () => {
class="nc-view-icon w-4 h-4 flex-none" class="nc-view-icon w-4 h-4 flex-none"
/> />
<NcTooltip class="max-w-full truncate" placement="top"> <NcTooltip class="max-w-full truncate text-gray-800" placement="top" show-on-truncate-only>
<template #title> {{ base.title }}</template> <template #title> {{ base.title }}</template>
{{ base.title }} {{ base.title }}
</NcTooltip> </NcTooltip>
@ -366,69 +449,103 @@ onMounted(async () => {
</NcMenuItem> </NcMenuItem>
</template> </template>
</NcMenu> </NcMenu>
</div>
</template> </template>
</NcDropdown> </NcDropdown>
<NcDropdown v-if="collaborators?.length" v-model:visible="auditDropdowns.user"> <NcDropdown
v-model:visible="auditDropdowns.type"
@update:visible="
(value) => {
if (value) {
auditDropdownsSearch.type = ''
}
}
"
>
<NcButton type="secondary" size="small"> <NcButton type="secondary" size="small">
<div class="flex items-center gap-2"> <div class="!w-[106px] flex items-center justify-between gap-2">
<div class="max-w-[120px] truncate text-sm !leading-5"> <div class="max-w-[120px] truncate text-sm !leading-5">
User: Type:
{{ <span :class="{ 'text-brand-500': auditLogsQuery.type }">
(auditLogsQuery.user && {{ auditLogsQuery.type ? auditOperationTypeLabels[auditLogsQuery.type] : 'All' }}
(collaboratorsMap.get(auditLogsQuery.user)?.display_name || </span>
collaboratorsMap
.get(auditLogsQuery.user)
?.email?.slice(0, collaboratorsMap.get(auditLogsQuery.user)?.email.indexOf('@')))) ||
'All'
}}
</div> </div>
<GeneralIcon icon="arrowDown" class="flex-none h-4 w-4" /> <GeneralIcon icon="arrowDown" class="flex-none h-4 w-4" />
</div> </div>
</NcButton> </NcButton>
<template #overlay> <template #overlay>
<div class="w-[256px]">
<div class="px-2 pt-2" @click.stop>
<a-input
v-model:value="auditDropdownsSearch.type"
type="text"
:ref="focusTypeSearchRef"
autocomplete="off"
class="nc-input-sm nc-input-shadow"
placeholder="Search"
data-testid="nc-audit-dropdown-type-search-input"
>
<template #prefix>
<GeneralIcon icon="search" class="mr-1 h-4 w-4 text-gray-500 group-hover:text-black" />
</template>
<template #suffix>
<GeneralIcon
v-if="auditDropdownsSearch.type.length > 0"
icon="close"
class="ml-1 h-4 w-4 text-gray-500 group-hover:text-black"
data-testid="nc-audit-logs-clear-search"
@click="auditDropdownsSearch.type = ''"
/>
</template>
</a-input>
</div>
<NcMenu <NcMenu
class="w-[256px]" class="w-full max-h-[360px] nc-scrollbar-thin"
@click=" @click="
() => { () => {
auditDropdowns.user = false auditDropdowns.type = false
loadAudits() loadAudits()
} }
" "
> >
<NcMenuItem class="!children:w-full" @click="auditLogsQuery.user = undefined"> <NcMenuItem
class="!children:w-full ant-dropdown-menu-item ant-dropdown-menu-item-only-child"
@click="auditLogsQuery.type = undefined"
>
<div class="w-full flex items-center justify-between gap-3"> <div class="w-full flex items-center justify-between gap-3">
<span class="flex-1"> All Users </span> <span class="flex-1 text-gray-800"> All Types </span>
<GeneralIcon v-if="!auditLogsQuery.user" icon="check" class="flex-none text-primary w-4 h-4" /> <GeneralIcon v-if="!auditLogsQuery.type" icon="check" class="flex-none text-primary w-4 h-4" />
</div> </div>
</NcMenuItem> </NcMenuItem>
<NcDivider /> <NcDivider />
<template v-for="type in auditTypeOptions" :key="type.value">
<NcMenuItem <NcMenuItem
v-for="(coll, index) of collaborators" v-if="type.label.toLowerCase().includes(auditDropdownsSearch.type.toLowerCase())"
:key="index" class="!children:w-full ant-dropdown-menu-item ant-dropdown-menu-item-only-child"
class="!children:w-full" @click="
@click="auditLogsQuery.user = coll.email" () => {
auditLogsQuery.type = type.value
auditLogsQuery.subType = undefined
}
"
> >
<div class="w-full flex items-center justify-between gap-3"> <div class="w-full flex items-center justify-between gap-3">
<div v-if="coll?.email" class="w-full flex gap-3 items-center max-w-[calc(100%_-_28px)]"> <div class="flex-1 flex items-center gap-2 max-w-[calc(100%_-_28px)] text-gray-800">
<GeneralUserIcon :email="coll?.email" size="base" class="flex-none" /> {{ type.label }}
<div class="flex-1 flex flex-col max-w-[calc(100%_-_44px)]">
<div class="w-full flex gap-3">
<span class="text-sm text-gray-800 capitalize font-semibold truncate">
{{ coll?.display_name || coll?.email?.slice(0, coll?.email.indexOf('@')) }}
</span>
</div>
<span class="text-xs text-gray-600 truncate">
{{ coll?.email }}
</span>
</div>
</div> </div>
<template v-else>{{ coll.email }} </template>
<GeneralIcon v-if="auditLogsQuery.user === coll.email" icon="check" class="flex-none text-primary w-4 h-4" /> <GeneralIcon
v-if="auditLogsQuery.type === type.value"
icon="check"
class="flex-none text-primary w-4 h-4"
/>
</div> </div>
</NcMenuItem> </NcMenuItem>
</template>
</NcMenu> </NcMenu>
</div>
</template> </template>
</NcDropdown> </NcDropdown>
</div> </div>
@ -438,46 +555,32 @@ onMounted(async () => {
<div class="nc-audit-logs-table table h-full"> <div class="nc-audit-logs-table table h-full">
<div class="thead sticky top-0"> <div class="thead sticky top-0">
<div class="tr"> <div class="tr">
<div class="th cell-user"> <div class="th cell-user !hover:bg-gray-100" @click="toggleOrderBy('user')">
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<div class="flex-1">User</div> <div class="flex-1">User</div>
<button class="!p-0 flex flex-col" @click="toggleOrderBy('user')"> <NcButton type="text" size="xs" class="!p-0">
<GeneralIcon
icon="arrowUp"
class="flex-none h-4 w-4"
:class="{
'!text-brand-500': auditLogsQuery.orderBy?.user === 'asc',
}"
/>
<GeneralIcon <GeneralIcon
icon="arrowDown" icon="chevronUpDown"
class="flex-none h-4 w-4"
:class="{ :class="{
'!text-brand-500': auditLogsQuery.orderBy?.user === 'desc', 'sort-asc': auditLogsQuery.orderBy?.user === 'asc',
'sort-desc': auditLogsQuery.orderBy?.user === 'desc',
}" }"
/> />
</button> </NcButton>
</div> </div>
</div> </div>
<div class="th cell-timestamp"> <div class="th cell-timestamp !hover:bg-gray-100" @click="toggleOrderBy('created_at')">
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<div class="flex-1">Time stamp</div> <div class="flex-1">Time stamp</div>
<button class="!p-0 flex flex-col" @click="toggleOrderBy('created_at')"> <NcButton type="text" size="xs" class="!p-0">
<GeneralIcon
icon="arrowUp"
class="flex-none h-4 w-4"
:class="{
'!text-brand-500': auditLogsQuery.orderBy?.created_at === 'asc',
}"
/>
<GeneralIcon <GeneralIcon
icon="arrowDown" icon="chevronUpDown"
class="flex-none h-4 w-4"
:class="{ :class="{
'!text-brand-500': auditLogsQuery.orderBy?.created_at === 'desc', 'sort-asc': auditLogsQuery.orderBy?.created_at === 'asc',
'sort-desc': auditLogsQuery.orderBy?.created_at === 'desc',
}" }"
/> />
</button> </NcButton>
</div> </div>
</div> </div>
<div class="th cell-base">Base</div> <div class="th cell-base">Base</div>
@ -761,4 +864,18 @@ onMounted(async () => {
.cell-header { .cell-header {
@apply uppercase text-tiny font-semibold text-gray-500; @apply uppercase text-tiny font-semibold text-gray-500;
} }
:deep(.nc-button) {
svg.sort-asc path.up {
@apply !stroke-brand-500;
}
svg.sort-desc path.down {
@apply !stroke-brand-500;
}
}
:deep(.nc-menu-item::after) {
content: none;
}
:deep(.ant-menu.nc-menu) {
@apply !pt-0;
}
</style> </style>

2
packages/nc-gui/utils/iconUtils.ts

@ -114,6 +114,7 @@ import NcCommentHere from '~icons/nc-icons/comment-here'
import NcAddDataSource from '~icons/nc-icons/add-data-source' import NcAddDataSource from '~icons/nc-icons/add-data-source'
import NcDatabaseIcon from '~icons/nc-icons/database' import NcDatabaseIcon from '~icons/nc-icons/database'
import NcChevronDown from '~icons/nc-icons/chevron-down' import NcChevronDown from '~icons/nc-icons/chevron-down'
import NcChevronUpDown from '~icons/nc-icons/chevron-up-down'
import NcTrash from '~icons/nc-icons/trash' import NcTrash from '~icons/nc-icons/trash'
import NcPencil from '~icons/nc-icons/pencil' import NcPencil from '~icons/nc-icons/pencil'
import NcRename from '~icons/nc-icons/rename' import NcRename from '~icons/nc-icons/rename'
@ -634,6 +635,7 @@ export const iconMap = {
maximizeAll: NcMaximizeAll, maximizeAll: NcMaximizeAll,
ncDrag: NcDrag, ncDrag: NcDrag,
refresh: NcRefresh, refresh: NcRefresh,
chevronUpDown: NcChevronUpDown,
} }
export const getMdiIcon = (type: string): any => { export const getMdiIcon = (type: string): any => {

Loading…
Cancel
Save