Browse Source

feat: duplicate table front-end

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest
mertmit 2 years ago
parent
commit
31ad97d21e
  1. 36
      packages/nc-gui/components/dashboard/TreeView.vue
  2. 39
      packages/nocodb-sdk/src/lib/Api.ts
  3. 2
      packages/nocodb/src/modules/jobs/export-import/duplicate.controller.ts
  4. 58
      packages/nocodb/src/schema/swagger.json

36
packages/nc-gui/components/dashboard/TreeView.vue

@ -37,7 +37,7 @@ const { isMobileMode } = useGlobal()
const { addTab, updateTab } = useTabs() const { addTab, updateTab } = useTabs()
const { $api, $e } = useNuxtApp() const { $api, $e, $jobs } = useNuxtApp()
const projectStore = useProject() const projectStore = useProject()
@ -389,6 +389,19 @@ const setIcon = async (icon: string, table: TableType) => {
message.error(await extractSdkResponseErrorMsg(e)) 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()
}
})
}
</script> </script>
<template> <template>
@ -734,6 +747,12 @@ const setIcon = async (icon: string, table: TableType) => {
</div> </div>
</a-menu-item> </a-menu-item>
<a-menu-item v-if="isUIAllowed('table-duplicate') && !table.mm" @click="duplicateTable(table)">
<div class="nc-project-menu-item">
{{ $t('general.duplicate') }}
</div>
</a-menu-item>
<a-menu-item <a-menu-item
v-if="isUIAllowed('table-delete')" v-if="isUIAllowed('table-delete')"
:data-testid="`sidebar-table-delete-${table.title}`" :data-testid="`sidebar-table-delete-${table.title}`"
@ -1050,6 +1069,12 @@ const setIcon = async (icon: string, table: TableType) => {
</div> </div>
</a-menu-item> </a-menu-item>
<a-menu-item v-if="isUIAllowed('table-duplicate') && !table.mm" @click="duplicateTable(table)">
<div class="nc-project-menu-item">
{{ $t('general.duplicate') }}
</div>
</a-menu-item>
<a-menu-item <a-menu-item
v-if="isUIAllowed('table-delete')" v-if="isUIAllowed('table-delete')"
:data-testid="`sidebar-table-delete-${table.title}`" :data-testid="`sidebar-table-delete-${table.title}`"
@ -1085,6 +1110,15 @@ const setIcon = async (icon: string, table: TableType) => {
</div> </div>
</a-menu-item> </a-menu-item>
<a-menu-item
v-if="isUIAllowed('table-duplicate') && !contextMenuTarget.value.mm"
@click="duplicateTable(contextMenuTarget.value)"
>
<div class="nc-project-menu-item">
{{ $t('general.duplicate') }}
</div>
</a-menu-item>
<a-menu-item v-if="isUIAllowed('table-delete')" @click="deleteTable(contextMenuTarget.value)"> <a-menu-item v-if="isUIAllowed('table-delete')" @click="deleteTable(contextMenuTarget.value)">
<div class="nc-project-menu-item"> <div class="nc-project-menu-item">
{{ $t('general.delete') }} {{ $t('general.delete') }}

39
packages/nocodb-sdk/src/lib/Api.ts

@ -5079,6 +5079,45 @@ export class Api<
...params, ...params,
}), }),
/**
* @description Duplicate a table
*
* @tags DB Table
* @name Duplicate
* @summary Duplicate Table
* @request POST:/api/v1/db/meta/duplicate/{projectId}/table/{tableId}
* @response `200` `{
name?: string,
id?: string,
}` OK
* @response `400` `{
\** @example BadRequest [Error]: <ERROR MESSAGE> *\
msg: string,
}`
*/
duplicate: (
projectId: IdType,
tableId: IdType,
params: RequestParams = {}
) =>
this.request<
{
name?: string;
id?: string;
},
{
/** @example BadRequest [Error]: <ERROR MESSAGE> */
msg: string;
}
>({
path: `/api/v1/db/meta/duplicate/${projectId}/table/${tableId}`,
method: 'POST',
format: 'json',
...params,
}),
/** /**
* @description Update the order of the given Table * @description Update the order of the given Table
* *

2
packages/nocodb/src/modules/jobs/export-import/duplicate.controller.ts

@ -81,7 +81,7 @@ export class DuplicateController {
return { id: job.id, name: job.name }; return { id: job.id, name: job.name };
} }
@Post('/api/v1/db/meta/duplicate/:projectId/model/:modelId') @Post('/api/v1/db/meta/duplicate/:projectId/table/:modelId')
@HttpCode(200) @HttpCode(200)
@Acl('duplicateModel') @Acl('duplicateModel')
async duplicateModel( async duplicateModel(

58
packages/nocodb/src/schema/swagger.json

@ -3881,6 +3881,64 @@
] ]
} }
}, },
"/api/v1/db/meta/duplicate/{projectId}/table/{tableId}": {
"post": {
"summary": "Duplicate Table",
"operationId": "db-table-duplicate",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"id": {
"type": "string"
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"tags": ["DB Table"],
"description": "Duplicate a table",
"parameters": [
{
"$ref": "#/components/parameters/xc-auth"
},
{
"schema": {
"$ref": "#/components/schemas/Id",
"example": "p_124hhlkbeasewh",
"type": "string"
},
"name": "projectId",
"in": "path",
"required": true,
"description": "Unique Project ID"
},
{
"schema": {
"$ref": "#/components/schemas/Id",
"example": "md_124hhlkbeasewh",
"type": "string"
},
"name": "tableId",
"in": "path",
"required": true,
"description": "Unique Table ID"
}
]
}
},
"/api/v1/db/meta/projects/{projectId}/{baseId}/tables": { "/api/v1/db/meta/projects/{projectId}/{baseId}/tables": {
"parameters": [ "parameters": [
{ {

Loading…
Cancel
Save