Skip to content

Commit

Permalink
Change-the-default-mode
Browse files Browse the repository at this point in the history
Signed-off-by: yael-spinner <[email protected]>
  • Loading branch information
yael-spinner committed Sep 22, 2024
1 parent f389539 commit 47fdc9a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -366,6 +400,7 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
<SetMode
isSingleApp={applications.length === 1 ? true : false}
isModeValid={isModeValid}
defaultValue={determineMode(applications)}
/>
</>
</WizardStep>,
Expand Down
33 changes: 19 additions & 14 deletions client/src/app/pages/applications/analysis-wizard/set-mode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import { SimpleSelectBasic } from "@app/components/SimpleSelectBasic";
interface ISetMode {
isSingleApp: boolean;
isModeValid: boolean;
defaultValue: string;
}

export const SetMode: React.FC<ISetMode> = ({ isSingleApp, isModeValid }) => {
export const SetMode: React.FC<ISetMode> = ({
isSingleApp,
isModeValid,
defaultValue,
}) => {
const { t } = useTranslation();

const { watch, control } = useFormContext<AnalysisWizardFormValues>();
Expand All @@ -30,22 +35,22 @@ export const SetMode: React.FC<ISetMode> = ({ 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 (
<Form
Expand All @@ -70,21 +75,21 @@ export const SetMode: React.FC<ISetMode> = ({ isSingleApp, isModeValid }) => {
toggleId="analysis-mode-toggle"
toggleAriaLabel="Analysis mode dropdown toggle"
aria-label={name}
value={value}
value={defaultValue}
onChange={onChange}
options={options}
/>
)}
/>
{!isModeValid && (
{/* {!isModeValid && (
<Alert
variant="warning"
isInline
title={t("wizard.label.notAllAnalyzable")}
>
<p>{t("wizard.label.notAllAnalyzableDetails")}</p>
</Alert>
)}
)} */}
{mode === "source-code" && (
<Alert
variant="info"
Expand Down

0 comments on commit 47fdc9a

Please sign in to comment.