diff --git a/packages/nc-gui-v2/components/smartsheet-column/DurationOptions.vue b/packages/nc-gui-v2/components/smartsheet-column/DurationOptions.vue
index 35bc764d7b..770ddccb99 100644
--- a/packages/nc-gui-v2/components/smartsheet-column/DurationOptions.vue
+++ b/packages/nc-gui-v2/components/smartsheet-column/DurationOptions.vue
@@ -1,8 +1,13 @@
@@ -25,7 +30,7 @@ formState.value.meta = {
-
+
{{ duration.title }}
diff --git a/packages/nc-gui-v2/components/smartsheet-column/EditOrAdd.vue b/packages/nc-gui-v2/components/smartsheet-column/EditOrAdd.vue
index 5e6f92a65a..78be8575dd 100644
--- a/packages/nc-gui-v2/components/smartsheet-column/EditOrAdd.vue
+++ b/packages/nc-gui-v2/components/smartsheet-column/EditOrAdd.vue
@@ -1,28 +1,26 @@
-
-
+
+
@@ -125,20 +127,28 @@ if (!formState.value?.column_name) {
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
+
{{ $t('general.cancel') }}
-
+
{{ $t('general.save') }}
diff --git a/packages/nc-gui-v2/components/smartsheet-column/EditOrAddProvider.vue b/packages/nc-gui-v2/components/smartsheet-column/EditOrAddProvider.vue
new file mode 100644
index 0000000000..27d8ce227c
--- /dev/null
+++ b/packages/nc-gui-v2/components/smartsheet-column/EditOrAddProvider.vue
@@ -0,0 +1,27 @@
+
+
+
+
+
diff --git a/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue b/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue
index 34ff75bfb7..c3c2dda53d 100644
--- a/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue
+++ b/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue
@@ -4,7 +4,7 @@ import type { ListItem as AntListItem } from 'ant-design-vue'
import jsep from 'jsep'
import type { ColumnType } from 'nocodb-sdk'
import { UITypes, jsepCurlyHook } from 'nocodb-sdk'
-import { onMounted, useColumnCreateStoreOrThrow, useDebounceFn } from '#imports'
+import { onMounted, useDebounceFn } from '#imports'
import { MetaInj } from '~/context'
import {
NcAutocompleteTree,
@@ -17,6 +17,16 @@ import {
validateDateWithUnknownFormat,
} from '@/utils'
+interface Props {
+ value: Record
+}
+
+const props = defineProps()
+const emit = defineEmits(['update:value'])
+const vModel = useVModel(props, 'value', emit)
+
+const { setAdditionalValidations, validateInfos, sqlUi, column } = useColumnCreateStoreOrThrow()
+
enum JSEPNode {
COMPOUND = 'Compound',
IDENTIFIER = 'Identifier',
@@ -29,8 +39,6 @@ enum JSEPNode {
ARRAY_EXP = 'ArrayExpression',
}
-const { formState, validateInfos, setAdditionalValidations, sqlUi, column } = useColumnCreateStoreOrThrow()
-
const meta = inject(MetaInj)
const columns = computed(() => meta?.value?.columns || [])
@@ -512,11 +520,11 @@ function appendText(item: Record) {
const len = wordToComplete.value?.length || 0
if (item.type === 'function') {
- formState.value.formula_raw = insertAtCursor(formulaRef.value.$el, text, len, 1)
+ vModel.value.formula_raw = insertAtCursor(formulaRef.value.$el, text, len, 1)
} else if (item.type === 'column') {
- formState.value.formula_raw = insertAtCursor(formulaRef.value.$el, `{${text}}`, len + +!isCurlyBracketBalanced())
+ vModel.value.formula_raw = insertAtCursor(formulaRef.value.$el, `{${text}}`, len + +!isCurlyBracketBalanced())
} else {
- formState.value.formula_raw = insertAtCursor(formulaRef.value.$el, text, len)
+ vModel.value.formula_raw = insertAtCursor(formulaRef.value.$el, text, len)
}
autocomplete.value = false
wordToComplete.value = ''
@@ -582,7 +590,7 @@ function scrollToSelectedOption() {
}
// set default value
-formState.value.formula_raw = (column?.value?.colOptions as Record)?.formula_raw || ''
+vModel.value.formula_raw = (column?.value?.colOptions as Record)?.formula_raw || ''
// set additional validations
setAdditionalValidations({
@@ -603,7 +611,7 @@ onMounted(() => {
import { ModelTypes, MssqlUi, SqliteUi } from 'nocodb-sdk'
-import { inject, useColumnCreateStoreOrThrow, useProject } from '#imports'
+import { inject, useProject } from '#imports'
import { MetaInj } from '~/context'
import MdiPlusIcon from '~icons/mdi/plus-circle-outline'
import MdiMinusIcon from '~icons/mdi/minus-circle-outline'
-const { formState, validateInfos, onDataTypeChange, setAdditionalValidations } = $(useColumnCreateStoreOrThrow())
-const { tables, sqlUi } = $(useProject())
+interface Props {
+ value: Record
+}
+
+const props = defineProps()
+const emit = defineEmits(['update:value'])
+const vModel = useVModel(props, 'value', emit)
+
const meta = $(inject(MetaInj)!)
+const { setAdditionalValidations, validateInfos, onDataTypeChange } = useColumnCreateStoreOrThrow()
+
+const { tables, sqlUi } = $(useProject())
+
setAdditionalValidations({
childId: [{ required: true, message: 'Required' }],
})
const onUpdateDeleteOptions = sqlUi === MssqlUi ? ['NO ACTION'] : ['NO ACTION', 'CASCADE', 'RESTRICT', 'SET NULL', 'SET DEFAULT']
-if (!formState.parentId) formState.parentId = meta.id
-if (!formState.childId) formState.childId = null
-if (!formState.childColumn) formState.childColumn = `${meta.table_name}_id`
-if (!formState.childTable) formState.childTable = meta.table_name
-if (!formState.parentTable) formState.parentTable = formState.rtn || ''
-if (!formState.parentColumn) formState.parentColumn = formState.rcn || ''
+if (!vModel.value.parentId) vModel.value.parentId = meta.id
+if (!vModel.value.childId) vModel.value.childId = null
+if (!vModel.value.childColumn) vModel.value.childColumn = `${meta.table_name}_id`
+if (!vModel.value.childTable) vModel.value.childTable = meta.table_name
+if (!vModel.value.parentTable) vModel.value.parentTable = vModel.value.rtn || ''
+if (!vModel.value.parentColumn) vModel.value.parentColumn = vModel.value.rcn || ''
-if (!formState.type) formState.type = 'hm'
-if (!formState.onUpdate) formState.onUpdate = onUpdateDeleteOptions[0]
-if (!formState.onDelete) formState.onDelete = onUpdateDeleteOptions[0]
-if (!formState.virtual) formState.virtual = sqlUi === SqliteUi
-if (!formState.alias) formState.alias = formState.column_name
+if (!vModel.value.type) vModel.value.type = 'hm'
+if (!vModel.value.onUpdate) vModel.value.onUpdate = onUpdateDeleteOptions[0]
+if (!vModel.value.onDelete) vModel.value.onDelete = onUpdateDeleteOptions[0]
+if (!vModel.value.virtual) vModel.value.virtual = sqlUi === SqliteUi
+if (!vModel.value.alias) vModel.value.alias = vModel.value.column_name
const advancedOptions = $(ref(false))
@@ -43,13 +53,13 @@ const refTables = $computed(() => {
-
+
Has Many
Many To Many
-
+
{{ table.title }}
@@ -68,14 +78,14 @@ const refTables = $computed(() => {
-
+
{{ option }}
-
+
{{ option }}
@@ -84,7 +94,7 @@ const refTables = $computed(() => {
- Virtual Relation
+ Virtual Relation
diff --git a/packages/nc-gui-v2/components/smartsheet-column/LookupOptions.vue b/packages/nc-gui-v2/components/smartsheet-column/LookupOptions.vue
index 38aeef670d..237df7df5d 100644
--- a/packages/nc-gui-v2/components/smartsheet-column/LookupOptions.vue
+++ b/packages/nc-gui-v2/components/smartsheet-column/LookupOptions.vue
@@ -1,12 +1,22 @@
-
+
@@ -25,13 +30,13 @@ if (!formState.meta?.default) formState.meta.default = null
-
+
-
+
Allow negative numbers
diff --git a/packages/nc-gui-v2/components/smartsheet-column/RatingOptions.vue b/packages/nc-gui-v2/components/smartsheet-column/RatingOptions.vue
index ef29523c60..14cf29d68b 100644
--- a/packages/nc-gui-v2/components/smartsheet-column/RatingOptions.vue
+++ b/packages/nc-gui-v2/components/smartsheet-column/RatingOptions.vue
@@ -1,8 +1,13 @@
@@ -67,20 +72,20 @@ watch(
-
+
@@ -90,7 +95,7 @@ watch(
-
+
{{ v }}
diff --git a/packages/nc-gui-v2/components/smartsheet-column/RollupOptions.vue b/packages/nc-gui-v2/components/smartsheet-column/RollupOptions.vue
index 15cddf2d29..91ba6ee0c0 100644
--- a/packages/nc-gui-v2/components/smartsheet-column/RollupOptions.vue
+++ b/packages/nc-gui-v2/components/smartsheet-column/RollupOptions.vue
@@ -1,13 +1,22 @@
@@ -50,12 +44,14 @@ useProvideColumnCreateStore(meta as Ref, column)
>
-
diff --git a/packages/nc-gui-v2/components/smartsheet-header/VirtualCell.vue b/packages/nc-gui-v2/components/smartsheet-header/VirtualCell.vue
index f08865ea9e..5c6b54173c 100644
--- a/packages/nc-gui-v2/components/smartsheet-header/VirtualCell.vue
+++ b/packages/nc-gui-v2/components/smartsheet-header/VirtualCell.vue
@@ -3,7 +3,7 @@ import { substituteColumnIdWithAliasInFormula } from 'nocodb-sdk'
import type { ColumnType, FormulaType, LinkToAnotherRecordType, LookupType, RollupType, TableType } from 'nocodb-sdk'
import type { Ref } from 'vue'
import { ColumnInj, IsFormInj, MetaInj } from '~/context'
-import { provide, toRef, useMetas, useProvideColumnCreateStore } from '#imports'
+import { provide, toRef, useMetas } from '#imports'
const props = defineProps<{ column: ColumnType & { meta: any }; hideMenu?: boolean; required?: boolean }>()
@@ -90,8 +90,6 @@ function onVisibleChange() {
// by clicking cancel button
editColumnDropdown.value = true
}
-
-useProvideColumnCreateStore(meta as Ref, column)
@@ -126,12 +124,14 @@ useProvideColumnCreateStore(meta as Ref, column)
>
-
diff --git a/packages/nc-gui-v2/components/smartsheet/Form.vue b/packages/nc-gui-v2/components/smartsheet/Form.vue
index 886de9f54b..353d76ae2e 100644
--- a/packages/nc-gui-v2/components/smartsheet/Form.vue
+++ b/packages/nc-gui-v2/components/smartsheet/Form.vue
@@ -30,8 +30,6 @@ const meta = inject(MetaInj)
const view = inject(ActiveViewInj)
-if (meta) useProvideColumnCreateStore(meta)
-
const { loadFormView, insertRow, formColumnData, formViewData, updateFormView } = useViewData(meta, view as any)
const { showAll, hideAll, saveOrUpdate } = useViewColumns(view, meta as any, false, async () => {
@@ -47,8 +45,6 @@ const hiddenColumns = ref>([])
const draggableRef = ref()
-const editOrAddRef = ref()
-
const systemFieldsIds = ref>([])
const showColumnDropdown = ref(false)
@@ -293,10 +289,6 @@ onClickOutside(draggableRef, () => {
activeRow.value = ''
})
-onClickOutside(editOrAddRef, () => {
- showColumnDropdown.value = false
-})
-
onMounted(async () => {
await loadFormView()
setFormData()
@@ -390,7 +382,7 @@ onMounted(async () => {
{{ $t('msg.info.dragDropHide') }}
-
+
@@ -398,7 +390,13 @@ onMounted(async () => {
-
+
diff --git a/packages/nc-gui-v2/components/smartsheet/Grid.vue b/packages/nc-gui-v2/components/smartsheet/Grid.vue
index 76939b0c64..681057375e 100644
--- a/packages/nc-gui-v2/components/smartsheet/Grid.vue
+++ b/packages/nc-gui-v2/components/smartsheet/Grid.vue
@@ -11,7 +11,6 @@ import {
ref,
useEventListener,
useGridViewColumnWidth,
- useProvideColumnCreateStore,
useSmartsheetStoreOrThrow,
useViewData,
watch,
@@ -127,9 +126,6 @@ defineExpose({
loadData,
})
-// instantiate column create store
-if (meta) useProvideColumnCreateStore(meta)
-
// reset context menu target on hide
watch(contextMenu, () => {
if (!contextMenu.value) {
@@ -329,14 +325,20 @@ const expandForm = (row: Row, state: Record
) => {
-
+ |
-
+
|
diff --git a/packages/nc-gui-v2/composables/useColumnCreateStore.ts b/packages/nc-gui-v2/composables/useColumnCreateStore.ts
index 260eea6f85..011df26bb1 100644
--- a/packages/nc-gui-v2/composables/useColumnCreateStore.ts
+++ b/packages/nc-gui-v2/composables/useColumnCreateStore.ts
@@ -1,4 +1,5 @@
import { createInjectionState } from '@vueuse/core'
+import clone from 'just-clone'
import { Form, message } from 'ant-design-vue'
import type { ColumnType, TableType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk'
@@ -25,18 +26,28 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
const { $api } = useNuxtApp()
const { getMeta } = useMetas()
+ const isEdit = computed(() => !!column?.value?.id)
+
const idType = null
- // state
- // todo: give proper type - ColumnType
+ const additionalValidations = ref>({})
+
+ const setAdditionalValidations = (validations: Record) => {
+ additionalValidations.value = validations
+ }
+
const formState = ref>({
title: 'title',
uidt: UITypes.SingleLineText,
- ...(column?.value || {}),
- meta: column?.value?.meta || {},
+ ...clone(column?.value || {}),
})
- const additionalValidations = ref>({})
+ // actions
+ const generateNewColumnMeta = () => {
+ setAdditionalValidations({})
+ formState.value = { meta: {}, ...sqlUi.value.getNewColumn((meta.value?.columns?.length || 0) + 1) }
+ formState.value.title = formState.value.column_name
+ }
const validators = computed(() => {
return {
@@ -77,17 +88,6 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
const { resetFields, validate, validateInfos } = useForm(formState, validators)
- const setAdditionalValidations = (validations: Record) => {
- additionalValidations.value = validations
- }
-
- // actions
- const generateNewColumnMeta = () => {
- setAdditionalValidations({})
- formState.value = { meta: {}, ...sqlUi.value.getNewColumn((meta.value?.columns?.length || 0) + 1) }
- formState.value.title = formState.value.title || formState.value.column_name
- }
-
const onUidtOrIdTypeChange = () => {
const { isCurrency } = useColumn(ref(formState.value as ColumnType))
@@ -177,6 +177,8 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
console.log(formState, validators)
if (!(await validate())) return
} catch (e) {
+ console.log(e)
+ console.trace()
message.error('Form validation failed')
return
}
@@ -220,18 +222,18 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
return {
formState,
+ generateNewColumnMeta,
+ addOrUpdate,
+ onAlter,
+ onDataTypeChange,
+ onUidtOrIdTypeChange,
+ setAdditionalValidations,
resetFields,
validate,
validateInfos,
- setAdditionalValidations,
- onUidtOrIdTypeChange,
- sqlUi,
- onDataTypeChange,
- onAlter,
- addOrUpdate,
- generateNewColumnMeta,
- isEdit: computed(() => !!column?.value?.id),
+ isEdit,
column,
+ sqlUi,
}
},
)
diff --git a/packages/nc-gui-v2/package.json b/packages/nc-gui-v2/package.json
index efa84dabdc..61948750c0 100644
--- a/packages/nc-gui-v2/package.json
+++ b/packages/nc-gui-v2/package.json
@@ -18,6 +18,7 @@
"dayjs": "^1.11.3",
"file-saver": "^2.0.5",
"jsep": "^1.3.6",
+ "just-clone": "^6.1.1",
"jwt-decode": "^3.1.2",
"locale-codes": "^1.3.1",
"monaco-editor": "^0.33.0",