From 31ad97d21e2ee099bcdc9aa45e64fb57dc7c0535 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 6 May 2023 03:41:11 +0300 Subject: [PATCH] feat: duplicate table front-end Signed-off-by: mertmit --- .../nc-gui/components/dashboard/TreeView.vue | 36 +++++++++++- packages/nocodb-sdk/src/lib/Api.ts | 39 +++++++++++++ .../export-import/duplicate.controller.ts | 2 +- packages/nocodb/src/schema/swagger.json | 58 +++++++++++++++++++ 4 files changed, 133 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/components/dashboard/TreeView.vue b/packages/nc-gui/components/dashboard/TreeView.vue index cdcbacb674..82c7cbcb17 100644 --- a/packages/nc-gui/components/dashboard/TreeView.vue +++ b/packages/nc-gui/components/dashboard/TreeView.vue @@ -37,7 +37,7 @@ const { isMobileMode } = useGlobal() const { addTab, updateTab } = useTabs() -const { $api, $e } = useNuxtApp() +const { $api, $e, $jobs } = useNuxtApp() const projectStore = useProject() @@ -389,6 +389,19 @@ const setIcon = async (icon: string, table: TableType) => { message.error(await extractSdkResponseErrorMsg(e)) } } + +const duplicateTable = async (table: TableType) => { + if (!table || !table.id || !table.project_id) return + const jobData = await $api.dbTable.duplicate(table.project_id, table.id) + $jobs.subscribe({ name: jobData.name, id: jobData.id }, undefined, async (status: string) => { + if (status === 'completed') { + await loadTables() + } else if (status === 'failed') { + message.error('Failed to duplicate table') + await loadTables() + } + }) +}