-
Notifications
You must be signed in to change notification settings - Fork 60
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
ee304cb
commit bc5aee9
Showing
27 changed files
with
2,478 additions
and
91 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,22 @@ | ||
'use server' | ||
|
||
import { DatasetsRepository } from '@latitude-data/core/repositories' | ||
import { destroyDataset } from '@latitude-data/core/services/datasets/destroy' | ||
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).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
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
'use client' | ||
|
||
import { useState } from 'react' | ||
|
||
import { Dataset } from '@latitude-data/core/browser' | ||
import { | ||
Button, | ||
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 /> | ||
</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 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.