Skip to content

Commit

Permalink
added datapoint count on dataset table (#288)
Browse files Browse the repository at this point in the history
* eval time progression (#210)

* initial work to compare evals

* remove unnecessary div

* design

---------

Co-authored-by: Din <[email protected]>

* added datapoint count on dataset table

* added types and empty check

---------

Co-authored-by: Dinmukhamed Mailibay <[email protected]>
Co-authored-by: skull8888888 <[email protected]>
Co-authored-by: Din <[email protected]>
  • Loading branch information
4 people authored Dec 27, 2024
1 parent 9898691 commit a11f537
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
16 changes: 13 additions & 3 deletions frontend/app/api/projects/[projectId]/datasets/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { and, desc, eq, inArray } from 'drizzle-orm';
import { and, desc, eq, getTableColumns, inArray, sql } from 'drizzle-orm';
import { NextRequest } from 'next/server';

import { db } from '@/lib/db/drizzle';
import { datasets } from '@/lib/db/migrations/schema';
import { datasetDatapoints,datasets } from '@/lib/db/migrations/schema';
import { paginatedGet } from '@/lib/db/utils';

export async function POST(
Expand Down Expand Up @@ -42,12 +42,22 @@ export async function GET(
const pageSize =
parseInt(req.nextUrl.searchParams.get('pageSize') ?? '50') || 50;
const filters = [eq(datasets.projectId, projectId)];
const { ...columns } = getTableColumns(datasets);

const datasetsData = await paginatedGet({
table: datasets,
pageNumber,
pageSize,
filters,
orderBy: desc(datasets.createdAt)
orderBy: desc(datasets.createdAt),
columns: {
...columns,
datapointsCount: sql<number>`COALESCE((
SELECT COUNT(*)
FROM ${datasetDatapoints} dp
WHERE dp.dataset_id = datasets.id
), 0)::int`.as('datapointsCount')
}
});

return new Response(JSON.stringify(datasetsData), { status: 200 });
Expand Down
13 changes: 9 additions & 4 deletions frontend/components/datasets/datasets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
DialogTrigger
} from '@/components/ui/dialog';
import { useProjectContext } from '@/contexts/project-context';
import { Dataset } from '@/lib/dataset/types';
import { DatasetInfo } from '@/lib/dataset/types';
import { useToast } from '@/lib/hooks/use-toast';
import { PaginatedResponse } from '@/lib/types';
import { swrFetcher } from '@/lib/utils';
Expand All @@ -33,7 +33,7 @@ export default function Datasets() {
const { projectId } = useProjectContext();

const router = useRouter();
const { data, mutate } = useSWR<PaginatedResponse<Dataset>>(
const { data, mutate } = useSWR<PaginatedResponse<DatasetInfo>>(
`/api/projects/${projectId}/datasets/`,
swrFetcher
);
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function Datasets() {
setIsDeleteDialogOpen(false);
};

const columns: ColumnDef<Dataset>[] = [
const columns: ColumnDef<DatasetInfo>[] = [
{
cell: ({ row }) => <Mono>{row.original.id}</Mono>,
size: 300,
Expand All @@ -83,6 +83,11 @@ export default function Datasets() {
header: 'name',
size: 300
},
{
accessorKey: 'datapointsCount',
header: 'Datapoints Count',
size: 300
},
{
header: 'Created at',
accessorKey: 'createdAt',
Expand All @@ -107,7 +112,7 @@ export default function Datasets() {
onRowClick={(row) => {
router.push(`/project/${projectId}/datasets/${row.original.id}`);
}}
getRowId={(row: Dataset) => row.id}
getRowId={(row: DatasetInfo) => row.id}
columns={columns}
data={data?.items}
selectionPanel={(selectedRowIds) => (
Expand Down
4 changes: 4 additions & 0 deletions frontend/lib/dataset/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface Dataset {
indexedOn: string | null;
}

export interface DatasetInfo extends Dataset {
datapointsCount: number;
}

export interface Datapoint {
id: string;
createdAt: string;
Expand Down

0 comments on commit a11f537

Please sign in to comment.