Browse Source

refactor(nc-gui): defer loading project to subpage

pull/3606/head
braks 2 years ago
parent
commit
e84b8b2272
  1. 13
      packages/nc-gui/components/tabs/auth/UserManagement.vue
  2. 2
      packages/nc-gui/composables/useSharedView.ts
  3. 45
      packages/nc-gui/pages/[projectType]/[projectId]/index.vue
  4. 55
      packages/nc-gui/pages/[projectType]/[projectId]/index/index.vue
  5. 4
      packages/nc-gui/pages/index/index.vue
  6. 7
      packages/nc-gui/pages/index/index/index.vue

13
packages/nc-gui/components/tabs/auth/UserManagement.vue

@ -5,7 +5,7 @@ import UsersModal from './user-management/UsersModal.vue'
import FeedbackForm from './user-management/FeedbackForm.vue' import FeedbackForm from './user-management/FeedbackForm.vue'
import { import {
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
onMounted, onBeforeMount,
projectRoleTagColors, projectRoleTagColors,
ref, ref,
useApi, useApi,
@ -128,7 +128,7 @@ const resendInvite = async (user: User) => {
if (!project.value?.id) return if (!project.value?.id) return
try { try {
await api.auth.projectUserResendInvite(project.value.id, user.id) await api.auth.projectUserResendInvite(project.value.id, user.id, null)
// Invite email sent successfully // Invite email sent successfully
message.success(t('msg.success.inviteEmailSent')) message.success(t('msg.success.inviteEmailSent'))
@ -150,11 +150,13 @@ const copyInviteUrl = (user: User) => {
$e('c:user:copy-url') $e('c:user:copy-url')
} }
onMounted(() => { onBeforeMount(async () => {
if (!users) { if (!users) {
isLoading = true isLoading = true
loadUsers().finally(() => (isLoading = false)) await loadUsers()
isLoading = false
} }
}) })
@ -162,9 +164,10 @@ watchDebounced(searchText, () => loadUsers(), { debounce: 300, maxWait: 600 })
</script> </script>
<template> <template>
<div v-if="isLoading" class="h-full w-full flex flex-row justify-center mt-42"> <div v-if="isLoading" class="h-full w-full flex items-center justify-center">
<a-spin size="large" /> <a-spin size="large" />
</div> </div>
<div v-else class="flex flex-col w-full px-6"> <div v-else class="flex flex-col w-full px-6">
<UsersModal <UsersModal
:key="showUserModal" :key="showUserModal"

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

@ -17,7 +17,7 @@ export function useSharedView() {
const formColumns = computed( const formColumns = computed(
() => () =>
meta.value.columns meta.value.columns
.filter( ?.filter(
(f: Record<string, any>) => (f: Record<string, any>) =>
f.show && f.uidt !== UITypes.Rollup && f.uidt !== UITypes.Lookup && f.uidt !== UITypes.Formula, f.show && f.uidt !== UITypes.Rollup && f.uidt !== UITypes.Lookup && f.uidt !== UITypes.Formula,
) )

45
packages/nc-gui/pages/[projectType]/[projectId]/index.vue

@ -1,7 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import tinycolor from 'tinycolor2' import tinycolor from 'tinycolor2'
import { useI18n } from 'vue-i18n'
import { import {
computed, computed,
definePageMeta, definePageMeta,
@ -14,26 +13,26 @@ import {
ref, ref,
useClipboard, useClipboard,
useGlobal, useGlobal,
useI18n,
useProject, useProject,
useRoute, useRoute,
useTabs, useTabs,
useUIPermission, useUIPermission,
} from '#imports' } from '#imports'
import { TabType } from '~/composables'
definePageMeta({ definePageMeta({
hideHeader: true, hideHeader: true,
}) })
const route = useRoute() const { t } = useI18n()
const router = useRouter() const route = useRoute()
const { appInfo, token, signOut, signedIn, user } = useGlobal() const { appInfo, token, signOut, signedIn, user } = useGlobal()
const { project, loadProject, loadTables, isSharedBase, loadProjectMetaInfo, projectMetaInfo, saveTheme } = useProject() const { project, isSharedBase, loadProjectMetaInfo, projectMetaInfo, saveTheme } = useProject()
const { addTab, clearTabs } = useTabs() const { clearTabs } = useTabs()
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
@ -62,27 +61,11 @@ const logout = () => {
navigateTo('/signin') navigateTo('/signin')
} }
onKeyStroke(
'Escape',
() => {
dropdownOpen.value = false
},
{ eventName: 'keydown' },
)
clearTabs()
function toggleDialog(value?: boolean, key?: string) { function toggleDialog(value?: boolean, key?: string) {
dialogOpen.value = value ?? !dialogOpen.value dialogOpen.value = value ?? !dialogOpen.value
openDialogKey.value = key openDialogKey.value = key
} }
await loadProject()
await loadTables()
const { t } = useI18n()
const handleThemeColor = async (mode: 'swatch' | 'primary' | 'accent', color: string) => { const handleThemeColor = async (mode: 'swatch' | 'primary' | 'accent', color: string) => {
switch (mode) { switch (mode) {
case 'swatch': { case 'swatch': {
@ -117,10 +100,6 @@ const handleThemeColor = async (mode: 'swatch' | 'primary' | 'accent', color: st
} }
} }
if (!route.params.type && isUIAllowed('teamAndAuth')) {
addTab({ type: TabType.AUTH, title: t('title.teamAndAuth') })
}
const copyProjectInfo = async () => { const copyProjectInfo = async () => {
try { try {
await loadProjectMetaInfo() await loadProjectMetaInfo()
@ -150,11 +129,15 @@ const copyAuthToken = async () => {
} }
} }
/** If v1 url found navigate to corresponding new url */ onKeyStroke(
const { type, name, view } = route.query 'Escape',
if (type && name) { () => {
router.replace(`/nc/${route.params.projectId}/${type}/${name}${view ? `/${view}` : ''}`) dropdownOpen.value = false
} },
{ eventName: 'keydown' },
)
clearTabs()
</script> </script>
<template> <template>

55
packages/nc-gui/pages/[projectType]/[projectId]/index/index.vue

@ -1,15 +1,58 @@
<script setup lang="ts"> <script setup lang="ts">
import type { TabItem } from '~/composables' import type { TabItem } from '~/composables'
import { TabType } from '~/composables' import { TabType } from '~/composables'
import { TabMetaInj, provide, useGlobal, useSidebar, useTabs } from '#imports' import {
TabMetaInj,
onBeforeMount,
provide,
ref,
useGlobal,
useI18n,
useProject,
useRoute,
useRouter,
useSidebar,
useTabs,
useUIPermission,
} from '#imports'
import MdiAirTableIcon from '~icons/mdi/table-large' import MdiAirTableIcon from '~icons/mdi/table-large'
import MdiView from '~icons/mdi/eye-circle-outline' import MdiView from '~icons/mdi/eye-circle-outline'
import MdiAccountGroup from '~icons/mdi/account-group' import MdiAccountGroup from '~icons/mdi/account-group'
const { tabs, activeTabIndex, activeTab, closeTab } = useTabs() const { t } = useI18n()
const { loadProject, loadTables } = useProject()
const { tabs, activeTabIndex, activeTab, closeTab, addTab } = useTabs()
const { isLoading } = useGlobal() const { isLoading } = useGlobal()
const route = useRoute()
const router = useRouter()
const { isUIAllowed } = useUIPermission()
const isReady = ref(false)
onBeforeMount(async () => {
await loadProject()
if (!route.params.type && isUIAllowed('teamAndAuth')) {
addTab({ type: TabType.AUTH, title: t('title.teamAndAuth') })
}
/** If v1 url found navigate to corresponding new url */
const { type, name, view } = route.query
if (type && name) {
await router.replace(`/nc/${route.params.projectId}/${type}/${name}${view ? `/${view}` : ''}`)
}
await loadTables()
isReady.value = true
})
provide(TabMetaInj, activeTab) provide(TabMetaInj, activeTab)
const icon = (tab: TabItem) => { const icon = (tab: TabItem) => {
@ -71,13 +114,17 @@ function onEdit(targetKey: number, action: 'add' | 'remove' | string) {
<div v-show="isLoading" class="flex items-center gap-2 ml-3 text-gray-200"> <div v-show="isLoading" class="flex items-center gap-2 ml-3 text-gray-200">
{{ $t('general.loading') }} {{ $t('general.loading') }}
<MdiLoading :class="{ 'animate-infinite animate-spin': isLoading }" /> <MdiLoading class="animate-infinite animate-spin" />
</div> </div>
</div> </div>
</div> </div>
<div class="w-full min-h-[300px] flex-auto"> <div class="w-full min-h-[300px] flex-auto">
<NuxtPage /> <NuxtPage v-if="isReady" />
<div v-else class="w-full h-full flex justify-center items-center">
<a-spin size="large" />
</div>
</div> </div>
</div> </div>
</div> </div>

4
packages/nc-gui/pages/index/index.vue

@ -22,11 +22,11 @@ const route = useRoute()
<div class="flex flex-1 justify-between gap-6 lg:block"> <div class="flex flex-1 justify-between gap-6 lg:block">
<template v-if="route.name === 'index-index'"> <template v-if="route.name === 'index-index'">
<TransitionGroup name="page" mode="out-in"> <TransitionGroup name="page" mode="out-in">
<div> <div key="social-card">
<GeneralSocialCard /> <GeneralSocialCard />
</div> </div>
<div class="block mt-0 lg:(!mt-6) xl:hidden"> <div key="sponsors" class="block mt-0 lg:(!mt-6) xl:hidden">
<GeneralSponsors /> <GeneralSponsors />
</div> </div>
</TransitionGroup> </TransitionGroup>

7
packages/nc-gui/pages/index/index/index.vue

@ -176,18 +176,18 @@ const getProjectPrimary = (project: ProjectType) => {
</div> </div>
<TransitionGroup name="layout" mode="out-in"> <TransitionGroup name="layout" mode="out-in">
<div v-if="isLoading"> <div v-if="isLoading" key="skeleton">
<a-skeleton /> <a-skeleton />
</div> </div>
<a-table <a-table
v-else v-else
key="table"
:custom-row=" :custom-row="
(record) => ({ (record) => ({
onClick: () => { onClick: () => {
$e('a:project:open')
navigateTo(`/nc/${record.id}`) navigateTo(`/nc/${record.id}`)
$e('a:project:open')
}, },
class: ['group'], class: ['group'],
}) })
@ -198,6 +198,7 @@ const getProjectPrimary = (project: ProjectType) => {
<template #emptyText> <template #emptyText>
<a-empty :image="Empty.PRESENTED_IMAGE_SIMPLE" :description="$t('labels.noData')" /> <a-empty :image="Empty.PRESENTED_IMAGE_SIMPLE" :description="$t('labels.noData')" />
</template> </template>
<!-- Title --> <!-- Title -->
<a-table-column key="title" :title="$t('general.title')" data-index="title"> <a-table-column key="title" :title="$t('general.title')" data-index="title">
<template #default="{ text, record }"> <template #default="{ text, record }">

Loading…
Cancel
Save