From c5e27b860ffcfc395e0127b9e88599865654f428 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 2 Sep 2024 08:45:49 +0100 Subject: [PATCH] Add row actions to tables in data section --- .../bbui/src/ActionMenu/ActionMenu.svelte | 6 +-- .../bbui/src/Actions/position_dropdown.js | 2 +- .../data/table/[tableId]/index.svelte | 54 ++++++++++++++++++- .../src/components/app/GridBlock.svelte | 6 ++- packages/frontend-core/src/api/rowActions.js | 5 +- .../grid/layout/ButtonColumn.svelte | 49 ++++++++++------- 6 files changed, 93 insertions(+), 29 deletions(-) diff --git a/packages/bbui/src/ActionMenu/ActionMenu.svelte b/packages/bbui/src/ActionMenu/ActionMenu.svelte index c8d0dde8f9..e3de70e3ee 100644 --- a/packages/bbui/src/ActionMenu/ActionMenu.svelte +++ b/packages/bbui/src/ActionMenu/ActionMenu.svelte @@ -15,7 +15,6 @@ let anchor let dropdown let timeout - let open // This is needed because display: contents is considered "invisible". // It should only ever be an action button, so should be fine. @@ -23,7 +22,7 @@ anchor = node.firstChild } - export const show = () => { + export const show = e => { cancelHide() dropdown.show() } @@ -64,11 +63,10 @@ on:mouseenter={openOnHover ? show : null} on:mouseleave={openOnHover ? queueHide : null} > - + - import { Banner } from "@budibase/bbui" + import { Banner, Menu, MenuItem, Popover } from "@budibase/bbui" import { datasources, tables, integrations, appStore } from "stores/builder" import { themeStore, admin } from "stores/portal" import { TableNames } from "constants" @@ -28,7 +28,12 @@ status: { displayName: "Status", disabled: true }, } + let rowActions = [] let generateButton + let rowActionPopover + let rowActionRow + let rowActionAnchor + let refreshRow $: autoColumnStatus = verifyAutocolumns($tables?.selected) $: duplicates = Object.values(autoColumnStatus).reduce((acc, status) => { @@ -53,6 +58,20 @@ $: relationshipsEnabled = relationshipSupport(tableDatasource) $: currentTheme = $themeStore?.theme $: darkMode = !currentTheme.includes("light") + $: buttons = [ + { + text: "Actions", + type: "cta", + icon: "ChevronDown", + onClick: async (e, row, refresh) => { + rowActionRow = row + rowActionAnchor = e.currentTarget + rowActionPopover.show() + refreshRow = refresh + }, + }, + ] + $: fetchRowActions(id) const relationshipSupport = datasource => { const integration = $integrations[datasource?.source] @@ -82,6 +101,25 @@ return acc }, {}) } + + const fetchRowActions = async tableId => { + if (!tableId) { + rowActions = [] + return + } + const res = await API.rowActions.fetch(tableId) + rowActions = Object.values(res || {}) + } + + const runRowAction = async action => { + await API.rowActions.trigger({ + rowActionId: action.id, + tableId: id, + rowId: rowActionRow._id, + }) + await refreshRow() + rowActionPopover.hide() + } {#if $tables?.selected?.name} @@ -105,6 +143,7 @@ schemaOverrides={isUsersTable ? userSchemaOverrides : null} showAvatars={false} isCloud={$admin.cloud} + buttons={rowActions.length ? buttons : null} on:updatedatasource={handleGridTableUpdate} > @@ -153,6 +192,19 @@ Create your first table to start building {/if} + + + {#each rowActions as action} + runRowAction(action)}>{action.name} + {/each} + + +