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

View File

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

View File

@ -465,6 +465,29 @@ export const createActions = context => {
return true 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 // Saves any pending changes to a row, as well as any additional changes
// specified // specified
const applyRowChanges = async ({ const applyRowChanges = async ({
@ -685,6 +708,7 @@ export const createActions = context => {
...rows, ...rows,
actions: { actions: {
addRow, addRow,
saveRow,
duplicateRow, duplicateRow,
bulkDuplicate, bulkDuplicate,
updateValue, updateValue,

View File

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