Repository navigation
fix: Resolve error when checking pipeline parsing result - #15778
Conversation
📝 WalkthroughWalkthroughThis PR improves file type detection for document preview rendering. Image type validation moves from hardcoded extension lists to a centralized constant, and file extension extraction is made null-safe using optional chaining with a fallback to the cached document extension. ChangesDocument Preview File Type Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
web/src/pages/dataflow-result/index.tsx (1)
69-74:⚠️ Potential issue | 🟠 Major | ⚡ Quick winIncomplete fix - same null reference issue exists in non-agent flow.
Lines 71 and 73 use
documentInfo?.name.split('.')which will throw an error ifdocumentInfo.nameis undefined or null (same issue that was fixed at line 66 for the agent flow).For consistency and completeness, these should also use optional chaining:
🔒 Proposed fix to add optional chaining
case 'doc': - return documentInfo?.name.split('.').pop() || 'doc'; + return documentInfo?.name?.split('.').pop() || 'doc'; case 'visual': - return documentInfo?.name.split('.').pop() || 'visual'; + return documentInfo?.name?.split('.').pop() || 'visual';🤖 Prompt for 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. In `@web/src/pages/dataflow-result/index.tsx` around lines 69 - 74, The switch in dataflow-result's type handling (switch on documentInfo?.type with cases 'doc' and 'visual') still calls documentInfo?.name.split('.') which can throw if name is null/undefined; update those expressions to safely access name (e.g., use optional chaining on name before split and a fallback) so both the 'doc' and 'visual' branches mirror the agent-flow fix (replace documentInfo?.name.split('.') with documentInfo?.name?.split('.')?.pop() || 'doc' / 'visual' as appropriate).
🧹 Nitpick comments (1)
web/src/components/document-preview/index.tsx (1)
48-48: 💤 Low valueGood refactor - centralizes image type detection.
This change follows the DRY principle by using the centralized
Imagesconstant instead of a hardcoded array.Optional: The entire file could be modernized to use
.includes()instead of.indexOf() > -1(lines 38, 43, 48, 53-65, 70, 75, 80, 85), but this change is consistent with the existing pattern and improves maintainability.🤖 Prompt for 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. In `@web/src/components/document-preview/index.tsx` at line 48, Replace the repeated pattern of using Images.indexOf(fileType) > -1 with the clearer, modern Array.prototype.includes usage across this component: locate the checks that compare Images to fileType (e.g., the JSX conditional at Images.indexOf(fileType) > -1 and the other indexOf occurrences around lines where fileType and Images are used) and change them to Images.includes(fileType) so the conditional reads more idiomatically and avoids the > -1 pattern; ensure all occurrences in document-preview/index.tsx that reference Images.indexOf(...) are updated to Images.includes(...).
🤖 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.
Outside diff comments:
In `@web/src/pages/dataflow-result/index.tsx`:
- Around line 69-74: The switch in dataflow-result's type handling (switch on
documentInfo?.type with cases 'doc' and 'visual') still calls
documentInfo?.name.split('.') which can throw if name is null/undefined; update
those expressions to safely access name (e.g., use optional chaining on name
before split and a fallback) so both the 'doc' and 'visual' branches mirror the
agent-flow fix (replace documentInfo?.name.split('.') with
documentInfo?.name?.split('.')?.pop() || 'doc' / 'visual' as appropriate).
---
Nitpick comments:
In `@web/src/components/document-preview/index.tsx`:
- Line 48: Replace the repeated pattern of using Images.indexOf(fileType) > -1
with the clearer, modern Array.prototype.includes usage across this component:
locate the checks that compare Images to fileType (e.g., the JSX conditional at
Images.indexOf(fileType) > -1 and the other indexOf occurrences around lines
where fileType and Images are used) and change them to Images.includes(fileType)
so the conditional reads more idiomatically and avoids the > -1 pattern; ensure
all occurrences in document-preview/index.tsx that reference Images.indexOf(...)
are updated to Images.includes(...).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a858960b-5010-4622-b4ac-9592849864a1
📒 Files selected for processing (2)
web/src/components/document-preview/index.tsxweb/src/pages/dataflow-result/index.tsx
What problem does this PR solve?
fix: Resolve error when checking pipeline parsing result
Type of change