mirror of
https://gitlab.com/bramw/baserow.git
synced 2024-09-16 17:48:19 +00:00
122 lines
3.0 KiB
JavaScript
122 lines
3.0 KiB
JavaScript
import {
|
|
FieldType,
|
|
FormulaFieldType,
|
|
} from '@baserow/modules/database/fieldTypes'
|
|
import RowHistoryFieldText from '@baserow/modules/database/components/row/RowHistoryFieldText'
|
|
import RowCardFieldText from '@baserow/modules/database/components/card/RowCardFieldText'
|
|
import { collatedStringCompare } from '@baserow/modules/core/utils/string'
|
|
import {
|
|
genericContainsFilter,
|
|
genericContainsWordFilter,
|
|
} from '@baserow/modules/database/utils/fieldFilters'
|
|
|
|
import GridViewFieldAI from '@baserow_premium/components/views/grid/fields/GridViewFieldAI'
|
|
import FunctionalGridViewFieldAI from '@baserow_premium/components/views/grid/fields/FunctionalGridViewFieldAI'
|
|
import RowEditFieldAI from '@baserow_premium/components/row/RowEditFieldAI'
|
|
import FieldAISubForm from '@baserow_premium/components/field/FieldAISubForm'
|
|
import FormulaFieldAI from '@baserow_premium/components/field/FormulaFieldAI'
|
|
import GridViewFieldAIGenerateValuesContextItem from '@baserow_premium/components/views/grid/fields/GridViewFieldAIGenerateValuesContextItem'
|
|
import PremiumModal from '@baserow_premium/components/PremiumModal'
|
|
import PremiumFeatures from '@baserow_premium/features'
|
|
|
|
export class AIFieldType extends FieldType {
|
|
static getType() {
|
|
return 'ai'
|
|
}
|
|
|
|
getIconClass() {
|
|
return 'iconoir-magic-wand'
|
|
}
|
|
|
|
getName() {
|
|
const { i18n } = this.app
|
|
return i18n.t('premiumFieldType.ai')
|
|
}
|
|
|
|
getGridViewFieldComponent() {
|
|
return GridViewFieldAI
|
|
}
|
|
|
|
getFunctionalGridViewFieldComponent() {
|
|
return FunctionalGridViewFieldAI
|
|
}
|
|
|
|
getRowEditFieldComponent(field) {
|
|
return RowEditFieldAI
|
|
}
|
|
|
|
getCardComponent() {
|
|
return RowCardFieldText
|
|
}
|
|
|
|
getRowHistoryEntryComponent() {
|
|
return RowHistoryFieldText
|
|
}
|
|
|
|
getFormComponent() {
|
|
return FieldAISubForm
|
|
}
|
|
|
|
getFormViewFieldComponents(field) {
|
|
return {}
|
|
}
|
|
|
|
getEmptyValue(field) {
|
|
return null
|
|
}
|
|
|
|
getSort(name, order) {
|
|
return (a, b) => {
|
|
const stringA = a[name] === null ? '' : '' + a[name]
|
|
const stringB = b[name] === null ? '' : '' + b[name]
|
|
|
|
return collatedStringCompare(stringA, stringB, order)
|
|
}
|
|
}
|
|
|
|
getDocsDataType(field) {
|
|
return 'string'
|
|
}
|
|
|
|
getDocsDescription(field) {
|
|
const { i18n } = this.app
|
|
return i18n.t('premiumFieldType.aiDescription')
|
|
}
|
|
|
|
getDocsRequestExample(field) {
|
|
return 'string'
|
|
}
|
|
|
|
getContainsFilterFunction() {
|
|
return genericContainsFilter
|
|
}
|
|
|
|
getContainsWordFilterFunction(field) {
|
|
return genericContainsWordFilter
|
|
}
|
|
|
|
getGridViewContextItemsOnCellsSelection(field) {
|
|
return [GridViewFieldAIGenerateValuesContextItem]
|
|
}
|
|
|
|
isEnabled(workspace) {
|
|
return Object.values(workspace.generative_ai_models_enabled).some(
|
|
(models) => models.length > 0
|
|
)
|
|
}
|
|
|
|
isDeactivated(workspaceId) {
|
|
return !this.app.$hasFeature(PremiumFeatures.PREMIUM, workspaceId)
|
|
}
|
|
|
|
getDeactivatedClickModal(workspaceId) {
|
|
return PremiumModal
|
|
}
|
|
}
|
|
|
|
export class PremiumFormulaFieldType extends FormulaFieldType {
|
|
getAdditionalFormInputComponents() {
|
|
return [FormulaFieldAI]
|
|
}
|
|
}
|