Browse Source

feat(gui-v2): allow excluding certain columns

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2716/head
Pranav C 2 years ago
parent
commit
e8e3cfbb65
  1. 93
      packages/nc-gui-v2/components/dlg/TableCreate.vue
  2. 22
      packages/nc-gui-v2/composables/useTableCreate.ts

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

@ -7,6 +7,11 @@ const { modelValue } = defineProps<{ modelValue?: boolean }>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const idTypes = [
{ value: 'AI', text: 'Auto increment number' },
{ value: 'AG', text: 'Auto generated string' },
]
const dialogShow = computed({ const dialogShow = computed({
get() { get() {
return modelValue return modelValue
@ -32,91 +37,11 @@ const validateDuplicate = (v: string) => {
return (tables?.value || []).every((t) => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name' return (tables?.value || []).every((t) => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name'
} }
const inputEl = ref<HTMLInputElement>()
onMounted(() => { onMounted(() => {
generateUniqueTitle() generateUniqueTitle()
}) })
/* import { validateTableName } from '~/helpers'
export default {
name: 'DlgTableCreate',
props: ['value'],
data() {
return {
isAdvanceOptVisible: false,
table: {
name: '',
columns: ['id', 'title', 'created_at', 'updated_at'],
},
isIdToggleAllowed: false,
valid: false,
idType: 'AI',
idTypes: [
{ value: 'AI', text: 'Auto increment number' },
{ value: 'AG', text: 'Auto generated string' },
],
}
},
computed: {
dialogShow: {
get() {
return this.value
},
set(v) {
this.$emit('input', v)
},
},
projectPrefix() {
return this.$store.getters['project/GtrProjectPrefix']
},
tables() {
return this.$store.state.project.tables || []
},
},
watch: {
'table.alias': function (alias) {
this.$set(this.table, 'name', `${this.projectPrefix || ''}${alias}`)
},
},
created() {
this.populateDefaultTitle()
},
mounted() {
setTimeout(() => {
const el = this.$refs.input.$el
el.querySelector('input').focus()
el.querySelector('input').select()
}, 100)
},
methods: {
populateDefaultTitle() {
let c = 1
while (this.tables.some((t) => t.title === `Sheet${c}`)) {
c++
}
this.$set(this.table, 'alias', `Sheet${c}`)
},
validateTableName(v) {
return validateTableName(v, this.$store.getters['project/GtrProjectIsGraphql'])
},
validateDuplicateAlias(v) {
return (this.tables || []).every((t) => t.title !== (v || '')) || 'Duplicate table alias'
},
validateLedingOrTrailingWhiteSpace(v) {
return !/^\s+|\s+$/.test(v) || 'Leading or trailing whitespace not allowed in table name'
},
validateDuplicate(v) {
return (this.tables || []).every((t) => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name'
},
onCreateBtnClick() {
this.$emit('create', {
...this.table,
columns: this.table.columns.map((c) => (c === 'id' && this.idType === 'AG' ? 'id_ag' : c)),
})
},
},
} */
</script> </script>
<template> <template>
@ -137,7 +62,7 @@ export default {
<v-card-text class="py-6 px-10"> <v-card-text class="py-6 px-10">
<!-- hint="Enter table name" --> <!-- hint="Enter table name" -->
<v-text-field <v-text-field
ref="input" :ref="inputEl"
v-model="table.title" v-model="table.title"
solo solo
flat flat
@ -161,7 +86,7 @@ export default {
<div class="nc-table-advanced-options" :class="{ active: isAdvanceOptVisible }"> <div class="nc-table-advanced-options" :class="{ active: isAdvanceOptVisible }">
<!-- hint="Table name as saved in database" --> <!-- hint="Table name as saved in database" -->
<v-text-field <v-text-field
v-if="!projectPrefix" v-if="!project.prefix"
v-model="table.table_name" v-model="table.table_name"
solo solo
flat flat

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

@ -1,9 +1,11 @@
import { UITypes } from 'nocodb-sdk'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
export default (onTableCreate?: (tableMeta: any) => void) => { export default (onTableCreate?: (tableMeta: any) => void) => {
const table = reactive<{ title: string; table_name: string }>({ const table = reactive<{ title: string; table_name: string; columns: string[] }>({
title: '', title: '',
table_name: '', table_name: '',
columns: ['id', 'title', 'created_at', 'updated_at'],
}) })
const { sqlUi, project, tables } = useProject() const { sqlUi, project, tables } = useProject()
@ -12,17 +14,15 @@ export default (onTableCreate?: (tableMeta: any) => 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" && newTable.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); 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 this.nodes.newTable.columns.includes(col.column_name);
return true
}) })
await $api.dbTable.create(project?.value?.id as string, { await $api.dbTable.create(project?.value?.id as string, {
...table, ...table,
columns, columns,

Loading…
Cancel
Save