Update codeaction menu options availability#2233
Conversation
…s in root level mappings in inline data mapper
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ExpressionLabelWidget's code action command-building logic adds a conditional check to prevent custom function and transform function actions from being offered when they would hang on record type mappings during variable declaration. ChangesFunction Action Gating for Record Types
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the Data Mapper expression label code-action menu to align option availability with context (reusable mode / multi-view / nested field FQN), addressing wso2/product-integrator#1493.
Changes:
- Gate “Custom Function” and “Transform Function” code actions behind a shared
shouldFnsIncludedcondition. - Rename menu titles to “Map Using Custom Function” / “Map Using Transform Function” for consistency.
Comments suppressed due to low confidence (1)
workspaces/ballerina/data-mapper/src/components/Diagram/Label/ExpressionLabelWidget.tsx:265
shouldFnsIncludeduseslink.getTargetPort().attributes.fieldFQN.includes('.')without guarding forlink/targetPort/fieldFQNbeing undefined (the model types allowlink?, and temporary links may not have a target yet). To avoid a render-time crash, consider reusing the already computedtargetPort(link?.getTargetPort()) and optional-chain thefieldFQNaccess, defaulting the condition tofalsewhen missing.
const shouldFnsIncluded = context.reusable ||
context.views.length !== 1 ||
(link.getTargetPort() as InputOutputPortModel).attributes.fieldFQN.includes('.');
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@workspaces/ballerina/data-mapper/src/components/Diagram/Label/ExpressionLabelWidget.tsx`:
- Around line 263-265: The conditional computing shouldFnsIncluded uses
link.getTargetPort() unsafely; reuse the previously obtained targetPort (from
link?.getTargetPort()) and guard access with optional chaining so it won't
dereference null: compute shouldFnsIncluded by referencing context and
targetPort (e.g., (targetPort as InputOutputPortModel)?.attributes?.fieldFQN) or
checking targetPort exists before calling attributes.fieldFQN, ensuring no
direct call to link.getTargetPort() when link may be undefined.
- Around line 263-265: The conditional computing shouldFnsIncluded can throw
when getTargetPort() or attributes.fieldFQN is undefined; update the expression
that currently casts and calls .includes on (link.getTargetPort() as
InputOutputPortModel).attributes.fieldFQN to use optional chaining and a safe
fallback (e.g., treat missing fieldFQN as an empty string) so the includes call
is always on a string; apply the same null-safe pattern in ExpressionLabelWidget
(shouldFnsIncluded) and the analogous check in MappingOptionsWidget to prevent
runtime crashes.
🪄 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: 93a1100d-532d-4fe4-9d70-a64065120daf
📒 Files selected for processing (1)
workspaces/ballerina/data-mapper/src/components/Diagram/Label/ExpressionLabelWidget.tsx
Purpose
Summary by CodeRabbit