Browse Source

fix: default value with single quote

pull/6584/head
mertmit 1 year ago
parent
commit
d5c0599547
  1. 2
      packages/nc-gui/components/cell/MultiSelect.vue
  2. 2
      packages/nc-gui/components/cell/SingleSelect.vue
  3. 5
      packages/nc-gui/components/smartsheet/Cell.vue
  4. 53
      packages/nc-gui/components/smartsheet/column/DefaultValue.vue
  5. 21
      packages/nc-gui/components/smartsheet/column/SelectOptions.vue
  6. 12
      packages/nocodb/src/services/columns.service.ts

2
packages/nc-gui/components/cell/MultiSelect.vue

@ -255,7 +255,7 @@ async function addIfMissingAndSave() {
} }
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql(column.value.source_id)) { if (!isMysql(column.value.source_id) && !isPg(column.value.source_id)) {
updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'") updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'")
} }
} }

2
packages/nc-gui/components/cell/SingleSelect.vue

@ -183,7 +183,7 @@ async function addIfMissingAndSave() {
} }
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql(column.value.source_id)) { if (!isMysql(column.value.source_id) && !isPg(column.value.source_id)) {
updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'") updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'")
} }
} }

5
packages/nc-gui/components/smartsheet/Cell.vue

@ -63,7 +63,7 @@ interface Props {
const props = defineProps<Props>() const props = defineProps<Props>()
const emit = defineEmits(['update:modelValue', 'save', 'navigate', 'update:editEnabled', 'update:value']) const emit = defineEmits(['update:modelValue', 'save', 'navigate', 'update:editEnabled', 'update:cdf'])
const column = toRef(props, 'column') const column = toRef(props, 'column')
@ -118,8 +118,7 @@ const vModel = computed({
}, },
set: (val) => { set: (val) => {
if (isEditColumnMenu.value) { if (isEditColumnMenu.value) {
column.value.cdf = val emit('update:cdf', val)
emit('update:value', val)
} else if (val !== props.modelValue) { } else if (val !== props.modelValue) {
currentRow.value.rowMeta.changed = true currentRow.value.rowMeta.changed = true
emit('update:modelValue', val) emit('update:modelValue', val)

53
packages/nc-gui/components/smartsheet/column/DefaultValue.vue

@ -5,54 +5,49 @@ import { iconMap } from '#imports'
const props = defineProps<{ const props = defineProps<{
value: any value: any
}>() }>()
const emit = defineEmits(['update:value']) const emits = defineEmits(['update:value'])
const meta = inject(MetaInj, ref())
provide(EditColumnInj, ref(true)) provide(EditColumnInj, ref(true))
const vModel = useVModel(props, 'value', emit) const vModel = useVModel(props, 'value', emits)
const rowRef = ref({ const rowRef = ref({
row: {}, row: {},
oldRow: {}, oldRow: {},
rowMeta: { rowMeta: {
isUpdatedFromCopyNPaste: [vModel?.value.title], isUpdatedFromCopyNPaste: [vModel.value?.title],
}, },
}) })
const cdfValue = computed({ useProvideSmartsheetRowStore(meta, rowRef)
get: () => {
if (vModel.value.uidt === UITypes.MultiSelect || vModel.value.uidt === UITypes.SingleSelect) {
return (vModel.value.cdf ?? '').replaceAll("'", '')
} else if (
vModel.value.uidt === UITypes.SingleLineText ||
vModel.value.uidt === UITypes.LongText ||
vModel.value.uidt === UITypes.Email ||
vModel.value.uidt === UITypes.URL ||
vModel.value.uidt === UITypes.JSON ||
vModel.value.uidt === UITypes.DateTime ||
vModel.value.uidt === UITypes.Time ||
vModel.value.uidt === UITypes.Year ||
vModel.value.uidt === UITypes.Date
) {
return (vModel.value.cdf ?? '').replace(/^'/, '').replace(/'$/, '')
}
return vModel.value.cdf
},
set: (value) => {
vModel.value.cdf = value
},
})
useProvideSmartsheetRowStore(vModel, rowRef) const cdfValue = ref<string | null>(null)
const updateCdfValue = (cdf: string | null) => {
vModel.value.cdf = cdf
cdfValue.value = vModel.value.cdf
}
onMounted(() => {
updateCdfValue(vModel.value.cdf.replace(/^'/, '').replace(/'$/, ''))
})
</script> </script>
<template> <template>
<div class="!my-3 text-xs">{{ $t('placeholder.defaultValue') }}</div> <div class="!my-3 text-xs">{{ $t('placeholder.defaultValue') }}</div>
<div class="flex flex-row gap-2"> <div class="flex flex-row gap-2">
<div class="border-1 flex items-center w-full px-3 my-[-4px] border-gray-300 rounded-md"> <div class="border-1 flex items-center w-full px-3 my-[-4px] border-gray-300 rounded-md">
<LazySmartsheetCell :column="vModel" :model-value="cdfValue" :edit-enabled="true" class="!border-none" /> <LazySmartsheetCell
:model-value="cdfValue"
:column="vModel"
:edit-enabled="true"
class="!border-none"
@update:cdf="updateCdfValue"
/>
<component <component
:is="iconMap.close" :is="iconMap.close"
v-if="vModel.uidt !== UITypes.Year" v-if="![UITypes.Year, UITypes.SingleSelect, UITypes.MultiSelect].includes(vModel.uidt)"
class="w-4 h-4 cursor-pointer rounded-full !text-black-500 text-gray-500 cursor-pointer hover:bg-gray-50" class="w-4 h-4 cursor-pointer rounded-full !text-black-500 text-gray-500 cursor-pointer hover:bg-gray-50"
@click="cdfValue = null" @click="cdfValue = null"
/> />

21
packages/nc-gui/components/smartsheet/column/SelectOptions.vue

@ -21,7 +21,7 @@ const emit = defineEmits(['update:value'])
const vModel = useVModel(props, 'value', emit) const vModel = useVModel(props, 'value', emit)
const { setAdditionalValidations, validateInfos, isMysql } = useColumnCreateStoreOrThrow() const { setAdditionalValidations, validateInfos, isMysql, isPg } = useColumnCreateStoreOrThrow()
// const { base } = storeToRefs(useBase()) // const { base } = storeToRefs(useBase())
@ -102,7 +102,7 @@ onMounted(() => {
if (vModel.value.cdf) { if (vModel.value.cdf) {
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql.value) { if (!isMysql.value && !isPg.value) {
vModel.value.cdf = vModel.value.cdf.replace(/''/g, "'") vModel.value.cdf = vModel.value.cdf.replace(/''/g, "'")
} }
} }
@ -181,23 +181,6 @@ const undoRemoveRenderedOption = (index: number) => {
} }
} }
// focus last created input
// watch(inputs, () => {
// if (inputs.value?.$el) {
// inputs.value.$el.focus()
// }
// })
// Removes the Select Option from cdf if the option is removed
watch(vModel.value, (next) => {
const cdfs = (next.cdf ?? '').split(',')
const values = (next.colOptions.options ?? []).map((col) => {
return col.title.replace(/^'/, '').replace(/'$/, '')
})
const newCdf = cdfs.filter((c: string) => values.includes(c)).join(',')
next.cdf = newCdf.length === 0 ? null : newCdf
})
const loadListData = async ($state: any) => { const loadListData = async ($state: any) => {
if (loadedOptionCount.value === options.value.length) { if (loadedOptionCount.value === options.value.length) {
$state.complete() $state.complete()

12
packages/nocodb/src/services/columns.service.ts

@ -387,7 +387,11 @@ export class ColumnsService {
} }
// handle single quote for default value // handle single quote for default value
if (driverType === 'mysql' || driverType === 'mysql2') { if (
driverType === 'mysql' ||
driverType === 'mysql2' ||
driverType === 'pg'
) {
colBody.cdf = colBody.cdf.replace(/'/g, "'"); colBody.cdf = colBody.cdf.replace(/'/g, "'");
} else { } else {
colBody.cdf = colBody.cdf.replace(/'/g, "''"); colBody.cdf = colBody.cdf.replace(/'/g, "''");
@ -1158,7 +1162,11 @@ export class ColumnsService {
} }
// handle single quote for default value // handle single quote for default value
if (driverType === 'mysql' || driverType === 'mysql2') { if (
driverType === 'mysql' ||
driverType === 'mysql2' ||
driverType === 'pg'
) {
colBody.cdf = colBody.cdf.replace(/'/g, "'"); colBody.cdf = colBody.cdf.replace(/'/g, "'");
} else { } else {
colBody.cdf = colBody.cdf.replace(/'/g, "''"); colBody.cdf = colBody.cdf.replace(/'/g, "''");

Loading…
Cancel
Save