Skip to content

[Customer Portal][FE][web] Refactor: related case naming + code block parsing improvements + UI enhancements - #504

Merged
cloby99 merged 7 commits into
wso2-open-operations:dev-app-customer-portalfrom
dileepapeiris:code-clean-up-v3
Apr 17, 2026
Merged

cloby99 merged 7 commits into
wso2-open-operations:dev-app-customer-portalfrom
dileepapeiris:code-clean-up-v3

Conversation

@dileepapeiris

@dileepapeiris dileepapeiris commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

This pull request introduces several improvements and refactors across the support case details and related features, focusing on consistent naming, improved code block handling in messages, and better display of preferred call times. The most significant changes are grouped below:

Refactor and Consistency in Related Case Naming:

  • Renamed all usages of parentCase/parentCaseId to relatedCase/relatedCaseId in types, navigation state, and API requests for clarity and consistency. This affects types like CaseDetails, CreateCaseRequest, RelatedCaseState, and related components and tests. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Enhanced Code Block Handling in Support Messages:

  • Improved the convertCodeTagsToHtml and stripAllCodeBlocks utility functions to normalize and correctly handle escaped or orphaned [code] tags, ensuring cleaner rendering and text extraction. [1] [2]
  • Added comprehensive tests for edge cases in code block parsing, such as handling escaped markers and orphan tags. [1] [2]

UI Improvements for Message and Call Time Display:

  • Updated the chat message card styling to better handle code blocks, ensuring proper width, background color, and code formatting.
  • Refactored the display of preferred call times in CallRequestCard to present them as a list when multiple times are provided and improved the formatting logic for clarity. [1] [2] [3]

These changes collectively improve code maintainability, user experience, and the robustness of message parsing and display.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved code block handling to properly normalize escaped markers and edge cases for better content display
  • Style

    • Enhanced styling for code and pre-formatted text blocks with improved content sizing and background colors
  • UI Improvements

    • Preferred times now display as a formatted bullet list for improved readability

Improve handling of [code] blocks by normalizing backslash-escaped and case-variant tags (e.g. [\code], [\/code], [CODE]) and inserting newlines between adjacent tags. Updates convertCodeTagsToHtml to convert normalized [code]...[/code] into <code> blocks and to strip any remaining code tags into newlines. Updates stripAllCodeBlocks to normalize tags and remove code wrappers while preserving inner content and adding newlines where appropriate. These changes make parsing more robust against various tag formats.
Add unit tests covering edge cases for convertCodeTagsToHtml and stripAllCodeBlocks: handling escaped closing/opening markers (e.g. "[\/code][code]"), dropping orphan markers while preserving blank-line separators, and ensuring blank lines/trailing newlines are preserved when stripping multiple code blocks. Also adjust an existing expectation to include blank-line separators and trailing newlines.
Update ChatMessageCard styles to improve code block layout and background handling. Change width from 100% to max-content with a minWidth of 100% for the content and pre elements, add boxSizing, and set pre background to action.disabledBackground so code blocks don't stretch full width and scroll correctly. Also ensure nested code has a transparent background to avoid double backgrounds.
Rename navigation state property from parentCaseId to relatedCaseId when creating a related case to match expected payload. Update CallRequestCard to support multiple preferred times: formatPreferredTimes now returns an array of formatted time strings (or ["--"]) and the component renders them as a bulleted list, falling back to "--" when no times are available. Adds preferredTimeLines local variable and adjusts markup/styling for list rendering.
Rename parentCase -> relatedCase across support types and page to standardize related-case naming. Updates:
- CreateCasePage: use relatedCase?.relatedCaseId when building the create request payload.
- types/cases.ts: CaseDetails.parentCase -> relatedCase; CreateCaseRequest.parentCaseId -> relatedCaseId.
- types/createCasePage.ts: RelatedCaseState.parentCaseId -> relatedCaseId.
This aligns frontend state and request payload keys for creating related cases; adjust any backend expectations or consumers accordingly.
Replace occurrences of parentCase/parentCaseId with relatedCase/relatedCaseId to keep naming consistent. Updated mock data in two test files and adjusted the CaseDetailsPage navigate payload to use relatedCaseId when creating a related case.
Update mockCaseDetails in CaseDetailsContent.test.tsx to use the relatedCase property instead of parentCase. This aligns the test fixture with the updated data model property name; no other logic changes were made.
@coderabbitai

coderabbitai Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR systematically renames the case linkage field from parentCaseId to relatedCaseId across the customer portal frontend, updating type definitions, navigation payloads, page handlers, and test fixtures. Additionally, it refines UI rendering in CallRequestCard (preferred times list formatting), improves code block styling in ChatMessageCard, and enhances support utility functions for better code tag normalization.

Changes

Cohort / File(s) Summary
Type Definitions
apps/customer-portal/webapp/src/features/support/types/cases.ts, apps/customer-portal/webapp/src/features/support/types/createCasePage.ts
Renamed case linkage fields from parentCaseId to relatedCaseId and parentCase to relatedCase across exported types CaseDetails and CreateCaseRequest; updated navigation state type RelatedCaseState.
Navigation & Page Handlers
apps/customer-portal/webapp/src/features/operations/pages/ServiceRequestDetailsPage.tsx, apps/customer-portal/webapp/src/features/support/pages/CaseDetailsPage.tsx, apps/customer-portal/webapp/src/features/support/pages/CreateCasePage.tsx
Updated navigation state and submission payloads to use relatedCaseId instead of parentCaseId when opening/creating related support cases.
Component Styling & UI
apps/customer-portal/webapp/src/features/support/components/case-details/calls-tab/CallRequestCard.tsx, apps/customer-portal/webapp/src/features/support/components/case-details/activity-tab/ChatMessageCard.tsx
Updated preferred times rendering in CallRequestCard to display as a bullet list instead of comma-joined string; refined <code> and <pre> block styling in ChatMessageCard for better content-aware sizing and background transparency.
Support Utilities
apps/customer-portal/webapp/src/features/support/utils/support.ts, apps/customer-portal/webapp/src/features/support/utils/__tests__/support.test.ts
Enhanced convertCodeTagsToHtml and stripAllCodeBlocks to normalize escaped/mixed-case code tag variants and handle edge cases; added comprehensive test coverage for tag normalization scenarios.
Test Fixtures
apps/customer-portal/webapp/src/features/support/components/case-details/details-tab/__tests__/CaseDetailsContent.test.tsx, apps/customer-portal/webapp/src/features/support/components/case-details/details-tab/__tests__/CaseDetailsDetailsPanel.test.tsx, apps/customer-portal/webapp/src/features/support/components/case-details/header/__tests__/CaseDetailsTabPanels.test.tsx
Updated mockCaseDetails fixture across test files to replace parentCase field with relatedCase for consistency with type changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

Type/Improvement, Type/Task, Type/UX, App/Customer Portal, Area/Frontend, Platform/Web

Suggested reviewers

  • Rashmika998
  • v15a1
  • shayanmalinda

Poem

🐰 A case by any other name renews,
From parent to related—fresh new hues!
With bullets and boxes, styled just right,
Code blocks now gleam in proper light.
Field names align, from front to back,
One consistent, well-tested track! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks required template sections such as Purpose, Goals, Approach, User stories, Release notes, Documentation, Training, Certification, Marketing, Automation tests, Security checks, and other mandatory sections. Complete the description by adding all required template sections with relevant details about the changes, testing coverage, security considerations, and any documentation/release note impact.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the three main changes: renaming parentCase to relatedCase, improving code block parsing, and enhancing UI for message and call time display.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@dileepapeiris dileepapeiris changed the title Code clean up v3 [Customer Portal][FE][web] Refactor: related case naming + code block parsing improvements + UI enhancements Apr 17, 2026
@dileepapeiris dileepapeiris self-assigned this Apr 17, 2026
@dileepapeiris dileepapeiris added Type/Improvement Marks enhancements or improvements to existing features Type/Task General task that does not fit into other categories Type/UX Refers to user experience-related tasks or issues App/Customer Portal Area/Frontend Platform/Web labels Apr 17, 2026

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/customer-portal/webapp/src/features/support/utils/support.ts (1)

1133-1141: Optional: drop the redundant case-sensitive escape regexes.

/\[\\\/code\]/gi already matches [\/CODE] (and any casing) due to the i flag, which makes the subsequent /\[\\\/CODE\]/g a no-op. Same for the [\\code] / [\\CODE] pair. Collapsing the duplicate chains is clearer and slightly cheaper. The same applies in stripAllCodeBlocks.

♻️ Suggested cleanup (apply to both functions)
   const normalized = content
-    .replace(/\[\\\/code\]/gi, "[/code]")
-    .replace(/\[\\\/CODE\]/g, "[/code]")
-    .replace(/\[\\code\]/gi, "[code]")
-    .replace(/\[\\CODE\]/g, "[code]")
-    .replace(
-    /\[\/code\]\s*\[code\]/gi,
-    "[/code]\n[code]",
-  );
+    .replace(/\[\\\/code\]/gi, "[/code]")
+    .replace(/\[\\code\]/gi, "[code]")
+    .replace(/\[\/code\]\s*\[code\]/gi, "[/code]\n[code]");

Also applies to: 1156-1161

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

In `@apps/customer-portal/webapp/src/features/support/utils/support.ts` around
lines 1133 - 1141, The regex chain normalizing escaped code tags contains
redundant case-specific variants; simplify the replacements in the normalized
assignment (and the analogous block in stripAllCodeBlocks) by removing the
duplicate `/\[\\\/CODE\]/g` and `/\[\\CODE\]/g` entries and rely on the
case-insensitive `/i` flag (e.g., keep `/\[\\\/code\]/gi` and `/\[\\code\]/gi`).
Update the replacement sequence around the `normalized` const and the
corresponding logic in `stripAllCodeBlocks` to use only the case-insensitive
regexes and preserve the final `/\[\/code\]\s*\[code\]/gi` replacement so
behavior stays identical but simpler and slightly more efficient.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/customer-portal/webapp/src/features/support/components/case-details/calls-tab/CallRequestCard.tsx`:
- Around line 274-278: The list items in CallRequestCard use key={timeValue}
which can produce duplicate React keys when two preferred times format to the
same string; update the map over preferredTimeLines in CallRequestCard to use a
unique key per item (e.g., include the map index or a compound key like
`${timeValue}-${index}`) by changing the map callback signature to (timeValue,
index) => ... and setting the key to the index or compound value so the list is
stable and avoids duplicate keys during reconciliation.

---

Nitpick comments:
In `@apps/customer-portal/webapp/src/features/support/utils/support.ts`:
- Around line 1133-1141: The regex chain normalizing escaped code tags contains
redundant case-specific variants; simplify the replacements in the normalized
assignment (and the analogous block in stripAllCodeBlocks) by removing the
duplicate `/\[\\\/CODE\]/g` and `/\[\\CODE\]/g` entries and rely on the
case-insensitive `/i` flag (e.g., keep `/\[\\\/code\]/gi` and `/\[\\code\]/gi`).
Update the replacement sequence around the `normalized` const and the
corresponding logic in `stripAllCodeBlocks` to use only the case-insensitive
regexes and preserve the final `/\[\/code\]\s*\[code\]/gi` replacement so
behavior stays identical but simpler and slightly more efficient.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f56a24df-b61c-4a19-9e7d-be983c8cde50

📥 Commits

Reviewing files that changed from the base of the PR and between 8f77711 and 2891578.

📒 Files selected for processing (12)
  • apps/customer-portal/webapp/src/features/operations/pages/ServiceRequestDetailsPage.tsx
  • apps/customer-portal/webapp/src/features/support/components/case-details/activity-tab/ChatMessageCard.tsx
  • apps/customer-portal/webapp/src/features/support/components/case-details/calls-tab/CallRequestCard.tsx
  • apps/customer-portal/webapp/src/features/support/components/case-details/details-tab/__tests__/CaseDetailsContent.test.tsx
  • apps/customer-portal/webapp/src/features/support/components/case-details/details-tab/__tests__/CaseDetailsDetailsPanel.test.tsx
  • apps/customer-portal/webapp/src/features/support/components/case-details/header/__tests__/CaseDetailsTabPanels.test.tsx
  • apps/customer-portal/webapp/src/features/support/pages/CaseDetailsPage.tsx
  • apps/customer-portal/webapp/src/features/support/pages/CreateCasePage.tsx
  • apps/customer-portal/webapp/src/features/support/types/cases.ts
  • apps/customer-portal/webapp/src/features/support/types/createCasePage.ts
  • apps/customer-portal/webapp/src/features/support/utils/__tests__/support.test.ts
  • apps/customer-portal/webapp/src/features/support/utils/support.ts

@cloby99
cloby99 merged commit efaade1 into wso2-open-operations:dev-app-customer-portal Apr 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App/Customer Portal Area/Frontend Platform/Web Type/Improvement Marks enhancements or improvements to existing features Type/Task General task that does not fit into other categories Type/UX Refers to user experience-related tasks or issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants