Browse Source

fix(gui-v2): change columns to Record<string, boolean>

pull/2885/head
Wing-Kam Wong 2 years ago
parent
commit
915674dd1e
  1. 13
      packages/nc-gui-v2/composables/useTableCreate.ts

13
packages/nc-gui-v2/composables/useTableCreate.ts

@ -4,10 +4,15 @@ import { useNuxtApp } from '#app'
import { useProject } from '#imports' import { useProject } from '#imports'
export default (onTableCreate?: (tableMeta: TableType) => void) => { export default (onTableCreate?: (tableMeta: TableType) => void) => {
const table = reactive<{ title: string; table_name: string; columns: string[] }>({ const table = reactive<{ title: string; table_name: string; columns: Record<string, boolean> }>({
title: '', title: '',
table_name: '', table_name: '',
columns: ['id', 'title', 'created_at', 'updated_at'], columns: {
id: true,
title: true,
created_at: true,
updated_at: true,
},
}) })
const { sqlUi, project, tables } = useProject() const { sqlUi, project, tables } = useProject()
@ -16,13 +21,13 @@ export default (onTableCreate?: (tableMeta: TableType) => void) => {
const createTable = async () => { const createTable = async () => {
if (!sqlUi?.value) return if (!sqlUi?.value) return
const columns = sqlUi?.value?.getNewTableColumns().filter((col) => { const columns = sqlUi?.value?.getNewTableColumns().filter((col) => {
if (col.column_name === 'id' && table.columns.includes('id_ag')) { if (col.column_name === 'id' && table.columns.id_ag) {
Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG')) Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG'))
col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt) col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt)
col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt) col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt)
return true return true
} }
return table.columns.includes(col.column_name) return !!table.columns[col.column_name]
}) })
const tableMeta = await $api.dbTable.create(project?.value?.id as string, { const tableMeta = await $api.dbTable.create(project?.value?.id as string, {

Loading…
Cancel
Save