Skip to content

Wizard: Filter out empty users from review step (HMS-10691)#4444

Merged
kingsleyzissou merged 1 commit into
osbuild:mainfrom
mgold1234:user_b
May 21, 2026
Merged

Wizard: Filter out empty users from review step (HMS-10691)#4444
kingsleyzissou merged 1 commit into
osbuild:mainfrom
mgold1234:user_b

Conversation

@mgold1234
Copy link
Copy Markdown
Collaborator

@mgold1234 mgold1234 commented May 18, 2026

When a user was added and then removed, an empty user object remained in the Redux store.
The review step displayed it because it only checked users.length === 0, showing a blank row with no meaningful data.

Filter out users that have no name, password, SSH key, or stored password before rendering the review section.

ISSUE IN GITHUB: 4423
JIRA: 4423

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.77%. Comparing base (464b7c5) to head (4cc1dc8).
⚠️ Report is 3 commits behind head on main.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4444   +/-   ##
=======================================
  Coverage   74.76%   74.77%           
=======================================
  Files         229      229           
  Lines        7612     7614    +2     
  Branches     2867     2872    +5     
=======================================
+ Hits         5691     5693    +2     
  Misses       1653     1653           
  Partials      268      268           
Files with missing lines Coverage Δ
...w/components/AdvancedSettings/components/Users.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 464b7c5...4cc1dc8. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mgold1234 mgold1234 marked this pull request as ready for review May 18, 2026 14:55
@mgold1234 mgold1234 requested a review from a team as a code owner May 18, 2026 14:55
Copy link
Copy Markdown

@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 - I've found 1 issue, and left some high level feedback:

  • The nonEmptyUsers filter treats any non-empty string as valid; consider trimming name, password, and ssh_key so users with only whitespace are still considered empty and excluded from the review.
  • The logic that defines what constitutes a non-empty user is now embedded in the component; consider extracting this predicate into a shared helper or selector to keep the definition centralized and reusable across the app.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `nonEmptyUsers` filter treats any non-empty string as valid; consider trimming `name`, `password`, and `ssh_key` so users with only whitespace are still considered empty and excluded from the review.
- The logic that defines what constitutes a non-empty user is now embedded in the component; consider extracting this predicate into a shared helper or selector to keep the definition centralized and reusable across the app.

## Individual Comments

### Comment 1
<location path="src/Components/CreateImageWizard/steps/Review/components/AdvancedSettings/tests/AdvancedSettings.test.tsx" line_range="729-748" />
<code_context>
       expect(screen.queryByText('Users')).not.toBeInTheDocument();
     });

+    test('does not render users section when only empty users exist', () => {
+      renderWithRedux(
+        <AdvancedSettingsOverview restrictions={createDefaultRestrictions()} />,
+        {
+          imageTypes: ['guest-image'],
+          users: [
+            {
+              name: '',
+              password: '',
+              hasPassword: false,
+              ssh_key: '',
+              groups: [],
+              isAdministrator: false,
+            },
+          ],
+        },
+      );
+
+      expect(screen.queryByText('Users')).not.toBeInTheDocument();
+    });
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test case where both empty and non-empty users are present to ensure only non-empty users are rendered and the section still appears.

This test covers the case with only empty users. To more fully exercise the filtering logic, please add a complementary test with a mix of empty and non-empty users that asserts the Users section is rendered and only the non-empty users are shown (e.g., by checking the rendered row count and usernames).

```suggestion
    test('does not render users section when only empty users exist', () => {
      renderWithRedux(
        <AdvancedSettingsOverview restrictions={createDefaultRestrictions()} />,
        {
          imageTypes: ['guest-image'],
          users: [
            {
              name: '',
              password: '',
              hasPassword: false,
              ssh_key: '',
              groups: [],
              isAdministrator: false,
            },
          ],
        },
      );

      expect(screen.queryByText('Users')).not.toBeInTheDocument();
    });

    test('renders users section with only non-empty users when mix of users is provided', () => {
      renderWithRedux(
        <AdvancedSettingsOverview restrictions={createDefaultRestrictions()} />,
        {
          imageTypes: ['guest-image'],
          users: [
            {
              // empty user that should be filtered out
              name: '',
              password: '',
              hasPassword: false,
              ssh_key: '',
              groups: [],
              isAdministrator: false,
            },
            {
              // non-empty user that should be rendered
              name: 'regular-user',
              password: '',
              hasPassword: false,
              ssh_key: '',
              groups: [],
              isAdministrator: false,
            },
          ],
        },
      );

      expect(screen.getByText('Users')).toBeInTheDocument();
      expect(screen.getByText('regular-user')).toBeInTheDocument();
      // Ensure no extra non-empty usernames are rendered
      expect(screen.getAllByText('regular-user')).toHaveLength(1);
    });
```
</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.

@mgold1234 mgold1234 force-pushed the user_b branch 2 times, most recently from e413958 to 80c59bc Compare May 20, 2026 11:57
@mgold1234 mgold1234 changed the title Wizard: Filter out empty users from review step (HMS-4423) Wizard: Filter out empty users from review step (HMS-10691) May 20, 2026
Copy link
Copy Markdown
Collaborator

@kingsleyzissou kingsleyzissou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment, but this looks great

return state.wizard.users;
};

export const selectNonEmptyUsers = (state: RootState) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Love this 🫶

When a user was added and then removed, an empty user object remained
in the Redux store. The review step displayed it because it only
checked users.length === 0, showing a blank row with no meaningful data.

Filter out users that have no name, password, SSH key, or stored
password before rendering the review section.
Copy link
Copy Markdown
Collaborator

@kingsleyzissou kingsleyzissou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff

@kingsleyzissou kingsleyzissou enabled auto-merge May 21, 2026 12:41
@kingsleyzissou kingsleyzissou added this pull request to the merge queue May 21, 2026
Merged via the queue into osbuild:main with commit 53a8fd7 May 21, 2026
36 checks passed
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.

2 participants