-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8facbfe
commit 80d05bb
Showing
17 changed files
with
248 additions
and
86 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,13 @@ | ||
'use server' | ||
|
||
import { DatasetsRepository } from '@latitude-data/core/repositories' | ||
|
||
import { authProcedure } from '../procedures' | ||
|
||
export const getDatasetsAction = authProcedure | ||
.createServerAction() | ||
.handler(async ({ ctx }) => { | ||
const datasetsScope = new DatasetsRepository(ctx.workspace.id) | ||
|
||
return datasetsScope.findAll().then((r) => r.unwrap()) | ||
}) |
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
54 changes: 54 additions & 0 deletions
54
apps/web/src/app/(private)/datasets/_components/DatasetsTable/index.tsx
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,54 @@ | ||
'use client' | ||
|
||
import { Dataset } from '@latitude-data/core/browser' | ||
import { | ||
Button, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
Text, | ||
} from '@latitude-data/web-ui' | ||
import useDatasets from '$/stores/datasets' | ||
|
||
export function DatasetsTable({ | ||
datasets: serverDatasets, | ||
}: { | ||
datasets: Dataset[] | ||
}) { | ||
const { data: datasets } = useDatasets(undefined, { | ||
fallbackData: serverDatasets, | ||
}) | ||
return ( | ||
<Table> | ||
<TableHeader> | ||
<TableRow verticalPadding> | ||
<TableHead>Name</TableHead> | ||
<TableHead>Rows</TableHead> | ||
<TableHead>Columns</TableHead> | ||
<TableHead /> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{datasets.map((dataset) => ( | ||
<TableRow key={dataset.id} verticalPadding> | ||
<TableCell> | ||
<Text.H4>{dataset.name}</Text.H4> | ||
</TableCell> | ||
<TableCell> | ||
<Text.H4>{dataset.fileMetadata.rowCount}</Text.H4> | ||
</TableCell> | ||
<TableCell> | ||
<Text.H4>{dataset.fileMetadata.headers.length}</Text.H4> | ||
</TableCell> | ||
<TableCell align='center'> | ||
<Button variant='nope' iconProps={{ name: 'trash', color: 'destructive' }} /> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
) | ||
} |
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
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,50 @@ | ||
import { useCallback } from 'react' | ||
|
||
import type { Dataset } from '@latitude-data/core/browser' | ||
import { useToast } from '@latitude-data/web-ui' | ||
import { createDatasetAction } from '$/actions/datasets/create' | ||
import { getDatasetsAction } from '$/actions/datasets/fetch' | ||
import useLatitudeAction from '$/hooks/useLatitudeAction' | ||
import useCurrentWorkspace from '$/stores/currentWorkspace' | ||
import useSWR, { SWRConfiguration } from 'swr' | ||
|
||
export default function useDatasets( | ||
{ onCreateSuccess }: { onCreateSuccess?: (dataset: Dataset) => void } = {}, | ||
opts?: SWRConfiguration, | ||
) { | ||
const { data: workspace } = useCurrentWorkspace() | ||
const { toast } = useToast() | ||
const fetcher = useCallback(async () => { | ||
const [data, error] = await getDatasetsAction() | ||
if (error) { | ||
toast({ | ||
title: 'Error', | ||
description: error.message, | ||
variant: 'destructive', | ||
}) | ||
|
||
return [] | ||
} | ||
|
||
return data | ||
}, [toast]) | ||
const { | ||
data = [], | ||
mutate, | ||
...rest | ||
} = useSWR<Dataset[]>(['workspace', workspace.id, 'datasets'], fetcher, opts) | ||
const { error: createError, executeFormAction: createFormAction } = | ||
useLatitudeAction(createDatasetAction, { | ||
onSuccess: ({ data: dataset }) => { | ||
toast({ | ||
title: 'Success', | ||
description: 'Dataset uploaded successfully! 🎉', | ||
}) | ||
|
||
mutate([...data, dataset]) | ||
onCreateSuccess?.(dataset) | ||
}, | ||
}) | ||
|
||
return { data, mutate, createFormAction, createError, ...rest } | ||
} |
2 changes: 1 addition & 1 deletion
2
...ges/core/drizzle/0044_real_rick_jones.sql → ...ges/core/drizzle/0044_dazzling_legion.sql
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
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,15 @@ | ||
import { eq, getTableColumns } from 'drizzle-orm' | ||
|
||
import { datasets } from '../schema' | ||
import Repository from './repository' | ||
|
||
const datasetColumns = getTableColumns(datasets) | ||
export class DatasetsRepository extends Repository<typeof datasetColumns> { | ||
get scope() { | ||
return this.db | ||
.select(datasetColumns) | ||
.from(datasets) | ||
.where(eq(datasets.workspaceId, this.workspaceId)) | ||
.as('datasetsScope') | ||
} | ||
} |
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
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.