Skip to content

Commit 3d260c9

Browse files
neotrowneotobGianmarco Manni
authored
Migrate to TanStack Table (#57)
Co-authored-by: neotob <tobias.merki@neolution.ch> Co-authored-by: Gianmarco Manni <gianmarco.manni@neolution.ch>
1 parent c5be98c commit 3d260c9

40 files changed

Lines changed: 2200 additions & 5044 deletions

.eslintrc.cjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ module.exports = {
33
node: true,
44
jest: true,
55
},
6-
extends: ["eslint:recommended", "plugin:import/recommended", "prettier", "plugin:storybook/recommended"],
6+
extends: [
7+
"eslint:recommended",
8+
"plugin:react/recommended",
9+
"plugin:react-hooks/recommended",
10+
"plugin:import/recommended",
11+
"plugin:@typescript-eslint/eslint-recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"prettier",
14+
],
715
parser: "@typescript-eslint/parser",
816
parserOptions: {
917
project: "tsconfig.json",
@@ -59,12 +67,6 @@ module.exports = {
5967
max: 200,
6068
},
6169
],
62-
complexity: [
63-
"error",
64-
{
65-
max: 12,
66-
},
67-
],
6870
"prefer-destructuring": "error",
6971
"no-empty-function": "error",
7072
"arrow-body-style": ["error", "as-needed"],

.storybook/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Skeletons for when the data is loading
13+
14+
### Changed
15+
16+
- :boom: Fundamentally changed how this package works. The state is now managed by the consumer of this package. This means that the consumer has to provide the data and the functions to update the data. The package only provides the UI components to display the data. This change was necessary to make the package more flexible and to allow the consumer to use the package in a wider range of use cases. Behind the scenes, the package uses the `useTable` hook from the `@tanstack/react-table` package. The consumer can use the `useTable` hook directly if he wants to. The `ReactDataTable` component is just a wrapper around the `useTable` hook. The `ReactDataTable` component is still the recommended way to use this package.
17+
18+
- :boom: renamed `possiblePageItemCounts` to `pageSizes`.
19+
20+
- :boom: `columns` is now of type `ColumnDef<TData, TValue>` from the `@tanstack/react-table` package. Please refer to the documentation of the `@tanstack/react-table` package for more information: https://tanstack.com/table/v8/docs/api/core/table#columns (there are additional custom fields in the column.meta object defined by us: `src/react-table.d.ts`)
21+
22+
### Removed
23+
24+
- :boom: removed `rowHighlight`. Use `rowStyle` instead.
25+
- :boom: removed `enablePredefinedSort` prop. Use `initialState.sorting` instead. Or `state.sorting` if you want to manage the state yourself.
26+
- :boom: removed `predefinedFilter` prop. Use `initialState`.
27+
- :boom: removed `asc` prop. Use `initialState.sorting` instead. Or `state.sorting` if you want to manage the state yourself.
28+
- :boom: removed `predefinedItemsPerPage` prop. Use `initialState.pagination.pageSize` instead. Or `state.pagination.pageSize` if you want to manage the state yourself.
29+
- :boom: removed `orderBy` prop. Use `initialState.sorting` instead. Or `state.sorting` if you want to manage the state yourself.
30+
- :boom: removed `client` prop. Use `data` prop instead and manage the state of the data yourself.
31+
- :boom: removed `query` prop. Use `data` prop instead and manage the state of the data yourself.
32+
- :boom: removed `handlers` prop. Since the state is now managed by the user, the user is responsible for updating the data.
33+
- :boom: removed `actions` props. You can easily define whatever actions you would like to have in the `columns` prop.
34+
This is an example of how you could configure the actions column:
35+
36+
```tsx
37+
import { createColumnHelper } from "@tanstack/react-table";
38+
39+
const columnHelper = createColumnHelper<YourData>();
40+
columnHelper.display({
41+
id: "edit",
42+
header: () => <span>Aktionen</span>,
43+
cell: (props) => (
44+
<>
45+
<Link href={{ pathname: "/addresses/[addressId]", query: { addressId: props.row.getValue("addressId") } }}>
46+
<FontAwesomeIcon icon={faEye} style={{ marginRight: "5px" }} />
47+
</Link>
48+
<FontAwesomeIcon
49+
icon={faTrash}
50+
style={{ marginRight: "5px" }}
51+
onClick={async () => {
52+
// do something
53+
}}
54+
/>
55+
</>
56+
),
57+
}),
58+
```
59+
1060
## [3.8.0] - 2023-11-20
1161

1262
- Changed `DeleteAction` to expose `cancelButtonText` and `deleteButtonText` props for translations

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
11
# react-data-table
22

3-
A react data-table that uses bootstrap design, can be either used for showing static content or also as fully interactive table together with an api client, supports filtering, sorting, paging and many more interactions.
3+
This package relies heavly on `tanstack/react-table` and `reactstrap` to provide a simple and easy to use data table.
44

5-
## Storybook
5+
## Installation
66

7-
The storybook is a visual testing tool that makes it easy to test and tinker with the components.
7+
```bash
8+
npm install @neolution-ch/react-data-table
9+
or
10+
yarn add @neolution-ch/react-data-table
11+
```
812

9-
It can be found at https://neolution-ch.github.io/react-data-table
13+
### CSS
14+
15+
The skeletons are provided by `react-loading-skeleton` so you need to import the css file in your project.
16+
17+
```tsx
18+
import "react-loading-skeleton/dist/skeleton.css";
19+
```
20+
21+
### Peer dependencies
22+
23+
todo
24+
25+
## Usage
26+
27+
The main entry point for everything is the `ReactDataTable` component.
28+
29+
The props that you provide will determine if the table is sorted, filtered, paginated, etc. on the client or if the consumer of this package has to provide the data and the functions to update the data.
30+
31+
### Fully Static / Client Side Example
32+
33+
In this configuration the table is fully static meaning that the data will be sorted, filtered, paginated, etc. on the client.
34+
35+
```tsx
36+
<ReactDataTable<Person, string> data={data} columns={columns} />
37+
```
38+
39+
### Fully Dynamic / Server Side Example
40+
41+
In this configuration the table is fully dynamic meaning that the consumer of this package has to provide the data and the functions to update the data.
42+
43+
| use case | onSorting | sorting |
44+
| ---------------------------------------------------------------------------------------------------------- | --------- | ------- |
45+
| you want to manually sort your data (possible server side) but you don't want to manage the state yourself | yes | no |
46+
| you want the data table to handle the sorting but would like to influence the sorting from the outside | no | yes |
47+
| you want to manually sort your data AND you want to mange the state yourself | yes | yes |
48+
| you want the data table to handle the sorting and you don't want to manually influence the state | no | no |

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,25 @@
3030
"dist"
3131
],
3232
"scripts": {
33-
"build": "rollup -c",
33+
"build": "rollup -c && yarn copy-definitionfile",
3434
"build-storybook": "build-storybook",
3535
"lint": "eslint \"**/*.{ts,tsx}\" --cache --max-warnings 0",
3636
"prepack": "yarn build",
3737
"prepare-pr": "yarn prettier . --write && yarn lint && yarn build && yarn test\"",
3838
"prettier-check": "prettier --check .",
3939
"prettier-write": "prettier --write .",
40-
"start": "rollup -c -w",
40+
"copy-definitionfile": "shx cp -r src/react-table.d.ts dist/react-table.d.ts",
41+
"start": "yarn copy-definitionfile && rollup -c -w",
4142
"start-all": "concurrently \"yarn start\" \"yarn start-yalc\"",
4243
"start-yalc": "yarn nodemon --watch dist -x \"yarn yalc push\"",
4344
"storybook": "start-storybook -p 6006",
4445
"test": "cross-env DEBUG_PRINT_LIMIT=100 jest",
4546
"tsc": "tsc"
4647
},
4748
"dependencies": {
48-
"@neolution-ch/react-pattern-ui": "2.9.0"
49+
"@neolution-ch/react-pattern-ui": "^3.1.0",
50+
"@tanstack/react-table": "^8.10.7",
51+
"react-loading-skeleton": "^3.3.1"
4952
},
5053
"devDependencies": {
5154
"@babel/core": "^7.21.8",
@@ -65,6 +68,7 @@
6568
"@testing-library/dom": "^8.13.0",
6669
"@testing-library/jest-dom": "^5.16.4",
6770
"@testing-library/react": "^12.1.2",
71+
"@testing-library/react-hooks": "^8.0.1",
6872
"@testing-library/user-event": "^14.0.4",
6973
"@types/jest": "^27.4.1",
7074
"@types/node": "^18.16.3",
@@ -80,6 +84,8 @@
8084
"eslint-config-prettier": "^8.8.0",
8185
"eslint-import-resolver-typescript": "^3.5.5",
8286
"eslint-plugin-import": "^2.27.5",
87+
"eslint-plugin-react": "^7.33.2",
88+
"eslint-plugin-react-hooks": "^4.6.0",
8389
"eslint-plugin-storybook": "^0.6.12",
8490
"gh-pages": "^5.0.0",
8591
"jest": "^27.5.1",

rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const plugins = [
2626
terser({
2727
output: { comments: false },
2828
compress: {
29-
drop_console: true,
29+
drop_console: false,
3030
},
3131
}),
3232
];

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
export * from "./lib/DataTable/DataTable";
2-
export * from "./lib/DataTable/DataTableInterfaces";
3-
export * from "./lib/DataTable/DataTableRouted";
4-
export * from "./lib/DataTable/DataTableTypes";
1+
export * from "./lib/translations/translations";
2+
export * from "./lib/useReactDataTableState/useReactDataTableState";
3+
export * from "./lib/useReactDataTable/useReactDataTable";
4+
export * from "./lib/ReactDataTable/ReactDataTable";
5+
export * from "./lib/utils/getStronglyTypedColumnFilter";
6+
export * from "./lib/useFullyControlledReactDataTable/useFullyControlledReactDataTable";
7+
export * from "./lib/utils/createReactDataTableColumnHelper";
8+
export * from "./lib/utils/getModelFromColumnFilter";
9+
export * from "./lib/utils/getColumnFilterFromModel";

src/lib/DataTable/Actions/ActionsCell.tsx

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/lib/DataTable/Actions/ActionsHeaderFilterCell.tsx

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/lib/DataTable/Actions/ActionsHeaderTitleCell.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)