Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/components/demo/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react'
import { Page } from '../src/index.js'

import { HttpFileSystem } from '../src/index.ts'
import { Source } from '../src/lib/filesystem.js'
import { Source, createHttpFileSystem, getSource } from '../src/index.ts'
export interface Navigation {
col?: number
row?: number
Expand All @@ -17,7 +16,7 @@ function getNumberParam(search: URLSearchParams, key: string): number | undefine
}

const fileSystems = [
new HttpFileSystem(),
createHttpFileSystem(),
]

export default function App() {
Expand All @@ -34,7 +33,7 @@ export default function App() {

let source: Source | undefined = undefined
for (const fileSystem of fileSystems) {
const fsSource = fileSystem.getSource(url)
const fsSource = getSource(url, fileSystem)
if (fsSource){
source = fsSource
break
Expand All @@ -47,8 +46,8 @@ export default function App() {
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}`,
getSourceRouteUrl: ({ sourceId }) => `/?url=${sourceId}`,
getCellRouteUrl: ({ sourceId, col, row }) => `/?url=${sourceId}&col=${col}&row=${row}`,
},
}} />
}
Expand Down
7 changes: 3 additions & 4 deletions packages/components/src/components/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Source } from '../lib/filesystem.js'
import { RoutesConfig } from '../lib/routes.js'
import { Source } from '../lib/source.js'

export type BreadcrumbConfig = RoutesConfig
interface BreadcrumbProps {
Expand All @@ -13,10 +13,9 @@ interface BreadcrumbProps {
export default function Breadcrumb({ source, config }: BreadcrumbProps) {
return <nav className='top-header'>
<div className='path'>
{source.getSourceParts().map((part, depth) =>
<a href={config?.routes?.getSourceRouteUrl?.({ source: part.source }) ?? ''} key={depth}>{part.name}</a>,
{source.sourceParts.map((part, depth) =>
<a href={config?.routes?.getSourceRouteUrl?.({ sourceId: part.sourceId }) ?? ''} key={depth}>{part.text}</a>,
)}
</div>
</nav>

}
2 changes: 1 addition & 1 deletion packages/components/src/components/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { asyncRows } from 'hightable'
import { asyncBufferFromUrl, parquetMetadataAsync } from 'hyparquet'
import { useEffect, useState } from 'react'
import { FileSource } from '../lib/filesystem.js'
import { FileSource } from '../lib/source.js'
import { parquetDataFrame } from '../lib/tableProvider.js'
import Breadcrumb, { BreadcrumbConfig } from './Breadcrumb.js'
import Layout from './Layout.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/File.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { FileSource } from '../lib/filesystem.js'
import { FileSource } from '../lib/source.js'
import Breadcrumb, { BreadcrumbConfig } from './Breadcrumb.js'
import Layout from './Layout.js'
import Viewer, { ViewerConfig } from './viewers/Viewer.js'
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/Folder.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import { DirSource, FileMetadata } from '../lib/filesystem.js'
import type { DirSource, FileMetadata } from '../lib/source.js'
import { cn, formatFileSize, getFileDate, getFileDateShort } from '../lib/utils.js'
import Breadcrumb, { BreadcrumbConfig } from './Breadcrumb.js'
import Layout, { Spinner } from './Layout.js'
Expand Down Expand Up @@ -35,7 +35,7 @@ export default function Folder({ source, config }: FolderProps) {
{files && files.length > 0 && <ul className='file-list'>
{files.map((file, index) =>
<li key={index}>
<a href={config?.routes?.getSourceRouteUrl?.({ source: file.source }) ?? location.href}>
<a href={config?.routes?.getSourceRouteUrl?.({ sourceId: file.sourceId }) ?? location.href}>
<span className={cn('file-name', 'file', file.kind === 'directory' && 'folder')}>
{file.name}
</span>
Expand Down
7 changes: 2 additions & 5 deletions packages/components/src/components/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DirSource, FileSource, Source } from '../lib/filesystem.js'
import { Source } from '../lib/source.js'
import { BreadcrumbConfig } from './Breadcrumb.js'
import Cell from './Cell.js'
import File, { FileConfig } from './File.js'
Expand All @@ -17,12 +17,9 @@ interface PageProps {
}

export default function Page({ source, navigation, config }: PageProps) {
if (source instanceof DirSource) {
if (source.kind === 'directory') {
return <Folder source={source} config={config}/>
}
if (!(source instanceof FileSource)) {
return <div>Invalid source</div>
}
if (navigation?.row !== undefined && navigation.col !== undefined) {
// cell view
return <Cell source={source} row={navigation.row} col={navigation.col} config={config} />
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/viewers/ImageView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import { FileSource } from '../../lib/filesystem.js'
import { FileSource } from '../../lib/source.js'
import { contentTypes, parseFileSize } from '../../lib/utils.js'
import { Spinner } from '../Layout.js'
import ContentHeader from './ContentHeader.js'
Expand Down Expand Up @@ -64,7 +64,7 @@ export default function ImageView({ source, setError }: ViewerProps) {

return <ContentHeader content={content}>
{content?.dataUri && <img
alt={source.source}
alt={source.sourceId}
className='image'
src={content.dataUri} />}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import { FileSource } from '../../lib/filesystem.js'
import { FileSource } from '../../lib/source.js'
import { parseFileSize } from '../../lib/utils.js'
import { Spinner } from '../Layout.js'
import Markdown from '../Markdown.js'
Expand Down
14 changes: 7 additions & 7 deletions packages/components/src/components/viewers/ParquetView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import HighTable, { DataFrame, rowCache } from 'hightable'
import { asyncBufferFromUrl, parquetMetadataAsync } from 'hyparquet'
import React, { useCallback, useEffect, useState } from 'react'
import { FileSource } from '../../lib/filesystem.js'
import { RoutesConfig, appendSearchParams } from '../../lib/routes.js'
import { FileSource } from '../../lib/source.js'
import { parquetDataFrame } from '../../lib/tableProvider.js'
import { Spinner } from '../Layout.js'
import CellPanel from './CellPanel.js'
Expand Down Expand Up @@ -36,7 +36,7 @@ export default function ParquetView({ source, setProgress, setError, config }: V
const [content, setContent] = useState<Content>()
const [cell, setCell] = useState<{ row: number, col: number } | undefined>()

const { resolveUrl } = source
const { resolveUrl, sourceId } = source
useEffect(() => {
async function loadParquetDataFrame() {
try {
Expand Down Expand Up @@ -82,13 +82,13 @@ export default function ParquetView({ source, setProgress, setError, config }: V
return () => { window.removeEventListener('keydown', handleKeyDown) }
}, [cell])

const getCellRouteUrl = useCallback(({ source, col, row }: {source: string, col: number, row: number}) => {
const url = config?.routes?.getCellRouteUrl?.({ source, col, row })
const getCellRouteUrl = useCallback(({ col, row }: {col: number, row: number}) => {
const url = config?.routes?.getCellRouteUrl?.({ sourceId, col, row })
if (url) {
return url
}
return appendSearchParams({ col: col.toString(), row: row.toString() })
}, [config])
}, [config, sourceId])

const onDoubleClickCell = useCallback((col: number, row: number) => {
if (cell?.col === col && cell.row === row) {
Expand All @@ -101,9 +101,9 @@ export default function ParquetView({ source, setProgress, setError, config }: V
if (event.button === 1) {
// Middle click open in new tab
event.preventDefault()
window.open(getCellRouteUrl({ source: source.source, row, col }), '_blank')
window.open(getCellRouteUrl({ row, col }), '_blank')
}
}, [source.source, getCellRouteUrl])
}, [getCellRouteUrl])

const headers = <span>{content?.dataframe.numRows.toLocaleString() ?? '...'} rows</span>

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/viewers/TextView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import { FileSource } from '../../lib/filesystem.js'
import { FileSource } from '../../lib/source.js'
import { parseFileSize } from '../../lib/utils.js'
import { Spinner } from '../Layout.js'
import ContentHeader, { TextContent } from './ContentHeader.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/viewers/Viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileSource } from '../../lib/filesystem.js'
import { FileSource } from '../../lib/source.js'
import { imageTypes } from '../../lib/utils.js'
import ImageView from './ImageView.js'
import MarkdownView from './MarkdownView.js'
Expand Down
Loading