Skip to content

Conversation

@carlosthe19916
Copy link
Collaborator

@carlosthe19916 carlosthe19916 commented Sep 8, 2025

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:

Screenshot From 2025-09-11 16-50-02 Screenshot From 2025-09-11 16-51-27 Screenshot From 2025-09-11 16-50-13 Screenshot From 2025-09-11 16-50-59 Screenshot From 2025-09-11 16-50-43 Screenshot From 2025-09-11 16-50-31

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:

  • Implement importer creation and editing flows with a multi-step wizard and integrate create/update API mutations with notifications
  • Add Create Importer button in the importer list toolbar and Edit action in each row, and register new routes for importer creation and editing

Enhancements:

  • Extend HookFormPFTextInput to support integer inputs
  • Introduce form components (General Information, Configuration, Review) with Yup validation schemas and useAsyncYupValidation hook
  • Extract validateLabelString utility and centralize importer type handling in type-utils
  • Refactor useCreateImporterMutation and useUpdateImporterMutation to pass payload details to success callbacks

Chores:

  • Remove unused PageContentWithDrawerProvider wrapper in DefaultLayout and adjust notification placement

@carlosthe19916 carlosthe19916 marked this pull request as ready for review September 11, 2025 15:07
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 11, 2025

Reviewer's Guide

This 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 interactions

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Extended HookFormPFTextInput to support integer inputs
  • Introduced WithIntegerType interface and inputType mapping
  • Handled integer vs number parsing in onChange
  • Updated type prop usage and fallback to 'number'
HookFormPFTextInput.tsx
Added Create/Edit navigation and routes for importers list
  • Injected useNavigate and Create Importer button into ImporterList toolbar
  • Added Edit action in row ActionsColumn with dynamic path
  • Defined importerCreate and importerEdit paths and lazy-loaded pages in Routes.tsx
importer-list.tsx
Routes.tsx
Enhanced API hooks for create/update importer mutations
  • Updated useCreateImporterMutation and useUpdateImporterMutation to pass payload to onSuccess
  • Returned importer vs credentials consistently in useFetchImporterById
  • Invalidated queries after mutations
importers.ts
Introduced wizard-driven ImporterWizard with form steps
  • Built ImporterWizard wrapping React Hook Form and PatternFly Wizard
  • Created SetGeneralInformation, SetConfiguration, and Review components
  • Defined dynamic Yup schemas and useAsyncYupValidation hook
importer-wizard.tsx
set-general-information.tsx
set-configuration.tsx
review.tsx
schema.ts
useAsyncYupValidation.ts
Added helper utilities and type mapping for importer configurations
  • Implemented type-utils for parsing/generating config fields and units
  • Extracted validateLabelString into utils
  • Updated EditLabelsForm to use new validator
type-utils.tsx
utils.ts
EditLabelsForm.tsx
Minor layout and component refinements
  • Removed unnecessary wrapper in DefaultLayout around children and Notifications
  • Refactored HookFormPFGroupController imports ordering
default-layout.tsx
HookFormPFTextInput.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant