Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Change-the-default-mode #2106

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading