From a24611b4742e7a01a7297d65fb0e7ee29e7f9106 Mon Sep 17 00:00:00 2001 From: Armin Talaie Date: Fri, 10 Jan 2025 15:27:01 -0800 Subject: [PATCH] tiny edits --- src/components/forms/applications/columns.tsx | 6 +- .../forms/applications/data-table.tsx | 105 +++++++++++------- 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/src/components/forms/applications/columns.tsx b/src/components/forms/applications/columns.tsx index 294675af..cfbd6329 100644 --- a/src/components/forms/applications/columns.tsx +++ b/src/components/forms/applications/columns.tsx @@ -113,7 +113,11 @@ export function createColumns( ); }, - enableColumnFilter: field.type !== "textarea" && field.type !== "url", + enableColumnFilter: + field.type !== "textarea" && + field.type !== "url" && + field.type !== "text" && + field.type !== "date", filterFn: ( row: Row, columnId: string, diff --git a/src/components/forms/applications/data-table.tsx b/src/components/forms/applications/data-table.tsx index 94f306dc..0ae24ba5 100644 --- a/src/components/forms/applications/data-table.tsx +++ b/src/components/forms/applications/data-table.tsx @@ -20,7 +20,7 @@ import { Button } from "@/components/primitives/button"; import { Input } from "@/components/primitives/input"; import { Table, TableCell, TableRow } from "@/components/primitives/table"; -import React, { CSSProperties, useState } from "react"; +import React, { CSSProperties, useMemo, useState } from "react"; import { ChartArea, ListFilterIcon, TableIcon } from "lucide-react"; import { DataTableProps } from "@/components/forms/applications/dataTableWrapper"; import AnalyticsPage from "@/components/forms/applications/AnalyticsPage"; @@ -228,6 +228,30 @@ function TableFilter({ }) { const [showFilters, setShowFilters] = useState(false); + const groupColumnsByType = useMemo(() => { + return columns.reduce( + (acc, column) => { + if ( + !column.columnDef || + !column.columnDef.meta || + !column.columnDef.meta.field || + !column.columnDef.meta.field.type + ) { + return acc; + } + const type = column.columnDef.meta.field.type; + if (!acc[type]) { + acc[type] = []; + } + + acc[type].push(column); + + return acc; + }, + {} as Record[]>, + ); + }, [columns]); + if (!showFilters) { return (
-
+

Filters

- {columns - .filter((c) => c.getCanFilter()) - .map((column: any, index: number) => ( -
- - {column.columnDef.header()} - - c.id === column.id)} - updateColumnFilter={(value) => - setColumnFilters([ - ...columnFilters.filter((c) => c.id !== column.id), - ...value, - ]) - } - /> -
- ))} + {Object.values(groupColumnsByType).map((columns, groupIndex) => ( +
+ {columns + .filter((c) => c.getCanFilter()) + .map((column, columnIndex) => ( +
+ + {column.columnDef.header()} + + c.id === column.id, + )} + updateColumnFilter={(value) => + setColumnFilters([ + ...columnFilters.filter((c) => c.id !== column.id), + ...value, + ]) + } + /> +
+ ))} +
+ ))} +