From 7e7f31b967fbb4d0111a657579ff07ddfae0f12f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 25 Mar 2024 13:01:41 +0100 Subject: [PATCH] Allow downloading attachment --- .../actions/DownloadFile.svelte | 28 ++++--------------- packages/client/src/utils/buttonActions.js | 7 ++++- 2 files changed, 12 insertions(+), 23 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 702f0cc911..6a9cc7b02c 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,7 +3,6 @@ import { onMount } from "svelte" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import { FieldType } from "@budibase/types" - import { processStringSync } from "@budibase/string-templates" export let parameters export let bindings = [] @@ -12,8 +11,6 @@ b => b.fieldSchema?.type === FieldType.ATTACHMENT ) - let selectedAttachment - const fileOptions = [ { label: "Attachment", @@ -25,14 +22,6 @@ }, ] - const onAttachmentSelect = e => { - const fileData = processStringSync(e.detail, bindings) - parameters.value ??= {} - parameters.value.file_name = e.detail.name - parameters.value.url = e.detail.url - console.log({ parameters, bindings, fileData }) - } - onMount(() => { if (!parameters.type) { parameters.type = "attachment" @@ -46,9 +35,6 @@ placeholder={null} bind:value={parameters.type} options={fileOptions} - on:change={() => { - delete parameters.value - }} /> {#if parameters.type === "attachment"} @@ -56,25 +42,23 @@ title="Attachment" bindings={fileBindings} allowHelpers={false} - bind:value={selectedAttachment} - on:change={onAttachmentSelect} + value={parameters.attachment} + on:change={value => (parameters.attachment = value.detail)} /> {:else} - (parameters.value = { ...parameters.value, url: e.detail })} + value={parameters.url} + on:change={value => (parameters.url = value.detail)} /> - (parameters.value = { ...parameters.value, file_name: e.detail })} + value={parameters.file_name} + on:change={value => (parameters.file_name = value.detail)} /> {/if} diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index e00c6c6640..d76f154752 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -401,7 +401,12 @@ const closeSidePanelHandler = () => { } const downloadFileHandler = async (action, context) => { - const { url, file_name } = action.parameters.value + let { url, file_name, type, attachment } = action.parameters + if (type === "attachment") { + const attachmentObject = JSON.parse(attachment) + url = attachmentObject.url + file_name = attachmentObject.name + } const response = await fetch(url)