From 5d12dd648960d3e0ea6163f57d9ee0377992a235 Mon Sep 17 00:00:00 2001 From: Shira Elfer Date: Wed, 11 Dec 2024 15:57:49 +0200 Subject: [PATCH] finish write the default mode logic --- .../analysis-wizard/analysis-wizard.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx index 96befc64e..6461c4391 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -60,7 +60,22 @@ const determineMode = ( | "binary-upload" | undefined => { if (applications.length === 0) return undefined; + + const modes = Array.from( + new Set( + applications.map((app) => { + const { repository, binary } = app; + return repository || (repository && binary) + ? "source-code-deps" + : binary && binary !== "" + ? "binary" + : undefined; + }) + ) + ); + return modes.length === 1 ? modes[0] : undefined; }; + const defaultTaskData: TaskData = { tagger: { enabled: true, @@ -173,7 +188,7 @@ export const AnalysisWizard: React.FC = ({ const methods = useForm({ defaultValues: { artifact: null, - mode: determineMode(applications), + mode: determineMode(applications) ?? "source-code-deps", formLabels: [], selectedTargets: [], // defaults will be passed as initialFilterValues to the table hook