Browse Source

refactor/Added project info copy

pull/3166/head
Muhammed Mustafa 2 years ago
parent
commit
2d22bff82a
  1. 24
      packages/nc-gui-v2/composables/useProject.ts
  2. 11
      packages/nc-gui-v2/lib/types.ts
  3. 24
      packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue

24
packages/nc-gui-v2/composables/useProject.ts

@ -2,6 +2,7 @@ import { SqlUiFactory } from 'nocodb-sdk'
import type { OracleUi, ProjectType, TableType } from 'nocodb-sdk'
import type { MaybeRef } from '@vueuse/core'
import { useNuxtApp, useRoute, useState } from '#app'
import type { ProjectMetaInfo } from '~/lib'
import { USER_PROJECT_ROLES } from '~/lib'
export function useProject(projectId?: MaybeRef<string>) {
@ -13,10 +14,17 @@ export function useProject(projectId?: MaybeRef<string>) {
const tables = useState<TableType[]>('tables', () => [] as TableType[])
const route = useRoute()
const { includeM2M } = useGlobal()
const projectMetaInfo = useState<ProjectMetaInfo | undefined>('projectMetaInfo')
// todo: refactor path param name and variable name
const projectType = $computed(() => route.params.projectType as string)
async function loadProjectMetaInfo(force?: boolean) {
if (!projectMetaInfo.value || force) {
const data = await $api.project.metaGet(project.value.id!, {}, {})
projectMetaInfo.value = data
}
}
async function loadProjectRoles() {
projectRoles.value = {}
@ -59,5 +67,17 @@ export function useProject(projectId?: MaybeRef<string>) {
)
const isSharedBase = computed(() => projectType === 'base')
return { project, tables, loadProjectRoles, loadProject, loadTables, isMysql, isPg, sqlUi, isSharedBase }
return {
project,
tables,
loadProjectRoles,
loadProject,
loadTables,
isMysql,
isPg,
sqlUi,
isSharedBase,
loadProjectMetaInfo,
projectMetaInfo,
}
}

11
packages/nc-gui-v2/lib/types.ts

@ -10,4 +10,15 @@ export interface User {
project_id?: string
}
export interface ProjectMetaInfo {
Node?: string
Arch?: string
Platform?: string
Docker?: boolean
Database?: string
ProjectOnRootDB?: string
RootDB?: string
PackageVersion?: string
}
export type Roles = Record<Role, boolean>

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

@ -1,10 +1,12 @@
<script setup lang="ts">
import { message } from 'ant-design-vue'
import {
navigateTo,
onKeyStroke,
openLink,
provideSidebar,
ref,
useClipboard,
useElementHover,
useProject,
useRoute,
@ -12,17 +14,18 @@ import {
useUIPermission,
} from '#imports'
import { TabType } from '~/composables'
const route = useRoute()
const { appInfo } = useGlobal()
const { project, loadProject, loadTables, isSharedBase } = useProject()
const { project, loadProject, loadTables, isSharedBase, loadProjectMetaInfo, projectMetaInfo } = useProject()
const { addTab, clearTabs } = useTabs()
const { isUIAllowed } = useUIPermission()
const { copy } = useClipboard()
// create a new sidebar state
const { isOpen, toggle } = provideSidebar({ isOpen: true })
@ -59,6 +62,21 @@ await loadProject()
await loadTables()
const isHovered = useElementHover(sidebar)
const copyProjectInfo = async () => {
try {
await loadProjectMetaInfo()
copy(
Object.entries(projectMetaInfo.value!)
.map(([k, v]) => `${k}: **${v}**`)
.join('\n'),
)
message.info('Copied project info to clipboard')
} catch (e: any) {
console.log(e)
message.error(e.message)
}
}
</script>
<template>
@ -143,7 +161,7 @@ const isHovered = useElementHover(sidebar)
</template>
<a-menu-item key="copy">
<div class="nc-project-menu-item group">
<div class="nc-project-menu-item group" @click.stop="copyProjectInfo">
<MdiContentCopy class="group-hover:text-pink-500 nc-copy-project-info" />
Copy Project Info
</div>

Loading…
Cancel
Save