Browse Source

feat(nc-gui): handle import datetime

pull/3811/head
Wing-Kam Wong 2 years ago
parent
commit
b635e3c121
  1. 22
      packages/nc-gui/components/template/Editor.vue

22
packages/nc-gui/components/template/Editor.vue

@ -1,4 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import type { ColumnType, TableType } from 'nocodb-sdk' import type { ColumnType, TableType } from 'nocodb-sdk'
import { UITypes, isSystemColumn, isVirtualCol } from 'nocodb-sdk' import { UITypes, isSystemColumn, isVirtualCol } from 'nocodb-sdk'
import { srcDestMappingColumns, tableColumns } from './utils' import { srcDestMappingColumns, tableColumns } from './utils'
@ -30,6 +32,8 @@ const { quickImportType, projectTemplate, importData, importColumns, importOnly,
const emit = defineEmits(['import']) const emit = defineEmits(['import'])
dayjs.extend(utc)
const { t } = useI18n() const { t } = useI18n()
interface Props { interface Props {
@ -222,13 +226,19 @@ function setEditableTn(tableIdx: number, val: boolean) {
function remapColNames(batchData: any[], columns: ColumnType[]) { function remapColNames(batchData: any[], columns: ColumnType[]) {
return batchData.map((data) => return batchData.map((data) =>
(columns || []).reduce( (columns || []).reduce((aggObj, col: Record<string, any>) => {
(aggObj, col: Record<string, any>) => ({ let d = data[col.ref_column_name || col.column_name]
// TODO: handle Date format
if (col.uidt === UITypes.DateTime && d) {
d = dayjs(data[col.ref_column_name || col.column_name])
.utc()
.format('YYYY-MM-DD HH:mm')
}
return {
...aggObj, ...aggObj,
[col.column_name]: data[col.ref_column_name || col.column_name], [col.column_name]: d,
}), }
{}, }, {}),
),
) )
} }

Loading…
Cancel
Save