diff --git a/packages/nc-gui/components/smartsheet/column/LongTextOptions.vue b/packages/nc-gui/components/smartsheet/column/LongTextOptions.vue index 95fad7dda8..08db2880e8 100644 --- a/packages/nc-gui/components/smartsheet/column/LongTextOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/LongTextOptions.vue @@ -107,7 +107,7 @@ const generate = async () => { const isPromptEnabled = computed(() => { if (isEdit.value) { - return isAIPromptCol(column.value) + return isAIPromptCol(column.value) || isFeatureEnabled(FEATURE_FLAG.AI_FEATURES) } return isFeatureEnabled(FEATURE_FLAG.AI_FEATURES) @@ -118,10 +118,29 @@ onMounted(() => { vModel.value.prompt_raw = (column?.value?.colOptions as Record)?.prompt_raw || '' }) +const validators = { + fk_integration_id: [ + { + validator: (_: any, value: any) => { + return new Promise((resolve, reject) => { + if (isEnabledGenerateText.value && !value) { + reject(new Error(t('title.aiIntegrationMissing'))) + } + resolve() + }) + }, + }, + ], +} + if (isEdit.value) { vModel.value.fk_integration_id = vModel.value?.colOptions?.fk_integration_id } +setAdditionalValidations({ + ...validators, +}) + provide(EditColumnInj, ref(true)) const richMode = computed({ @@ -156,24 +175,6 @@ watch(richMode, () => { watch(isPreviewEnabled, handleDisableSubmitBtn, { immediate: true, }) - -watch( - isEnabledGenerateText, - (newValue) => { - if (newValue) { - setAdditionalValidations({ - fk_integration_id: [{ required: true, message: t('title.aiIntegrationMissing') }], - }) - } else { - setAdditionalValidations({ - fk_integration_id: [{ required: false }], - }) - } - }, - { - immediate: true, - }, -) + diff --git a/packages/nc-gui/components/smartsheet/details/Fields.vue b/packages/nc-gui/components/smartsheet/details/Fields.vue index 503f9ebf9c..6b41cd413b 100644 --- a/packages/nc-gui/components/smartsheet/details/Fields.vue +++ b/packages/nc-gui/components/smartsheet/details/Fields.vue @@ -4,6 +4,7 @@ import { message } from 'ant-design-vue' import { ButtonActionsType, UITypes, + isAIPromptCol, isLinksOrLTAR, isSystemColumn, isVirtualCol, @@ -650,21 +651,12 @@ const isColumnValid = (column: TableExplorerColumn) => { } if (column.type === ButtonActionsType.Ai) { - if (isNew) { - return !( - !column.fk_integration_id || - !column.formula_raw?.trim() || - !column.cdfoutput_column_ids?.length || - !column.output_column_ids?.split(',')?.length - ) - } else { - !( - !column.colOptions?.fk_integration_id || - !column.colOptions?.formula_raw?.trim() || - !column.colOptions?.output_column_ids?.length || - !column.colOptions?.output_column_ids?.split(',')?.length - ) - } + return !( + !column.fk_integration_id || + !column.formula_raw?.trim() || + !column.output_column_ids?.length || + !column.output_column_ids?.split(',')?.length + ) } } @@ -724,6 +716,11 @@ function updateDefaultColumnValues(column: TableExplorerColumn) { column.fk_webhook_id = colOptions?.fk_webhook_id column.icon = colOptions?.icon column.formula_raw = column.colOptions?.formula_raw + + if (column.type === ButtonActionsType.Ai) { + column.output_column_ids = colOptions?.output_column_ids + column.fk_integration_id = colOptions?.fk_integration_id + } } else { column.type = column?.type || ButtonActionsType.Url @@ -732,8 +729,6 @@ function updateDefaultColumnValues(column: TableExplorerColumn) { column.label = column.label || 'Generate data' column.color = column.color || 'purple' column.icon = column.icon || 'ncAutoAwesome' - column.output_column_ids = colOptions?.output_column_ids - column.fk_integration_id = colOptions?.fk_integration_id } else { column.theme = column.theme || 'solid' column.label = column.label || 'Button' @@ -745,6 +740,16 @@ function updateDefaultColumnValues(column: TableExplorerColumn) { } } + if (column.uidt === UITypes.LongText && isAIPromptCol(column)) { + if (column?.id) { + const colOptions = column.colOptions as Record + + column.prompt_raw = colOptions?.prompt_raw + } else { + column.prompt_raw = column.prompt_raw || '' + } + } + return column }