Browse Source

fix/Fixed table column toggle while table creation

pull/3237/head
Muhammed Mustafa 2 years ago
parent
commit
68f8f58ae5
  1. 1
      packages/nc-gui-v2/components.d.ts
  2. 48
      packages/nc-gui-v2/components/dlg/TableCreate.vue
  3. 34
      packages/nc-gui-v2/composables/useTable.ts
  4. 1
      packages/nc-gui-v2/lib/constants.ts

1
packages/nc-gui-v2/components.d.ts vendored

@ -15,6 +15,7 @@ declare module '@vue/runtime-core' {
ACardMeta: typeof import('ant-design-vue/es')['CardMeta'] ACardMeta: typeof import('ant-design-vue/es')['CardMeta']
ACarousel: typeof import('ant-design-vue/es')['Carousel'] ACarousel: typeof import('ant-design-vue/es')['Carousel']
ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] ACheckbox: typeof import('ant-design-vue/es')['Checkbox']
ACheckboxGroup: typeof import('ant-design-vue/es')['CheckboxGroup']
ACol: typeof import('ant-design-vue/es')['Col'] ACol: typeof import('ant-design-vue/es')['Col']
ACollapse: typeof import('ant-design-vue/es')['Collapse'] ACollapse: typeof import('ant-design-vue/es')['Collapse']
ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel'] ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']

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

@ -45,6 +45,11 @@ const validators = computed(() => {
}) })
const { validateInfos } = useForm(table, validators) const { validateInfos } = useForm(table, validators)
const systemColumnsCheckboxInfo = SYSTEM_COLUMNS.map((c, index) => ({
value: c,
disabled: index === 0,
}))
onMounted(() => { onMounted(() => {
generateUniqueTitle() generateUniqueTitle()
@ -78,8 +83,8 @@ onMounted(() => {
/> />
</a-form-item> </a-form-item>
<div class="flex justify-end"> <div class="flex justify-end items-center">
<div class="pointer" @click="isAdvanceOptVisible = !isAdvanceOptVisible"> <div class="pointer flex flex-row items-center gap-x-1" @click="isAdvanceOptVisible = !isAdvanceOptVisible">
{{ isAdvanceOptVisible ? 'Hide' : 'Show' }} more {{ isAdvanceOptVisible ? 'Hide' : 'Show' }} more
<MdiMinusCircleOutline v-if="isAdvanceOptVisible" class="text-gray-500" /> <MdiMinusCircleOutline v-if="isAdvanceOptVisible" class="text-gray-500" />
@ -95,32 +100,29 @@ onMounted(() => {
</a-form-item> </a-form-item>
<div> <div>
<div class="mb-5"> <div class="mb-1">
<!-- Add Default Columns --> <!-- Add Default Columns -->
{{ $t('msg.info.addDefaultColumns') }} {{ $t('msg.info.addDefaultColumns') }}
</div> </div>
<a-row> <a-row>
<a-col :span="6"> <a-checkbox-group
<a-tooltip placement="top"> v-model:value="table.columns"
<template #title> :options="systemColumnsCheckboxInfo"
<span>ID column is required, you can rename this later if required.</span> class="!flex flex-row justify-between w-full"
</template> >
<a-checkbox v-model:checked="table.columnsToggleInfo.id" disabled>ID</a-checkbox> <template #label="{ value }">
</a-tooltip> <a-tooltip v-if="value === 'id'" placement="top" class="!flex">
</a-col> <template #title>
<span>ID column is required, you can rename this later if required.</span>
<a-col :span="6"> </template>
<a-checkbox v-model:checked="table.columnsToggleInfo.title"> title </a-checkbox> ID
</a-col> </a-tooltip>
<div v-else class="flex">
<a-col :span="6"> {{ value }}
<a-checkbox v-model:checked="table.columnsToggleInfo.created_at"> created_at </a-checkbox> </div>
</a-col> </template>
</a-checkbox-group>
<a-col :span="6">
<a-checkbox v-model:checked="table.columnsToggleInfo.updated_at"> updated_at </a-checkbox>
</a-col>
</a-row> </a-row>
</div> </div>
</div> </div>

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

@ -1,22 +1,15 @@
import { Modal, message } from 'ant-design-vue' import { Modal, message } from 'ant-design-vue'
import type { LinkToAnotherRecordType, TableType } from 'nocodb-sdk' import type { LinkToAnotherRecordType, TableType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import { useProject } from './useProject'
import { TabType } from '~/composables/useTabs'
import { extractSdkResponseErrorMsg } from '~/utils'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { TabType } from '~/composables/useTabs'
import { SYSTEM_COLUMNS, extractSdkResponseErrorMsg, useProject } from '#imports'
export function useTable(onTableCreate?: (tableMeta: TableType) => void) { export function useTable(onTableCreate?: (tableMeta: TableType) => void) {
const table = reactive<{ title: string; table_name: string; columns: string[]; columnsToggleInfo: Record<string, boolean> }>({ 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: [...SYSTEM_COLUMNS],
columnsToggleInfo: {
id: true,
title: true,
created_at: true,
updated_at: true,
},
}) })
const { $e, $api } = useNuxtApp() const { $e, $api } = useNuxtApp()
@ -27,18 +20,15 @@ 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 const columns = sqlUi?.value?.getNewTableColumns().filter((col) => {
?.getNewTableColumns() if (col.column_name === 'id' && table.columns.includes('id_ag')) {
.filter((col) => { Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG'))
if (col.column_name === 'id' && table.columns.includes('id_ag')) { col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt)
Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG')) col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt)
col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt) return true
col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt) }
return true 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,

1
packages/nc-gui-v2/lib/constants.ts

@ -1,2 +1,3 @@
export const NOCO = 'noco' export const NOCO = 'noco'
export const USER_PROJECT_ROLES = 'user_project_roles' export const USER_PROJECT_ROLES = 'user_project_roles'
export const SYSTEM_COLUMNS = ['id', 'title', 'created_at', 'updated_at']

Loading…
Cancel
Save