-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI] Fix large file and png preview issues in the object viewer (#4569)
* Fix large file and png preview issues * Add renderers for PNG and JPEG files, so they are viewable in the UI directly
- Loading branch information
1 parent
f47abed
commit 20f2c15
Showing
7 changed files
with
346 additions
and
184 deletions.
There are no files selected for viewing
This file contains 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 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
30 changes: 0 additions & 30 deletions
30
webui/src/pages/repositories/repository/fileRenderers/index.jsx
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
webui/src/pages/repositories/repository/fileRenderers/index.tsx
This file contains 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,73 @@ | ||
import React, { FC, useEffect } from "react"; | ||
import remarkGfm from 'remark-gfm' | ||
import remarkHtml from 'remark-html' | ||
import ReactMarkdown from 'react-markdown'; | ||
import { IpynbRenderer as NbRenderer } from "react-ipynb-renderer"; | ||
|
||
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & { | ||
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> | ||
}[Keys]; | ||
|
||
interface RendererComponentBase { | ||
content: string; | ||
contentBlob: Blob; | ||
} | ||
|
||
export type RendererComponent = RequireAtLeastOne<RendererComponentBase, 'content' | 'contentBlob'>; | ||
|
||
export const MarkdownRenderer: FC<RendererComponent> = ({ content }) => { | ||
if (content) { | ||
return ( | ||
<ReactMarkdown remarkPlugins={[remarkGfm, remarkHtml]} linkTarget={"_blank"}> | ||
{content} | ||
</ReactMarkdown> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export const IpynbRenderer: FC<RendererComponent> = ({ content }) => { | ||
if (content) { | ||
return ( | ||
<NbRenderer | ||
ipynb={JSON.parse(content)} | ||
syntaxTheme="ghcolors" | ||
language="python" | ||
bgTransparent={true} | ||
/> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export const ImageRenderer: FC<RendererComponent> = ({ contentBlob }) => { | ||
let blobUrl: string; | ||
useEffect(() => () => { | ||
if (blobUrl) { | ||
URL.revokeObjectURL(blobUrl); | ||
} | ||
}, []); | ||
|
||
if (contentBlob) { | ||
blobUrl = URL.createObjectURL(contentBlob) | ||
return ( | ||
<img src={blobUrl} /> | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
export const supportedFileExtensionRenderers: Record<string, FC<RendererComponent>> = { | ||
md: MarkdownRenderer, | ||
ipynb: IpynbRenderer, | ||
png: ImageRenderer, | ||
jpg: ImageRenderer, | ||
jpeg: ImageRenderer, | ||
}; | ||
|
||
export const supportedContentTypeRenderers: Record<string, FC<RendererComponent>> = { | ||
"application/x-ipynb+json": IpynbRenderer, | ||
"text/markdown":MarkdownRenderer, | ||
"image/png": ImageRenderer, | ||
"image/jpeg": ImageRenderer, | ||
}; |
152 changes: 0 additions & 152 deletions
152
webui/src/pages/repositories/repository/objectViewer.jsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.