Browse Source

fix: PR requested changes

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/6953/head
mertmit 1 year ago
parent
commit
1672e3ead9
  1. 17
      packages/nc-gui/components/dlg/ColumnDuplicate.vue
  2. 90
      packages/nc-gui/components/smartsheet/header/Menu.vue
  3. 1
      packages/nocodb-sdk/src/lib/Api.ts
  4. 2
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts
  5. 3
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts
  6. 3
      packages/nocodb/src/schema/swagger.json

17
packages/nc-gui/components/dlg/ColumnDuplicate.vue

@ -2,11 +2,11 @@
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { useVModel } from '#imports' import { useVModel } from '#imports'
import type { TabType } from '#imports'
const props = defineProps<{ const props = defineProps<{
modelValue: boolean modelValue: boolean
column: ColumnType column: ColumnType
extra: any
}>() }>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
@ -15,28 +15,14 @@ const { api } = useApi()
const dialogShow = useVModel(props, 'modelValue', emit) const dialogShow = useVModel(props, 'modelValue', emit)
const { addTab } = useTabs()
const { $e, $poller } = useNuxtApp() const { $e, $poller } = useNuxtApp()
const basesStore = useBases() const basesStore = useBases()
const { createProject: _createProject } = basesStore const { createProject: _createProject } = basesStore
const { openTable } = useTablesStore()
const baseStore = useBase()
const { loadTables } = baseStore
const { tables } = storeToRefs(baseStore)
const { t } = useI18n()
const { activeTable: _activeTable } = storeToRefs(useTablesStore()) const { activeTable: _activeTable } = storeToRefs(useTablesStore())
const { refreshCommandPalette } = useCommandPalette()
const reloadDataHook = inject(ReloadViewDataHookInj) const reloadDataHook = inject(ReloadViewDataHookInj)
const { eventBus } = useSmartsheetStoreOrThrow() const { eventBus } = useSmartsheetStoreOrThrow()
@ -69,6 +55,7 @@ const _duplicate = async () => {
isLoading.value = true isLoading.value = true
const jobData = await api.dbTable.duplicateColumn(props.column.base_id!, props.column.id!, { const jobData = await api.dbTable.duplicateColumn(props.column.base_id!, props.column.id!, {
options: optionsToExclude.value, options: optionsToExclude.value,
extra: props.extra,
}) })
$poller.subscribe( $poller.subscribe(

90
packages/nc-gui/components/smartsheet/header/Menu.vue

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { ColumnType } from 'nocodb-sdk' import type { ColumnReqType, ColumnType } from 'nocodb-sdk'
import { RelationTypes, UITypes, isLinksOrLTAR } from 'nocodb-sdk' import { RelationTypes, UITypes, isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk'
import { import {
ActiveViewInj, ActiveViewInj,
ColumnInj, ColumnInj,
@ -112,12 +112,84 @@ const sortByColumn = async (direction: 'asc' | 'desc') => {
const isDuplicateDlgOpen = ref(false) const isDuplicateDlgOpen = ref(false)
const selectedColumnToDuplicate = ref<ColumnType>() const selectedColumnToDuplicate = ref<ColumnType>()
const selectedColumnExtra = ref<any>()
const duplicateVirtualColumn = async () => {
let columnCreatePayload = {}
// generate duplicate column title
const duplicateColumnTitle = getUniqueColumnName(`${column!.value.title} copy`, meta!.value!.columns!)
columnCreatePayload = {
...column!.value!,
...(column!.value.colOptions ?? {}),
title: duplicateColumnTitle,
column_name: duplicateColumnTitle.replace(/\s/g, '_'),
id: undefined,
colOptions: undefined,
order: undefined,
}
try {
const gridViewColumnList = (await $api.dbViewColumn.list(view.value?.id as string)).list
const currentColumnIndex = gridViewColumnList.findIndex((f) => f.fk_column_id === column!.value.id)
let newColumnOrder
if (currentColumnIndex === gridViewColumnList.length - 1) {
newColumnOrder = gridViewColumnList[currentColumnIndex].order! + 1
} else {
newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex + 1].order!) / 2
}
const openDuplicateDlg = () => { await $api.dbTableColumn.create(meta!.value!.id!, {
...columnCreatePayload,
pv: false,
view_id: view.value!.id as string,
column_order: {
order: newColumnOrder,
view_id: view.value!.id as string,
},
} as ColumnReqType)
await getMeta(meta!.value!.id!, true)
eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD)
reloadDataHook?.trigger()
// message.success(t('msg.success.columnDuplicated'))
} catch (e) {
message.error(await extractSdkResponseErrorMsg(e))
}
// closing dropdown
isOpen.value = false
}
const openDuplicateDlg = async () => {
if (!column?.value) return if (!column?.value) return
if (column.value.uidt && [UITypes.Formula, UITypes.Lookup, UITypes.Rollup].includes(column.value.uidt as UITypes)) {
duplicateVirtualColumn()
} else {
const gridViewColumnList = (await $api.dbViewColumn.list(view.value?.id as string)).list
const currentColumnIndex = gridViewColumnList.findIndex((f) => f.fk_column_id === column!.value.id)
let newColumnOrder
if (currentColumnIndex === gridViewColumnList.length - 1) {
newColumnOrder = gridViewColumnList[currentColumnIndex].order! + 1
} else {
newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex + 1].order!) / 2
}
selectedColumnExtra.value = {
pv: false,
view_id: view.value!.id as string,
column_order: {
order: newColumnOrder,
view_id: view.value!.id as string,
},
}
selectedColumnToDuplicate.value = column.value selectedColumnToDuplicate.value = column.value
isDuplicateDlgOpen.value = true isDuplicateDlgOpen.value = true
isOpen.value = false isOpen.value = false
}
} }
// add column before or after current column // add column before or after current column
@ -266,10 +338,7 @@ const onInsertAfter = () => {
<a-divider class="!my-0" /> <a-divider class="!my-0" />
<a-menu-item <a-menu-item v-if="!column?.pk" @click="openDuplicateDlg">
v-if="!column?.pk && column?.uidt !== UITypes.Lookup && column?.uidt !== UITypes.Rollup"
@click="openDuplicateDlg"
>
<div v-e="['a:field:duplicate']" class="nc-column-duplicate nc-header-menu-item my-0.5"> <div v-e="['a:field:duplicate']" class="nc-column-duplicate nc-header-menu-item my-0.5">
<component :is="iconMap.duplicate" class="text-gray-700 mx-0.75" /> <component :is="iconMap.duplicate" class="text-gray-700 mx-0.75" />
<!-- Duplicate --> <!-- Duplicate -->
@ -303,7 +372,12 @@ const onInsertAfter = () => {
</template> </template>
</a-dropdown> </a-dropdown>
<SmartsheetHeaderDeleteColumnModal v-model:visible="showDeleteColumnModal" /> <SmartsheetHeaderDeleteColumnModal v-model:visible="showDeleteColumnModal" />
<DlgColumnDuplicate v-if="selectedColumnToDuplicate" v-model="isDuplicateDlgOpen" :column="selectedColumnToDuplicate" /> <DlgColumnDuplicate
v-if="selectedColumnToDuplicate"
v-model="isDuplicateDlgOpen"
:column="selectedColumnToDuplicate"
:extra="selectedColumnExtra"
/>
</template> </template>
<style scoped> <style scoped>

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

@ -5771,6 +5771,7 @@ export class Api<
options?: { options?: {
excludeData?: boolean; excludeData?: boolean;
}; };
extra?: object;
}, },
params: RequestParams = {} params: RequestParams = {}
) => ) =>

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

@ -233,6 +233,7 @@ export class DuplicateController {
options?: { options?: {
excludeData?: boolean; excludeData?: boolean;
}; };
extra?: any;
}, },
) { ) {
const base = await Base.get(baseId); const base = await Base.get(baseId);
@ -262,6 +263,7 @@ export class DuplicateController {
modelId: model.id, modelId: model.id,
columnId: column.id, columnId: column.id,
options: body.options || {}, options: body.options || {},
extra: body.extra || {},
req: { req: {
user: req.user, user: req.user,
clientIp: req.clientIp, clientIp: req.clientIp,

3
packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts

@ -236,7 +236,7 @@ export class DuplicateProcessor {
const hrTime = initTime(); const hrTime = initTime();
const { baseId, sourceId, columnId, req, options } = job.data; const { baseId, sourceId, columnId, extra, req, options } = job.data;
const excludeData = options?.excludeData || false; const excludeData = options?.excludeData || false;
@ -308,6 +308,7 @@ export class DuplicateProcessor {
replacedColumn.title = title; replacedColumn.title = title;
replacedColumn.column_name = title.toLowerCase().replace(/ /g, '_'); replacedColumn.column_name = title.toLowerCase().replace(/ /g, '_');
Object.assign(replacedColumn, extra);
const idMap = await this.importService.importModels({ const idMap = await this.importService.importModels({
baseId, baseId,

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

@ -4630,6 +4630,9 @@
"required": false "required": false
} }
} }
},
"extra": {
"type": "object"
} }
} }
}, },

Loading…
Cancel
Save