Browse Source

feat(gui-v2): make active table selected in treeview

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3057/head
Pranav C 2 years ago
parent
commit
b5914425af
  1. 2
      packages/nc-gui-v2/components.d.ts
  2. 56
      packages/nc-gui-v2/components/dashboard/TreeView.vue

2
packages/nc-gui-v2/components.d.ts vendored

@ -41,12 +41,14 @@ declare module '@vue/runtime-core' {
AMenuItemGroup: typeof import('ant-design-vue/es')['MenuItemGroup'] AMenuItemGroup: typeof import('ant-design-vue/es')['MenuItemGroup']
AModal: typeof import('ant-design-vue/es')['Modal'] AModal: typeof import('ant-design-vue/es')['Modal']
APagination: typeof import('ant-design-vue/es')['Pagination'] APagination: typeof import('ant-design-vue/es')['Pagination']
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
ARadio: typeof import('ant-design-vue/es')['Radio'] ARadio: typeof import('ant-design-vue/es')['Radio']
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup'] ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
ARate: typeof import('ant-design-vue/es')['Rate'] ARate: typeof import('ant-design-vue/es')['Rate']
ARow: typeof import('ant-design-vue/es')['Row'] ARow: typeof import('ant-design-vue/es')['Row']
ASelect: typeof import('ant-design-vue/es')['Select'] ASelect: typeof import('ant-design-vue/es')['Select']
ASelectOption: typeof import('ant-design-vue/es')['SelectOption'] ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
ASkeleton: typeof import('ant-design-vue/es')['Skeleton']
ASkeletonImage: typeof import('ant-design-vue/es')['SkeletonImage'] ASkeletonImage: typeof import('ant-design-vue/es')['SkeletonImage']
ASpin: typeof import('ant-design-vue/es')['Spin'] ASpin: typeof import('ant-design-vue/es')['Spin']
ASubMenu: typeof import('ant-design-vue/es')['SubMenu'] ASubMenu: typeof import('ant-design-vue/es')['SubMenu']

56
packages/nc-gui-v2/components/dashboard/TreeView.vue

@ -1,15 +1,23 @@
<script setup lang="ts"> <script setup lang="ts">
import { useNuxtApp, useRoute } from '#app'
import { computed, useProject, useTable, useTabs, useUIPermission, watchEffect } from '#imports'
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import Sortable from 'sortablejs' import Sortable from 'sortablejs'
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
import { useProject, useTable, useTabs, watchEffect } from '#imports' import { TabType } from '~/composables'
import { useNuxtApp, useRoute } from '#app'
import MdiTable from '~icons/mdi/table' import MdiTable from '~icons/mdi/table'
import MdiView from '~icons/mdi/eye-circle-outline' import MdiView from '~icons/mdi/eye-circle-outline'
import MdiTableLarge from '~icons/mdi/table-large' import MdiTableLarge from '~icons/mdi/table-large'
import MdiMenuDown from '~icons/mdi/chevron-down' import MdiMenuDown from '~icons/mdi/chevron-down'
import MdiPlus from '~icons/mdi/plus-circle-outline' import MdiSettingIcon from '~icons/mdi/cog'
import MdiMenuIcon from '~icons/mdi/dots-vertical'
import MdiDrag from '~icons/mdi/drag-vertical' import MdiDrag from '~icons/mdi/drag-vertical'
import MdiView from '~icons/mdi/eye-circle-outline'
import MdiAPIDocIcon from '~icons/mdi/open-in-new'
import MdiPlus from '~icons/mdi/plus-circle-outline'
import MdiTable from '~icons/mdi/table'
import MdiTableLarge from '~icons/mdi/table-large'
import SettingsModal from './settings/SettingsModal.vue'
import MdiMenuIcon from '~icons/mdi/dots-vertical' import MdiMenuIcon from '~icons/mdi/dots-vertical'
const { addTab } = useTabs() const { addTab } = useTabs()
@ -21,9 +29,10 @@ const { $api, $e } = useNuxtApp()
const route = useRoute() const route = useRoute()
const { tables, loadTables } = useProject(route.params.projectId as string) const { tables, loadTables } = useProject(route.params.projectId as string)
const { closeTab, activeTab } = useTabs()
const { deleteTable } = useTable() const { deleteTable } = useTable()
const tablesById = $computed<Record<string, TableType>>(() => const tablesById = $computed<Record<string, TableType>>(() =>
tables?.value?.reduce((acc: Record<string, TableType>, table: TableType) => { tables?.value?.reduce((acc: Record<string, TableType>, table: TableType) => {
acc[table.id as string] = table acc[table.id as string] = table
@ -31,14 +40,12 @@ const tablesById = $computed<Record<string, TableType>>(() =>
}, {}), }, {}),
) )
const settingsDlg = ref(false)
const showTableList = ref(true) const showTableList = ref(true)
const tableCreateDlg = ref(false) const tableCreateDlg = ref(false)
const tableDeleteDlg = ref(false)
const menuRef = $ref<HTMLLIElement>() const menuRef = $ref<HTMLLIElement>()
let key = $ref(0) let key = $ref(0)
let sortable: Sortable let sortable: Sortable
// todo: replace with vuedraggable // todo: replace with vuedraggable
@ -106,13 +113,11 @@ const icon = (table: TableType) => {
} }
const filterQuery = $ref('') const filterQuery = $ref('')
const filteredTables = $computed(() => { const filteredTables = $computed(() => {
return tables?.value?.filter((table) => !filterQuery || table?.title.toLowerCase()?.includes(filterQuery.toLowerCase())) return tables?.value?.filter((table) => !filterQuery || table?.title.toLowerCase()?.includes(filterQuery.toLowerCase()))
}) })
const contextMenuTarget = reactive<{ type?: 'table' | 'main'; value?: any }>({}) const contextMenuTarget = reactive<{ type?: 'table' | 'main'; value?: any }>({})
const setMenuContext = (type: 'table' | 'main', value?: any) => { const setMenuContext = (type: 'table' | 'main', value?: any) => {
contextMenuTarget.type = type contextMenuTarget.type = type
contextMenuTarget.value = value contextMenuTarget.value = value
@ -120,24 +125,25 @@ const setMenuContext = (type: 'table' | 'main', value?: any) => {
} }
const renameTableDlg = ref(false) const renameTableDlg = ref(false)
const renameTableMeta = ref() const renameTableMeta = ref()
const showRenameTableDlg = (table: TableType, rightClick = false) => { const showRenameTableDlg = (table: TableType, rightClick = false) => {
$e(rightClick ? 'c:table:rename:navdraw:right-click' : 'c:table:rename:navdraw:options') $e(rightClick ? 'c:table:rename:navdraw:right-click' : 'c:table:rename:navdraw:options')
renameTableMeta.value = table renameTableMeta.value = table
renameTableDlg.value = true renameTableDlg.value = true
} }
const reloadTables = async () => { const reloadTables = async () => {
$e('a:table:refresh:navdraw') $e('a:table:refresh:navdraw')
await loadTables() await loadTables()
} }
const addTableTab = (table: TableType) => { const addTableTab = (table: TableType) => {
$e('a:table:open') $e('a:table:open')
addTab({ title: table.title, id: table.id, type: table.type as any }) addTab({ title: table.title, id: table.id, type: table.type as any })
} }
const activeTable = computed(() => {
return [TabType.TABLE, TabType.VIEW].includes(activeTab.value?.type) ? activeTab.value.title : null
})
</script> </script>
<template> <template>
@ -185,12 +191,9 @@ const addTableTab = (table: TableType) => {
v-for="table of tables" v-for="table of tables"
:key="table.id" :key="table.id"
v-t="['a:table:open']" v-t="['a:table:open']"
:class="[ :class="[{ hidden: !filteredTables?.includes(table),
{ hidden: !filteredTables?.includes(table) }, 'active': activeTable === table.title,}, `nc-project-tree-tbl nc-project-tree-tbl-${table.title}`,]"
`nc-project-tree-tbl nc-project-tree-tbl-${table.title}`, class="nc-tree-item pl-5 pr-3 py-2 text-sm cursor-pointer group"
route.params.title && route.params.title.includes(table.title) ? 'bg-blue-500/15' : '',
]"
class="pl-5 pr-3 py-2 text-sm cursor-pointer group"
:data-order="table.order" :data-order="table.order"
:data-id="table.id" :data-id="table.id"
@click="addTableTab(table)" @click="addTableTab(table)"
@ -299,4 +302,17 @@ const addTableTab = (table: TableType) => {
@apply !bg-primary/25 text-primary; @apply !bg-primary/25 text-primary;
} }
} }
.nc-tree-item{
@apply relative cursor-pointer after:(content-[''] absolute top-0 left-0 w-full h-full right-0 !bg-current transition transition-opactity duration-100 opacity-0);
}
.nc-tree-item.active{
@apply !text-primary after:(!opacity-10);
}
.nc-tree-item:hover{
@apply !text-grey after:(!opacity-5);
}
</style> </style>

Loading…
Cancel
Save