Merge branch 'v3-ui' into view-calc-count-non-numeric

This commit is contained in:
Andrew Kingston 2024-10-31 15:26:41 +00:00 committed by GitHub
commit a8ef64b9c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 122 additions and 22 deletions

View File

@ -9,7 +9,7 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { onMount, createEventDispatcher } from "svelte" import { onMount, createEventDispatcher } from "svelte"
import { flags } from "stores/builder" import { flags } from "stores/builder"
import { licensing } from "stores/portal" import { featureFlags } from "stores/portal"
import { API } from "api" import { API } from "api"
import MagicWand from "../../../../assets/MagicWand.svelte" import MagicWand from "../../../../assets/MagicWand.svelte"
@ -26,8 +26,7 @@
let aiCronPrompt = "" let aiCronPrompt = ""
let loadingAICronExpression = false let loadingAICronExpression = false
$: aiEnabled = $: aiEnabled = $featureFlags.AI_CUSTOM_CONFIGS || $featureFlags.BUDIBASE_AI
$licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled
$: { $: {
if (cronExpression) { if (cronExpression) {
try { try {

View File

@ -8,6 +8,7 @@ const MAX_DEPTH = 1
const TYPES_TO_SKIP = [ const TYPES_TO_SKIP = [
FieldType.FORMULA, FieldType.FORMULA,
FieldType.AI,
FieldType.LONGFORM, FieldType.LONGFORM,
FieldType.SIGNATURE_SINGLE, FieldType.SIGNATURE_SINGLE,
FieldType.ATTACHMENTS, FieldType.ATTACHMENTS,

View File

@ -26,7 +26,7 @@
import { createEventDispatcher, getContext, onMount } from "svelte" import { createEventDispatcher, getContext, onMount } from "svelte"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { tables, datasources } from "stores/builder" import { tables, datasources } from "stores/builder"
import { licensing } from "stores/portal" import { featureFlags } from "stores/portal"
import { TableNames, UNEDITABLE_USER_FIELDS } from "constants" import { TableNames, UNEDITABLE_USER_FIELDS } from "constants"
import { import {
FIELDS, FIELDS,
@ -101,8 +101,7 @@
let optionsValid = true let optionsValid = true
$: rowGoldenSample = RowUtils.generateGoldenSample($rows) $: rowGoldenSample = RowUtils.generateGoldenSample($rows)
$: aiEnabled = $: aiEnabled = $featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS
$licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled
$: if (primaryDisplay) { $: if (primaryDisplay) {
editableColumn.constraints.presence = { allowEmpty: false } editableColumn.constraints.presence = { allowEmpty: false }
} }

View File

@ -80,6 +80,9 @@
if (columnType === FieldType.FORMULA) { if (columnType === FieldType.FORMULA) {
return "https://docs.budibase.com/docs/formula" return "https://docs.budibase.com/docs/formula"
} }
if (columnType === FieldType.AI) {
return "https://docs.budibase.com/docs/ai"
}
if (columnType === FieldType.OPTIONS) { if (columnType === FieldType.OPTIONS) {
return "https://docs.budibase.com/docs/options" return "https://docs.budibase.com/docs/options"
} }

View File

@ -1,6 +1,6 @@
<script> <script>
import { viewsV2, rowActions } from "stores/builder" import { viewsV2, rowActions } from "stores/builder"
import { admin, themeStore, licensing } from "stores/portal" import { admin, themeStore, featureFlags } from "stores/portal"
import { Grid } from "@budibase/frontend-core" import { Grid } from "@budibase/frontend-core"
import { API } from "api" import { API } from "api"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
@ -53,7 +53,7 @@
{buttons} {buttons}
allowAddRows allowAddRows
allowDeleteRows allowDeleteRows
aiEnabled={$licensing.budibaseAIEnabled || $licensing.customAIConfigsEnabled} aiEnabled={$featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS}
showAvatars={false} showAvatars={false}
on:updatedatasource={handleGridViewUpdate} on:updatedatasource={handleGridViewUpdate}
isCloud={$admin.cloud} isCloud={$admin.cloud}

View File

@ -8,7 +8,7 @@
rowActions, rowActions,
roles, roles,
} from "stores/builder" } from "stores/builder"
import { themeStore, admin, licensing } from "stores/portal" import { themeStore, admin, featureFlags } from "stores/portal"
import { TableNames } from "constants" import { TableNames } from "constants"
import { Grid } from "@budibase/frontend-core" import { Grid } from "@budibase/frontend-core"
import { API } from "api" import { API } from "api"
@ -130,8 +130,7 @@
schemaOverrides={isUsersTable ? userSchemaOverrides : null} schemaOverrides={isUsersTable ? userSchemaOverrides : null}
showAvatars={false} showAvatars={false}
isCloud={$admin.cloud} isCloud={$admin.cloud}
aiEnabled={$licensing.budibaseAIEnabled || aiEnabled={$featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS}
$licensing.customAIConfigsEnabled}
{buttons} {buttons}
buttonsCollapsed buttonsCollapsed
on:updatedatasource={handleGridTableUpdate} on:updatedatasource={handleGridTableUpdate}

View File

@ -4,6 +4,8 @@ import { auth } from "stores/portal"
export const INITIAL_FEATUREFLAG_STATE = { export const INITIAL_FEATUREFLAG_STATE = {
SQS: false, SQS: false,
DEFAULT_VALUES: false, DEFAULT_VALUES: false,
BUDIBASE_AI: false,
AI_CUSTOM_CONFIGS: false,
} }
export const featureFlags = derived([auth], ([$auth]) => { export const featureFlags = derived([auth], ([$auth]) => {

View File

@ -1,4 +1,4 @@
import { AutoFieldSubType, FieldType } from "@budibase/types" import { AIOperationEnum, AutoFieldSubType, FieldType } from "@budibase/types"
import TestConfiguration from "../../../../tests/utilities/TestConfiguration" import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
import { importToRows } from "../utils" import { importToRows } from "../utils"
@ -92,5 +92,65 @@ describe("utils", () => {
expect(result).toHaveLength(3) expect(result).toHaveLength(3)
}) })
}) })
it("Imports write as expected with AI columns", async () => {
await config.doInContext(config.appId, async () => {
const table = await config.createTable({
name: "table",
type: "table",
schema: {
autoId: {
name: "autoId",
type: FieldType.NUMBER,
subtype: AutoFieldSubType.AUTO_ID,
autocolumn: true,
constraints: {
type: FieldType.NUMBER,
presence: true,
},
},
name: {
name: "name",
type: FieldType.STRING,
constraints: {
type: FieldType.STRING,
presence: true,
},
},
aicol: {
name: "aicol",
type: FieldType.AI,
operation: AIOperationEnum.PROMPT,
prompt: "Test prompt",
},
},
})
const data = [
{ name: "Alice", aicol: "test" },
{ name: "Bob", aicol: "test" },
{ name: "Claire", aicol: "test" },
]
const result = await importToRows(data, table, config.user?._id)
expect(result).toEqual([
expect.objectContaining({
autoId: 1,
name: "Alice",
aicol: "test",
}),
expect.objectContaining({
autoId: 2,
name: "Bob",
aicol: "test",
}),
expect.objectContaining({
autoId: 3,
name: "Claire",
aicol: "test",
}),
])
})
})
}) })
}) })

View File

@ -15,7 +15,7 @@ import { getViews, saveView } from "../view/utils"
import viewTemplate from "../view/viewBuilder" import viewTemplate from "../view/viewBuilder"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { quotas } from "@budibase/pro" import { quotas } from "@budibase/pro"
import { context, events, features } from "@budibase/backend-core" import { context, events, features, HTTPError } from "@budibase/backend-core"
import { import {
AutoFieldSubType, AutoFieldSubType,
Database, Database,
@ -145,14 +145,21 @@ export async function importToRows(
// the real schema of the table passed in, not the clone used for // the real schema of the table passed in, not the clone used for
// incrementing auto IDs // incrementing auto IDs
for (const [fieldName, schema] of Object.entries(originalTable.schema)) { for (const [fieldName, schema] of Object.entries(originalTable.schema)) {
const rowVal = Array.isArray(row[fieldName]) if (schema.type === FieldType.LINK) {
? row[fieldName] throw new HTTPError(
: [row[fieldName]] `Can't bulk import relationship fields for internal databases, found value in field "${fieldName}"`,
400
)
}
if ( if (
(schema.type === FieldType.OPTIONS || (schema.type === FieldType.OPTIONS ||
schema.type === FieldType.ARRAY) && schema.type === FieldType.ARRAY) &&
row[fieldName] row[fieldName]
) { ) {
const rowVal = Array.isArray(row[fieldName])
? row[fieldName]
: [row[fieldName]]
let merged = [...schema.constraints!.inclusion!, ...rowVal] let merged = [...schema.constraints!.inclusion!, ...rowVal]
let superSet = new Set(merged) let superSet = new Set(merged)
schema.constraints!.inclusion = Array.from(superSet) schema.constraints!.inclusion = Array.from(superSet)

View File

@ -1823,6 +1823,39 @@ describe.each([
expect(row.autoId).toEqual(3) expect(row.autoId).toEqual(3)
}) })
isInternal &&
it("should reject bulkImporting relationship fields", async () => {
const table1 = await config.api.table.save(saveTableRequest())
const table2 = await config.api.table.save(
saveTableRequest({
schema: {
relationship: {
name: "relationship",
type: FieldType.LINK,
tableId: table1._id!,
relationshipType: RelationshipType.ONE_TO_MANY,
fieldName: "relationship",
},
},
})
)
const table1Row1 = await config.api.row.save(table1._id!, {})
await config.api.row.bulkImport(
table2._id!,
{
rows: [{ relationship: [table1Row1._id!] }],
},
{
status: 400,
body: {
message:
'Can\'t bulk import relationship fields for internal databases, found value in field "relationship"',
},
}
)
})
it("should be able to bulkImport rows", async () => { it("should be able to bulkImport rows", async () => {
const table = await config.api.table.save( const table = await config.api.table.save(
saveTableRequest({ saveTableRequest({
@ -2462,7 +2495,7 @@ describe.each([
[FieldType.ATTACHMENT_SINGLE]: setup.structures.basicAttachment(), [FieldType.ATTACHMENT_SINGLE]: setup.structures.basicAttachment(),
[FieldType.FORMULA]: undefined, // generated field [FieldType.FORMULA]: undefined, // generated field
[FieldType.AUTO]: undefined, // generated field [FieldType.AUTO]: undefined, // generated field
[FieldType.AI]: undefined, // generated field [FieldType.AI]: "LLM Output",
[FieldType.JSON]: { name: generator.guid() }, [FieldType.JSON]: { name: generator.guid() },
[FieldType.INTERNAL]: generator.guid(), [FieldType.INTERNAL]: generator.guid(),
[FieldType.BARCODEQR]: generator.guid(), [FieldType.BARCODEQR]: generator.guid(),
@ -2494,6 +2527,7 @@ describe.each([
}), }),
[FieldType.FORMULA]: fullSchema[FieldType.FORMULA].formula, [FieldType.FORMULA]: fullSchema[FieldType.FORMULA].formula,
[FieldType.AUTO]: expect.any(Number), [FieldType.AUTO]: expect.any(Number),
[FieldType.AI]: expect.any(String),
[FieldType.JSON]: rowValues[FieldType.JSON], [FieldType.JSON]: rowValues[FieldType.JSON],
[FieldType.INTERNAL]: rowValues[FieldType.INTERNAL], [FieldType.INTERNAL]: rowValues[FieldType.INTERNAL],
[FieldType.BARCODEQR]: rowValues[FieldType.BARCODEQR], [FieldType.BARCODEQR]: rowValues[FieldType.BARCODEQR],
@ -2566,7 +2600,7 @@ describe.each([
expectedRowData["bb_reference_single"].sample, expectedRowData["bb_reference_single"].sample,
false false
), ),
ai: null, ai: "LLM Output",
}, },
]) ])
}) })

View File

@ -216,10 +216,6 @@ export async function inputProcessing(
if (field.type === FieldType.FORMULA) { if (field.type === FieldType.FORMULA) {
delete clonedRow[key] delete clonedRow[key]
} }
// remove any AI values, they are to be generated
if (field.type === FieldType.AI) {
delete clonedRow[key]
}
// otherwise coerce what is there to correct types // otherwise coerce what is there to correct types
else { else {
clonedRow[key] = coerce(value, field.type) clonedRow[key] = coerce(value, field.type)