From 47fdc9adbf2c476db83b6465cd762267113903d1 Mon Sep 17 00:00:00 2001 From: yael-spinner Date: Sun, 22 Sep 2024 11:24:44 +0300 Subject: [PATCH 1/7] 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" && ( Date: Tue, 8 Oct 2024 10:39:24 +0300 Subject: [PATCH 2/7] finish change the default mode Signed-off-by: yael-spinner --- .../analysis-wizard/analysis-wizard.tsx | 13 ++++---- .../applications/analysis-wizard/set-mode.tsx | 30 +++++++++++-------- 2 files changed, 24 insertions(+), 19 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 ccbe74e6d1..2ec6753a67 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -50,6 +50,7 @@ interface IAnalysisWizard { onClose: () => void; isOpen: boolean; } + const determineMode = ( applications: Application[] ): "binary" | "source-code-deps" | "" => { @@ -374,12 +375,12 @@ export const AnalysisWizard: React.FC = ({ const analyzableApplications = useAnalyzableApplications(applications, mode); - const isStepEnabled = (stepId: StepId) => { - return ( - stepIdReached + 1 >= stepId && - (firstInvalidStep === null || firstInvalidStep >= stepId) - ); - }; + const isStepEnabled = (stepId: StepId) => true; //{ + // return ( + // stepIdReached + 1 >= stepId && + // (firstInvalidStep === null || firstInvalidStep >= stepId) + // ); + // }; const steps = [ = ({ 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", + }); + } + const [selectedValue, setSelectedValue] = useState(defaultValue); return ( = ({ toggleId="analysis-mode-toggle" toggleAriaLabel="Analysis mode dropdown toggle" aria-label={name} - value={defaultValue} - onChange={onChange} + value={selectedValue} + onChange={(value) => { + setSelectedValue(value); + onChange(value); // עדכון של הערך בשדה + }} options={options} /> )} From fcd823f62b7bab80c8915cc7ebcf19ac0e974da5 Mon Sep 17 00:00:00 2001 From: yael-spinner Date: Wed, 9 Oct 2024 14:48:31 +0300 Subject: [PATCH 3/7] successful change the default mode Signed-off-by: yael-spinner --- .../analysis-wizard/analysis-wizard.tsx | 27 ++++++++++++++----- .../applications/analysis-wizard/set-mode.tsx | 12 ++++----- 2 files changed, 27 insertions(+), 12 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 2ec6753a67..1ee74df90e 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -1,4 +1,4 @@ -import * as React from "react"; +import React, { useEffect } from "react"; import { useIsMutating } from "@tanstack/react-query"; import { FormProvider, useForm } from "react-hook-form"; import { @@ -53,8 +53,14 @@ interface IAnalysisWizard { const determineMode = ( applications: Application[] -): "binary" | "source-code-deps" | "" => { +): + | "binary" + | "source-code" + | "source-code-deps" + | "binary-upload" + | undefined => { // If only one application is selected + console.log(applications.length); if (applications.length === 1) { const app = applications[0]; // Check if the application has only source definitions or both source and binary @@ -67,7 +73,7 @@ const determineMode = ( } // If the application has no definitions else { - return ""; // Return empty string if no definitions (no default selection) + return undefined; // Return empty string if no definitions (no default selection) } } // If more than one application is selected @@ -198,10 +204,9 @@ export const AnalysisWizard: React.FC = ({ const methods = useForm({ defaultValues: { artifact: null, - mode: "source-code-deps", + mode: determineMode(applications), formLabels: [], selectedTargets: [], - // defaults will be passed as initialFilterValues to the table hook targetFilters: undefined, selectedSourceLabels: [], withKnownLibs: "app", @@ -223,6 +228,16 @@ export const AnalysisWizard: React.FC = ({ mode: "all", }); + // Using useEffect to update the form's mode when the applications change + useEffect(() => { + const mode = determineMode(applications); + + // Check if the mode is not undefined + if (mode) { + methods.setValue("mode", mode); // Update the mode value in the form + } + }, [applications]); // Trigger the effect when 'applications' changes + const { handleSubmit, watch, reset } = methods; const values = watch(); @@ -401,7 +416,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 371ae43326..d917f9e9d2 100644 --- a/client/src/app/pages/applications/analysis-wizard/set-mode.tsx +++ b/client/src/app/pages/applications/analysis-wizard/set-mode.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import { SelectOptionProps, TextContent, @@ -17,13 +17,13 @@ import { SimpleSelectBasic } from "@app/components/SimpleSelectBasic"; interface ISetMode { isSingleApp: boolean; isModeValid: boolean; - defaultValue: string; + //defaultValue: string; } export const SetMode: React.FC = ({ isSingleApp, isModeValid, - defaultValue, + //defaultValue, }) => { const { t } = useTranslation(); @@ -51,7 +51,7 @@ export const SetMode: React.FC = ({ children: "Upload a local binary", }); } - const [selectedValue, setSelectedValue] = useState(defaultValue); + //const [selectedValue, setSelectedValue] = useState(defaultValue); return ( = ({ toggleId="analysis-mode-toggle" toggleAriaLabel="Analysis mode dropdown toggle" aria-label={name} - value={selectedValue} + value={value} onChange={(value) => { - setSelectedValue(value); + //setSelectedValue(value); onChange(value); // עדכון של הערך בשדה }} options={options} From ab92d333a24d80e71c5f9056f691cdd4ec42df51 Mon Sep 17 00:00:00 2001 From: yael-spinner Date: Thu, 10 Oct 2024 13:19:54 +0300 Subject: [PATCH 4/7] Final update to default mode Signed-off-by: yael-spinner --- .../applications/analysis-wizard/analysis-wizard.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 1ee74df90e..5978d10d42 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -390,12 +390,12 @@ export const AnalysisWizard: React.FC = ({ const analyzableApplications = useAnalyzableApplications(applications, mode); - const isStepEnabled = (stepId: StepId) => true; //{ - // return ( - // stepIdReached + 1 >= stepId && - // (firstInvalidStep === null || firstInvalidStep >= stepId) - // ); - // }; + const isStepEnabled = (stepId: StepId) => { + return ( + stepIdReached + 1 >= stepId && + (firstInvalidStep === null || firstInvalidStep >= stepId) + ); + }; const steps = [ Date: Sun, 27 Oct 2024 16:00:00 +0200 Subject: [PATCH 5/7] Final update on default mode change before upload Signed-off-by: yael-spinner --- .../analysis-wizard/analysis-wizard.tsx | 60 ++++++++----------- .../applications/analysis-wizard/set-mode.tsx | 15 ++--- 2 files changed, 30 insertions(+), 45 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 5978d10d42..99ff5d573b 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -55,42 +55,32 @@ const determineMode = ( applications: Application[] ): | "binary" - | "source-code" | "source-code-deps" + | "source-code" | "binary-upload" | undefined => { // If only one application is selected - console.log(applications.length); 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 undefined; // 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 { repository, binary } = applications[0]; + // If the application has a repository or both repository and binary definitions, return "source-code-deps" + // If the application has only binary definitions, return "binary" + // If no definitions are present, return undefined + return repository || (repository && binary) + ? "source-code-deps" + : binary && binary !== "" + ? "binary" + : undefined; } + // Check if all selected applications have only binary definitions + const allBinary = applications.every((app) => app.binary); + // Check if all selected applications have repository or binary definitions + const allSourceDeps = applications.every( + (app) => app.repository || app.binary + ); + // If all applications are binary, return "binary" + // If all applications are repository or a mix of repository and binary, return "source-code-deps" + // If neither condition is met, return undefined + return allBinary ? "binary" : allSourceDeps ? "source-code-deps" : undefined; }; const defaultTaskData: TaskData = { tagger: { @@ -228,15 +218,18 @@ export const AnalysisWizard: React.FC = ({ mode: "all", }); - // Using useEffect to update the form's mode when the applications change useEffect(() => { const mode = determineMode(applications); - // Check if the mode is not undefined + // Check if the mode is undefined if (mode) { methods.setValue("mode", mode); // Update the mode value in the form + } else { + // If the mode is undefined, you can decide what to do + // For example: set a default value or do nothing + methods.setValue("mode", "source-code-deps"); // Here you can replace it with your default value } - }, [applications]); // Trigger the effect when 'applications' changes + }, [applications]); // Trigger the effect when `applications` changes const { handleSubmit, watch, reset } = methods; const values = watch(); @@ -416,7 +409,6 @@ 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 d917f9e9d2..1d49972b88 100644 --- a/client/src/app/pages/applications/analysis-wizard/set-mode.tsx +++ b/client/src/app/pages/applications/analysis-wizard/set-mode.tsx @@ -17,14 +17,9 @@ import { SimpleSelectBasic } from "@app/components/SimpleSelectBasic"; interface ISetMode { isSingleApp: boolean; isModeValid: boolean; - //defaultValue: string; } -export const SetMode: React.FC = ({ - isSingleApp, - isModeValid, - //defaultValue, -}) => { +export const SetMode: React.FC = ({ isSingleApp, isModeValid }) => { const { t } = useTranslation(); const { watch, control } = useFormContext(); @@ -51,7 +46,6 @@ export const SetMode: React.FC = ({ children: "Upload a local binary", }); } - //const [selectedValue, setSelectedValue] = useState(defaultValue); return ( = ({ aria-label={name} value={value} onChange={(value) => { - //setSelectedValue(value); - onChange(value); // עדכון של הערך בשדה + onChange(value); // Update the value in the field }} options={options} /> )} /> - {/* {!isModeValid && ( + {!isModeValid && ( = ({ >

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

- )} */} + )} {mode === "source-code" && ( Date: Thu, 31 Oct 2024 12:36:05 +0200 Subject: [PATCH 6/7] Arrange the notes on the change default mode Signed-off-by: shirael --- .../analysis-wizard/analysis-wizard.tsx | 43 +++++-------------- .../applications/analysis-wizard/set-mode.tsx | 4 +- .../applications-table/applications-table.tsx | 1 + 3 files changed, 13 insertions(+), 35 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 99ff5d573b..0137ddc0c6 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import * as React from "react"; import { useIsMutating } from "@tanstack/react-query"; import { FormProvider, useForm } from "react-hook-form"; import { @@ -59,29 +59,20 @@ const determineMode = ( | "source-code" | "binary-upload" | undefined => { - // If only one application is selected - if (applications.length === 1) { - const { repository, binary } = applications[0]; - // If the application has a repository or both repository and binary definitions, return "source-code-deps" - // If the application has only binary definitions, return "binary" - // If no definitions are present, return undefined + if (applications.length === 0) return undefined; + const modes = applications.map((app) => { + const { repository, binary } = app; return repository || (repository && binary) ? "source-code-deps" : binary && binary !== "" ? "binary" : undefined; - } - // Check if all selected applications have only binary definitions - const allBinary = applications.every((app) => app.binary); - // Check if all selected applications have repository or binary definitions - const allSourceDeps = applications.every( - (app) => app.repository || app.binary - ); - // If all applications are binary, return "binary" - // If all applications are repository or a mix of repository and binary, return "source-code-deps" - // If neither condition is met, return undefined - return allBinary ? "binary" : allSourceDeps ? "source-code-deps" : undefined; + }); + const firstMode = modes[0]; + const allSame = modes.every((mode) => mode === firstMode); + return allSame ? firstMode : undefined; }; + const defaultTaskData: TaskData = { tagger: { enabled: true, @@ -194,9 +185,10 @@ 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 targetFilters: undefined, selectedSourceLabels: [], withKnownLibs: "app", @@ -218,19 +210,6 @@ export const AnalysisWizard: React.FC = ({ mode: "all", }); - useEffect(() => { - const mode = determineMode(applications); - - // Check if the mode is undefined - if (mode) { - methods.setValue("mode", mode); // Update the mode value in the form - } else { - // If the mode is undefined, you can decide what to do - // For example: set a default value or do nothing - methods.setValue("mode", "source-code-deps"); // Here you can replace it with your default value - } - }, [applications]); // Trigger the effect when `applications` changes - const { handleSubmit, watch, reset } = methods; const values = watch(); 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 1d49972b88..5050d3df66 100644 --- a/client/src/app/pages/applications/analysis-wizard/set-mode.tsx +++ b/client/src/app/pages/applications/analysis-wizard/set-mode.tsx @@ -71,9 +71,7 @@ export const SetMode: React.FC = ({ isSingleApp, isModeValid }) => { toggleAriaLabel="Analysis mode dropdown toggle" aria-label={name} value={value} - onChange={(value) => { - onChange(value); // Update the value in the field - }} + onChange={onChange} options={options} /> )} 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..d4affbb41c 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -1060,6 +1060,7 @@ export const ApplicationsTable: React.FC = () => { name).join()} applications={selectedRows} isOpen={isAnalyzeModalOpen} onClose={() => { From f549ed744cc93caca9c578e7d6f5d9653db91bed Mon Sep 17 00:00:00 2001 From: yael-spinner Date: Sat, 2 Nov 2024 22:45:00 +0200 Subject: [PATCH 7/7] Completely final update by changing the default state before uploading Signed-off-by: yael-spinner --- .../analysis-wizard/analysis-wizard.tsx | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 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 0137ddc0c6..6e2040e566 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -60,17 +60,21 @@ const determineMode = ( | "binary-upload" | undefined => { if (applications.length === 0) return undefined; - const modes = applications.map((app) => { - const { repository, binary } = app; - return repository || (repository && binary) - ? "source-code-deps" - : binary && binary !== "" - ? "binary" - : undefined; - }); - const firstMode = modes[0]; - const allSame = modes.every((mode) => mode === firstMode); - return allSame ? firstMode : 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 = {