From c4ec69244effbc8b2be203cde6d0215d13ef029e Mon Sep 17 00:00:00 2001 From: shevijacobson Date: Mon, 28 Oct 2024 13:21:59 +0200 Subject: [PATCH] Add file download functionality for JSON/YAML tasks data Signed-off-by: shevijacobson --- .../applications-table/applications-table.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index b53078ff3..44e46446f 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -215,6 +215,20 @@ export const ApplicationsTable: React.FC = () => { selectedFormat === "yaml" ? yaml.dump(tasks, { indent: 2 }) : JSON.stringify(tasks, null, 2); + + const blob = new Blob([data], { + type: + selectedFormat === "json" ? "application/json" : "application/x-yaml", + }); + const url = URL.createObjectURL(blob); + const downloadLink = document.createElement("a"); // שינוי שם למשתנה + downloadLink.href = url; + downloadLink.download = `logs - ${ids}.${selectedFormat}`; + document.body.appendChild(downloadLink); + downloadLink.click(); + document.body.removeChild(downloadLink); + URL.revokeObjectURL(url); + setIsDownloadModalOpen(false); } catch (error) { console.error("Error fetching tasks:", error);