tycho-components 0.0.17-SNAPSHOT-12 → 0.0.17-SNAPSHOT-13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
import { PaginationState, SortingState } from '@tanstack/react-table';
|
|
1
2
|
import './styles.scss';
|
|
2
3
|
import { AppPage } from './types/AppPage';
|
|
3
|
-
import { AppPageable } from './types/AppPageable';
|
|
4
4
|
type Props = {
|
|
5
5
|
columns: any;
|
|
6
6
|
data: AppPage<any>;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
pagination: PaginationState;
|
|
8
|
+
setPagination: (p: PaginationState) => void;
|
|
9
|
+
sorting: SortingState;
|
|
10
|
+
setSorting: (s: SortingState) => void;
|
|
9
11
|
className?: string;
|
|
10
12
|
onClickRow?: (row: any, col: any) => void;
|
|
11
13
|
onMouseEnter?: (row: any) => void;
|
|
12
14
|
onMouseLeave?: (row: any) => void;
|
|
13
15
|
hiddenColumns?: string[];
|
|
14
16
|
};
|
|
15
|
-
export default function AppTable({ columns, data, className, onClickRow, onMouseEnter, onMouseLeave,
|
|
17
|
+
export default function AppTable({ columns, data, pagination, setPagination, sorting, setSorting, className, onClickRow, onMouseEnter, onMouseLeave, hiddenColumns, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
16
18
|
export {};
|
|
@@ -8,17 +8,12 @@ import TableContainer from '@mui/material/TableContainer';
|
|
|
8
8
|
import TableHead from '@mui/material/TableHead';
|
|
9
9
|
import TableRow from '@mui/material/TableRow';
|
|
10
10
|
import { flexRender, getCoreRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from '@tanstack/react-table';
|
|
11
|
-
import { useEffect
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
12
|
import AppPagination from '../AppPagination';
|
|
13
13
|
import { tableTheme } from './AppTableTheme';
|
|
14
14
|
import './styles.scss';
|
|
15
|
-
|
|
16
|
-
export default function AppTable({ columns, data, className, onClickRow, onMouseEnter, onMouseLeave, pageable, setPageable, hiddenColumns, }) {
|
|
15
|
+
export default function AppTable({ columns, data, pagination, setPagination, sorting, setSorting, className, onClickRow, onMouseEnter, onMouseLeave, hiddenColumns, }) {
|
|
17
16
|
const { content, totalPages, totalElements } = data;
|
|
18
|
-
const [pagination, setPagination] = useState({
|
|
19
|
-
pageIndex: pageable.page,
|
|
20
|
-
pageSize: pageable.size,
|
|
21
|
-
});
|
|
22
17
|
const columnVisibility = hiddenColumns?.reduce((acc, col) => {
|
|
23
18
|
acc[col] = false;
|
|
24
19
|
return acc;
|
|
@@ -28,8 +23,8 @@ export default function AppTable({ columns, data, className, onClickRow, onMouse
|
|
|
28
23
|
columns,
|
|
29
24
|
pageCount: totalPages,
|
|
30
25
|
state: {
|
|
31
|
-
pagination
|
|
32
|
-
sorting
|
|
26
|
+
pagination,
|
|
27
|
+
sorting,
|
|
33
28
|
columnVisibility,
|
|
34
29
|
},
|
|
35
30
|
manualPagination: true,
|
|
@@ -42,25 +37,8 @@ export default function AppTable({ columns, data, className, onClickRow, onMouse
|
|
|
42
37
|
const sort = table.getState().sorting.length > 0
|
|
43
38
|
? table.getState().sorting
|
|
44
39
|
: undefined;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
setPageable({
|
|
48
|
-
size: pagination.pageSize,
|
|
49
|
-
page: 0,
|
|
50
|
-
sort,
|
|
51
|
-
seed: DateUtils.millis(),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
else if (pageable.page !== pagination.pageIndex ||
|
|
55
|
-
pageable.sort !== sort) {
|
|
56
|
-
setPageable({
|
|
57
|
-
size: pagination.pageSize,
|
|
58
|
-
page: pagination.pageIndex,
|
|
59
|
-
sort,
|
|
60
|
-
seed: DateUtils.millis(),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}, [pagination, table.getState().sorting]);
|
|
40
|
+
setSorting(table.getState().sorting);
|
|
41
|
+
}, [table.getState().sorting]);
|
|
64
42
|
return (_jsx(ThemeProvider, { theme: tableTheme, children: _jsxs(Paper, { className: `ds-table ${className}`, children: [_jsx(TableContainer, { children: _jsxs(Table, { children: [_jsx(TableHead, { children: table.getHeaderGroups().map((headerGroup) => (_jsx(TableRow, { children: headerGroup.headers.map((header) => (_jsxs(TableCell, { onClick: header.column.getToggleSortingHandler(), style: { width: `${header.column.columnDef.size}%` }, children: [flexRender(header.column.columnDef.header, header.getContext()), header.column.getIsSorted()
|
|
65
43
|
? header.column.getIsSorted() === 'desc'
|
|
66
44
|
? ' 🔽'
|
|
@@ -4,18 +4,12 @@ export type AppPageable = {
|
|
|
4
4
|
size: number;
|
|
5
5
|
seed?: number;
|
|
6
6
|
sort?: SortingState;
|
|
7
|
-
filter?: any;
|
|
8
7
|
};
|
|
9
|
-
export declare const EMPTY_PAGEABLE:
|
|
8
|
+
export declare const EMPTY_PAGEABLE: AppPageable;
|
|
9
|
+
export declare const EMPTY_GRID_PAGEABLE: AppPageable;
|
|
10
|
+
export declare function convertPageable(pageable: AppPageable): {
|
|
11
|
+
sort: string;
|
|
10
12
|
page: number;
|
|
11
13
|
size: number;
|
|
12
|
-
seed
|
|
13
|
-
filter: {};
|
|
14
|
-
};
|
|
15
|
-
export declare const EMPTY_GRID_PAGEABLE: {
|
|
16
|
-
page: number;
|
|
17
|
-
size: number;
|
|
18
|
-
seed: number;
|
|
19
|
-
filter: {};
|
|
14
|
+
seed?: number;
|
|
20
15
|
};
|
|
21
|
-
export declare function convertPageable(pageable: AppPageable): any;
|
|
@@ -2,25 +2,18 @@ export const EMPTY_PAGEABLE = {
|
|
|
2
2
|
page: 0,
|
|
3
3
|
size: 10,
|
|
4
4
|
seed: 1,
|
|
5
|
-
filter: {},
|
|
6
5
|
};
|
|
7
6
|
export const EMPTY_GRID_PAGEABLE = {
|
|
8
7
|
page: 0,
|
|
9
8
|
size: 12,
|
|
10
9
|
seed: 1,
|
|
11
|
-
filter: {},
|
|
12
10
|
};
|
|
13
11
|
export function convertPageable(pageable) {
|
|
14
|
-
const
|
|
15
|
-
page: pageable.page,
|
|
16
|
-
size: pageable.size,
|
|
17
|
-
};
|
|
12
|
+
const sort = [];
|
|
18
13
|
if (pageable.sort) {
|
|
19
|
-
const sort = [];
|
|
20
14
|
pageable.sort.forEach((item, index) => {
|
|
21
15
|
sort.push(`${item.id},${item.desc ? 'desc' : 'asc'}`);
|
|
22
16
|
});
|
|
23
|
-
request.sort = sort;
|
|
24
17
|
}
|
|
25
|
-
return
|
|
18
|
+
return { ...pageable, sort: sort.join(',') };
|
|
26
19
|
}
|