From 9e773c7c1898ca24454d3e8f2d2e174c9b44cca6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 2 Apr 2024 19:58:04 +0200 Subject: [PATCH] Select table on config --- .../actions/DownloadFile.svelte | 56 +++++++++++++++---- packages/client/src/utils/buttonActions.js | 14 +++-- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte index 1bd017de79..c8f4ef11f1 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte @@ -3,14 +3,11 @@ import { onMount } from "svelte" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import { FieldType } from "@budibase/types" + import { tables, viewsV2 } from "stores/builder" export let parameters export let bindings = [] - $: fileBindings = bindings?.filter( - b => b.fieldSchema?.type === FieldType.ATTACHMENT - ) - const fileOptions = [ { label: "Attachment", @@ -22,6 +19,26 @@ }, ] + $: tableOptions = $tables.list.map(table => ({ + label: table.name, + resourceId: table._id, + schema: table.schema, + })) + $: viewOptions = $viewsV2.list.map(view => ({ + label: view.name, + resourceId: view.id, + schema: view.schema, + })) + $: options = [...(tableOptions || []), ...(viewOptions || [])] + + $: selectedTable = + parameters.tableId && options.find(t => t.resourceId === parameters.tableId) + $: attachmentColumns = + selectedTable && + Object.values(selectedTable.schema).filter( + c => c.type === FieldType.ATTACHMENT + ) + onMount(() => { if (!parameters.type) { parameters.type = "attachment" @@ -37,13 +54,30 @@ options={fileOptions} /> {#if parameters.type === "attachment"} - + + c.name)} + /> + + (parameters.attachment = value.detail)} + {bindings} + title="Row ID" + value={parameters.rowId} + on:change={value => (parameters.rowId = value.detail)} /> {:else} @@ -70,7 +104,7 @@ row-gap: var(--spacing-s); grid-template-columns: 60px 1fr; align-items: center; - max-width: 400px; + max-width: 800px; margin: 0 auto; } diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index 7564f3f36d..75a4ce99d5 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -1,5 +1,6 @@ import { get } from "svelte/store" import download from "downloadjs" +import { downloadStream } from "@budibase/frontend-core" import { routeStore, builderStore, @@ -400,15 +401,18 @@ const closeSidePanelHandler = () => { sidePanelStore.actions.close() } -const downloadFileHandler = async (action, _context) => { +const downloadFileHandler = async action => { try { - let { url, fileName, type, attachment } = action.parameters + const { type } = action.parameters if (type === "attachment") { - const attachmentObject = JSON.parse(attachment) - url = attachmentObject.url - fileName = attachmentObject.name + const { tableId, rowId, attachmentColumn } = action.parameters + const res = await API.downloadAttachment(tableId, rowId, attachmentColumn) + await downloadStream(res) + return } + const { url, fileName } = action.parameters + const response = await fetch(url) if (!response.ok) {