|
|
@ -1,9 +1,13 @@ |
|
|
|
import { createInjectionState } from '@vueuse/core' |
|
|
|
import { createInjectionState } from '@vueuse/core' |
|
|
|
import { Form } from 'ant-design-vue' |
|
|
|
import { Form } from 'ant-design-vue' |
|
|
|
import type { ColumnType } from 'nocodb-sdk' |
|
|
|
import type { ColumnType, TableType } from 'nocodb-sdk' |
|
|
|
import { UITypes } from 'nocodb-sdk' |
|
|
|
import { UITypes } from 'nocodb-sdk' |
|
|
|
|
|
|
|
import type { Ref } from 'vue' |
|
|
|
|
|
|
|
import { useToast } from 'vue-toastification' |
|
|
|
import { computed } from '#imports' |
|
|
|
import { computed } from '#imports' |
|
|
|
|
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
import useColumn from '~/composables/useColumn' |
|
|
|
import useColumn from '~/composables/useColumn' |
|
|
|
|
|
|
|
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' |
|
|
|
|
|
|
|
|
|
|
|
const useForm = Form.useForm |
|
|
|
const useForm = Form.useForm |
|
|
|
|
|
|
|
|
|
|
@ -16,8 +20,12 @@ const useForm = Form.useForm |
|
|
|
|
|
|
|
|
|
|
|
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber] |
|
|
|
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber] |
|
|
|
|
|
|
|
|
|
|
|
const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState((column?: ColumnType) => { |
|
|
|
const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState((meta: Ref<TableType>, column?: ColumnType) => { |
|
|
|
const { sqlUi } = useProject() |
|
|
|
const { sqlUi } = useProject() |
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const toast = useToast() |
|
|
|
|
|
|
|
|
|
|
|
const idType = null |
|
|
|
const idType = null |
|
|
|
|
|
|
|
|
|
|
|
// state
|
|
|
|
// state
|
|
|
@ -48,6 +56,8 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { resetFields, validate, validateInfos } = useForm(formState, validators) |
|
|
|
|
|
|
|
|
|
|
|
// actions
|
|
|
|
// actions
|
|
|
|
const setAdditionalValidations = (validations: Record<string, any>) => { |
|
|
|
const setAdditionalValidations = (validations: Record<string, any>) => { |
|
|
|
additionalValidations.value = validations |
|
|
|
additionalValidations.value = validations |
|
|
@ -136,12 +146,34 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState |
|
|
|
if (cdf) formState.value.cdf = formState.value.cdf || null |
|
|
|
if (cdf) formState.value.cdf = formState.value.cdf || null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const addOrUpdate = () => { |
|
|
|
const addOrUpdate = async (onSuccess: () => {}) => { |
|
|
|
// todo
|
|
|
|
if (!(await validate())) return |
|
|
|
console.log('To be done') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { resetFields, validate, validateInfos } = useForm(formState, validators) |
|
|
|
formState.value.table_name = meta.value.table_name |
|
|
|
|
|
|
|
formState.value.title = formState.value.column_name |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (column) { |
|
|
|
|
|
|
|
await $api.dbTableColumn.update(column.id as string, formState.value) |
|
|
|
|
|
|
|
toast.success('Column updated') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// todo : set additional meta for auto generated string id
|
|
|
|
|
|
|
|
if (formState.value.uidt === UITypes.ID) { |
|
|
|
|
|
|
|
// based on id column type set autogenerated meta prop
|
|
|
|
|
|
|
|
// if (isAutoGenId) {
|
|
|
|
|
|
|
|
// this.newColumn.meta = {
|
|
|
|
|
|
|
|
// ag: 'nc',
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await $api.dbTableColumn.create(meta.value.id as string, formState.value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toast.success('Column created') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
onSuccess() |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
formState, |
|
|
|
formState, |
|
|
@ -157,7 +189,7 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
export { useProvideColumnCreateStore, useColumnCreateStore } |
|
|
|
export { useProvideColumnCreateStore } |
|
|
|
|
|
|
|
|
|
|
|
export function useColumnCreateStoreOrThrow() { |
|
|
|
export function useColumnCreateStoreOrThrow() { |
|
|
|
const columnCreateStore = useColumnCreateStore() |
|
|
|
const columnCreateStore = useColumnCreateStore() |
|
|
|