feat: file viewer#87
Conversation
✅ Deploy Preview for kleros-v2-ui-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a FileViewer component with URL safety checks, PDF.js worker setup and override, a Markdown renderer, runtime dependency additions and version bump, expanded Storybook stories covering blocked/unsupported inputs, and re-exports FileViewer and configurePdfWorker from the library barrel. ChangesFileViewer feature + runtime deps
sequenceDiagram
participant Storybook as rgba(135,206,235,0.5)
participant FileViewer as rgba(144,238,144,0.5)
participant DocViewer as rgba(255,182,193,0.5)
participant GlobalPdfJs as rgba(255,228,181,0.5)
Storybook->>FileViewer: render(url, fileName?, config?)
FileViewer->>FileViewer: isSafeUrl(url)
alt safe
FileViewer->>GlobalPdfJs: ensure/set workerSrc (module init or configurePdfWorker)
FileViewer->>DocViewer: provide docs, pluginRenderers (incl. Markdown)
DocViewer-->>FileViewer: rendered UI
else blocked/unsupported
FileViewer-->>Storybook: render UnsupportedUrlMessage / NoRendererFallback
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6ef2e95a-52e0-4a1a-a4af-09ac37cc1090
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (7)
.gitignorepackage.jsonsrc/lib/file-viewer/index.tsxsrc/lib/file-viewer/markdown-viewer.tsxsrc/lib/file-viewer/styles.csssrc/lib/index.tssrc/stories/file-viewer.stories.tsx
tractorss
left a comment
There was a problem hiding this comment.
looking good, left a couple of comments 🙌
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/lib/file-viewer/markdown-viewer.tsx`:
- Around line 21-27: The data: URI handling in markdown-viewer.tsx currently
always attempts base64 decode; change the logic in the block handling
fileData.startsWith("data:") to inspect the metadata portion (the part before
the first comma) for the ";base64" parameter and only call
decodeBase64Utf8(payload) when that parameter is present; otherwise call
decodeURIComponent(payload). Locate the parsing near the
fileData.startsWith("data:") check and update the branch that assigns to text so
it checks the metadata string (from start of the data: header up to the comma)
for ";base64" before choosing between decodeBase64Utf8 and decodeURIComponent.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d3139612-82a4-41db-916a-06e69c59d261
📒 Files selected for processing (4)
.gitignoresrc/lib/file-viewer/index.tsxsrc/lib/file-viewer/markdown-viewer.tsxsrc/stories/file-viewer.stories.tsx
✅ Files skipped from review due to trivial changes (2)
- .gitignore
- src/stories/file-viewer.stories.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- src/lib/file-viewer/index.tsx
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/lib/file-viewer/markdown-viewer.tsx`:
- Around line 32-36: The current catch block sets text = "" on decode failures
which hides all content; instead, on error keep a lossy-but-visible fallback by
assigning the raw payload (or the raw base64 string) to text so the viewer can
display or allow download; update the catch to set text = payload (using the
existing variables isBase64, payload and the decode helpers
decodeBase64Utf8/decodeURIComponent) and optionally annotate or attempt a
best-effort fallback display rather than clearing text.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7e766754-895b-408e-b861-b08847679393
📒 Files selected for processing (1)
src/lib/file-viewer/markdown-viewer.tsx
tractorss
left a comment
There was a problem hiding this comment.
left few more comments
|



after confirmed, this package needs NPM deployment to version 3.8.0
then 5 frontends were updated to use this newer version: scout, gtcr, kleros-v2, escrow-v2, curate-v2
added a dark mode style too, especially useful for pngs background so it looks better depending on the theme of the app.
security, what was done:
PR-Codex overview
This PR primarily introduces a new
FileViewercomponent that supports rendering various file types, including SVG and Markdown, while enhancing security against potential script execution vulnerabilities.Detailed summary
FileViewercomponent insrc/lib/file-viewer.SvgDocRendererfor SVG files.MarkdownDocRendererfor Markdown files.package.jsonto version3.8.0and added new dependencies.--klerosUIComponentsImageCheckerColorintheme.css.FileViewer.Summary by CodeRabbit
New Features
Documentation / Examples
Chores