From 88a553efe0bd8f00729f7befcb9c25842f8a9c6a Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 3 Aug 2022 19:42:31 +0530 Subject: [PATCH] fix(gui-v2): reset validators on new column meta generation and include meta prop Signed-off-by: Pranav C --- .../composables/useColumnCreateStore.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/nc-gui-v2/composables/useColumnCreateStore.ts b/packages/nc-gui-v2/composables/useColumnCreateStore.ts index b384e9f6d7..cdf2b78063 100644 --- a/packages/nc-gui-v2/composables/useColumnCreateStore.ts +++ b/packages/nc-gui-v2/composables/useColumnCreateStore.ts @@ -33,8 +33,9 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState const formState = ref>>({ title: 'title', uidt: UITypes.SingleLineText, - meta: {}, ...(column || {}), + // todo: swagger json update - include meta + meta: (column as any)?.meta || {}, }) const additionalValidations = ref>({}) @@ -78,14 +79,16 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState const { resetFields, validate, validateInfos } = useForm(formState, validators) + const setAdditionalValidations = (validations: Record) => { + additionalValidations.value = validations + } + // actions const generateNewColumnMeta = () => { - formState.value = sqlUi.value.getNewColumn((meta.value.columns?.length || 0) + 1) + setAdditionalValidations({}) + formState.value = { meta: {}, ...sqlUi.value.getNewColumn((meta.value.columns?.length || 0) + 1) } } - const setAdditionalValidations = (validations: Record) => { - additionalValidations.value = validations - } const onUidtOrIdTypeChange = () => { const { isCurrency } = useColumn(formState.value as ColumnType) @@ -171,11 +174,13 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState } const addOrUpdate = async (onSuccess: () => {}) => { - if (!(await validate())) return - formState.value.table_name = meta.value.table_name - formState.value.title = formState.value.column_name try { + console.log(formState, validators) + if (!(await validate())) return + + formState.value.table_name = meta.value.table_name + formState.value.title = formState.value.column_name if (column) { await $api.dbTableColumn.update(column.id as string, formState.value) toast.success('Column updated')