Browse Source

fix(nc-gui): some MFE related issues

pull/9997/head
Ramesh Mane 3 days ago
parent
commit
66259d3fd4
  1. 171
      packages/nc-gui/components/smartsheet/column/LongTextOptions.vue
  2. 39
      packages/nc-gui/components/smartsheet/details/Fields.vue

171
packages/nc-gui/components/smartsheet/column/LongTextOptions.vue

@ -107,7 +107,7 @@ const generate = async () => {
const isPromptEnabled = computed(() => { const isPromptEnabled = computed(() => {
if (isEdit.value) { if (isEdit.value) {
return isAIPromptCol(column.value) return isAIPromptCol(column.value) || isFeatureEnabled(FEATURE_FLAG.AI_FEATURES)
} }
return 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<string, any>)?.prompt_raw || '' vModel.value.prompt_raw = (column?.value?.colOptions as Record<string, any>)?.prompt_raw || ''
}) })
const validators = {
fk_integration_id: [
{
validator: (_: any, value: any) => {
return new Promise<void>((resolve, reject) => {
if (isEnabledGenerateText.value && !value) {
reject(new Error(t('title.aiIntegrationMissing')))
}
resolve()
})
},
},
],
}
if (isEdit.value) { if (isEdit.value) {
vModel.value.fk_integration_id = vModel.value?.colOptions?.fk_integration_id vModel.value.fk_integration_id = vModel.value?.colOptions?.fk_integration_id
} }
setAdditionalValidations({
...validators,
})
provide(EditColumnInj, ref(true)) provide(EditColumnInj, ref(true))
const richMode = computed({ const richMode = computed({
@ -156,24 +175,6 @@ watch(richMode, () => {
watch(isPreviewEnabled, handleDisableSubmitBtn, { watch(isPreviewEnabled, handleDisableSubmitBtn, {
immediate: true, 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,
},
)
</script> </script>
<template> <template>
@ -196,31 +197,28 @@ watch(
<NcTooltip :disabled="!richMode" class="flex items-center"> <NcTooltip :disabled="!richMode" class="flex items-center">
<template #title> Generate text using AI is not supported when rich text formatting is enabled </template> <template #title> Generate text using AI is not supported when rich text formatting is enabled </template>
<NcSwitch <NcSwitch
v-model:checked="isEnabledGenerateText" v-model:checked="isEnabledGenerateText"
:disabled="richMode" :disabled="richMode"
class="nc-ai-field-generate-text nc-ai-input" class="nc-ai-field-generate-text nc-ai-input"
@change="handleDisableSubmitBtn" @change="handleDisableSubmitBtn"
>
<span
class="text-sm font-semibold pl-1"
:class="{
'text-nc-content-purple-dark': isEnabledGenerateText,
'text-nc-content-gray': !isEnabledGenerateText,
}"
> >
<span Generate text using AI
class="text-sm font-semibold pl-1" </span>
:class="{ </NcSwitch>
'text-nc-content-purple-dark': isEnabledGenerateText, </NcTooltip>
'text-nc-content-gray': !isEnabledGenerateText, <NcTooltip class="ml-2 mr-[40px] flex cursor-pointer">
}" <template #title> Use AI to generate content based on record data. </template>
> <GeneralIcon icon="info" class="text-nc-content-gray-muted hover:text-nc-content-gray-subtle opacity-70 w-3.5 h-3.5" />
Generate text using AI </NcTooltip>
</span> <div class="flex-1"></div>
</NcSwitch>
</NcTooltip>
<NcTooltip class="ml-2 mr-[40px] flex cursor-pointer">
<template #title> Use AI to generate content based on record data. </template>
<GeneralIcon
icon="info"
class="text-nc-content-gray-muted hover:text-nc-content-gray-subtle opacity-70 w-3.5 h-3.5"
/>
</NcTooltip>
<div class="flex-1"></div>
<div class="absolute right-0"> <div class="absolute right-0">
<AiSettings <AiSettings
@ -283,56 +281,55 @@ watch(
</span> </span>
</div> </div>
<NcTooltip :disabled="isPreviewEnabled"> <NcTooltip :disabled="isPreviewEnabled">
<template #title> Include at least 1 field in prompt to generate </template> <template #title> Include at least 1 field in prompt to generate </template>
<NcButton <NcButton
class="nc-aioptions-preview-generate-btn" class="nc-aioptions-preview-generate-btn"
:class="{
'nc-is-already-generated': isAlreadyGenerated,
'nc-preview-enabled': isPreviewEnabled,
}"
size="xs"
:type="isAlreadyGenerated ? 'text' : 'secondary'"
:theme="isPreviewEnabled ? 'ai' : 'default'"
:disabled="!isPreviewEnabled"
:loading="generatingPreview"
@click.stop="generate"
>
<div
:class="{ :class="{
'nc-is-already-generated': isAlreadyGenerated, 'nc-animate-dots min-w-[91px] text-left': generatingPreview,
'nc-preview-enabled': isPreviewEnabled, 'min-w-[102px]': isAlreadyGenerated && generatingPreview,
'min-w-[80px]': !isAlreadyGenerated && generatingPreview,
}" }"
size="xs"
:type="isAlreadyGenerated ? 'text' : 'secondary'"
:theme="isPreviewEnabled ? 'ai' : 'default'"
:disabled="!isPreviewEnabled"
:loading="generatingPreview"
@click.stop="generate"
> >
<div {{
:class="{ isAlreadyGenerated
'nc-animate-dots min-w-[91px] text-left': generatingPreview, ? generatingPreview
'min-w-[102px]': isAlreadyGenerated && generatingPreview, ? 'Re-generating'
'min-w-[80px]': !isAlreadyGenerated && generatingPreview, : 'Re-generate'
}" : generatingPreview
> ? 'Generating'
{{ : 'Generate preview'
isAlreadyGenerated }}
? generatingPreview </div>
? 'Re-generating' </NcButton>
: 'Re-generate' </NcTooltip>
: generatingPreview </div>
? 'Generating' <div v-if="previewRow.row?.[previewFieldTitle]?.value">
: 'Generate preview' <div class="relative">
}} <LazySmartsheetRow :row="previewRow">
</div> <LazySmartsheetCell
</NcButton> :edit-enabled="true"
</NcTooltip> :model-value="previewRow.row[previewFieldTitle]"
</div> :column="vModel"
<div v-if="previewRow.row?.[previewFieldTitle]?.value"> class="!border-none h-auto my-auto pl-1"
<div class="relative"> />
<LazySmartsheetRow :row="previewRow"> </LazySmartsheetRow>
<LazySmartsheetCell
:edit-enabled="true"
:model-value="previewRow.row[previewFieldTitle]"
:column="vModel"
class="!border-none h-auto my-auto pl-1"
/>
</LazySmartsheetRow>
</div>
</div> </div>
</div> </div>
</div> </div>
</template> </div>
</template> </template>
<AiIntegrationNotFound v-if="!aiIntegrationAvailable && isEnabledGenerateText && isPromptEnabled" /> <AiIntegrationNotFound v-if="!aiIntegrationAvailable && isEnabledGenerateText && isPromptEnabled" />

39
packages/nc-gui/components/smartsheet/details/Fields.vue

@ -4,6 +4,7 @@ import { message } from 'ant-design-vue'
import { import {
ButtonActionsType, ButtonActionsType,
UITypes, UITypes,
isAIPromptCol,
isLinksOrLTAR, isLinksOrLTAR,
isSystemColumn, isSystemColumn,
isVirtualCol, isVirtualCol,
@ -650,21 +651,12 @@ const isColumnValid = (column: TableExplorerColumn) => {
} }
if (column.type === ButtonActionsType.Ai) { if (column.type === ButtonActionsType.Ai) {
if (isNew) { return !(
return !( !column.fk_integration_id ||
!column.fk_integration_id || !column.formula_raw?.trim() ||
!column.formula_raw?.trim() || !column.output_column_ids?.length ||
!column.cdfoutput_column_ids?.length || !column.output_column_ids?.split(',')?.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
)
}
} }
} }
@ -724,6 +716,11 @@ function updateDefaultColumnValues(column: TableExplorerColumn) {
column.fk_webhook_id = colOptions?.fk_webhook_id column.fk_webhook_id = colOptions?.fk_webhook_id
column.icon = colOptions?.icon column.icon = colOptions?.icon
column.formula_raw = column.colOptions?.formula_raw 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 { } else {
column.type = column?.type || ButtonActionsType.Url column.type = column?.type || ButtonActionsType.Url
@ -732,8 +729,6 @@ function updateDefaultColumnValues(column: TableExplorerColumn) {
column.label = column.label || 'Generate data' column.label = column.label || 'Generate data'
column.color = column.color || 'purple' column.color = column.color || 'purple'
column.icon = column.icon || 'ncAutoAwesome' column.icon = column.icon || 'ncAutoAwesome'
column.output_column_ids = colOptions?.output_column_ids
column.fk_integration_id = colOptions?.fk_integration_id
} else { } else {
column.theme = column.theme || 'solid' column.theme = column.theme || 'solid'
column.label = column.label || 'Button' 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<string, any>
column.prompt_raw = colOptions?.prompt_raw
} else {
column.prompt_raw = column.prompt_raw || ''
}
}
return column return column
} }

Loading…
Cancel
Save