-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: main
Are you sure you want to change the base?
✨ Change-the-default-mode #2106
Conversation
Signed-off-by: yael-spinner <[email protected]>
Signed-off-by: yael-spinner <[email protected]>
Signed-off-by: yael-spinner <[email protected]>
Signed-off-by: yael-spinner <[email protected]>
…inner/tackle2-ui into s_y_change_deafault_mode
Signed-off-by: yael-spinner <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2106 +/- ##
==========================================
+ Coverage 39.20% 42.09% +2.89%
==========================================
Files 146 175 +29
Lines 4857 5644 +787
Branches 1164 1423 +259
==========================================
+ Hits 1904 2376 +472
- Misses 2939 3147 +208
- Partials 14 121 +107
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check my questions below.
client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx
Outdated
Show resolved
Hide resolved
client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing the context for the changes. I have some more comments (see below). I need also verify how useEffect
behaves in this place - will comment here when I'm done.
client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx
Outdated
Show resolved
Hide resolved
client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks on the right track, but it can be paired down a bit and still work properly.
client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx
Outdated
Show resolved
Hide resolved
@@ -163,10 +194,9 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({ | |||
const methods = useForm<AnalysisWizardFormValues>({ | |||
defaultValues: { | |||
artifact: null, | |||
mode: "source-code-deps", | |||
mode: determineMode(applications), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode: determineMode(applications), | |
mode: determineMode(applications) ?? "source-code-deps", |
That way, if a mode can't be figured out from the selected apps, the fallback/default mode is the original default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjd78 unfortunately @yael-spinner hit a real bug - the AnalysisWizard
gets re-rendered with every change on the applications screen which means that the defaults are being set at start time when no apps are selected.
So useEffect
is necessary here as a workaround. The good news is that using (our old friend) key
property we can force re-creating the wizard when selected apps change. The following fix worked for me:
iff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx
index d102d69a..d4affbb4 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 = () => {
<TaskGroupProvider>
<AnalysisWizard
+ key={selectedRows.map(({ name }) => name).join()}
applications={selectedRows}
isOpen={isAnalyzeModalOpen}
onClose={() => {
(END)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right! I forgot about the order state gets loaded up in modals like this. Using the key
prop does make sense.
For some reference: https://react.dev/learn/preserving-and-resetting-state#resetting-a-form-with-a-key
So use the key
attribute and drop useEffect()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Just put it in a function, iterate through the applications array and get the mode for each application. At the end either all of the modes are the same, or they are different. Same = return that mode, different = return undefined.
Signed-off-by: shirael <[email protected]>
Arrange the notes on the change default mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code according to the previous requests and comments, If there are any questions, I'm available for clarification."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Consider the comment below as nice-to-have but not mandatory. It would be also nice to change the title of this PR to better reflect the change and remove hyphens between words.
? "binary" | ||
: undefined; | ||
}); | ||
const firstMode = modes[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this could be reduced to problem of removing duplicates i.e.
// using array -> set -> array
const modes =Array.from(new Set(application.map(....
// or using radash
const modes = unique(application.map(...
This update introduces a function that changes the default state based on the type of application being deployed, ensuring optimal configuration for different scenarios while maintaining backward compatibility.
Related issue: #1837
Related enhancement PR: #209