From 4cac553b7b1d60c5b503e3b68bf578ccbec65a62 Mon Sep 17 00:00:00 2001 From: andresgutgon Date: Fri, 6 Sep 2024 17:51:04 +0200 Subject: [PATCH] Dataset preview data --- apps/web/src/actions/datasets/preview.ts | 21 ++++++++++ .../_components/DatasetsTable/index.tsx | 18 ++++++++ .../_components/PreviewDatasetModal/index.tsx | 37 ++++++++++++++++ apps/web/src/stores/datasetPreviews.ts | 42 +++++++++++++++++++ packages/core/src/lib/readCsv.ts | 38 ++++++++++++----- .../core/src/services/datasets/preview.ts | 21 ++++++++++ packages/web-ui/src/ds/atoms/Icons/index.tsx | 2 + 7 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 apps/web/src/actions/datasets/preview.ts create mode 100644 apps/web/src/app/(private)/datasets/_components/PreviewDatasetModal/index.tsx create mode 100644 apps/web/src/stores/datasetPreviews.ts create mode 100644 packages/core/src/services/datasets/preview.ts diff --git a/apps/web/src/actions/datasets/preview.ts b/apps/web/src/actions/datasets/preview.ts new file mode 100644 index 000000000..f0cba9e97 --- /dev/null +++ b/apps/web/src/actions/datasets/preview.ts @@ -0,0 +1,21 @@ +'use server' + +import { DatasetsRepository } from '@latitude-data/core/repositories' +import { previewDataset } from '@latitude-data/core/services/datasets/preview' +import disk from '$/lib/disk' +import { z } from 'zod' + +import { authProcedure } from '../procedures' + +export const previewDatasetAction = authProcedure + .createServerAction() + .input( + z.object({ + id: z.number(), + }), + ) + .handler(async ({ ctx, input }) => { + const repo = new DatasetsRepository(ctx.workspace.id) + const dataset = await repo.find(input.id).then((r) => r.unwrap()) + return await previewDataset({ dataset, disk }).then((r) => r.unwrap()) + }) diff --git a/apps/web/src/app/(private)/datasets/_components/DatasetsTable/index.tsx b/apps/web/src/app/(private)/datasets/_components/DatasetsTable/index.tsx index 67f5d4b7c..dbf692d00 100644 --- a/apps/web/src/app/(private)/datasets/_components/DatasetsTable/index.tsx +++ b/apps/web/src/app/(private)/datasets/_components/DatasetsTable/index.tsx @@ -13,8 +13,10 @@ import { TableHeader, TableRow, Text, + Tooltip, } from '@latitude-data/web-ui' import DeleteDatasetModal from '$/app/(private)/datasets/_components/DeleteDatasetModal' +import PreviewDatasetModal from '$/app/(private)/datasets/_components/PreviewDatasetModal' import useDatasets from '$/stores/datasets' export function DatasetsTable({ @@ -23,12 +25,14 @@ export function DatasetsTable({ datasets: Dataset[] }) { const [deletable, setDeletable] = useState(null) + const [preview, setPreview] = useState(null) const { data: datasets } = useDatasets(undefined, { fallbackData: serverDatasets, }) return ( <> + @@ -38,6 +42,7 @@ export function DatasetsTable({ Author Created at + @@ -60,6 +65,19 @@ export function DatasetsTable({ {dateFormatter.formatDate(dataset.createdAt)} + + setPreview(dataset)} + variant='nope' + iconProps={{ name: 'eye', color: 'foregroundMuted' }} + /> + } + > + Show file preview (first 100 rows) + +