Skip to content

Improve product handling and state sync - #251

Merged
Rashmika998 merged 1 commit into
wso2-open-operations:customer-portal-milestone-1from
dileepapeiris:feat/add-chat-details
Feb 24, 2026
Merged

Rashmika998 merged 1 commit into
wso2-open-operations:customer-portal-milestone-1from
dileepapeiris:feat/add-chat-details

Conversation

@dileepapeiris

@dileepapeiris dileepapeiris commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Introduce a memoized handleProductChange callback and pass it to BasicInformationSection instead of directly passing setProduct. Ensure classificationProductLabel is set when productLabel is available, and adjust the product-selection logic to preserve user input when it matches the classification label (case-insensitive normalized comparison) rather than always falling back to base options. Also update effect dependencies to include classificationProductLabel and tidy up related state updates to avoid unintended overwrites.

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter �N/A� plus brief explanation of why there�s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type �Sent� when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type �N/A� and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved product selection synchronization when classifications are applied during case creation.
    • Enhanced product matching logic to ensure consistency between classification data and product dropdown selections, resulting in more reliable form behavior and better state management when users create new cases.

Introduce a memoized handleProductChange callback and pass it to BasicInformationSection instead of directly passing setProduct. Ensure classificationProductLabel is set when productLabel is available, and adjust the product-selection logic to preserve user input when it matches the classification label (case-insensitive normalized comparison) rather than always falling back to base options. Also update effect dependencies to include classificationProductLabel and tidy up related state updates to avoid unintended overwrites.
@dileepapeiris dileepapeiris self-assigned this Feb 24, 2026
@coderabbitai

coderabbitai Bot commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR refactors product state synchronization in CreateCasePage by introducing a handleProductChange callback, restructuring how classification-derived product labels are applied, and enhancing product matching logic with case-insensitive comparison support.

Changes

Cohort / File(s) Summary
Product State Synchronization
apps/customer-portal/webapp/src/pages/CreateCasePage.tsx
Added handleProductChange callback to manage product state updates from child components. Refactored classification-applied effect to store and apply classification-derived productLabel to classificationProductLabel state. Enhanced product matching logic with case-insensitive comparison and fallback handling. Updated effect dependencies and wired new callback to BasicInformationSection component.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Type/Improvement, App/Customer Portal, Area/Frontend, Type/UX

Suggested reviewers

  • Rashmika998
  • sacheeramesh
  • v15a1

Poem

🐰 A callback hops, state syncs with care,
Classification labels match case-unaware,
Dependencies dance in the effect's tight hold,
Product flows smoothly, where stories unfold! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a clear technical summary of changes but fails to complete required template sections like Purpose, Goals, Approach, and others. Complete the PR description template by filling in Purpose, Goals, Approach, and other required sections to provide context for reviewers.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: improving product handling and state synchronization logic in the component.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
apps/customer-portal/webapp/src/pages/CreateCasePage.tsx (2)

234-237: useCallback on a trivial setter wrapper conflicts with the project's React Compiler policy

handleProductChange does nothing beyond forwarding to setProduct, which is already a stable reference (React guarantees useState setters never change). Wrapping it in useCallback with an empty deps array adds no stability and violates the project convention of deferring memoization to the compiler. The simplest fix is to drop the wrapper entirely and pass setProduct directly at the call site, matching how other plain setters (e.g., setTitle, setSeverity) are passed to CaseDetailsSection.

♻️ Proposed refactor
-  const handleProductChange = useCallback((value: string) => {
-    setProduct(value);
-  }, []);
-
-            setProduct={handleProductChange}
+            setProduct={setProduct}

If the intent is to keep a named handler for future extensibility (adding side-effects alongside the state update), that's reasonable — but drop the useCallback wrapper and let the compiler handle memoization if and when it matters.

Based on learnings from PR #88: "rely on the bundler/compiler optimizations (React Compiler via babel-plugin-react-compiler with Vite) for memoization. Do not manually wrap handlers/selectors with useCallback, useMemo, or React.memo unless you have a measured, proven performance issue independent of the compiler."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/customer-portal/webapp/src/pages/CreateCasePage.tsx` around lines 234 -
237, The handleProductChange wrapper is unnecessary and conflicts with the
project's React Compiler policy; remove the useCallback wrapper and either pass
the state setter setProduct directly to the consumer (e.g., where
CaseDetailsSection receives other setters like setTitle and setSeverity) or, if
you need a named handler for future side-effects, keep a plain function named
handleProductChange that calls setProduct but do not wrap it with useCallback so
the compiler can handle memoization.

359-368: Dead fallback on line 368 — consider simplifying to return current

By the time execution reaches line 368, current is already guaranteed to be a non-empty, non-whitespace string (the early return on line 357 handles the empty/whitespace case). The ?? baseProductOptions[0] ?? "" tail is therefore unreachable dead code.

♻️ Proposed simplification
-      return current ?? baseProductOptions[0] ?? "";
+      return current;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/customer-portal/webapp/src/pages/CreateCasePage.tsx` around lines 359 -
368, The final return includes an unreachable fallback tail (return current ??
baseProductOptions[0] ?? "") even though earlier logic already ensures current
is a non-empty, non-whitespace string; simplify the end of the block by
returning current directly—locate the branch that checks match and the
subsequent normalization logic (references: match, classificationProductLabel,
current, baseProductOptions) and replace the fallback expression with a plain
return current to remove dead code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/customer-portal/webapp/src/pages/CreateCasePage.tsx`:
- Around line 234-237: The handleProductChange wrapper is unnecessary and
conflicts with the project's React Compiler policy; remove the useCallback
wrapper and either pass the state setter setProduct directly to the consumer
(e.g., where CaseDetailsSection receives other setters like setTitle and
setSeverity) or, if you need a named handler for future side-effects, keep a
plain function named handleProductChange that calls setProduct but do not wrap
it with useCallback so the compiler can handle memoization.
- Around line 359-368: The final return includes an unreachable fallback tail
(return current ?? baseProductOptions[0] ?? "") even though earlier logic
already ensures current is a non-empty, non-whitespace string; simplify the end
of the block by returning current directly—locate the branch that checks match
and the subsequent normalization logic (references: match,
classificationProductLabel, current, baseProductOptions) and replace the
fallback expression with a plain return current to remove dead code.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de42344 and eda3caa.

📒 Files selected for processing (1)
  • apps/customer-portal/webapp/src/pages/CreateCasePage.tsx

@Rashmika998
Rashmika998 merged commit 766211a into wso2-open-operations:customer-portal-milestone-1 Feb 24, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Feb 25, 2026
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