Browse Source

feat: implement useProject to project edit route

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3368/head
mertmit 2 years ago
parent
commit
d7cc322474
  1. 13
      packages/nc-gui-v2/composables/useProject.ts
  2. 21
      packages/nc-gui-v2/pages/index/index/[id].vue

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

@ -76,11 +76,24 @@ export function useProject(projectId?: MaybeRef<string>) {
await loadTables() await loadTables()
} }
async function updateProject(data: Partial<ProjectType>) {
if (unref(projectId)) {
_projectId = unref(projectId)!
} else if (projectType === 'base') {
return
} else {
_projectId = route.params.projectId as string
}
await $api.project.update(_projectId, data)
}
return { return {
project, project,
tables, tables,
loadProjectRoles, loadProjectRoles,
loadProject, loadProject,
updateProject,
loadTables, loadTables,
isMysql, isMysql,
isMssql, isMssql,

21
packages/nc-gui-v2/pages/index/index/[id].vue

@ -1,6 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { Form } from 'ant-design-vue' import type { Form } from 'ant-design-vue'
import type { ProjectType } from 'nocodb-sdk'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { import {
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
@ -15,12 +14,16 @@ import {
useSidebar, useSidebar,
} from '#imports' } from '#imports'
const { api, isLoading } = useApi() const { isLoading } = useApi()
useSidebar({ hasSidebar: false }) useSidebar({ hasSidebar: false })
const route = useRoute() const route = useRoute()
const { project, loadProject, updateProject } = useProject(route.params.id as string)
await loadProject()
const nameValidationRules = [ const nameValidationRules = [
{ {
required: true, required: true,
@ -35,18 +38,9 @@ const formState = reactive({
title: '', title: '',
}) })
const getProject = async () => {
try {
const result: ProjectType = await api.project.read(route.params.id as string)
formState.title = result.title as string
} catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e))
}
}
const renameProject = async () => { const renameProject = async () => {
try { try {
await api.project.update(route.params.id as string, formState) await updateProject(formState)
navigateTo(`/nc/${route.params.id}`) navigateTo(`/nc/${route.params.id}`)
} catch (e: any) { } catch (e: any) {
@ -56,6 +50,7 @@ const renameProject = async () => {
// select and focus title field on load // select and focus title field on load
onMounted(async () => { onMounted(async () => {
formState.title = project.value.title as string
await nextTick(() => { await nextTick(() => {
// todo: replace setTimeout and follow better approach // todo: replace setTimeout and follow better approach
setTimeout(() => { setTimeout(() => {
@ -67,8 +62,6 @@ onMounted(async () => {
}, 500) }, 500)
}) })
}) })
await getProject()
</script> </script>
<template> <template>

Loading…
Cancel
Save