import { Button } from "@repo/shadcn-ui/components/button"; import { Checkbox } from "@repo/shadcn-ui/components/checkbox"; import type { Table as TableModel } from "@tanstack/react-table"; import { useId, useState } from "react"; import { entityListLabels } from "../lib/entity-list"; import { FormDialog } from "./form-dialog"; import { SelectWithAction } from "./select-with-action"; export function EntityTableConfiguration({ table, locale, onSort, }: { table: TableModel; locale: string; onSort: () => void; }) { const id = useId(); const labels = entityListLabels(locale); const [columnsOpen, setColumnsOpen] = useState(false); const sorting = table.getState().sorting; const columns = table.getAllLeafColumns().map((column) => ({ id: column.id, label: String(column.columnDef.header), value: column.getCanSort(), })); const setSorting = table.setSorting; return ( <>
{ const [column, direction] = value.split(":"); setSorting( column && column !== "initial" ? [{ id: column, desc: direction === "desc" }] : [] ); onSort(); }} options={[ { value: "initial", label: labels.initial }, ...columns .filter((column) => column.value) .flatMap((column) => [ { value: `${column.id}:asc`, label: `${column.label} · ${labels.ascending}` }, { value: `${column.id}:desc`, label: `${column.label} · ${labels.descending}` }, ]), ]} placeholder={labels.sort} value={sorting[0] ? `${sorting[0].id}:${sorting[0].desc ? "desc" : "asc"}` : "initial"} />
{" "}
{table.getAllLeafColumns().map((column) => ( ))}
); }