Skip to content

Commit

Permalink
Merge branch 'v3-ui' of github.com:budibase/budibase into feature/aut…
Browse files Browse the repository at this point in the history
…omation-branching-ux
  • Loading branch information
samwho committed Oct 31, 2024
2 parents 86aabcc + df8ec41 commit 30a3013
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 61 deletions.
9 changes: 8 additions & 1 deletion packages/backend-core/src/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,14 @@ class InternalBuilder {
)
}
} else {
query = query.count(`* as ${aggregation.name}`)
if (this.client === SqlClient.ORACLE) {
const field = this.convertClobs(`${tableName}.${aggregation.field}`)
query = query.select(
this.knex.raw(`COUNT(??) as ??`, [field, aggregation.name])
)
} else {
query = query.count(`${aggregation.field} as ${aggregation.name}`)
}
}
} else {
const fieldSchema = this.getFieldSchema(aggregation.field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
} from "@budibase/bbui"
import { onMount, createEventDispatcher } from "svelte"
import { flags } from "stores/builder"
import { licensing } from "stores/portal"
import { featureFlags } from "stores/portal"
import { API } from "api"
import MagicWand from "../../../../assets/MagicWand.svelte"
Expand All @@ -26,8 +26,7 @@
let aiCronPrompt = ""
let loadingAICronExpression = false
$: aiEnabled =
$licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled
$: aiEnabled = $featureFlags.AI_CUSTOM_CONFIGS || $featureFlags.BUDIBASE_AI
$: {
if (cronExpression) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const MAX_DEPTH = 1

const TYPES_TO_SKIP = [
FieldType.FORMULA,
FieldType.AI,
FieldType.LONGFORM,
FieldType.SIGNATURE_SINGLE,
FieldType.ATTACHMENTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { createEventDispatcher, getContext, onMount } from "svelte"
import { cloneDeep } from "lodash/fp"
import { tables, datasources } from "stores/builder"
import { licensing } from "stores/portal"
import { featureFlags } from "stores/portal"
import { TableNames, UNEDITABLE_USER_FIELDS } from "constants"
import {
FIELDS,
Expand Down Expand Up @@ -101,8 +101,7 @@
let optionsValid = true
$: rowGoldenSample = RowUtils.generateGoldenSample($rows)
$: aiEnabled =
$licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled
$: aiEnabled = $featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS
$: if (primaryDisplay) {
editableColumn.constraints.presence = { allowEmpty: false }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
if (columnType === FieldType.FORMULA) {
return "https://docs.budibase.com/docs/formula"
}
if (columnType === FieldType.AI) {
return "https://docs.budibase.com/docs/ai"
}
if (columnType === FieldType.OPTIONS) {
return "https://docs.budibase.com/docs/options"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
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 { API } from "api"
import { notifications } from "@budibase/bbui"
Expand Down Expand Up @@ -53,7 +53,7 @@
{buttons}
allowAddRows
allowDeleteRows
aiEnabled={$licensing.budibaseAIEnabled || $licensing.customAIConfigsEnabled}
aiEnabled={$featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS}
showAvatars={false}
on:updatedatasource={handleGridViewUpdate}
isCloud={$admin.cloud}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
rowActions,
roles,
} from "stores/builder"
import { themeStore, admin, licensing } from "stores/portal"
import { themeStore, admin, featureFlags } from "stores/portal"
import { TableNames } from "constants"
import { Grid } from "@budibase/frontend-core"
import { API } from "api"
Expand Down Expand Up @@ -130,8 +130,7 @@
schemaOverrides={isUsersTable ? userSchemaOverrides : null}
showAvatars={false}
isCloud={$admin.cloud}
aiEnabled={$licensing.budibaseAIEnabled ||
$licensing.customAIConfigsEnabled}
aiEnabled={$featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS}
{buttons}
buttonsCollapsed
on:updatedatasource={handleGridTableUpdate}
Expand Down
2 changes: 2 additions & 0 deletions packages/builder/src/stores/portal/featureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { auth } from "stores/portal"
export const INITIAL_FEATUREFLAG_STATE = {
SQS: false,
DEFAULT_VALUES: false,
BUDIBASE_AI: false,
AI_CUSTOM_CONFIGS: false,
}

export const featureFlags = derived([auth], ([$auth]) => {
Expand Down
62 changes: 61 additions & 1 deletion packages/server/src/api/controllers/table/tests/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AutoFieldSubType, FieldType } from "@budibase/types"
import { AIOperationEnum, AutoFieldSubType, FieldType } from "@budibase/types"
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
import { importToRows } from "../utils"

Expand Down Expand Up @@ -92,5 +92,65 @@ describe("utils", () => {
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",
}),
])
})
})
})
})
30 changes: 18 additions & 12 deletions packages/server/src/api/controllers/view/viewsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
RelationSchemaField,
ViewFieldMetadata,
CalculationType,
CountDistinctCalculationFieldMetadata,
CountCalculationFieldMetadata,
} from "@budibase/types"
import { builderSocket, gridSocket } from "../../../websockets"
import { helpers } from "@budibase/shared-core"
Expand All @@ -22,27 +24,31 @@ function stripUnknownFields(
if (helpers.views.isCalculationField(field)) {
if (field.calculationType === CalculationType.COUNT) {
if ("distinct" in field && field.distinct) {
return {
order: field.order,
width: field.width,
visible: field.visible,
readonly: field.readonly,
icon: field.icon,
distinct: field.distinct,
calculationType: field.calculationType,
field: field.field,
columns: field.columns,
}
const strippedField: RequiredKeys<CountDistinctCalculationFieldMetadata> =
{
order: field.order,
width: field.width,
visible: field.visible,
readonly: field.readonly,
icon: field.icon,
distinct: field.distinct,
calculationType: field.calculationType,
field: field.field,
columns: field.columns,
}
return strippedField
} else {
return {
const strippedField: RequiredKeys<CountCalculationFieldMetadata> = {
order: field.order,
width: field.width,
visible: field.visible,
readonly: field.readonly,
icon: field.icon,
calculationType: field.calculationType,
field: field.field,
columns: field.columns,
}
return strippedField
}
}
const strippedField: RequiredKeys<ViewCalculationFieldMetadata> = {
Expand Down
5 changes: 3 additions & 2 deletions packages/server/src/api/routes/tests/row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ describe.each([
[FieldType.ATTACHMENT_SINGLE]: setup.structures.basicAttachment(),
[FieldType.FORMULA]: undefined, // generated field
[FieldType.AUTO]: undefined, // generated field
[FieldType.AI]: undefined, // generated field
[FieldType.AI]: "LLM Output",
[FieldType.JSON]: { name: generator.guid() },
[FieldType.INTERNAL]: generator.guid(),
[FieldType.BARCODEQR]: generator.guid(),
Expand Down Expand Up @@ -2494,6 +2494,7 @@ describe.each([
}),
[FieldType.FORMULA]: fullSchema[FieldType.FORMULA].formula,
[FieldType.AUTO]: expect.any(Number),
[FieldType.AI]: expect.any(String),
[FieldType.JSON]: rowValues[FieldType.JSON],
[FieldType.INTERNAL]: rowValues[FieldType.INTERNAL],
[FieldType.BARCODEQR]: rowValues[FieldType.BARCODEQR],
Expand Down Expand Up @@ -2566,7 +2567,7 @@ describe.each([
expectedRowData["bb_reference_single"].sample,
false
),
ai: null,
ai: "LLM Output",
},
])
})
Expand Down
Loading

0 comments on commit 30a3013

Please sign in to comment.