-
Couldn't load subscription status.
- Fork 20
feat: add Importers Create/Update actions #707
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Carlos Feria <[email protected]>
Signed-off-by: Carlos Feria <[email protected]>
Signed-off-by: Carlos Feria <[email protected]>
Signed-off-by: Carlos Feria <[email protected]>
Signed-off-by: Carlos Feria <[email protected]>
Reviewer's GuideThis PR implements full Create and Update workflows for importers by introducing a wizard-driven form with three steps (General Information, Configuration, Review), integrating new routes and navigation actions, and enhancing existing components and hooks to support the dynamic importer types and payloads. Sequence diagram for Importer Create/Update wizard interactionssequenceDiagram
actor User
participant ImporterListPage
participant ImporterWizard
participant BackendAPI
participant Notifications
User->>ImporterListPage: Clicks "Create Importer" or "Edit"
ImporterListPage->>ImporterWizard: Opens wizard (with or without importer data)
User->>ImporterWizard: Fills steps and submits
ImporterWizard->>BackendAPI: POST/PUT importer (create/update)
BackendAPI-->>ImporterWizard: Returns success/failure
ImporterWizard->>Notifications: Show success/failure notification
ImporterWizard->>ImporterListPage: Redirect to Importer List
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `client/src/app/components/HookFormPFFields/HookFormPFTextInput.tsx:48` </location>
<code_context>
onChange={(_, value) => {
if (type === "number") {
onChange(
- ((value && Number.parseInt(value, 10)) || "") as PathValue<
+ ((value && Number(value)) ?? "") as PathValue<
+ TFieldValues,
+ TName
</code_context>
<issue_to_address>
Switch from parseInt to Number for 'number' type may cause issues with non-integer input.
Number(value) can return NaN for empty or invalid input. Please handle NaN before passing to onChange, or restrict the input to valid numbers.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
onChange={(_, value) => {
if (type === "number") {
onChange(
((value && Number(value)) ?? "") as PathValue<
TFieldValues,
TName
>,
);
=======
onChange={(_, value) => {
if (type === "number") {
const numValue = Number(value);
onChange(
(value && !isNaN(numValue) ? numValue : "") as PathValue<
TFieldValues,
TName
>,
);
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `client/src/app/utils/utils.ts:150` </location>
<code_context>
return localeNumericCompare(String(a ?? ""), String(b ?? ""), locale);
};
+
+export const validateLabelString = (value: string) =>
+ !!value &&
+ value.trim().length > 0 &&
+ /^(?!.*\\)(?!\s*\\)(?!\s*=)[^=\\\s][^=\\]*\s*=?\s*[^=\\]+$/.test(value);
</code_context>
<issue_to_address>
Regex for label validation is complex; consider edge cases.
Please verify that the regex correctly handles all valid and invalid label cases, and add unit tests for this function if they are missing.
</issue_to_address>
### Comment 3
<location> `client/src/app/pages/importer-create-update/components/type-utils.tsx:175` </location>
<code_context>
+ let configuration: ImporterConfiguration | null = null;
+
+ switch (importerType) {
+ case "sbom": {
+ configuration = {
+ sbom: {
+ ...commonConfigurationFields,
+ fetchRetries: formValues.fetchRetries,
+ ignoreMissing: formValues.ignoreMissing,
+ keys: formValues.keys.map((e) => e.value),
+ onlyPatterns: formValues.onlyPatterns.map((e) => e.value),
+ sizeLimit: formValues.sizeLimitValue
+ ? `${formValues.sizeLimitValue}${formValues.sizeLimitUnit.trim()}`
+ : undefined,
+ v3Signatures: formValues.v3Signatures,
+ },
+ };
+ break;
+ }
+ case "csaf": {
</code_context>
<issue_to_address>
String concatenation for sizeLimit and period may lead to formatting issues.
Trim and validate the concatenated sizeLimit and period strings to prevent formatting errors.
Suggested implementation:
```typescript
}, {}),
period: validateAndFormatPeriod(formValues.periodValue, formValues.periodUnit),
source: formValues.source,
description: formValues.description,
disabled: !formValues.enabled,
};
// Utility function to format and validate sizeLimit
function validateAndFormatSizeLimit(value: string | number | undefined, unit: string | undefined): string | undefined {
if (!value || !unit) return undefined;
const trimmedValue = typeof value === "string" ? value.trim() : value;
const trimmedUnit = unit.trim();
if (trimmedValue === "" || trimmedUnit === "") return undefined;
// Add more validation logic here if needed (e.g., regex, allowed units)
return `${trimmedValue}${trimmedUnit}`;
}
// Utility function to format and validate period
function validateAndFormatPeriod(value: string | number | undefined, unit: string | undefined): string | undefined {
if (!value || !unit) return undefined;
const trimmedValue = typeof value === "string" ? value.trim() : value;
const trimmedUnit = unit.trim();
if (trimmedValue === "" || trimmedUnit === "") return undefined;
// Add more validation logic here if needed (e.g., regex, allowed units)
return `${trimmedValue}${trimmedUnit}`;
}
let configuration: ImporterConfiguration | null = null;
```
```typescript
sizeLimit: validateAndFormatSizeLimit(formValues.sizeLimitValue, formValues.sizeLimitUnit),
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This PR allows to Create and Edit importers.
There are no mockups to compare with but a reverse engineering of what the rest endpoint exposes.
The current implementation also has an impact on a "todo" task on the backend side to enhance the unit of measurement guacsec/trustify#1969 but that should not be a blocker for us and we can assume it will be fixed by the backend soon.
Some screehshots of how it would look like:
Summary by Sourcery
Add UI support for creating and editing importers in the client, including new pages, routes, wizard-based form flows, and API integration.
New Features:
Enhancements:
Chores: