-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement datasets data model #137
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,23 @@ | ||
'use server' | ||
|
||
import { DatasetsRepository } from '@latitude-data/core/repositories' | ||
import { destroyDataset } from '@latitude-data/core/services/datasets/destroy' | ||
import disk from '$/lib/disk' | ||
import { z } from 'zod' | ||
|
||
import { authProcedure } from '../procedures' | ||
|
||
export const destroyDatasetAction = authProcedure | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
id: z.string(), | ||
}), | ||
) | ||
.handler(async ({ input, ctx }) => { | ||
const { id } = input | ||
const repo = new DatasetsRepository(ctx.workspace.id) | ||
const dataset = await repo.find(id).then((r) => r.unwrap()) | ||
|
||
return await destroyDataset({ dataset, disk }).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use server' | ||
|
||
import { DatasetsRepository } from '@latitude-data/core/repositories' | ||
|
||
import { authProcedure } from '../procedures' | ||
|
||
export const getDatasetsAction = authProcedure | ||
.createServerAction() | ||
.handler(async ({ ctx }) => { | ||
const scope = new DatasetsRepository(ctx.workspace.id) | ||
return await scope.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
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
'use client' | ||
|
||
import { useState } from 'react' | ||
|
||
import { Dataset } from '@latitude-data/core/browser' | ||
import { | ||
Button, | ||
dateFormatter, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
Text, | ||
} from '@latitude-data/web-ui' | ||
import DeleteDatasetModal from '$/app/(private)/datasets/_components/DeleteDatasetModal' | ||
import useDatasets from '$/stores/datasets' | ||
|
||
export function DatasetsTable({ | ||
datasets: serverDatasets, | ||
}: { | ||
datasets: Dataset[] | ||
}) { | ||
const [deletable, setDeletable] = useState<Dataset | null>(null) | ||
const { data: datasets } = useDatasets(undefined, { | ||
fallbackData: serverDatasets, | ||
}) | ||
return ( | ||
<> | ||
<DeleteDatasetModal dataset={deletable} setDataset={setDeletable} /> | ||
<Table> | ||
<TableHeader> | ||
<TableRow verticalPadding> | ||
<TableHead>Name</TableHead> | ||
<TableHead>Rows</TableHead> | ||
<TableHead>Columns</TableHead> | ||
<TableHead>Author</TableHead> | ||
<TableHead>Created at</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> | ||
<Text.H4>{dataset.author?.name}</Text.H4> | ||
</TableCell> | ||
<TableCell> | ||
<Text.H4 color='foregroundMuted'> | ||
{dateFormatter.formatDate(dataset.createdAt)} | ||
</Text.H4> | ||
</TableCell> | ||
<TableCell align='center'> | ||
<Button | ||
onClick={() => setDeletable(dataset)} | ||
variant='nope' | ||
iconProps={{ name: 'trash', color: 'destructive' }} | ||
/> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</> | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
apps/web/src/app/(private)/datasets/_components/DeleteDatasetModal/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,35 @@ | ||
import { Dataset } from '@latitude-data/core/browser' | ||
import { ReactStateDispatch } from '@latitude-data/web-ui' | ||
import { destroyDatasetAction } from '$/actions/datasets/destroy' | ||
import DestroyModal from '$/components/modals/DestroyModal' | ||
import useDatasets from '$/stores/datasets' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export default function DeleteDatasetModal({ | ||
dataset, | ||
setDataset, | ||
}: { | ||
dataset: Dataset | null | ||
setDataset: ReactStateDispatch<Dataset | null> | ||
}) { | ||
const router = useRouter() | ||
const { data, destroy } = useDatasets() | ||
const isLast = data?.length === 1 | ||
if (!dataset) return null | ||
|
||
return ( | ||
<DestroyModal<typeof destroyDatasetAction> | ||
title={`Delete ${dataset.name}`} | ||
description='Deleted datasets will no longer accessible to generate new evaluations.' | ||
onOpenChange={(open: boolean) => !open && setDataset(null)} | ||
action={destroy} | ||
submitStr='Delete dataset' | ||
model={dataset} | ||
onSuccess={() => { | ||
if (isLast) router.refresh() | ||
|
||
setDataset(null) | ||
}} | ||
/> | ||
) | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3mb only? that's very small, i'd push it to 25 or so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
25mb of text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well the theory is that they want to evaluate on a large body of data no?, 3mb doesn't push our infra hard at all and it can be limiting for no reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
25 then. But node server will handle it?
We'll have to do this https://nextjs.org/docs/app/api-reference/next-config-js/serverActions#bodysizelimit
Although the best approach would be to direct upload to S3 and then process the file when S3 responds. But we need to change how upload is done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll start with 15MB and see if someone complains