Skip to content

Conversation

@sachiniSam
Copy link
Contributor

@sachiniSam sachiniSam commented Nov 25, 2025

Purpose

This PR includes the following enhancements:

  • Automatically selects the first record type by default when the view opens.
  • Updates the visibility toggle for optional fields with clearer hide/show behavior.
  • Improves the styling of the dropdown for union record types.
  • Fixes an issue where values were not being reset when a field was unchecked.
Screen.Recording.2025-11-25.at.13.54.17.mov

related issue wso2/product-ballerina-integrator#1952

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 [email protected] 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.

UI Component Development

Specify the reason if following are not followed.

  • Added reusable UI components to the ui-toolkit. Follow the intructions when adding the componenent.
  • Use ui-toolkit components wherever possible. Run npm run storybook from the root directory to view current components.
  • Matches with the native VSCode look and feel.

Manage Icons

Specify the reason if following are not followed.

  • Added Icons to the font-wso2-vscode. Follow the instructions.

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 [email protected] 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

  • New Features

    • Auto-selects the first record and its required fields on selection.
    • Icon-based toggle for optional parameter sections with clearer visual state and indentation when collapsed.
    • Parameter branch rendering optimized via memoization for smoother UI.
  • Bug Fixes

    • Field values now reset when deselecting custom, inclusion, record, and union types.
    • Empty-expression handling now deselects fields and clears related state/diagnostics.
  • Style

    • Optional-parameters header and title restyled with theme-aware colors and hover effects.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 25, 2025

Walkthrough

Adds a recursive resetFieldValues utility and calls it when unchecking type fields; refactors ParameterBranch to a collapsible optional-fields header with Codicon icons; RecordConfigModal gains a ref-backed model, auto-selects the first record and required fields, and deselects fields when the expression is cleared.

Changes

Cohort / File(s) Summary
UI: ParameterBranch
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
Replaced previous toggle with an icon-based collapsible header using Codicon; added shouldShowOptionalParamsDirectly to decide direct rendering vs collapsible list; exported MemoizedParameterBranch = React.memo(ParameterBranch).
Styling: optional list header
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts
Removed fixed height and adjusted margins on listOptionalWrapper; added listOptionalHeader and listOptionalTitle classes and ThemeColors usage; updated hover and layout styles.
New utility: resetFieldValues
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx
Added exported resetFieldValues(field: FormField): void that recursively clears a field's value and resets nested/union/inclusion members.
Field types: invoke reset on uncheck
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx, .../InclusionType/index.tsx, .../RecordType/index.tsx, .../UnionType/index.tsx
Imported resetFieldValues and call it when a parameter is unchecked (newSelectedState === false) to clear associated values; existing selection logic otherwise preserved.
Modal: auto-select & deselect on empty expression
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Views/RecordConfigModal.tsx
Added recordModelRef to mirror state; implemented autoSelectFirstRecord(model) to auto-select first record and its required fields; on empty expression, deselects record/fields via updateFieldsSelection, clears source and diagnostics, and forces model re-render; adjusted dropdown width props.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Modal as RecordConfigModal
    participant Types as TypeComponents
    participant Utils as resetFieldValues
    participant UI as ParameterBranch

    User->>UI: Click optional header / toggle
    UI->>UI: Toggle open/closed (Codicon changes)

    User->>Types: Uncheck a field
    Types->>Utils: Call resetFieldValues(param) when unchecked
    Utils->>Utils: Recursively clear values (nested, unions, inclusions)

    User->>Modal: Select a model / change model
    Modal->>Modal: set state & recordModelRef
    Modal->>Modal: autoSelectFirstRecord(model) -> select required fields
    Modal->>Modal: generate source from auto-selected state

    User->>Modal: Clear expression input
    Modal->>Modal: updateFieldsSelection(deselect all)
    Modal->>Modal: clear sourceCode, diagnostics, and force re-render
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

  • Inspect recursive safety and completeness of resetFieldValues (union/inclusion/nested handling).
  • Verify autoSelectFirstRecord correctness and timing relative to state/ref updates to avoid stale reads.
  • Confirm UI toggle logic in ParameterBranch and accessibility (click targets, event.stopPropagation usage).
  • Check that calls to resetFieldValues do not unintentionally clear needed state on complex selection flows.

Possibly related PRs

Suggested reviewers

  • hevayo
  • gigara
  • kanushka

Poem

🐰 I nudge the fields, then gently clear away,

Optional headers hop out to play,
First record chosen, required ones wake,
Values reset softly, no messy mistake,
A tiny rabbit cheers the tidy array.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The description has the Purpose section partially filled with specific enhancements and a linked issue, but most required template sections (Goals, Approach, User stories, Release note, Documentation, etc.) remain as unfilled prompts. Complete the critical sections: Goals (solutions for each problem), Approach (implementation details), Release note (concise feature summary), and Documentation (link or 'N/A' with explanation). Consider filling automation tests and security checks.
Title check ❓ Inconclusive The title "Improvements in Record Constrcut View" is partially related to the changeset but contains a typo ("Constrcut" instead of "Construct") and is overly broad, not clearly summarizing the specific improvements. Correct the typo to "Construct" and be more specific about the main improvements, such as "Add auto-selection and field reset logic to Record Construct View" to better reflect the primary changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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.

Copy link
Contributor

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Views/RecordConfigModal.tsx (1)

548-556: ---

Cancel pending diagnostics when expression is cleared to prevent stale diagnostics from resurfacing

The empty-expression handling correctly clears diagnostics and prevents a new fetchDiagnostics call via early return. However, the issue remains real: any pending debounced fetchDiagnostics call scheduled from the previous non-empty value will still execute after the clear and overwrite the cleared state with stale diagnostics.

Recommended fix: Add (fetchDiagnostics as any).cancel?.(); before the early return in the empty-expression block (line 585) to cancel the pending debounced invocation. This prevents the race condition where old diagnostics would resurface after clearing the expression.

// Inside the `if (updatedValue.trim() === '') { ... }` block (before line 586 return):
(fetchDiagnostics as any).cancel?.();
🧹 Nitpick comments (3)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts (1)

297-332: Optional polish for hover selector and transitions

The new listOptionalWrapper / listOptionalHeader / listOptionalTitle styles read well and should give a clear interactive affordance.

Two small, non-blocking suggestions:

  • The &:hover > div:last-of-type selector for the title is a bit layout‑dependent; if the header’s children order changes later, the hover styling could accidentally move to a different element. Consider a more explicit selector (e.g., always applying the title class to the hovered element) if the structure evolves.
  • transition: 'all 0.2s ease' on both header and title works but is broader than necessary; constraining it to the specific properties that change (e.g., color, opacity, background-color) can be a minor perf/readability improvement.

These are nice‑to‑have only; the current implementation is fine to ship.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (2)

74-76: Consider adding a comment to document the depth-based logic.

The shouldShowOptionalParamsDirectly calculation uses specific depth thresholds (depth === 1 and depth < 3) without explanation. Adding a brief comment would improve maintainability by clarifying the UI/UX rationale behind these values.

Example:

+    // Show optional params directly at shallow depths to reduce UI clutter:
+    // - Always show at depth 1 if optional params exist
+    // - Show at depth < 3 when there are no required params
     const shouldShowOptionalParamsDirectly = (optionalParams.length > 0 && depth === 1) ||
         (requiredParams.length === 0 && optionalParams.length > 0 && depth < 3);

106-108: Use CSS class instead of inline style for consistency.

The margin-left styling uses an inline style, which is inconsistent with the rest of the codebase that uses CSS classes from useHelperPaneStyles().

Consider adding a CSS class to the styles hook:

// In styles.ts
listOptionalContent: {
    marginLeft: '15px',
}

Then use it here:

-                    <div style={{ marginLeft: '15px' }}>
+                    <div className={helperStyleClass.listOptionalContent}>
                         {showOptionalParams && optionalParams.length > 0 && optionalParams}
                     </div>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61167a4 and 795ce37.

📒 Files selected for processing (8)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (2 hunks)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx (2 hunks)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/InclusionType/index.tsx (2 hunks)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/RecordType/index.tsx (2 hunks)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/UnionType/index.tsx (2 hunks)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts (2 hunks)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx (1 hunks)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Views/RecordConfigModal.tsx (8 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/**/*.{ts,tsx} : Define all constants (node types, sizing, spacing) in src/resources/constants.ts and import them where needed instead of hardcoding values

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/InclusionType/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/UnionType/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/RecordType/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/**/*.{ts,tsx} : Use TypeScript 5.8.3 with strict type checking enabled for all source files

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/UnionType/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/components/**/*.tsx : Use React 18.2.0 features including concurrent rendering and automatic batching; avoid class components in favor of functional components with hooks

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Views/RecordConfigModal.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/components/nodes/EntryNode/components/**/*.tsx : Implement lazy expansion of functions: only render function items when they are visible to improve performance for large function lists

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/**/*.test.{ts,tsx} : Create snapshot tests for all node widgets and verify visual consistency across renders

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/components/**/*.tsx : Use Emotion for CSS-in-JS styling instead of inline styles or external CSS files

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts
🧬 Code graph analysis (6)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/InclusionType/index.tsx (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx (1)
  • resetFieldValues (67-95)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/UnionType/index.tsx (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx (1)
  • resetFieldValues (67-95)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/RecordType/index.tsx (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx (1)
  • resetFieldValues (67-95)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx (1)
  • resetFieldValues (67-95)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Views/RecordConfigModal.tsx (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx (1)
  • updateFieldsSelection (97-141)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts (1)
workspaces/common-libs/ui-toolkit/src/styles/Theme.ts (1)
  • ThemeColors (79-104)
🔇 Additional comments (9)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/styles.ts (1)

19-19: ThemeColors import usage looks good

Importing ThemeColors from @wso2/ui-toolkit is consistent with the shared theme utilities and keeps colors aligned with the design system. No issues here.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (2)

21-21: LGTM!

The Codicon import is correctly added to support the new icon-based toggle UI.


115-115: Verify that React.memo's default comparison works correctly for the parameters prop.

React.memo uses shallow comparison by default, which compares prop references. If the parameters array is recreated on each parent render (new reference), the memoization won't prevent re-renders. Conversely, if the array reference stays the same while its contents change, necessary re-renders might be skipped.

Verify that the parent component manages the parameters array in a way compatible with shallow comparison. If the array is frequently recreated, consider providing a custom comparison function:

export const MemoizedParameterBranch = React.memo(
    ParameterBranch,
    (prevProps, nextProps) => {
        // Custom comparison logic
        return prevProps.depth === nextProps.depth &&
               prevProps.parameters.length === nextProps.parameters.length &&
               prevProps.parameters.every((p, i) => p === nextProps.parameters[i]);
    }
);

Or ensure the parent component uses useMemo to stabilize the parameters array reference.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/CustomType/index.tsx (1)

25-48: Value reset on uncheck is consistent and correct

Wiring resetFieldValues(param) into the uncheck path keeps this type in line with the others and correctly clears values when the checkbox is turned off, without touching required params.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/utils/index.tsx (1)

67-95: Recursive reset implementation looks sound

resetFieldValues correctly walks all relevant structures (nested fields, union members, inclusion-type fields) and only clears value, leaving selection flags to higher-level logic. This matches the PR’s intent and keeps responsibilities nicely separated.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/RecordType/index.tsx (1)

26-51: Record deselection now fully clears nested state

Calling resetFieldValues(param) before updateFieldsSelection(param.fields, newSelectedState) ensures both values and selection flags are cleared when the record is unchecked, which aligns with the desired UX for “hide/reset” behavior.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/UnionType/index.tsx (1)

27-197: Union uncheck path correctly clears values and selections

Using resetFieldValues(param) ahead of the existing loop that clears field.selected and calls updateFieldsSelection(..., false) ensures both the union node and all member values are reset when the checkbox is turned off, with no change to the existing selection logic.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/Types/InclusionType/index.tsx (1)

26-54: Inclusion-type deselection reset is consistent with other types

On uncheck, resetFieldValues(param) followed by updateFieldsSelection(param.inclusionType.fields, newSelectedState) gives the expected “clear everything under this inclusion” behavior and matches the pattern used for record and union types.

workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Views/RecordConfigModal.tsx (1)

29-30: Auto-selection and record model ref handling are coherent

The introduction of recordModelRef plus autoSelectFirstRecord and the updated getNewRecordModel / handleMemberChange flows looks solid:

  • New models are funneled through a single newModel array, which is written to both React state and the ref.
  • autoSelectFirstRecord marks the first record selected and leverages updateFieldsSelection to recursively select required fields (including union members), aligning with the helper-pane behavior in the type components.
  • Immediately calling handleModelChange(newModel) after auto-selection ensures the right-hand expression and diagnostics are in sync with what’s selected in the tree.

This gives the “auto-select first record + required fields” behavior described in the PR without changing existing APIs.

Also applies to: 145-147, 253-267, 277-291, 335-344, 385-393

@sachiniSam sachiniSam marked this pull request as draft November 25, 2025 10:26
@sachiniSam sachiniSam marked this pull request as ready for review November 25, 2025 10:34
Copy link
Contributor

@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: 0

♻️ Duplicate comments (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (1)

86-103: Keyboard accessibility is still missing on the clickable header.

The clickable header div lacks keyboard navigation support, preventing keyboard users from toggling optional fields. This was flagged in the previous review but remains unaddressed. Users relying on keyboard navigation cannot interact with this control, violating WCAG accessibility guidelines.

Apply this diff to add keyboard accessibility:

-                            <div className={helperStyleClass.listOptionalHeader} onClick={toggleOptionalParams}>
+                            <div 
+                                className={helperStyleClass.listOptionalHeader} 
+                                role="button"
+                                tabIndex={0}
+                                onClick={toggleOptionalParams}
+                                onKeyDown={(e) => {
+                                    if (e.key === 'Enter' || e.key === ' ') {
+                                        e.preventDefault();
+                                        toggleOptionalParams();
+                                    }
+                                }}
+                                aria-expanded={showOptionalParams}
+                                aria-label="Toggle optional fields"
+                            >
                                 <Button
                                     data-testid="optional-toggle-button"
                                     appearance="icon"
                                     sx={{
                                         transition: "all 0.2s ease",
                                         "&:hover": {
                                             backgroundColor: "transparent !important",
                                         },
                                     }}
                                 >
                                     <Codicon
                                         name={showOptionalParams ? "chevron-down" : "chevron-right"}
                                         iconSx={{ fontSize: '13px' }}
                                     />
                                 </Button>
                                 <div className={helperStyleClass.listOptionalTitle}>Optional fields</div>
                             </div>
🧹 Nitpick comments (2)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (2)

74-76: Consider adding a comment to explain the visibility logic.

The shouldShowOptionalParamsDirectly computation uses depth-based conditions to determine when optional fields should be directly visible vs. collapsible. A brief comment explaining why depth 1 or depth < 3 (with no required params) trigger direct display would improve maintainability.


106-108: Consider moving inline style to the styles file.

The marginLeft: '15px' inline style could be moved to the styles.ts file (e.g., as listOptionalContent class) for better maintainability and consistency with the rest of the styling approach.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 795ce37 and 46f4781.

📒 Files selected for processing (1)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/components/**/*.tsx : Use React 18.2.0 features including concurrent rendering and automatic batching; avoid class components in favor of functional components with hooks

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/components/nodes/EntryNode/components/**/*.tsx : Implement lazy expansion of functions: only render function items when they are visible to improve performance for large function lists

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/resources/icons/**/*.tsx : Create separate SVG icon components in src/resources/icons/ for all diagram icons and import them as React components

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
📚 Learning: 2025-11-25T06:34:10.812Z
Learnt from: CR
Repo: wso2/vscode-extensions PR: 0
File: workspaces/ballerina/component-diagram/AGENTS.md:0-0
Timestamp: 2025-11-25T06:34:10.812Z
Learning: Applies to workspaces/ballerina/component-diagram/src/**/*.{ts,tsx} : Define all constants (node types, sizing, spacing) in src/resources/constants.ts and import them where needed instead of hardcoding values

Applied to files:

  • workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx
🧬 Code graph analysis (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (2)
workspaces/common-libs/ui-toolkit/src/components/Button/Button.tsx (1)
  • Button (54-65)
workspaces/common-libs/ui-toolkit/src/components/Codicon/Codicon.tsx (1)
  • Codicon (44-56)
🔇 Additional comments (3)
workspaces/ballerina/ballerina-visualizer/src/views/BI/HelperPaneNew/Components/RecordConstructView/ParameterBranch.tsx (3)

18-21: LGTM: Imports are appropriate for the new collapsible header.

The useState hook and UI toolkit components (Button, Codicon) are correctly imported to support the enhanced optional fields toggle functionality.


67-72: Good fix: Event type is now properly typed.

The event parameter is now correctly typed as React.MouseEvent<HTMLDivElement> instead of any, improving type safety as requested in the previous review.


115-115: Good addition: Component memoization improves performance.

Exporting a memoized version of the component is a good practice that prevents unnecessary re-renders when props haven't changed.

@sachiniSam sachiniSam changed the title Improvements on Record Constrcut View Improvements in Record Constrcut View Nov 25, 2025
@sachiniSam sachiniSam merged commit ee28dda into wso2:main Nov 27, 2025
6 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