tycho-components 0.0.17-SNAPSHOT-12 → 0.0.17-SNAPSHOT-14

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,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Select, MenuItem } from '@mui/material';
2
+ import { MenuItem, Select } from '@mui/material';
3
3
  import { Trans, useTranslation } from 'react-i18next';
4
4
  import { IconButton } from 'tycho-storybook';
5
5
  import './styles.scss';
@@ -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
- pageable: AppPageable;
8
- setPageable: (p: AppPageable) => void;
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, pageable, setPageable, hiddenColumns, }: Props): import("react/jsx-runtime").JSX.Element;
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, useState } from 'react';
11
+ import { useEffect } from 'react';
12
12
  import AppPagination from '../AppPagination';
13
13
  import { tableTheme } from './AppTableTheme';
14
14
  import './styles.scss';
15
- import DateUtils from '../functions/DateUtils';
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: { pageIndex: pageable.page, pageSize: pageable.size },
32
- sorting: pageable.sort || [],
26
+ pagination,
27
+ sorting,
33
28
  columnVisibility,
34
29
  },
35
30
  manualPagination: true,
@@ -39,28 +34,13 @@ export default function AppTable({ columns, data, className, onClickRow, onMouse
39
34
  getSortedRowModel: getSortedRowModel(),
40
35
  });
41
36
  useEffect(() => {
42
- const sort = table.getState().sorting.length > 0
43
- ? table.getState().sorting
44
- : undefined;
45
- if (pageable.size !== pagination.pageSize) {
46
- setPagination({ pageSize: pagination.pageSize, pageIndex: 0 });
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
- });
37
+ const currentSorting = table.getState().sorting;
38
+ if (currentSorting &&
39
+ sorting &&
40
+ JSON.stringify(currentSorting) !== JSON.stringify(sorting)) {
41
+ setSorting(currentSorting);
62
42
  }
63
- }, [pagination, table.getState().sorting]);
43
+ }, [table, sorting]);
64
44
  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
45
  ? header.column.getIsSorted() === 'desc'
66
46
  ? ' 🔽'
@@ -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: number;
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 request = {
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 request;
18
+ return { ...pageable, sort: sort.join(',') };
26
19
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.0.17-SNAPSHOT-12",
4
+ "version": "0.0.17-SNAPSHOT-14",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {