-
Notifications
You must be signed in to change notification settings - Fork 123
Add In-App PDF Preview for KA Citations #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eLysgaard
wants to merge
13
commits into
databricks:main
Choose a base branch
from
eLysgaard:pdf-preview-annotations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
11931bc
Add in-app PDF preview for Unity Catalog citations
eLysgaard 3530cff
Switch to react-pdf and add text highlighting
eLysgaard 76b6c07
undo port changes
eLysgaard a325db3
Add comprehensive integration tests for files route
eLysgaard edcf3bf
Add cited text display to PDF preview
eLysgaard bfa9c10
Bundle PDF.js worker and remove unused highlight package
eLysgaard 99897b4
Remove highlighting code from PDFViewer
eLysgaard 29b273d
Add pdfjs-dist as explicit dependency
eLysgaard 47222a2
Fix close button overlapping with download button
eLysgaard b62b2ec
Add page number to cited text display
eLysgaard fd3ef76
Merge remote-tracking branch 'upstream/main' into pdf-preview-annotat…
eLysgaard 46383ba
Address PR feedback for PDF preview feature
eLysgaard 51aa7b2
Merge remote-tracking branch 'upstream/main' into pdf-preview-annotat…
eLysgaard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
e2e-chatbot-app-next/client/src/components/pdf-preview/PDFCitationLink.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { useState, useCallback, type ReactNode } from 'react'; | ||
|
|
||
| import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; | ||
| import { PDFPreviewSheet } from './PDFPreviewSheet'; | ||
| import type { UCPDFMetadata } from '@/lib/pdf-utils'; | ||
|
|
||
| export interface PDFCitationLinkProps { | ||
| children: ReactNode; | ||
| pdfMetadata: UCPDFMetadata; | ||
| } | ||
|
|
||
| export function PDFCitationLink({ children, pdfMetadata }: PDFCitationLinkProps) { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
|
|
||
| const handleClick = useCallback((e: React.MouseEvent) => { | ||
| e.preventDefault(); | ||
| setIsOpen(true); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <> | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <button | ||
| type="button" | ||
| onClick={handleClick} | ||
| className="cursor-pointer rounded-md bg-muted-foreground px-2 py-0 font-medium text-zinc-200 underline" | ||
| > | ||
| {children} | ||
| </button> | ||
| </TooltipTrigger> | ||
| <TooltipContent | ||
| style={{ maxWidth: '350px', padding: '8px', wordWrap: 'break-word' }} | ||
| > | ||
| <div className="space-y-1"> | ||
| <div className="font-medium">{pdfMetadata.filename}</div> | ||
| {pdfMetadata.page && ( | ||
| <div className="text-muted-foreground text-xs"> | ||
| Page {pdfMetadata.page} | ||
| </div> | ||
| )} | ||
| {pdfMetadata.textFragment && ( | ||
| <div className='border-muted-foreground/50 border-l-2 pl-2 text-xs italic'> | ||
| "{pdfMetadata.textFragment}" | ||
| </div> | ||
| )} | ||
| </div> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
|
|
||
| <PDFPreviewSheet | ||
| open={isOpen} | ||
| onOpenChange={setIsOpen} | ||
| filename={pdfMetadata.filename} | ||
| volumePath={pdfMetadata.volumePath} | ||
| filePath={pdfMetadata.filePath} | ||
| initialPage={pdfMetadata.page} | ||
| highlightText={pdfMetadata.textFragment} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Howcome we are not using the button component that we use elsewhere?
import { Button } from '@/components/ui/button';