Skip to content

Conversation

@sjd78
Copy link
Member

@sjd78 sjd78 commented Oct 6, 2025

Following the pattern in discover-import-wizard from PR #2646, update generate-assets-wizard useWizardReducer to use immer and useImmerReducer for handling the initial state and all reducer actions. This helps keep the initial state clean and resettable, and helps keep the reducer logic simple and focused.

No visible changes.

Summary by CodeRabbit

  • Refactor

    • Reworked wizard state management to use an immutable-draft approach for more consistent initialization, stable setter references, and reliable reset behavior.
  • Bug Fixes

    • Fixed readiness computation so Continue/Next reflects profile, parameters, filters, and advanced options immediately and consistently.

@sjd78 sjd78 added this to the v0.8.1 milestone Oct 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

Replaces previous reducers with Immer-based draft reducers in two wizards, adds a lazy initial-state recipe and useImmerInitialState helper, computes isReady on the draft after mutations, changes RESET to carry a payload, and exposes stable setter callbacks and a reset function from the hook.

Changes

Cohort / File(s) Summary of changes
Generate-assets wizard (Immer migration & init recipe)
client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts
Migrates to useImmerReducer; reducer now has signature `(draft: WizardState, action?: WizardAction) => WizardState
Discover-import wizard (retyped reducer signature)
client/src/app/components/discover-import-wizard/useWizardReducer.ts
Removes WizardReducer type alias and updates reducer to explicit signature `(draft: WizardState, action?: WizardAction) => WizardState

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor UI as App/Consumer
  participant Hook as useWizardReducer(init?)
  participant Init as useImmerInitialState
  participant Reducer as wizardReducer (Immer draft)
  participant Store as Hook State

  UI->>Hook: initialize (optional init recipe)
  Hook->>Init: run recipe once -> initial draft
  Init-->>Hook: initial WizardState (ref-stored)
  Hook-->>Store: set initial state

  UI->>Hook: call setter (dispatch action)
  Hook->>Reducer: dispatch(action) with draft
  Reducer->>Reducer: mutate draft (fields, compute draft.isReady)
  Reducer-->>Hook: mutated draft applied
  Hook-->>Store: updated state visible to UI

  rect rgba(0,128,0,0.06)
  note right of Hook: RESET uses payload to replace draft
  UI->>Hook: reset(payload)
  Hook->>Reducer: dispatch({type: "RESET", payload})
  Reducer-->>Hook: return payload as new draft (isReady recomputed)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ibolton336
  • rszwajko

Poem

A nibble of draft where state seeds grow,
I hop through changes, tidy and slow.
RESET drops payload, fresh fields to comb,
isReady wakes up and calls this home.
A rabbit commits — then skips back to roam! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the main change of refactoring the generate-assets-wizard useWizardReducer to use useImmerReducer and follows the repository’s emoji prefix convention, making it concise and specific.
Description Check ✅ Passed The description clearly explains the context of aligning with a previous pattern, the objective of using immer for state management, and notes the lack of visible changes, satisfying the repository’s template requirements.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b219ef and a905660.

📒 Files selected for processing (2)
  • client/src/app/components/discover-import-wizard/useWizardReducer.ts (2 hunks)
  • client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (5)
client/src/app/components/discover-import-wizard/useWizardReducer.ts (3)
  • WizardState (10-15)
  • InitialStateRecipe (57-57)
  • useWizardReducer (73-113)
client/src/app/api/models.ts (1)
  • TargetProfile (931-935)
client/src/app/pages/applications/generate-assets-wizard/step-capture-parameters.tsx (1)
  • ParameterState (28-33)
client/src/app/pages/applications/generate-assets-wizard/step-advanced-options.tsx (1)
  • AdvancedOptionsState (21-24)
client/src/app/pages/applications/generate-assets-wizard/step-results.tsx (1)
  • ResultsData (26-36)
client/src/app/components/discover-import-wizard/useWizardReducer.ts (1)
client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (1)
  • WizardState (11-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: unit-test
  • GitHub Check: build-and-upload-for-global-ci
🔇 Additional comments (5)
client/src/app/components/discover-import-wizard/useWizardReducer.ts (1)

33-55: LGTM! Reducer correctly implements Immer's contract.

The explicit function signature (draft: WizardState, action?: WizardAction) => WizardState | void properly reflects Immer's dual-return contract: mutations return void, replacements (RESET) return a new state. The RESET case correctly returns action.payload directly, and isReady is computed inline after other mutations, which simplifies the logic and avoids the frozen-object mutation concern from the previous implementation.

client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (4)

1-3: LGTM! Imports correctly updated for Immer pattern.

The imports properly include useCallback and useRef from React, plus produce and useImmerReducer from Immer, which are all required for the refactored implementation.


40-68: LGTM! Reducer implementation correctly addresses past review concerns.

The reducer now:

  1. Uses the explicit signature (draft: WizardState, action?: WizardAction) => WizardState | void, properly reflecting Immer's replacement-state contract (addresses previous comment about type safety)
  2. Returns action.payload directly in the RESET case without attempting to mutate the frozen initial state (addresses previous comment about frozen-object mutation)
  3. Computes isReady inline after mutations, which only executes for non-RESET actions or during initialization

The optional action parameter enables initialization: when wizardReducer(draft) is called without an action (line 79), it skips the switch and goes straight to computing isReady on the draft, ensuring the initial state is correct.


72-84: LGTM! Initialization helper correctly memoizes initial state.

The useImmerInitialState helper properly:

  1. Memoizes the initial state computation in a ref to prevent recalculation on every render
  2. Applies the optional initialRecipe to customize the initial state
  3. Calls wizardReducer(draft) without an action to compute isReady for the initial state

This ensures firstInitialState always has the correct isReady value, which is why RESET can safely return the payload directly.


86-135: LGTM! Public hook provides a clean, stable API.

The hook correctly:

  1. Memoizes the initial state via useImmerInitialState
  2. Uses useImmerReducer with the Immer-based reducer
  3. Wraps all setters in useCallback with proper dependencies for stable references
  4. Provides a reset function that dispatches RESET with the memoized firstInitialState

The returned API is clean and follows React best practices for stable callbacks.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sjd78 sjd78 added the cherry-pick/release-0.8 This PR should be cherry-picked to release-0.8 branch label Oct 6, 2025
@sjd78 sjd78 force-pushed the update_generate-assets-wizard_useWizardReducer branch from c257b46 to 389a7c0 Compare October 6, 2025 17:53
…Reducer`

Following the pattern in discover-import-wizard from PR konveyor#2646,
update generate-assets-wizard `useWizardReducer` to use immer and
`useImmerReducer` for handling the initial state and all reducer
actions.  This helps keep the initial state clean and resettable,
and helps keep the reducer logic simple and focused.

Signed-off-by: Scott J Dickerson <[email protected]>
@sjd78 sjd78 force-pushed the update_generate-assets-wizard_useWizardReducer branch from 389a7c0 to 13fd9de Compare October 6, 2025 20:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d93d85c and 13fd9de.

📒 Files selected for processing (1)
  • client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (4)
client/src/app/api/models.ts (1)
  • TargetProfile (931-935)
client/src/app/pages/applications/generate-assets-wizard/step-capture-parameters.tsx (1)
  • ParameterState (28-33)
client/src/app/pages/applications/generate-assets-wizard/step-advanced-options.tsx (1)
  • AdvancedOptionsState (21-24)
client/src/app/pages/applications/generate-assets-wizard/step-results.tsx (1)
  • ResultsData (26-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: unit-test
  • GitHub Check: build-and-upload-for-global-ci

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13fd9de and 0b219ef.

📒 Files selected for processing (2)
  • client/src/app/components/discover-import-wizard/useWizardReducer.ts (1 hunks)
  • client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
client/src/app/components/discover-import-wizard/useWizardReducer.ts (1)
client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (1)
  • WizardState (11-17)
client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (5)
client/src/app/components/discover-import-wizard/useWizardReducer.ts (3)
  • WizardState (10-15)
  • InitialStateRecipe (62-62)
  • useWizardReducer (78-118)
client/src/app/api/models.ts (1)
  • TargetProfile (931-935)
client/src/app/pages/applications/generate-assets-wizard/step-capture-parameters.tsx (1)
  • ParameterState (28-33)
client/src/app/pages/applications/generate-assets-wizard/step-advanced-options.tsx (1)
  • AdvancedOptionsState (21-24)
client/src/app/pages/applications/generate-assets-wizard/step-results.tsx (1)
  • ResultsData (26-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-and-upload-for-global-ci
  • GitHub Check: unit-test
🔇 Additional comments (7)
client/src/app/components/discover-import-wizard/useWizardReducer.ts (1)

38-41: LGTM!

The explicit type annotation for the reducer signature is clearer and correctly encodes Immer's contract where reducers can either mutate the draft (void) or return a replacement state (WizardState).

client/src/app/pages/applications/generate-assets-wizard/useWizardReducer.ts (6)

1-3: LGTM!

The imports are appropriate for the Immer-based refactoring and align with the established pattern in the discover-import-wizard.


38-38: LGTM!

The RESET action with a WizardState payload enables proper reset functionality and follows the established pattern.


48-73: Reducer logic is sound.

The reducer correctly implements Immer's draft-mutation pattern for SET_* actions and properly updates isReady after each mutation. The explicit return type WizardState | void correctly documents the contract.

Note: The RESET case issue is addressed in a separate comment.


75-75: LGTM!

The InitialStateRecipe type provides a clean API for customizing initial state and matches the established pattern.


77-89: LGTM!

The lazy initialization pattern correctly computes the initial state once, applies the optional recipe, and ensures isReady is computed via the reducer. The use of useRef prevents recomputation on re-renders as noted in the linked React documentation.


91-140: LGTM!

The hook implementation follows React best practices with stable callbacks via useCallback, proper dependency arrays, and lazy initialization. The API is clean and type-safe, matching the established pattern in discover-import-wizard.

@sjd78 sjd78 merged commit a884643 into konveyor:main Oct 9, 2025
11 checks passed
@sjd78 sjd78 deleted the update_generate-assets-wizard_useWizardReducer branch October 9, 2025 13:41
github-actions bot pushed a commit that referenced this pull request Oct 9, 2025
…Reducer` (#2658)

Following the pattern in discover-import-wizard from PR #2646, update
generate-assets-wizard `useWizardReducer` to use immer and
`useImmerReducer` for handling the initial state and all reducer
actions. This helps keep the initial state clean and resettable, and
helps keep the reducer logic simple and focused.

No visible changes.

## Summary by CodeRabbit

- **Refactor**
- Reworked wizard state management to use an immutable-draft approach
for more consistent initialization, stable setter references, and
reliable reset behavior.

- **Bug Fixes**
- Fixed readiness computation so Continue/Next reflects profile,
parameters, filters, and advanced options immediately and consistently.

---------

Signed-off-by: Scott J Dickerson <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
sjd78 added a commit that referenced this pull request Oct 9, 2025
…Reducer` (#2658) (#2662)

Following the pattern in discover-import-wizard from PR #2646, update
generate-assets-wizard `useWizardReducer` to use immer and
`useImmerReducer` for handling the initial state and all reducer
actions. This helps keep the initial state clean and resettable, and
helps keep the reducer logic simple and focused.

No visible changes.

## Summary by CodeRabbit

- **Refactor**
- Reworked wizard state management to use an immutable-draft approach
for more consistent initialization, stable setter references, and
reliable reset behavior.

- **Bug Fixes**
- Fixed readiness computation so Continue/Next reflects profile,
parameters, filters, and advanced options immediately and consistently.

---------

Signed-off-by: Scott J Dickerson <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
Co-authored-by: Scott Dickerson <[email protected]>
sshveta pushed a commit to sshveta/tackle2-ui that referenced this pull request Oct 31, 2025
…Reducer` (konveyor#2658)

Following the pattern in discover-import-wizard from PR konveyor#2646, update
generate-assets-wizard `useWizardReducer` to use immer and
`useImmerReducer` for handling the initial state and all reducer
actions. This helps keep the initial state clean and resettable, and
helps keep the reducer logic simple and focused.

No visible changes.

## Summary by CodeRabbit

- **Refactor**
- Reworked wizard state management to use an immutable-draft approach
for more consistent initialization, stable setter references, and
reliable reset behavior.

- **Bug Fixes**
- Fixed readiness computation so Continue/Next reflects profile,
parameters, filters, and advanced options immediately and consistently.

---------

Signed-off-by: Scott J Dickerson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/release-0.8 This PR should be cherry-picked to release-0.8 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants