Skip to content

feat(context-center): in-app file preview for documents (md, txt, pdf, images) - #33734

Merged
ShaileshParmar11 merged 26 commits into
mainfrom
context-center-file-preview
Sep 23, 2026
Merged

ShaileshParmar11 merged 26 commits into
mainfrom
context-center-file-preview

Conversation

@karanh37

@karanh37 karanh37 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes https://github.com/open-metadata/openmetadata-collate/issues/4554

Description

Adds an in-app file preview for Context Center documents. Each document row gets an eye button (next to Download) that opens a modal rendering the file content. Supported in this PR: Markdown, plain text / CSV, PDF, and raster images. The renderer is a generic, reusable components/common/FilePreviewer/ that dispatches on the backend FileType enum, so new formats (docx, xlsx) plug in later without a parallel type map.

How it works

  • preview-btn on each row → opens FilePreviewModal.
  • FilePreviewModal fetches bytes from the same-origin authenticated downloadDriveFile(id), applies a 25 MB size guard and a processing-status guard (Failed/Unsupported → download-only), aborts in-flight fetches on close, and toasts on error.
  • FilePreviewer selects a renderer from a registry keyed on the backend FileType (generated/entity/data/contextFile.ts); extension/MIME are used only to (a) exclude SVG inside Image and (b) pick Markdown vs plain text inside Text, plus a fallback that mirrors the backend ContextFileUploadSupport.detectFileType classifier. Markdown and PDF renderers are lazy-loaded.

Security (file preview of untrusted uploads)

  • Markdown via react-markdown default sanitization — no rehype-raw, no dangerouslySetInnerHTML; javascript:/data: links neutralized.
  • PDF via pdfjs-dist with isEvalSupported: false, scripting/annotation JS off, canvas-only render (closes the CVE-2024-4367 class). PDF page render is bounded (max 50 pages) so a small-byte many-page PDF can't OOM the tab.
  • SVG is never rendered inline (can carry script) on any path — routed to download-only.
  • Bytes only ever come from the same-origin download endpoint; no file bytes are injected into the DOM as HTML; object URLs are revoked on unmount.

Type of change

  • New feature (non-breaking change which adds functionality)

Tests

  • Unit (Jest): renderer registry (incl. SVG-exclusion + backend-mirror fallback), Markdown sanitization against real react-markdown (script + javascript: link stripped), image/unsupported renderers, PDF renderer asserts isEvalSupported: false and the page cap, FilePreviewer object-URL revoke-on-unmount, FilePreviewModal size/status guards + single-fetch-across-rerender + fetch-error toast. Mocks only the downloadDriveFile boundary.
  • E2E (Playwright): ContextCenterFilePreview.spec.ts covers md/txt/pdf/image rendering in the modal, the unsupported download fallback, and modal close/focus-restore. Live run against the Docker stack is deferred to CI.

Notes for reviewers

  • New dependency: [email protected].
  • New i18n keys added and yarn i18n-synced; non-English locales carry English placeholders pending translation (per repo i18n norm; CI checks sync only).
  • The branch is based on an older main; a rebase may be needed before merge.

🤖 Generated with Claude Code

RetriggerConfidence Score: 5/5

The implementation appears safe to merge, with the non-blocking caveat that its end-to-end preview suite is not currently executed by CI.

Findings

  1. P2 Preview Tests Never Run ▶
  2. P2 Icon bypasses design system ▶
  3. P2 Locale placeholders remain English ▶
Summary

Adds reusable in-app previews for Context Center documents, including text/Markdown, PDF, and image rendering, guarded downloads, cancellation, modal integration, and design-system icon support.

  • Fetches preview blobs through the authenticated drive download endpoint with size and cancellation handling.
  • Dispatches content to lazy-loaded or direct renderers according to backend file metadata.
  • Adds unit coverage and an end-to-end preview suite, though the latter is currently outside configured CI execution.
  • Previously reported renderer, cancellation, size-limit, download-action, icon-layer, naming, and translation concerns are fixed or resolved.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Document row preview button] --> B[FilePreviewModal]
  B --> C[useFilePreviewContent]
  C --> D[Authenticated drive download]
  D --> E{Blob within 25 MB?}
  E -- No --> F[Download fallback]
  E -- Yes --> G[FilePreviewer]
  G --> H{Resolved renderer}
  H --> I[Markdown]
  H --> J[Plain text]
  H --> K[PDF canvas]
  H --> L[Image]
Loading

Reviews (7) · Last reviewed commit: "Merge remote-tracking branch 'origin/con..."

karanh37 and others added 12 commits September 21, 2026 20:06
Implement pure utility function to resolve renderer by file extension or MIME type.
Supports markdown, text, PDF, and raster images; SVG treated as unsupported per security requirement.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
Test the markdown renderer against real react-markdown (default
sanitization only, no rehype-raw/dangerouslySetInnerHTML) to assert
<script> content is neutralized and javascript: links are dropped.

Extends the Jest transformIgnorePatterns exception list to cover the
ESM-only unified/remark/rehype dependency chain react-markdown pulls
in, and polyfills Blob#text on jsdom's Blob (missing in jsdom 20) via
FileReader so renderers that read Blob content can be tested.
Copilot AI lite review requested due to automatic review settings September 21, 2026 16:23
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs UI UI specific issues labels Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Playwright impact map auto-refreshed

This PR touched specs or UI source that changed the source→spec routing map. I regenerated .github/playwright/impact-map.generated.json and pushed the diff to this branch.

- source entries: 796 → 796
- 0 added, 0 removed, 6 changed spec-list

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/playwright/e2e/fixtures/pages.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/ContextCenterUtil.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/common.ts
  openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/DocumentsView.component.tsx
  openmetadata-ui/src/main/resources/ui/src/generated/entity/data/table.ts
  openmetadata-ui/src/main/resources/ui/src/generated/entity/data/topic.ts

What is this file? It is the auto-generated half of Playwright's PR planner. It routes "if source X changes, run specs Y" by walking spec imports and cross-referencing getByTestId strings. Hand-authored routing in impact-map.json always wins on conflict.

What if I want to regenerate locally instead? Run this before pushing your next change to skip the bot commit:

python3 .github/scripts/generate_playwright_impact_map.py
git add .github/playwright/impact-map.generated.json
git commit --amend --no-edit  # or a separate commit

Copilot AI review requested due to automatic review settings September 21, 2026 16:23

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Typography,
} from '@openmetadata/ui-core-components';
import { Check, ChevronRight } from '@untitledui/icons';
import { Check, ChevronRight, Eye } from '@untitledui/icons';

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.

P2 Icon bypasses design system

The new Eye icon is imported directly from @untitledui/icons. The repository directive requires application icons and assets to go through the design-system layer using @openmetadata/ui-core-components/icons; this requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +3961 to +3964
"file-preview-pdf-page-limit": "Showing the first {{count}} pages. Download the file to view all pages.",
"file-size-exceeded": "حجم الملف يتجاوز الحد الأقصى المسموح به للـ {{size}}",
"file-size-limit-exceeded": "تتجاوز بعض الملفات الحد الأقصى للحجم 5 ميجابايت ولم يتم تحميلها.",
"file-too-large-to-preview": "This file is too large to preview. Download it to view.",

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.

P2 Locale placeholders remain English

These new Arabic locale entries are copied English placeholders rather than translations. The same three entries remain untranslated across the other changed non-English bundles, including de-de.json and es-es.json. The repository directive requires replacing synchronized placeholders with real translations in every non-English locale before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 72%
72.51% (103917/143306) 57.62% (63282/109817) 58.68% (20711/35294)

…caps, pdf error handling, download fallback, types rename
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 175151958e2937157d62c47a98e4c5f9ead8dbac in Playwright run 35745600455, attempt 1.

✅ 4551 passed · ❌ 0 failed · 🟡 7 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 59m 21s

⏱️ Max setup 4m 36s · max shard execution 21m 44s · max shard-job elapsed before upload 25m 16s · reporting 20s

🌐 224.54 requests/attempt · 2.23 app boots/UI scenario · 29.91% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 29.91% (convergence target: at most 15%).
  • Browser traffic was 224.54 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.23 per UI scenario (10809 boots / 4856 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 130 0 0 0 0 0
🟡 Shard chromium-01 147 0 1 0 0 0
✅ Shard chromium-02 163 0 0 0 0 0
✅ Shard chromium-03 194 0 0 0 0 0
✅ Shard chromium-04 185 0 0 0 0 0
✅ Shard chromium-05 173 0 0 0 0 0
🟡 Shard chromium-06 183 0 1 0 0 0
✅ Shard chromium-07 158 0 0 0 0 0
✅ Shard chromium-08 170 0 0 1 0 0
✅ Shard chromium-09 177 0 0 0 0 0
✅ Shard chromium-10 186 0 0 0 0 0
🟡 Shard chromium-11 155 0 1 0 0 0
✅ Shard chromium-12 177 0 0 0 0 0
✅ Shard chromium-13 182 0 0 0 0 0
✅ Shard chromium-14 171 0 0 0 0 0
🟡 Shard chromium-15 171 0 1 0 0 0
🟡 Shard chromium-16 196 0 1 0 0 0
✅ Shard chromium-17 179 0 0 0 0 0
✅ Shard chromium-18 166 0 0 0 0 0
🟡 Shard chromium-19 142 0 1 0 0 0
✅ Shard chromium-20 188 0 0 0 0 0
✅ Shard chromium-21 128 0 0 0 0 0
✅ Shard chromium-22 169 0 0 0 0 0
🟡 Shard chromium-23 215 0 1 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 51 0 0 0 0 0
✅ Shard import-export-02 99 0 0 0 0 0
✅ Shard ingestion-01 45 0 0 0 0 0
✅ Shard ingestion-02 55 0 0 0 0 0
✅ Shard reindex-01 40 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 7 flaky test(s) (passed on retry)
  • Pages/EntityDataConsumer.spec.ts › UpVote & DownVote entity (shard chromium-01, 1 retry)
  • Pages/EntityDataSteward.spec.ts › Glossary Term Add, Update and Remove (shard chromium-06, 1 retry)
  • Features/ActivityFeed.spec.ts › emoji reactions can be added and toggled off on a feed card (shard chromium-11, 1 retry)
  • Features/OntologyStudioIntegration.spec.ts › data mode renders tagged assets from the ontology data response (shard chromium-15, 1 retry)
  • Features/AccessControlSettings.spec.ts › should show all 4 landing cards and navigate to each panel (shard chromium-16, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-19, 1 retry)
  • Features/ContextCenterDocument.spec.ts › clicking document row opens preview panel with name, status, size, folder, updatedBy, updatedAt and copy button copies correct link (shard chromium-23, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

…pe-gated preview button

- add a reusable useFilePreviewContent hook (fetch + size guard) shared by the
  modal and a new detail-panel miniature preview that expands to the full modal
- support svg via the image renderer (<img> src is script-inert)
- gate the row preview button on renderer-supported types only
- preview no longer blocks on processingStatus (extraction status is
  independent of whether the uploaded bytes are viewable)
- dialog title shows the (truncated) filename
- FilePreviewer creates/revokes its object URL in one effect (StrictMode-safe)
- compact renderer mode (PDF first page, image fit-to-box)

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

… panel miniature

- render the row preview button as an invisible placeholder for
  renderer-unsupported files so the status badge and action icons stay
  column-aligned across rows
- remove the detail-panel miniature preview (preview stays on the row eye
  button + full modal); revert DocumentPreviewPanel to metadata-only

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…d in e2e

- reorder DocumentsView imports to satisfy organize-imports (ui-checkstyle src lint)
- route the /download endpoint in the preview e2e: the CI Playwright stack has
  no object storage configured (ASSET_UPLOADER unset), so the real endpoint
  404s (resolveAsset -> null). Serving the fixture bytes from the test keeps the
  fetch -> renderer -> DOM pipeline exercised on real bytes, storage-independent,
  and drops the now-unneeded processing-wait

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…real download

The per-PR fast lane has no object storage, so the preview /download 404s
there. The nightly/AUT deployment has real storage, so run the preview suite
there against the real upload/download/render pipeline (no route mock).

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Playwright impact map auto-refreshed

This PR touched specs or UI source that changed the source→spec routing map. I regenerated .github/playwright/impact-map.generated.json and pushed the diff to this branch.

- source entries: 805 → 805
- 0 added, 0 removed, 6 changed spec-list

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/playwright/e2e/fixtures/pages.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/ContextCenterUtil.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/common.ts
  openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/DocumentsView.component.tsx
  openmetadata-ui/src/main/resources/ui/src/generated/entity/data/table.ts
  openmetadata-ui/src/main/resources/ui/src/generated/entity/data/topic.ts

What is this file? It is the auto-generated half of Playwright's PR planner. It routes "if source X changes, run specs Y" by walking spec imports and cross-referencing getByTestId strings. Hand-authored routing in impact-map.json always wins on conflict.

What if I want to regenerate locally instead? Run this before pushing your next change to skip the bot commit:

python3 .github/scripts/generate_playwright_impact_map.py
git add .github/playwright/impact-map.generated.json
git commit --amend --no-edit  # or a separate commit

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Add an Eye SVG to ui-core-components and regenerate the icon set, then import
it from @openmetadata/ui-core-components/icons in DocumentsView instead of
@untitledui/icons — icons must go through the design-system layer per CLAUDE.md.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 4 closed / 4 findings

🟡 Medium risk · Adds Context Center previews with authenticated downloads and untrusted-file rendering.

Adds in-app file preview for Context Center documents (Markdown, text, PDF, images) with authenticated download, size guards, safe rendering, and comprehensive test coverage. Resolved abort signal handling, text preview buffering, modal stability, and eager-download issues.

✅ 4 closed
✅ Performance: Abort signal never passed to download request

📄 openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/FilePreviewModal/FilePreviewModal.tsx:58-72
In FilePreviewModal.tsx the effect creates an AbortController and calls controller.abort() on cleanup, but the signal is never forwarded to downloadDriveFile(file.id) (which does not accept a config/signal argument). So closing or switching files does not actually cancel the in-flight network download — the code only ignores the result via controller.signal.aborted. For files near the 25 MB cap this wastes bandwidth and keeps the request alive after close, contrary to the documented "aborts in-flight fetches on close" behavior. Consider threading an AbortSignal into downloadDriveFile so the request is genuinely cancelled.

✅ Performance: Text preview dumps up to 25MB into a single <pre>

📄 openmetadata-ui/src/main/resources/ui/src/components/common/FilePreviewer/TextRenderer.tsx:17-31 📄 openmetadata-ui/src/main/resources/ui/src/components/common/FilePreviewer/MarkdownRenderer.tsx:19-33 📄 openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/FilePreviewModal/FilePreviewModal.constants.ts:14
TextRenderer (and MarkdownRenderer) read the entire Blob via content.text() and render it into one <pre>/ReactMarkdown node. The only size guard is MAX_PREVIEW_SIZE = 25 * 1024 * 1024 in FilePreviewModal, which permits a 25 MB text/CSV file. Laying out tens of millions of characters with whitespace-pre-wrap/break-words (or parsing 25 MB of markdown) can freeze the browser tab. The PDF path is bounded to 50 pages but the text path has no comparable cap. Consider truncating text preview to a reasonable character/line limit (with a "download to view all" notice like the PDF page-limit notice).

✅ Bug: Unstable onClose forces preview modal to re-download

📄 openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/DocumentPreviewPanel.component.tsx:248 📄 openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/FilePreviewModal/FilePreviewModal.tsx:30-33 📄 openmetadata-ui/src/main/resources/ui/src/hooks/useFilePreviewContent.ts:108
useFilePreviewContent lists onError in its effect dependency array ([enabled, file, isMetadataTooLarge, onError]), and the hook's design explicitly relies on a stable onError/onClose (the modal test asserts "does not refetch when the parent re-renders with a stable onClose"). But DocumentPreviewPanel passes an inline arrow onClose={() => setIsPreviewModalOpen(false)} to FilePreviewModal, which forwards it as onError. That reference changes on every render of the panel, so while the modal is open any re-render of the panel (or its parent) re-runs the fetch effect: the cleanup aborts the in-flight download and a fresh downloadDriveFile is issued, dropping the modal back to the Loader state and re-fetching up to 25 MB each time. Wrap the close handler in useCallback so the reference is stable.

✅ Performance: Detail panel eagerly downloads full file for thumbnail

📄 openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/DocumentPreviewPanel.component.tsx:77-79 📄 openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/DocumentPreviewPanel.component.tsx:245-249 📄 openmetadata-ui/src/main/resources/ui/src/components/ContextCenter/DocumentsView/FilePreviewModal/FilePreviewModal.tsx:30-33
DocumentPreviewPanel calls useFilePreviewContent(file, { enabled: isPreviewSupported }) unconditionally, so as soon as any supported document is selected the full bytes (up to the 25 MB cap) are downloaded just to render the small miniature thumbnail — even a large PDF is fetched in full and parsed by pdf.js only to show its first page. When the user then opens the modal, FilePreviewModal mounts its own useFilePreviewContent for the same file.id, so the identical payload is downloaded a second time concurrently rather than being shared. Consider lazily fetching the miniature (e.g. only on intersection/hover) and/or sharing the resolved blob between the panel and the modal to avoid the duplicate transfer.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-09-22T16:29:49Z)

The entry left the queue before it was built, so no checks ran against it.

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-09-23T01:58:29Z)

Blocked the queue: playwright-summary

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants