allow regeneration of AI columns from context menu

This commit is contained in:
Martin McKeaveney 2024-10-04 17:20:30 +01:00
parent ddea2d137a
commit d5324388d6
4 changed files with 43 additions and 2 deletions

View File

@ -7,6 +7,7 @@
import { FIELDS } from "constants/backend"
const FORMULA_TYPE = FIELDS.FORMULA.type
const AI_TYPE = FIELDS.AI.type
export let row = {}
@ -60,7 +61,7 @@
}}
>
{#each tableSchema as [key, meta]}
{#if !meta.autocolumn && meta.type !== FORMULA_TYPE}
{#if !meta.autocolumn && meta.type !== FORMULA_TYPE && meta.type !== AI_TYPE}
<div>
<RowFieldControl error={errors[key]} {meta} bind:value={row[key]} />
</div>

View File

@ -53,6 +53,13 @@
await Helpers.copyToClipboard(value)
$notifications.success("Copied to clipboard")
}
const generateAIColumns = async () => {
await rows.actions.saveRow({ rowId: $focusedRowId })
await rows.actions.refreshData()
menu.actions.close()
$notifications.success("Generated AI columns")
}
</script>
<div bind:this={anchor} {style} class="menu-anchor" />
@ -161,6 +168,15 @@
>
Delete row
</MenuItem>
<MenuItem
icon="MagicWand"
disabled={isNewRow ||
!$focusedRow?._rev ||
!$hasBudibaseIdentifiers}
on:click={generateAIColumns}
>
Generate AI Columns
</MenuItem>
{/if}
</Menu>
</GridPopover>

View File

@ -465,6 +465,29 @@ export const createActions = context => {
return true
}
const saveRow = async ({ rowId }) => {
const $rowLookupMap = get(rowLookupMap)
const row = $rowLookupMap[rowId]
if (row == null) {
return
}
let savedRow
// Save row
try {
const newRow = cleanRow(row)
savedRow = await datasource.actions.updateRow(newRow)
if (savedRow?.id) {
// Handle users table edge case
await refreshRow(savedRow.id)
}
} catch (error) {
handleValidationError(rowId, error)
}
return savedRow
}
// Saves any pending changes to a row, as well as any additional changes
// specified
const applyRowChanges = async ({
@ -685,6 +708,7 @@ export const createActions = context => {
...rows,
actions: {
addRow,
saveRow,
duplicateRow,
bulkDuplicate,
updateValue,

View File

@ -4,7 +4,7 @@ import {
OperationFieldTypeEnum,
} from "@budibase/types"
const AIOperations = {
export const AIOperations = {
SUMMARISE_TEXT: {
label: "Summarise Text",
value: "SUMMARISE_TEXT",