From 47fdc9adbf2c476db83b6465cd762267113903d1 Mon Sep 17 00:00:00 2001 From: yael-spinner Date: Sun, 22 Sep 2024 11:24:44 +0300 Subject: [PATCH] Change-the-default-mode Signed-off-by: yael-spinner --- .../analysis-wizard/analysis-wizard.tsx | 37 ++++++++++++++++++- .../applications/analysis-wizard/set-mode.tsx | 33 ++++++++++------- 2 files changed, 55 insertions(+), 15 deletions(-) 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 05541b89b1..ccbe74e6d1 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -50,7 +50,41 @@ interface IAnalysisWizard { onClose: () => void; isOpen: boolean; } - +const determineMode = ( + applications: Application[] +): "binary" | "source-code-deps" | "" => { + // If only one application is selected + if (applications.length === 1) { + const app = applications[0]; + // Check if the application has only source definitions or both source and binary + if (app.repository || (app.repository && app.binary)) { + return "source-code-deps"; // Return 'Source + Dependencies' if source or both + } + // Check if the application has only binary definitions + else if (app.binary) { + return "binary"; // Return 'Binary' if binary only + } + // If the application has no definitions + else { + return ""; // Return empty string if no definitions (no default selection) + } + } + // If more than one application is selected + else { + // Check if all applications are in "binary" mode + const allBinary = applications.every((app) => app.binary); + // Check if all applications are in "source-code-deps" mode (or a mix of source-code and binary) + const allSourceDeps = applications.every( + (app) => app.repository || app.binary + ); + // If all applications are binary, return "binary" + if (allBinary) { + return "binary"; + } + // If all applications are source-code-deps or there's a mix, return "source-code-deps" + return "source-code-deps"; + } +}; const defaultTaskData: TaskData = { tagger: { enabled: true, @@ -366,6 +400,7 @@ export const AnalysisWizard: React.FC = ({ , diff --git a/client/src/app/pages/applications/analysis-wizard/set-mode.tsx b/client/src/app/pages/applications/analysis-wizard/set-mode.tsx index 5050d3df66..e2c0d44d4e 100644 --- a/client/src/app/pages/applications/analysis-wizard/set-mode.tsx +++ b/client/src/app/pages/applications/analysis-wizard/set-mode.tsx @@ -17,9 +17,14 @@ import { SimpleSelectBasic } from "@app/components/SimpleSelectBasic"; interface ISetMode { isSingleApp: boolean; isModeValid: boolean; + defaultValue: string; } -export const SetMode: React.FC = ({ isSingleApp, isModeValid }) => { +export const SetMode: React.FC = ({ + isSingleApp, + isModeValid, + defaultValue, +}) => { const { t } = useTranslation(); const { watch, control } = useFormContext(); @@ -30,22 +35,22 @@ export const SetMode: React.FC = ({ isSingleApp, isModeValid }) => { value: "source-code-deps", children: "Source code + dependencies", }, - { - value: "source-code", - children: "Source code", - }, + // { + // value: "source-code", + // children: "Source code", + // }, { value: "binary", children: "Binary", }, ]; - if (isSingleApp) { - options.push({ - value: "binary-upload", - children: "Upload a local binary", - }); - } + // if (isSingleApp) { + // options.push({ + // value: "binary-upload", + // children: "Upload a local binary", + // }); + // } return (
= ({ isSingleApp, isModeValid }) => { toggleId="analysis-mode-toggle" toggleAriaLabel="Analysis mode dropdown toggle" aria-label={name} - value={value} + value={defaultValue} onChange={onChange} options={options} /> )} /> - {!isModeValid && ( + {/* {!isModeValid && ( = ({ isSingleApp, isModeValid }) => { >

{t("wizard.label.notAllAnalyzableDetails")}

- )} + )} */} {mode === "source-code" && (