Browse Source

feat: allow overwriting props of duplicated project

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5752/head
mertmit 2 years ago
parent
commit
ae1a1e0ca9
  1. 7
      packages/nc-gui/components/dlg/ProjectDuplicate.vue
  2. 2
      packages/nc-gui/components/dlg/TableDuplicate.vue
  3. 8
      packages/nocodb-sdk/src/lib/Api.ts
  4. 16
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts
  5. 27
      packages/nocodb/src/schema/swagger.json

7
packages/nc-gui/components/dlg/ProjectDuplicate.vue

@ -34,7 +34,12 @@ const isLoading = ref(false)
const _duplicate = async () => { const _duplicate = async () => {
isLoading.value = true isLoading.value = true
try { try {
const jobData = await api.project.duplicate(props.project.id as string, optionsToExclude.value) const jobData = await api.project.duplicate(props.project.id as string, {
options: optionsToExclude.value,
project: {
meta: props.project.meta,
},
})
props.onOk(jobData as any) props.onOk(jobData as any)
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))

2
packages/nc-gui/components/dlg/TableDuplicate.vue

@ -34,7 +34,7 @@ const isLoading = ref(false)
const _duplicate = async () => { const _duplicate = async () => {
isLoading.value = true isLoading.value = true
try { try {
const jobData = await api.dbTable.duplicate(props.table.project_id!, props.table.id!, optionsToExclude.value) const jobData = await api.dbTable.duplicate(props.table.project_id!, props.table.id!, { options: optionsToExclude.value })
props.onOk(jobData as any) props.onOk(jobData as any)
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))

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

@ -4032,9 +4032,12 @@ export class Api<
baseDuplicate: ( baseDuplicate: (
projectId: IdType, projectId: IdType,
data: { data: {
options?: {
excludeData?: boolean; excludeData?: boolean;
excludeViews?: boolean; excludeViews?: boolean;
excludeHooks?: boolean; excludeHooks?: boolean;
};
project?: object;
}, },
baseId?: IdType, baseId?: IdType,
params: RequestParams = {} params: RequestParams = {}
@ -4078,9 +4081,12 @@ export class Api<
duplicate: ( duplicate: (
projectId: IdType, projectId: IdType,
data: { data: {
options?: {
excludeData?: boolean; excludeData?: boolean;
excludeViews?: boolean; excludeViews?: boolean;
excludeHooks?: boolean; excludeHooks?: boolean;
};
project?: object;
}, },
params: RequestParams = {} params: RequestParams = {}
) => ) =>
@ -5118,8 +5124,10 @@ export class Api<
projectId: IdType, projectId: IdType,
tableId: IdType, tableId: IdType,
data: { data: {
options?: {
excludeData?: boolean; excludeData?: boolean;
excludeViews?: boolean; excludeViews?: boolean;
};
}, },
params: RequestParams = {} params: RequestParams = {}
) => ) =>

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

@ -35,10 +35,14 @@ export class DuplicateController {
@Param('projectId') projectId: string, @Param('projectId') projectId: string,
@Param('baseId') baseId?: string, @Param('baseId') baseId?: string,
@Body() @Body()
body?: {
options?: { options?: {
excludeData?: boolean; excludeData?: boolean;
excludeViews?: boolean; excludeViews?: boolean;
excludeHooks?: boolean; excludeHooks?: boolean;
};
// override duplicated project
project?: any;
}, },
) { ) {
const project = await Project.get(projectId); const project = await Project.get(projectId);
@ -63,7 +67,11 @@ export class DuplicateController {
); );
const dupProject = await this.projectsService.projectCreate({ const dupProject = await this.projectsService.projectCreate({
project: { title: uniqueTitle, status: ProjectStatus.JOB }, project: {
title: uniqueTitle,
status: ProjectStatus.JOB,
...(body.project || {}),
},
user: { id: req.user.id }, user: { id: req.user.id },
}); });
@ -71,7 +79,7 @@ export class DuplicateController {
projectId: project.id, projectId: project.id,
baseId: base.id, baseId: base.id,
dupProjectId: dupProject.id, dupProjectId: dupProject.id,
options, options: body.options || {},
req: { req: {
user: req.user, user: req.user,
clientIp: req.clientIp, clientIp: req.clientIp,
@ -89,10 +97,12 @@ export class DuplicateController {
@Param('projectId') projectId: string, @Param('projectId') projectId: string,
@Param('modelId') modelId?: string, @Param('modelId') modelId?: string,
@Body() @Body()
body?: {
options?: { options?: {
excludeData?: boolean; excludeData?: boolean;
excludeViews?: boolean; excludeViews?: boolean;
excludeHooks?: boolean; excludeHooks?: boolean;
};
}, },
) { ) {
const project = await Project.get(projectId); const project = await Project.get(projectId);
@ -121,7 +131,7 @@ export class DuplicateController {
baseId: base.id, baseId: base.id,
modelId: model.id, modelId: model.id,
title: uniqueTitle, title: uniqueTitle,
options, options: body.options || {},
req: { req: {
user: req.user, user: req.user,
clientIp: req.clientIp, clientIp: req.clientIp,

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

@ -2131,6 +2131,9 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"type": "object",
"properties": {
"options": {
"type": "object", "type": "object",
"properties": { "properties": {
"excludeData": { "excludeData": {
@ -2147,6 +2150,12 @@
} }
} }
}, },
"project": {
"type": "object",
"required": false
}
}
},
"examples": { "examples": {
"Example 1": { "Example 1": {
"value": { "value": {
@ -2221,6 +2230,9 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"type": "object",
"properties": {
"options": {
"type": "object", "type": "object",
"properties": { "properties": {
"excludeData": { "excludeData": {
@ -2237,6 +2249,12 @@
} }
} }
}, },
"project": {
"type": "object",
"required": false
}
}
},
"examples": { "examples": {
"Example 1": { "Example 1": {
"value": { "value": {
@ -3976,6 +3994,9 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"type": "object",
"properties": {
"options": {
"type": "object", "type": "object",
"properties": { "properties": {
"excludeData": { "excludeData": {
@ -3985,6 +4006,12 @@
"excludeViews": { "excludeViews": {
"type": "boolean", "type": "boolean",
"required": false "required": false
},
"excludeHooks": {
"type": "boolean",
"required": false
}
}
} }
} }
}, },

Loading…
Cancel
Save