feat: deals filters

This commit is contained in:
2025-09-01 17:54:31 +04:00
parent ab7ef1e753
commit 48d539154c
24 changed files with 489 additions and 306 deletions

View File

@ -1,59 +1,18 @@
import React, { useEffect, useImperativeHandle } from "react";
import {
MantineReactTable,
MRT_ColumnDef,
MRT_RowData,
MRT_TableInstance,
MRT_TableOptions,
useMantineReactTable,
} from "mantine-react-table";
import { MRT_Localization_RU } from "mantine-react-table/locales/ru";
import React from "react";
import { DataTable, DataTableProps } from "mantine-datatable";
type Props<T extends MRT_RowData> = {
data: T[];
onSelectionChange?: (selectedRows: T[]) => void;
columns: MRT_ColumnDef<T>[];
restProps?: MRT_TableOptions<T>;
striped?: boolean | "odd" | "even";
};
export type BaseTableRef<T extends MRT_RowData> = {
getTable: () => MRT_TableInstance<T>;
};
function BaseTableInner<T extends MRT_RowData>(
{ data, columns, restProps, onSelectionChange, striped = false }: Props<T>,
ref: React.Ref<BaseTableRef<T>>
) {
const table = useMantineReactTable<T>({
localization: MRT_Localization_RU,
enablePagination: false,
data,
columns,
mantineTableProps: {
striped,
highlightOnHover: false,
},
enableTopToolbar: false,
enableBottomToolbar: false,
enableRowSelection: onSelectionChange !== undefined,
...restProps,
});
useEffect(() => {
if (!onSelectionChange) return;
onSelectionChange(
table.getSelectedRowModel().rows.map(r => r.original)
);
}, [onSelectionChange, table.getState().rowSelection]);
useImperativeHandle(ref, () => ({ getTable: () => table }));
return <MantineReactTable table={table} />;
function BaseTable<T>(props: DataTableProps<T>) {
return (
<DataTable
withTableBorder={false}
withRowBorders
striped={false}
verticalAlign={"center"}
borderRadius={"lg"}
backgroundColor={"transparent"}
{...props}
/>
);
}
const BaseTable = React.forwardRef(BaseTableInner) as <T extends MRT_RowData>(
props: Props<T> & { ref?: React.Ref<BaseTableRef<T>> }
) => React.ReactElement | null;
export default BaseTable;