-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove hardcoded path * implement filesystems and sources * rename Hyparam to Hyperparam * details
- Loading branch information
Showing
38 changed files
with
678 additions
and
441 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react' | ||
import { Page } from '../src/index.js' | ||
|
||
import { HttpFileSystem } from '../src/index.ts' | ||
import { Source } from '../src/lib/filesystem.js' | ||
export interface Navigation { | ||
col?: number | ||
row?: number | ||
} | ||
|
||
function getNumberParam(search: URLSearchParams, key: string): number | undefined { | ||
const value = search.get(key) | ||
if (value === null) return | ||
const number = Number(value) | ||
if (isNaN(number)) return | ||
return number | ||
} | ||
|
||
const fileSystems = [ | ||
new HttpFileSystem(), | ||
] | ||
|
||
export default function App() { | ||
const search = new URLSearchParams(location.search) | ||
const url = search.get('url') | ||
const defaultUrl = '/?url=https://huggingface.co/datasets/severo/test-parquet/resolve/main/parquet/csv-train-00000-of-00001.parquet' | ||
if (!url) { | ||
location.href = defaultUrl | ||
return <div>Redirecting...</div> | ||
} | ||
// row, col from url | ||
const row = getNumberParam(search, 'row') | ||
const col = getNumberParam(search, 'col') | ||
|
||
let source: Source | undefined = undefined | ||
for (const fileSystem of fileSystems) { | ||
const fsSource = fileSystem.getSource(url) | ||
if (fsSource){ | ||
source = fsSource | ||
break | ||
} | ||
} | ||
|
||
if (!source) { | ||
return <div>Could not load a data source. You have to pass a valid source in the url, eg: <a href={defaultUrl}>{defaultUrl}</a>.</div> | ||
} | ||
return <Page source={source} navigation={{ row, col }} config={{ | ||
slidePanel: { minWidth: 250, maxWidth: 750 }, | ||
routes: { | ||
getSourceRouteUrl: ({ source }) => `/?url=${source}`, | ||
getCellRouteUrl: ({ source, col, row }) => `/?url=${source}&col=${col}&row=${row}`, | ||
}, | ||
}} /> | ||
} | ||
|
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,9 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.tsx' | ||
|
||
const app = document.getElementById('app') | ||
if (!app) throw new Error('missing app element') | ||
|
||
const root = ReactDOM.createRoot(app) | ||
root.render(React.createElement(App)) |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,37 +1,22 @@ | ||
import { FileKey, UrlKey } from '../lib/key.js' | ||
import { Source } from '../lib/filesystem.js' | ||
import { RoutesConfig } from '../lib/routes.js' | ||
|
||
export type BreadcrumbConfig = RoutesConfig | ||
interface BreadcrumbProps { | ||
parsedKey: UrlKey | FileKey | ||
source: Source, | ||
config?: BreadcrumbConfig | ||
} | ||
|
||
function UrlBreadcrumb({ urlKey }: { urlKey: UrlKey}) { | ||
return <nav className='top-header'> | ||
<div className='path'> | ||
<a href={`/files?key=${urlKey.raw}`}>{urlKey.raw}</a> | ||
</div> | ||
</nav> | ||
} | ||
|
||
function FileBreadcrumb({ fileKey }: { fileKey: FileKey}) { | ||
const path = fileKey.raw.split('/') | ||
|
||
/** | ||
* Breadcrumb navigation | ||
*/ | ||
export default function Breadcrumb({ source, config }: BreadcrumbProps) { | ||
return <nav className='top-header'> | ||
<div className='path'> | ||
<a href='/files'>/</a> | ||
{path.slice(0, -1).map((sub, depth) => | ||
<a href={`/files?key=${path.slice(0, depth + 1).join('/')}/`} key={depth}>{sub}/</a>, | ||
{source.getSourceParts().map((part, depth) => | ||
<a href={config?.routes?.getSourceRouteUrl?.({ source: part.source }) ?? ''} key={depth}>{part.name}</a>, | ||
)} | ||
<a href={`/files?key=${fileKey.raw}`}>{fileKey.fileName}</a> | ||
</div> | ||
</nav> | ||
} | ||
|
||
/** | ||
* Breadcrumb navigation | ||
*/ | ||
export default function Breadcrumb({ parsedKey }: BreadcrumbProps) { | ||
if (parsedKey.kind === 'url') { | ||
return <UrlBreadcrumb urlKey={parsedKey} /> | ||
} | ||
return <FileBreadcrumb fileKey={parsedKey} /> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { useState } from 'react' | ||
import { FileKey, UrlKey } from '../lib/key.js' | ||
import Breadcrumb from './Breadcrumb.js' | ||
import { FileSource } from '../lib/filesystem.js' | ||
import Breadcrumb, { BreadcrumbConfig } from './Breadcrumb.js' | ||
import Layout from './Layout.js' | ||
import Viewer, { ViewerConfig } from './viewers/Viewer.js' | ||
|
||
export type FileConfig = ViewerConfig | ||
export type FileConfig = ViewerConfig & BreadcrumbConfig | ||
|
||
interface FileProps { | ||
parsedKey: UrlKey | FileKey | ||
source: FileSource | ||
config?: FileConfig | ||
} | ||
|
||
/** | ||
* File viewer page | ||
*/ | ||
export default function File({ parsedKey, config }: FileProps) { | ||
export default function File({ source, config }: FileProps) { | ||
const [progress, setProgress] = useState<number>() | ||
const [error, setError] = useState<Error>() | ||
|
||
return <Layout progress={progress} error={error} title={parsedKey.fileName}> | ||
<Breadcrumb parsedKey={parsedKey} /> | ||
<Viewer parsedKey={parsedKey} setProgress={setProgress} setError={setError} config={config} /> | ||
return <Layout progress={progress} error={error} title={source.fileName}> | ||
<Breadcrumb source={source} config={config} /> | ||
<Viewer source={source} setProgress={setProgress} setError={setError} config={config} /> | ||
</Layout> | ||
} |
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
Oops, something went wrong.