Browse Source

fix(gui): remove unnecessary chars from column default value

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4459/head
Pranav C 2 years ago
parent
commit
9b9894f72b
  1. 2
      packages/nc-gui/components/account/UserList.vue
  2. 2
      packages/nc-gui/components/account/UsersModal.vue
  3. 41
      packages/nc-gui/components/cell/MultiSelect.vue
  4. 25
      packages/nc-gui/components/cell/SingleSelect.vue

2
packages/nc-gui/components/account/UserList.vue

@ -29,7 +29,7 @@ const searchText = ref<string>('')
const pagination = reactive({
total: 0,
pageSize: 10,
position: ['bottomCenter']
position: ['bottomCenter'],
})
const loadUsers = async (page = currentPage, limit = currentLimit) => {

2
packages/nc-gui/components/account/UsersModal.vue

@ -4,13 +4,13 @@ import {
Form,
computed,
extractSdkResponseErrorMsg,
validateEmail,
message,
ref,
useCopy,
useDashboard,
useI18n,
useNuxtApp,
validateEmail,
} from '#imports'
import type { User } from '~/lib'
import { Role } from '~/lib'

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

@ -33,8 +33,6 @@ const { modelValue } = defineProps<Props>()
const emit = defineEmits(['update:modelValue'])
const { isMysql } = useProject()
const column = inject(ColumnInj)!
const readOnly = inject(ReadonlyInj)!
@ -59,6 +57,8 @@ const { $api } = useNuxtApp()
const { getMeta } = useMetas()
const { isPg, isMysql } = useProject()
// a variable to keep newly created options value
// temporary until it's add the option to column meta
const tempSelectedOptsState = reactive<string[]>([])
@ -107,13 +107,13 @@ const selectedTitles = computed(() =>
? typeof modelValue === 'string'
? isMysql
? modelValue.split(',').sort((a, b) => {
const opa = options.value.find((el) => el.title === a)
const opb = options.value.find((el) => el.title === b)
if (opa && opb) {
return opa.order! - opb.order!
}
return 0
})
const opa = options.value.find((el) => el.title === a)
const opb = options.value.find((el) => el.title === b)
if (opa && opb) {
return opa.order! - opb.order!
}
return 0
})
: modelValue.split(',')
: modelValue
: [],
@ -206,9 +206,26 @@ async function addIfMissingAndSave() {
})
column.value.colOptions = { options: newOptions.map(({ value: _, ...rest }) => rest) }
await $api.dbTableColumn.update((column.value as { fk_column_id?: string })?.fk_column_id || (column.value?.id as string), {
...column.value,
})
const updatedColMeta = { ...column.value }
// todo: refactor and avoid repetition
// 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) {
updatedColMeta.cdf = updatedColMeta.cdf.substring(
updatedColMeta.cdf.indexOf(`'`) + 1,
updatedColMeta.cdf.lastIndexOf(`'`),
)
}
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql.value) {
updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'")
}
await $api.dbTableColumn.update(
(column.value as { fk_column_id?: string })?.fk_column_id || (column.value?.id as string),
updatedColMeta,
)
activeOptCreateInProgress.value--
if (!activeOptCreateInProgress.value) {

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

@ -49,6 +49,8 @@ const searchVal = ref()
const { getMeta } = useMetas()
const { isPg, isMysql } = useProject()
// a variable to keep newly created option value
// temporary until it's add the option to column meta
const tempSelectedOptState = ref<string>()
@ -127,9 +129,26 @@ async function addIfMissingAndSave() {
})
column.value.colOptions = { options: options.value.map(({ value: _, ...rest }) => rest) }
await $api.dbTableColumn.update((column.value as { fk_column_id?: string })?.fk_column_id || (column.value?.id as string), {
...column.value,
})
const updatedColMeta = { ...column.value }
// todo: refactor and avoid repetition
// 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) {
updatedColMeta.cdf = updatedColMeta.cdf.substring(
updatedColMeta.cdf.indexOf(`'`) + 1,
updatedColMeta.cdf.lastIndexOf(`'`),
)
}
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql.value) {
updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'")
}
await $api.dbTableColumn.update(
(column.value as { fk_column_id?: string })?.fk_column_id || (column.value?.id as string),
updatedColMeta,
)
vModel.value = newOptValue
await getMeta(column.value.fk_model_id!, true)
} catch (e) {

Loading…
Cancel
Save