Skip to content

Commit

Permalink
Final update on default mode change before upload
Browse files Browse the repository at this point in the history
Signed-off-by: yael-spinner <[email protected]>
  • Loading branch information
yael-spinner committed Oct 27, 2024
1 parent 84fd2cb commit cb65e37
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -228,15 +218,18 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
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();
Expand Down Expand Up @@ -416,7 +409,6 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
<SetMode
isSingleApp={applications.length === 1 ? true : false}
isModeValid={isModeValid}
//defaultValue={determineMode(applications)}
/>
</>
</WizardStep>,
Expand Down
15 changes: 4 additions & 11 deletions client/src/app/pages/applications/analysis-wizard/set-mode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ import { SimpleSelectBasic } from "@app/components/SimpleSelectBasic";
interface ISetMode {
isSingleApp: boolean;
isModeValid: boolean;
//defaultValue: string;
}

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

const { watch, control } = useFormContext<AnalysisWizardFormValues>();
Expand All @@ -51,7 +46,6 @@ export const SetMode: React.FC<ISetMode> = ({
children: "Upload a local binary",
});
}
//const [selectedValue, setSelectedValue] = useState(defaultValue);

return (
<Form
Expand All @@ -78,22 +72,21 @@ export const SetMode: React.FC<ISetMode> = ({
aria-label={name}
value={value}
onChange={(value) => {
//setSelectedValue(value);
onChange(value); // עדכון של הערך בשדה
onChange(value); // Update the value in the field
}}
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 cb65e37

Please sign in to comment.