Browse Source

fix/Fixed table column toggle while table creation

pull/3237/head
Muhammed Mustafa 2 years ago
parent
commit
043fe29219
  1. 8
      packages/nc-gui-v2/components/dlg/TableCreate.vue
  2. 13
      packages/nc-gui-v2/composables/useTable.ts

8
packages/nc-gui-v2/components/dlg/TableCreate.vue

@ -106,20 +106,20 @@ onMounted(() => {
<template #title> <template #title>
<span>ID column is required, you can rename this later if required.</span> <span>ID column is required, you can rename this later if required.</span>
</template> </template>
<a-checkbox v-model:checked="table.columns.id" disabled>ID</a-checkbox> <a-checkbox v-model:checked="table.columnsToggleInfo.id" disabled>ID</a-checkbox>
</a-tooltip> </a-tooltip>
</a-col> </a-col>
<a-col :span="6"> <a-col :span="6">
<a-checkbox v-model:checked="table.columns.title"> title </a-checkbox> <a-checkbox v-model:checked="table.columnsToggleInfo.title"> title </a-checkbox>
</a-col> </a-col>
<a-col :span="6"> <a-col :span="6">
<a-checkbox v-model:checked="table.columns.created_at"> created_at </a-checkbox> <a-checkbox v-model:checked="table.columnsToggleInfo.created_at"> created_at </a-checkbox>
</a-col> </a-col>
<a-col :span="6"> <a-col :span="6">
<a-checkbox v-model:checked="table.columns.updated_at"> updated_at </a-checkbox> <a-checkbox v-model:checked="table.columnsToggleInfo.updated_at"> updated_at </a-checkbox>
</a-col> </a-col>
</a-row> </a-row>
</div> </div>

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

@ -7,10 +7,16 @@ import { extractSdkResponseErrorMsg } from '~/utils'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
export function useTable(onTableCreate?: (tableMeta: TableType) => void) { export function useTable(onTableCreate?: (tableMeta: TableType) => void) {
const table = reactive<{ title: string; table_name: string; columns: string[] }>({ const table = reactive<{ title: string; table_name: string; columns: string[]; columnsToggleInfo: Record<string, boolean> }>({
title: '', title: '',
table_name: '', table_name: '',
columns: ['id', 'title', 'created_at', 'updated_at'], columns: ['id', 'title', 'created_at', 'updated_at'],
columnsToggleInfo: {
id: true,
title: true,
created_at: true,
updated_at: true,
},
}) })
const { $e, $api } = useNuxtApp() const { $e, $api } = useNuxtApp()
@ -21,7 +27,9 @@ export function useTable(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.includes('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)
@ -30,6 +38,7 @@ export function useTable(onTableCreate?: (tableMeta: TableType) => void) {
} }
return table.columns.includes(col.column_name) return table.columns.includes(col.column_name)
}) })
.filter((col) => table.columnsToggleInfo[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, {
...table, ...table,

Loading…
Cancel
Save