Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Sep 7, 2024
1 parent 8510bd8 commit 1aab329
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Dataset } from '@latitude-data/core/browser'
import '@latitude-data/web-ui'

import {
Button,
Modal,
ModalTrigger,
ReactStateDispatch,
Table,
TableBody,
Expand All @@ -23,16 +25,25 @@ function PreviewModal({
setPreview: ReactStateDispatch<Dataset | null>
}) {
const { data, isLoading } = useDatasetPreview({ dataset })
const rows = data?.data ?? []
const rows = data?.rows ?? []
return (
<Modal
size='large'
open
title={`${dataset.name} preview`}
description='First 100 rows of the dataset'
onOpenChange={(open: boolean) => !open && setPreview(null)}
footer={
<ModalTrigger>
<Button fancy variant='outline'>
Go back
</Button>
</ModalTrigger>
}
>
{isLoading ? (<div>....</div>) : (
{isLoading ? (
<div>....</div>
) : (
<Table>
<TableHeader>
<TableRow verticalPadding>
Expand All @@ -47,7 +58,7 @@ function PreviewModal({
{rows.map((row, rowIndex) => {
return (
<TableRow key={rowIndex} verticalPadding>
{row.record.map((cell, cellIndex) => (
{row.map((cell, cellIndex) => (
<TableCell key={cellIndex}>{cell}</TableCell>
))}
</TableRow>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/stores/datasetPreviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function useDatasetPreview(
variant: 'destructive',
})

return { headers: [], data: [], rowCount: 0 }
return { headers: [], rows: [], rowCount: 0 }
}

return data
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/readCsv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type ParseResult = {
}
export type CsvParsedData = {
headers: string[]
rows: string[][]
rowCount: number
data: ParseResult[]
}
export async function syncReadCsv(
file: File | string,
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/services/datasets/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dataset } from '../../browser'
import { Result } from '../../lib'
import { DiskWrapper } from '../../lib/disk'
import { syncReadCsv } from '../../lib/readCsv'

Expand All @@ -17,5 +18,14 @@ export async function previewDataset({
const diskFile = disk.file(dataset.fileKey)
const bytes = await diskFile.getBytes()
const file = new TextDecoder().decode(bytes)
return syncReadCsv(file, { limit })
const readResult = await syncReadCsv(file, { limit })
if (readResult.error) readResult

const csv = readResult.value!
const rows = csv.data.map((row) => Object.values(row.record))
return Result.ok({
rowCount: csv.rowCount,
headers: csv.headers,
rows,
})
}
3 changes: 2 additions & 1 deletion packages/web-ui/src/ds/atoms/Icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export type IconProps = {
className?: string
}

type Size = 'normal' | 'large' | 'xlarge'
type Size = 'normal' | 'large' | 'xlarge' | 'xxxlarge'

export function Icon({
name,
Expand All @@ -89,6 +89,7 @@ export function Icon({
'w-4 h-4': size === 'normal',
'w-6 h-6': size === 'large',
'w-8 h-8': size === 'xlarge',
'w-14 h-14': size === 'xxxlarge',
'animate-spin': spin,
})}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/web-ui/src/ds/molecules/ErrorComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function ErrorComponent({
'text-destructive': type === 'red',
})}
>
<Icon name='logoMonochrome' className='w-14 h-14' />
<Icon name='logoMonochrome' size='xxxlarge'/>
<Text.H5 align='center' color='foregroundMuted'>
{message}
</Text.H5>
Expand Down

0 comments on commit 1aab329

Please sign in to comment.