From dfc290ed87bc5237571b794148f5886ca387c7e9 Mon Sep 17 00:00:00 2001 From: shevijacobson Date: Mon, 28 Oct 2024 12:51:12 +0200 Subject: [PATCH 1/6] Add getTasksByIds to fetch multiple tasks with JSON/YAML support Signed-off-by: shevijacobson --- client/src/app/api/rest.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/src/app/api/rest.ts b/client/src/app/api/rest.ts index 542507b07b..99f3ec5198 100644 --- a/client/src/app/api/rest.ts +++ b/client/src/app/api/rest.ts @@ -358,6 +358,24 @@ export function getTaskByIdAndFormat( }); } +export function getTasksByIds( + ids: number[], + format: "json" | "yaml" +): Promise { + const isYaml = format === "yaml"; + const headers = isYaml ? { ...yamlHeaders } : { ...jsonHeaders }; + const responseType = isYaml ? "text" : "json"; + + return axios + .post(`${TASKS}/multiple`, ids, { + headers: headers, + responseType: responseType, + }) + .then((response) => { + return response.data; + }); +} + export const getTasksDashboard = () => axios .get(`${TASKS}/report/dashboard`) From 564720bc11d129e7de75e5c6244f4da88a4ec275 Mon Sep 17 00:00:00 2001 From: MiriSafra Date: Mon, 28 Oct 2024 13:05:34 +0200 Subject: [PATCH 2/6] add handle download function Signed-off-by: MiriSafra --- .../applications-table/applications-table.tsx | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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 d102d69a2a..b53078ff39 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -71,7 +71,11 @@ import { checkAccess } from "@app/utils/rbac-utils"; import { useLocalTableControls } from "@app/hooks/table-controls"; // Queries -import { getArchetypeById, getAssessmentsByItemId } from "@app/api/rest"; +import { + getArchetypeById, + getAssessmentsByItemId, + getTasksByIds, +} from "@app/api/rest"; import { Assessment, Ref } from "@app/api/models"; import { useBulkDeleteApplicationMutation, @@ -109,6 +113,7 @@ import { DecoratedApplication, useDecoratedApplications, } from "./useDecoratedApplications"; +import yaml from "js-yaml"; export const ApplicationsTable: React.FC = () => { const { t } = useTranslation(); @@ -145,8 +150,13 @@ export const ApplicationsTable: React.FC = () => { const [applicationDependenciesToManage, setApplicationDependenciesToManage] = useState(null); + const isDependenciesModalOpen = applicationDependenciesToManage !== null; + const [isDownloadModalOpen, setIsDownloadModalOpen] = useState(false); + + const [selectedFormat, setSelectedFormat] = useState<"json" | "yaml">("json"); + const [assessmentToEdit, setAssessmentToEdit] = useState( null ); @@ -194,6 +204,23 @@ export const ApplicationsTable: React.FC = () => { }); }; + const handleDownload = async () => { + const ids = selectedRows + .map((row) => row.tasks.currentAnalyzer?.id) + .filter((id): id is number => typeof id === "number"); + + try { + const tasks = await getTasksByIds(ids, selectedFormat); + const data = + selectedFormat === "yaml" + ? yaml.dump(tasks, { indent: 2 }) + : JSON.stringify(tasks, null, 2); + setIsDownloadModalOpen(false); + } catch (error) { + console.error("Error fetching tasks:", error); + } + }; + const failedCancelTask = () => { pushNotification({ title: "Task", @@ -575,6 +602,20 @@ export const ApplicationsTable: React.FC = () => { > {t("actions.delete")} , + + application.tasks.currentAnalyzer?.id !== undefined + ) + } + onClick={() => { + setIsDownloadModalOpen(true); + }} + > + {t("actions.download", { what: "analysis details" })} + , ...(credentialsReadAccess ? [ Date: Mon, 28 Oct 2024 13:21:59 +0200 Subject: [PATCH 3/6] 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 b53078ff39..44e46446f1 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); From 398fafc056964821b58f7e1d1923300aafd0b793 Mon Sep 17 00:00:00 2001 From: MiriSafra Date: Tue, 29 Oct 2024 15:04:48 +0200 Subject: [PATCH 4/6] add modal Signed-off-by: MiriSafra --- .../applications-table/applications-table.tsx | 34 +++++++++++++++++++ 1 file changed, 34 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 44e46446f1..28580503e1 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -16,8 +16,10 @@ import { DropdownItem, Modal, Tooltip, + FormGroup, } from "@patternfly/react-core"; import { + CodeIcon, PencilAltIcon, TagIcon, WarningTriangleIcon, @@ -1357,6 +1359,38 @@ export const ApplicationsTable: React.FC = () => { }} /> + setIsDownloadModalOpen(false)} + > + + {" "} +
+ {" "} + {" "} + {" "} +
{" "} +

Selected Format: {selectedFormat}

{" "} +
{" "} + {" "} +
); }; From 88d9ff35482b078f69d4807c9c78b59f92169a09 Mon Sep 17 00:00:00 2001 From: shevijacobson Date: Tue, 29 Oct 2024 16:30:26 +0200 Subject: [PATCH 5/6] Change getTasksByIds from POST to GET and add filterParam Signed-off-by: shevijacobson --- client/src/app/api/rest.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/app/api/rest.ts b/client/src/app/api/rest.ts index 99f3ec5198..80f313204a 100644 --- a/client/src/app/api/rest.ts +++ b/client/src/app/api/rest.ts @@ -365,9 +365,10 @@ export function getTasksByIds( const isYaml = format === "yaml"; const headers = isYaml ? { ...yamlHeaders } : { ...jsonHeaders }; const responseType = isYaml ? "text" : "json"; + const filterParam = `id:(${ids.join("|")})`; return axios - .post(`${TASKS}/multiple`, ids, { + .get(`${TASKS}`, { headers: headers, responseType: responseType, }) From 4fe55c39793d95ad21ea63a22f85996c0144bf68 Mon Sep 17 00:00:00 2001 From: MiriSafra Date: Tue, 29 Oct 2024 16:33:36 +0200 Subject: [PATCH 6/6] add params Signed-off-by: MiriSafra --- client/src/app/api/rest.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/app/api/rest.ts b/client/src/app/api/rest.ts index 80f313204a..a054969a33 100644 --- a/client/src/app/api/rest.ts +++ b/client/src/app/api/rest.ts @@ -371,6 +371,9 @@ export function getTasksByIds( .get(`${TASKS}`, { headers: headers, responseType: responseType, + params: { + filter: filterParam, + }, }) .then((response) => { return response.data;