Skip to content

Commit 2c17bb1

Browse files
authored
Remove hardcoded paths (#93)
* remove hardcoded path * implement filesystems and sources * rename Hyparam to Hyperparam * details
1 parent 1088c5b commit 2c17bb1

38 files changed

+678
-441
lines changed

.github/workflows/deploy_pages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
- name: Move the build outputs to a folder
3030
run: |
3131
mkdir -p build_outputs_folder/apps
32-
echo "<h1 id="hyparam">Hyparam</h1>" > build_outputs_folder/index.html
32+
echo "<h1 id="hyparam">Hyperparam</h1>" > build_outputs_folder/index.html
3333
echo "<ul>" >> build_outputs_folder/index.html
3434
echo "<li><a href="./apps/hyparquet-demo">hyparquet demo</a></li>" >> build_outputs_folder/index.html
3535
echo "<li><a href="./apps/hightable-demo">hightable demo</a></li>" >> build_outputs_folder/index.html
3636
echo "</ul>" >> build_outputs_folder/index.html
37-
echo "<h1 id="hyparam">Hyparam</h1>" > build_outputs_folder/apps/index.html
37+
echo "<h1 id="hyparam">Hyperparam</h1>" > build_outputs_folder/apps/index.html
3838
echo "<ul>" >> build_outputs_folder/apps/index.html
3939
echo "<li><a href="./hyparquet-demo">hyparquet demo</a></li>" >> build_outputs_folder/apps/index.html
4040
echo "<li><a href="./hightable-demo">hightable demo</a></li>" >> build_outputs_folder/apps/index.html

packages/components/demo/App.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from 'react'
2+
import { Page } from '../src/index.js'
3+
4+
import { HttpFileSystem } from '../src/index.ts'
5+
import { Source } from '../src/lib/filesystem.js'
6+
export interface Navigation {
7+
col?: number
8+
row?: number
9+
}
10+
11+
function getNumberParam(search: URLSearchParams, key: string): number | undefined {
12+
const value = search.get(key)
13+
if (value === null) return
14+
const number = Number(value)
15+
if (isNaN(number)) return
16+
return number
17+
}
18+
19+
const fileSystems = [
20+
new HttpFileSystem(),
21+
]
22+
23+
export default function App() {
24+
const search = new URLSearchParams(location.search)
25+
const url = search.get('url')
26+
const defaultUrl = '/?url=https://huggingface.co/datasets/severo/test-parquet/resolve/main/parquet/csv-train-00000-of-00001.parquet'
27+
if (!url) {
28+
location.href = defaultUrl
29+
return <div>Redirecting...</div>
30+
}
31+
// row, col from url
32+
const row = getNumberParam(search, 'row')
33+
const col = getNumberParam(search, 'col')
34+
35+
let source: Source | undefined = undefined
36+
for (const fileSystem of fileSystems) {
37+
const fsSource = fileSystem.getSource(url)
38+
if (fsSource){
39+
source = fsSource
40+
break
41+
}
42+
}
43+
44+
if (!source) {
45+
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>
46+
}
47+
return <Page source={source} navigation={{ row, col }} config={{
48+
slidePanel: { minWidth: 250, maxWidth: 750 },
49+
routes: {
50+
getSourceRouteUrl: ({ source }) => `/?url=${source}`,
51+
getCellRouteUrl: ({ source, col, row }) => `/?url=${source}&col=${col}&row=${row}`,
52+
},
53+
}} />
54+
}
55+

packages/components/demo/demo.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom/client'
3+
import App from './App.tsx'
4+
5+
const app = document.getElementById('app')
6+
if (!app) throw new Error('missing app element')
7+
8+
const root = ReactDOM.createRoot(app)
9+
root.render(React.createElement(App))

packages/components/demo/demo.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.
1.04 KB
Loading

packages/components/demo/file.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

packages/components/demo/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
<link rel="stylesheet" href="./styles.css">
77
<link rel="stylesheet" href="./HighTable.css">
88
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Mulish:wght@400;600&display=swap"/>
9-
<meta name="description" content="demo for the Hyparam components" />
9+
<link href="favicon.png" rel="icon" />
10+
<meta name="description" content="demo for the Hyperparam components" />
1011
<meta name="theme-color" content="#6b00ff">
1112
<meta name="viewport" content="width=device-width, initial-scale=1" />
1213
</head>
1314
<body>
1415
<div id="app"></div>
15-
<script type="module" src="./demo.tsx"></script>
16+
<script type="module" src="./demo.ts"></script>
1617
</body>
1718
</html>

packages/components/demo/logo.svg

Lines changed: 8 additions & 0 deletions
Loading

packages/components/demo/styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ main {
226226

227227
/* file icons */
228228
.file {
229-
background: url(/public/file.svg);
229+
background: url(file.svg);
230230
background-position: left center;
231231
background-repeat: no-repeat;
232232
background-size: 12px;
233233
padding-left: 22px;
234234
}
235235
.folder {
236-
background-image: url(/public/folder.svg);
236+
background-image: url(folder.svg);
237237
}
238238

239239
/* viewer */

0 commit comments

Comments
 (0)