Browse Source

Merge pull request #3620 from nocodb/fix/pg-select-default

pull/3682/head
Braks 2 years ago committed by GitHub
parent
commit
0eb61eee65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      packages/nc-gui/components/smartsheet-column/AdvancedOptions.vue
  2. 4
      packages/nocodb/src/lib/meta/api/columnApis.ts

32
packages/nc-gui/components/smartsheet-column/AdvancedOptions.vue

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import type { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import { computed } from '#imports' import { computed } from '#imports'
interface Props { interface Props {
@ -10,12 +10,27 @@ const props = defineProps<Props>()
const emit = defineEmits(['update:value']) const emit = defineEmits(['update:value'])
const vModel = useVModel(props, 'value', emit) const vModel = useVModel(props, 'value', emit)
const { sqlUi } = useProject() const { sqlUi, isPg } = useProject()
const { onAlter, onDataTypeChange, validateInfos } = useColumnCreateStoreOrThrow() const { onAlter, onDataTypeChange, validateInfos } = useColumnCreateStoreOrThrow()
// todo: 2nd argument of `getDataTypeListForUiType` is missing! // todo: 2nd argument of `getDataTypeListForUiType` is missing!
const dataTypes = computed(() => sqlUi?.value?.getDataTypeListForUiType(vModel.value as { uidt: UITypes }, '' as any)) const dataTypes = computed(() => sqlUi.value.getDataTypeListForUiType(vModel.value as { uidt: UITypes }, '' as any))
const sampleValue = computed(() => {
switch (vModel.value.uidt) {
case UITypes.SingleSelect:
return 'eg : a'
case UITypes.MultiSelect:
return 'eg : a,b,c'
default:
return sqlUi.value.getDefaultValueForDatatype(vModel.value.dt)
}
})
const hideLength = computed(() => {
return [UITypes.SingleSelect, UITypes.MultiSelect].includes(vModel.value.uidt)
})
// to avoid type error with checkbox // to avoid type error with checkbox
vModel.value.rqd = !!vModel.value.rqd vModel.value.rqd = !!vModel.value.rqd
@ -23,6 +38,13 @@ vModel.value.pk = !!vModel.value.pk
vModel.value.un = !!vModel.value.un vModel.value.un = !!vModel.value.un
vModel.value.ai = !!vModel.value.ai vModel.value.ai = !!vModel.value.ai
vModel.value.au = !!vModel.value.au vModel.value.au = !!vModel.value.au
onBeforeMount(() => {
// Postgres returns default value wrapped with single quotes & casted with type so we have to get value between single quotes to keep it unified for all databases
if (isPg.value && vModel.value.cdf) {
vModel.value.cdf = vModel.value.cdf.substring(vModel.value.cdf.indexOf(`'`) + 1, vModel.value.cdf.lastIndexOf(`'`))
}
})
</script> </script>
<template> <template>
@ -66,7 +88,7 @@ vModel.value.au = !!vModel.value.au
</a-select-option> </a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item :label="$t('labels.lengthValue')"> <a-form-item v-if="!hideLength" :label="$t('labels.lengthValue')">
<a-input <a-input
v-model:value="vModel.dtxp" v-model:value="vModel.dtxp"
:disabled="sqlUi.getDefaultLengthIsDisabled(vModel.dt) || !sqlUi.columnEditable(vModel)" :disabled="sqlUi.getDefaultLengthIsDisabled(vModel.dt) || !sqlUi.columnEditable(vModel)"
@ -78,7 +100,7 @@ vModel.value.au = !!vModel.value.au
</a-form-item> </a-form-item>
<a-form-item :label="$t('placeholder.defaultValue')"> <a-form-item :label="$t('placeholder.defaultValue')">
<a-textarea v-model:value="vModel.cdf" auto-size @input="onAlter(2, true)" /> <a-textarea v-model:value="vModel.cdf" auto-size @input="onAlter(2, true)" />
<span class="text-gray-400 text-xs">{{ sqlUi.getDefaultValueForDatatype(vModel.dt) }}</span> <span class="text-gray-400 text-xs">{{ sampleValue }}</span>
</a-form-item> </a-form-item>
</div> </div>
</template> </template>

4
packages/nocodb/src/lib/meta/api/columnApis.ts

@ -513,7 +513,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
if ([UITypes.SingleSelect, UITypes.MultiSelect].includes(colBody.uidt)) { if ([UITypes.SingleSelect, UITypes.MultiSelect].includes(colBody.uidt)) {
const dbDriver = NcConnectionMgrv2.get(base); const dbDriver = NcConnectionMgrv2.get(base);
const driverType = dbDriver.clientType(); const driverType = dbDriver.clientType();
const optionTitles = colBody.colOptions.options.map(el => el.title); const optionTitles = colBody.colOptions.options.map(el => el.title.replace(/'/g, "''"));
// Handle default values // Handle default values
if (colBody.cdf) { if (colBody.cdf) {
if (colBody.uidt === UITypes.SingleSelect) { if (colBody.uidt === UITypes.SingleSelect) {
@ -756,7 +756,7 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
} }
// Handle default values // Handle default values
const optionTitles = colBody.colOptions.options.map(el => el.title); const optionTitles = colBody.colOptions.options.map(el => el.title.replace(/'/g, "''"));
if (colBody.cdf) { if (colBody.cdf) {
if (colBody.uidt === UITypes.SingleSelect) { if (colBody.uidt === UITypes.SingleSelect) {
if (!optionTitles.includes(colBody.cdf)) { if (!optionTitles.includes(colBody.cdf)) {

Loading…
Cancel
Save