@bsol-oss/react-datatable5 1.0.0
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.
- package/.cache/storybook/default/dev-server/a5a8bf6e622aef57065c6498611f40c911543d7d-3920d97c51b8ad2521918fb1205babd22b0ed3d7 +1 -0
- package/.cache/storybook/default/dev-server/a5a8bf6e622aef57065c6498611f40c911543d7d-43fdebe5fc35e4e9fabee9a83c7faea931b05ea0 +1 -0
- package/.cache/storybook/default/dev-server/a5a8bf6e622aef57065c6498611f40c911543d7d-f086b87885981c04ce7a583ff90a49313de83de7 +1 -0
- package/.eslintrc.cjs +19 -0
- package/.prettierignore +4 -0
- package/.storybook/main.ts +20 -0
- package/.storybook/preview.ts +14 -0
- package/README.md +42 -0
- package/package.json +59 -0
- package/prettier.json +6 -0
- package/rollup.config.js +10 -0
- package/src/assets/react.svg +1 -0
- package/src/components/ChakraDataTable.tsx +279 -0
- package/src/components/DataTable.tsx +97 -0
- package/src/components/DataTableContext.tsx +13 -0
- package/src/components/EditFilterButton.tsx +37 -0
- package/src/components/EditSortingButton.tsx +37 -0
- package/src/components/EditViewButton.tsx +46 -0
- package/src/components/PageSizeControl.tsx +29 -0
- package/src/components/ResetFilteringButton.tsx +18 -0
- package/src/components/ResetSortingButton.tsx +18 -0
- package/src/components/Table.tsx +20 -0
- package/src/components/TableBody.tsx +23 -0
- package/src/components/TableCardContainer.tsx +22 -0
- package/src/components/TableCards.tsx +36 -0
- package/src/components/TableFilter.tsx +34 -0
- package/src/components/TableFooter.tsx +27 -0
- package/src/components/TableHeader.tsx +106 -0
- package/src/components/TablePagination.tsx +57 -0
- package/src/components/TableSorter.tsx +62 -0
- package/src/components/TextCell.tsx +18 -0
- package/src/components/useDataFromUrl.tsx +52 -0
- package/src/components/useDataTable.tsx +7 -0
- package/src/index.tsx +27 -0
- package/src/stories/Button.stories.ts +52 -0
- package/src/stories/Button.tsx +52 -0
- package/src/stories/CardViewShowcase.tsx +103 -0
- package/src/stories/Configure.mdx +369 -0
- package/src/stories/DataTable-test.stories.tsx +83 -0
- package/src/stories/DataTable.stories.tsx +57 -0
- package/src/stories/DefaultDataTable.tsx +141 -0
- package/src/stories/Header.stories.ts +33 -0
- package/src/stories/Header.tsx +71 -0
- package/src/stories/Page.stories.ts +32 -0
- package/src/stories/Page.tsx +91 -0
- package/src/stories/TableViewShowcase.tsx +105 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +5 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +15 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +3 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +12 -0
- package/src/stories/assets/youtube.svg +4 -0
- package/src/stories/button.css +30 -0
- package/src/stories/header.css +32 -0
- package/src/stories/page.css +69 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +11 -0
- package/vite.config.ts +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"value":{"id":"NM6d5fdXkkt1OaUDHYoiA","lastUsed":1711519584091},"type":"Object","created":"2024-03-27T06:06:24.092Z","ttl":0}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"value":1711519525338,"type":"Number","created":"2024-03-27T06:05:25.338Z","ttl":0}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"value":{"scaffolded-empty":{"body":{"eventType":"scaffolded-empty","eventId":"FtCGR86XZ7Rp3ULfAJQUG","sessionId":"NM6d5fdXkkt1OaUDHYoiA","payload":{"packageManager":"npm","projectType":"react-vite-ts","metadataErrorMessage":"No configuration files have been found in your configDir: .storybook.\nStorybook needs a \"main.js\" file, please add it.\n\nYou can pass a --config-dir flag to tell Storybook, where your main.js file is located at).\n\nMore info: https://storybook.js.org/docs/configure\n"},"context":{"inCI":false,"isTTY":true,"platform":"Linux","cliVersion":"8.0.4"}},"timestamp":1711519525809},"init":{"body":{"eventType":"init","eventId":"e1I5uskKala1JiB8n7iFn","sessionId":"NM6d5fdXkkt1OaUDHYoiA","metadata":{"generatedAt":1711519583518,"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":true,"refCount":0,"packageManager":{"type":"npm","version":"10.2.0"},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-vite","options":{}},"builder":"@storybook/builder-vite","renderer":"@storybook/react","storybookVersion":"8.0.4","storybookVersionSpecifier":"^8.0.4","language":"typescript","storybookPackages":{"@storybook/blocks":{"version":"8.0.4"},"@storybook/react":{"version":"8.0.4"},"@storybook/react-vite":{"version":"8.0.4"},"@storybook/test":{"version":"8.0.4"},"eslint-plugin-storybook":{"version":"0.8.0"},"storybook":{"version":"8.0.4"}},"addons":{"@storybook/addon-onboarding":{"version":"8.0.4"},"@storybook/addon-links":{"version":"8.0.4"},"@storybook/addon-essentials":{"version":"8.0.4"},"@chromatic-com/storybook":{"version":"1.2.25"},"@storybook/addon-interactions":{"version":"8.0.4"}}},"payload":{"projectType":"REACT"},"context":{"inCI":false,"isTTY":true,"platform":"Linux","cliVersion":"8.0.4"}},"timestamp":1711519584095}},"type":"Object","created":"2024-03-27T06:06:24.095Z","ttl":0}
|
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: { browser: true, es2020: true },
|
|
4
|
+
extends: [
|
|
5
|
+
"eslint:recommended",
|
|
6
|
+
"plugin:@typescript-eslint/recommended",
|
|
7
|
+
"plugin:react-hooks/recommended",
|
|
8
|
+
"plugin:storybook/recommended",
|
|
9
|
+
],
|
|
10
|
+
ignorePatterns: ["dist", ".eslintrc.cjs"],
|
|
11
|
+
parser: "@typescript-eslint/parser",
|
|
12
|
+
plugins: ["react-refresh"],
|
|
13
|
+
rules: {
|
|
14
|
+
"react-refresh/only-export-components": [
|
|
15
|
+
"warn",
|
|
16
|
+
{ allowConstantExport: true },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
};
|
package/.prettierignore
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StorybookConfig } from "@storybook/react-vite";
|
|
2
|
+
|
|
3
|
+
const config: StorybookConfig = {
|
|
4
|
+
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
|
|
5
|
+
addons: [
|
|
6
|
+
"@storybook/addon-onboarding",
|
|
7
|
+
"@storybook/addon-links",
|
|
8
|
+
"@storybook/addon-essentials",
|
|
9
|
+
"@chromatic-com/storybook",
|
|
10
|
+
"@storybook/addon-interactions",
|
|
11
|
+
],
|
|
12
|
+
framework: {
|
|
13
|
+
name: "@storybook/react-vite",
|
|
14
|
+
options: {},
|
|
15
|
+
},
|
|
16
|
+
docs: {
|
|
17
|
+
autodocs: "tag",
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export default config;
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# React Datatable
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
<DataTable
|
|
7
|
+
columns={columns}
|
|
8
|
+
url={"http://localhost:8333/api/v1/gpt/chat/history/all"}
|
|
9
|
+
>
|
|
10
|
+
<EditViewButton />
|
|
11
|
+
<ResetSortingButton />
|
|
12
|
+
<TableFilter />
|
|
13
|
+
<ResetFilteringButton />
|
|
14
|
+
<Table>
|
|
15
|
+
<TableHeader />
|
|
16
|
+
<TableBody />
|
|
17
|
+
<TableFooter />
|
|
18
|
+
</Table>
|
|
19
|
+
<PageSizeControl />
|
|
20
|
+
<TablePagination />
|
|
21
|
+
</DataTable>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
<DataTable
|
|
26
|
+
columns={columns}
|
|
27
|
+
url={"http://localhost:8333/api/v1/gpt/chat/history/all"}
|
|
28
|
+
>
|
|
29
|
+
<TablePagination />
|
|
30
|
+
<ButtonGroup isAttached>
|
|
31
|
+
<EditViewButton />
|
|
32
|
+
<EditFilterButton />
|
|
33
|
+
<EditSortingButton />
|
|
34
|
+
</ButtonGroup>
|
|
35
|
+
|
|
36
|
+
<TableCardContainer>
|
|
37
|
+
<TableCards />
|
|
38
|
+
</TableCardContainer>
|
|
39
|
+
<PageSizeControl />
|
|
40
|
+
<TablePagination />
|
|
41
|
+
</DataTable>
|
|
42
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bsol-oss/react-datatable5",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": "https://github.com/bsol-oss/react-datatable5.git",
|
|
6
|
+
"homepage": "https://github.com/bsol-oss/react-datatabl5#react-datatable",
|
|
7
|
+
"author": "screw123",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"react",
|
|
11
|
+
"react-table",
|
|
12
|
+
"@chakra-ui/react",
|
|
13
|
+
"react-icons"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rollup -c",
|
|
17
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
18
|
+
"preview": "vite preview",
|
|
19
|
+
"storybook": "storybook dev -p 6006",
|
|
20
|
+
"build-storybook": "storybook build"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@chakra-ui/icons": "^2.1.1",
|
|
24
|
+
"@chakra-ui/react": "^2.8.2",
|
|
25
|
+
"@emotion/react": "^11.11.4",
|
|
26
|
+
"@emotion/styled": "^11.11.0",
|
|
27
|
+
"@tanstack/react-table": "^8.15.0",
|
|
28
|
+
"axios": "^1.6.8",
|
|
29
|
+
"framer-motion": "^11.0.22",
|
|
30
|
+
"react": "^18.2.0",
|
|
31
|
+
"react-dom": "^18.2.0",
|
|
32
|
+
"react-icons": "^5.2.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@chromatic-com/storybook": "^1.2.25",
|
|
36
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
37
|
+
"@storybook/addon-essentials": "^8.0.4",
|
|
38
|
+
"@storybook/addon-interactions": "^8.0.4",
|
|
39
|
+
"@storybook/addon-links": "^8.0.4",
|
|
40
|
+
"@storybook/addon-onboarding": "^8.0.4",
|
|
41
|
+
"@storybook/blocks": "^8.0.4",
|
|
42
|
+
"@storybook/react": "^8.0.4",
|
|
43
|
+
"@storybook/react-vite": "^8.0.4",
|
|
44
|
+
"@storybook/test": "^8.0.4",
|
|
45
|
+
"@types/react": "^18.2.66",
|
|
46
|
+
"@types/react-dom": "^18.2.22",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
48
|
+
"@typescript-eslint/parser": "^7.2.0",
|
|
49
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
50
|
+
"eslint": "^8.57.0",
|
|
51
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
52
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
53
|
+
"eslint-plugin-storybook": "^0.8.0",
|
|
54
|
+
"prettier": "3.2.5",
|
|
55
|
+
"storybook": "^8.0.4",
|
|
56
|
+
"typescript": "^5.2.2",
|
|
57
|
+
"vite": "^5.2.0"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/prettier.json
ADDED
package/rollup.config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
Button,
|
|
4
|
+
Checkbox,
|
|
5
|
+
Flex,
|
|
6
|
+
FormControl,
|
|
7
|
+
Grid,
|
|
8
|
+
Popover,
|
|
9
|
+
PopoverArrow,
|
|
10
|
+
PopoverBody,
|
|
11
|
+
PopoverContent,
|
|
12
|
+
PopoverTrigger,
|
|
13
|
+
Table,
|
|
14
|
+
Tbody,
|
|
15
|
+
Td,
|
|
16
|
+
Tfoot,
|
|
17
|
+
Th,
|
|
18
|
+
Thead,
|
|
19
|
+
Tr,
|
|
20
|
+
Text,
|
|
21
|
+
Input,
|
|
22
|
+
} from "@chakra-ui/react";
|
|
23
|
+
import { Table as ITable, flexRender } from "@tanstack/react-table";
|
|
24
|
+
// import React, { useRef } from "react";
|
|
25
|
+
import React, { CSSProperties } from "react";
|
|
26
|
+
import {
|
|
27
|
+
Column,
|
|
28
|
+
ColumnDef,
|
|
29
|
+
getCoreRowModel,
|
|
30
|
+
useReactTable,
|
|
31
|
+
} from "@tanstack/react-table";
|
|
32
|
+
|
|
33
|
+
interface ChakraDataTable<T> {
|
|
34
|
+
table: ITable<T>;
|
|
35
|
+
hasFooter: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const getCommonPinningStyles = (column: Column<any>): CSSProperties => {
|
|
39
|
+
const isPinned = column.getIsPinned();
|
|
40
|
+
const isLastLeftPinnedColumn =
|
|
41
|
+
isPinned === "left" && column.getIsLastColumn("left");
|
|
42
|
+
const isFirstRightPinnedColumn =
|
|
43
|
+
isPinned === "right" && column.getIsFirstColumn("right");
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
boxShadow: isLastLeftPinnedColumn
|
|
47
|
+
? "-4px 0 4px -4px gray inset"
|
|
48
|
+
: isFirstRightPinnedColumn
|
|
49
|
+
? "4px 0 4px -4px gray inset"
|
|
50
|
+
: undefined,
|
|
51
|
+
left: isPinned === "left" ? `${column.getStart("left")}px` : undefined,
|
|
52
|
+
right: isPinned === "right" ? `${column.getAfter("right")}px` : undefined,
|
|
53
|
+
opacity: isPinned ? 0.95 : 1,
|
|
54
|
+
position: isPinned ? "sticky" : "relative",
|
|
55
|
+
width: column.getSize(),
|
|
56
|
+
zIndex: isPinned ? 1 : 0,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const ChakraDataTable = <T,>({
|
|
61
|
+
table,
|
|
62
|
+
hasFooter,
|
|
63
|
+
refreshData,
|
|
64
|
+
}: ChakraDataTable<T>) => {
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<Flex justifyContent={"flex-end"}>
|
|
68
|
+
{JSON.stringify(table.getState().sorting)}
|
|
69
|
+
<Button
|
|
70
|
+
onClick={() => {
|
|
71
|
+
table.resetSorting();
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
Reset Sorting
|
|
75
|
+
</Button>
|
|
76
|
+
<Popover placement="bottom-end">
|
|
77
|
+
<PopoverTrigger>
|
|
78
|
+
<Button>Edit View</Button>
|
|
79
|
+
</PopoverTrigger>
|
|
80
|
+
<PopoverContent width={"auto"}>
|
|
81
|
+
<PopoverArrow />
|
|
82
|
+
<PopoverBody>
|
|
83
|
+
<Flex flexFlow={"column"} gap={"1rem"}>
|
|
84
|
+
{table.getAllLeafColumns().map((column) => {
|
|
85
|
+
return (
|
|
86
|
+
<FormControl key={crypto.randomUUID()} width={"auto"}>
|
|
87
|
+
<Checkbox
|
|
88
|
+
isChecked={column.getIsVisible()}
|
|
89
|
+
onChange={column.getToggleVisibilityHandler()}
|
|
90
|
+
>
|
|
91
|
+
{column.id}
|
|
92
|
+
</Checkbox>
|
|
93
|
+
</FormControl>
|
|
94
|
+
);
|
|
95
|
+
})}
|
|
96
|
+
</Flex>
|
|
97
|
+
</PopoverBody>
|
|
98
|
+
</PopoverContent>
|
|
99
|
+
</Popover>
|
|
100
|
+
</Flex>
|
|
101
|
+
{table.getLeafHeaders().map((header) => {
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
{header.column.getCanFilter() && (
|
|
105
|
+
<>
|
|
106
|
+
<Text>{header.column.id}</Text>
|
|
107
|
+
<Input
|
|
108
|
+
value={header.column.getFilterValue()}
|
|
109
|
+
onChange={(e) => {
|
|
110
|
+
header.column.setFilterValue(e.target.value);
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
<Button
|
|
114
|
+
onClick={() => {
|
|
115
|
+
refreshData();
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
Filter
|
|
119
|
+
</Button>
|
|
120
|
+
</>
|
|
121
|
+
)}
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
})}
|
|
125
|
+
|
|
126
|
+
<Grid overflowX={"scroll"} overflowY={"auto"}>
|
|
127
|
+
<Table variant="simple">
|
|
128
|
+
<Thead>
|
|
129
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
130
|
+
<Tr key={crypto.randomUUID()} style={{ columnSpan: "all" }}>
|
|
131
|
+
{headerGroup.headers.map((header) => {
|
|
132
|
+
return (
|
|
133
|
+
<Th
|
|
134
|
+
key={crypto.randomUUID()}
|
|
135
|
+
colSpan={header.colSpan}
|
|
136
|
+
width={`${header.getSize()}px`}
|
|
137
|
+
style={{ ...getCommonPinningStyles(header.column) }}
|
|
138
|
+
>
|
|
139
|
+
{header.isPlaceholder
|
|
140
|
+
? null
|
|
141
|
+
: flexRender(
|
|
142
|
+
header.column.columnDef.header,
|
|
143
|
+
header.getContext(),
|
|
144
|
+
)}
|
|
145
|
+
{header.column.getCanSort() && (
|
|
146
|
+
<>
|
|
147
|
+
<Button
|
|
148
|
+
onClick={(e) => {
|
|
149
|
+
const func =
|
|
150
|
+
header.column.getToggleSortingHandler();
|
|
151
|
+
if (func === undefined) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
func(e);
|
|
155
|
+
}}
|
|
156
|
+
>
|
|
157
|
+
Toggle Sort
|
|
158
|
+
</Button>
|
|
159
|
+
<Text>
|
|
160
|
+
{header.column.getIsSorted()
|
|
161
|
+
? "Sorted"
|
|
162
|
+
: "Not Sort"}
|
|
163
|
+
</Text>
|
|
164
|
+
{header.column.getNextSortingOrder() === false && (
|
|
165
|
+
<Text>To No sort</Text>
|
|
166
|
+
)}
|
|
167
|
+
{header.column.getNextSortingOrder() === "asc" && (
|
|
168
|
+
<Text>To asc</Text>
|
|
169
|
+
)}
|
|
170
|
+
{header.column.getNextSortingOrder() === "desc" && (
|
|
171
|
+
<Text>To desc</Text>
|
|
172
|
+
)}
|
|
173
|
+
</>
|
|
174
|
+
)}
|
|
175
|
+
|
|
176
|
+
{header.column.getIsFiltered() ? (
|
|
177
|
+
<Text>Filtered</Text>
|
|
178
|
+
) : (
|
|
179
|
+
<Text>Not Filtered</Text>
|
|
180
|
+
)}
|
|
181
|
+
<Box
|
|
182
|
+
padding={"1rem 0"}
|
|
183
|
+
borderRight={
|
|
184
|
+
header.column.getIsResizing()
|
|
185
|
+
? "1rem solid black"
|
|
186
|
+
: "0.5rem solid grey"
|
|
187
|
+
}
|
|
188
|
+
{...{
|
|
189
|
+
onDoubleClick: () => header.column.resetSize(),
|
|
190
|
+
onMouseDown: header.getResizeHandler(),
|
|
191
|
+
onTouchStart: header.getResizeHandler(),
|
|
192
|
+
}}
|
|
193
|
+
/>
|
|
194
|
+
{}
|
|
195
|
+
</Th>
|
|
196
|
+
);
|
|
197
|
+
})}
|
|
198
|
+
</Tr>
|
|
199
|
+
))}
|
|
200
|
+
</Thead>
|
|
201
|
+
<Tbody>
|
|
202
|
+
{table.getRowModel().rows.map((row) => (
|
|
203
|
+
<Tr key={crypto.randomUUID()}>
|
|
204
|
+
{row.getVisibleCells().map((cell) => (
|
|
205
|
+
<Td
|
|
206
|
+
key={crypto.randomUUID()}
|
|
207
|
+
width={`${cell.column.getSize()}px`}
|
|
208
|
+
>
|
|
209
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
210
|
+
</Td>
|
|
211
|
+
))}
|
|
212
|
+
</Tr>
|
|
213
|
+
))}
|
|
214
|
+
</Tbody>
|
|
215
|
+
{hasFooter && (
|
|
216
|
+
<Tfoot>
|
|
217
|
+
{table.getFooterGroups().map((footerGroup) => (
|
|
218
|
+
<Tr key={crypto.randomUUID()}>
|
|
219
|
+
{footerGroup.headers.map((header) => (
|
|
220
|
+
<Th key={crypto.randomUUID()} colSpan={header.colSpan}>
|
|
221
|
+
{header.isPlaceholder
|
|
222
|
+
? null
|
|
223
|
+
: flexRender(
|
|
224
|
+
header.column.columnDef.footer,
|
|
225
|
+
header.getContext(),
|
|
226
|
+
)}
|
|
227
|
+
</Th>
|
|
228
|
+
))}
|
|
229
|
+
</Tr>
|
|
230
|
+
))}
|
|
231
|
+
</Tfoot>
|
|
232
|
+
)}
|
|
233
|
+
</Table>
|
|
234
|
+
</Grid>
|
|
235
|
+
<Flex>
|
|
236
|
+
<Button
|
|
237
|
+
onClick={() => table.firstPage()}
|
|
238
|
+
disabled={!table.getCanPreviousPage()}
|
|
239
|
+
>
|
|
240
|
+
{"<<"}
|
|
241
|
+
</Button>
|
|
242
|
+
<Button
|
|
243
|
+
onClick={() => table.previousPage()}
|
|
244
|
+
disabled={!table.getCanPreviousPage()}
|
|
245
|
+
>
|
|
246
|
+
{"<"}
|
|
247
|
+
</Button>
|
|
248
|
+
<Text>{table.getState().pagination.pageIndex + 1}</Text>
|
|
249
|
+
|
|
250
|
+
<Button
|
|
251
|
+
onClick={() => table.nextPage()}
|
|
252
|
+
disabled={!table.getCanNextPage()}
|
|
253
|
+
>
|
|
254
|
+
{">"}
|
|
255
|
+
</Button>
|
|
256
|
+
<Button
|
|
257
|
+
onClick={() => table.lastPage()}
|
|
258
|
+
disabled={!table.getCanNextPage()}
|
|
259
|
+
>
|
|
260
|
+
{">>"}
|
|
261
|
+
</Button>
|
|
262
|
+
<select
|
|
263
|
+
value={table.getState().pagination.pageSize}
|
|
264
|
+
onChange={(e) => {
|
|
265
|
+
table.setPageSize(Number(e.target.value));
|
|
266
|
+
}}
|
|
267
|
+
>
|
|
268
|
+
{[10, 20, 30, 40, 50].map((pageSize) => (
|
|
269
|
+
<option key={pageSize} value={pageSize}>
|
|
270
|
+
{pageSize}
|
|
271
|
+
</option>
|
|
272
|
+
))}
|
|
273
|
+
</select>
|
|
274
|
+
</Flex>
|
|
275
|
+
</>
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
export default ChakraDataTable;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, { ReactNode, useEffect, useState } from "react";
|
|
2
|
+
// import { Box, Container } from "@chakra-ui/react";
|
|
3
|
+
|
|
4
|
+
// import {
|
|
5
|
+
// FilterContext,
|
|
6
|
+
// TableStatusContext,
|
|
7
|
+
// } from "./globalpartials/GlobalContext";
|
|
8
|
+
// import { FilterInterface } from "../const/types";
|
|
9
|
+
// import Footer from "./Footer";
|
|
10
|
+
import { TableContext } from "./DataTableContext";
|
|
11
|
+
import {
|
|
12
|
+
useReactTable,
|
|
13
|
+
getCoreRowModel,
|
|
14
|
+
ColumnFiltersState,
|
|
15
|
+
SortingState,
|
|
16
|
+
Column,
|
|
17
|
+
} from "@tanstack/react-table";
|
|
18
|
+
import useDataFromUrl from "./useDataFromUrl";
|
|
19
|
+
import { Container, Table } from "@chakra-ui/react";
|
|
20
|
+
|
|
21
|
+
interface DataTableProps {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
url: string;
|
|
24
|
+
columns: Column[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const DataTable = ({ columns, url, children }: DataTableProps) => {
|
|
28
|
+
const [sorting, setSorting] = useState<SortingState>([]);
|
|
29
|
+
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]); // can set initial column filter state here
|
|
30
|
+
const [pagination, setPagination] = useState({
|
|
31
|
+
pageIndex: 0, //initial page index
|
|
32
|
+
pageSize: 10, //default page size
|
|
33
|
+
});
|
|
34
|
+
const { data, loading, hasError, refreshData } = useDataFromUrl({
|
|
35
|
+
url: url,
|
|
36
|
+
defaultData: {
|
|
37
|
+
success: false,
|
|
38
|
+
results: [],
|
|
39
|
+
count: 0,
|
|
40
|
+
filterCount: 0,
|
|
41
|
+
},
|
|
42
|
+
params: {
|
|
43
|
+
pagination: JSON.stringify({
|
|
44
|
+
offset: pagination.pageIndex * pagination.pageSize,
|
|
45
|
+
rows: pagination.pageSize,
|
|
46
|
+
}),
|
|
47
|
+
sorting: JSON.stringify(
|
|
48
|
+
sorting.length > 0
|
|
49
|
+
? { field: sorting[0].id, sort: sorting[0].desc ? "desc" : "asc" }
|
|
50
|
+
: {},
|
|
51
|
+
),
|
|
52
|
+
where: JSON.stringify(
|
|
53
|
+
columnFilters.reduce((accumulator, filter) => {
|
|
54
|
+
const obj: any = {};
|
|
55
|
+
obj[filter.id] = filter.value;
|
|
56
|
+
return { ...accumulator, ...obj };
|
|
57
|
+
}, {}),
|
|
58
|
+
),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
const table = useReactTable({
|
|
62
|
+
data: data.results,
|
|
63
|
+
columns: columns,
|
|
64
|
+
getCoreRowModel: getCoreRowModel(),
|
|
65
|
+
// getPaginationRowModel: getPaginationRowModel(),
|
|
66
|
+
manualPagination: true,
|
|
67
|
+
manualSorting: true,
|
|
68
|
+
onPaginationChange: setPagination,
|
|
69
|
+
onSortingChange: setSorting,
|
|
70
|
+
onColumnFiltersChange: setColumnFilters,
|
|
71
|
+
columnResizeMode: "onChange",
|
|
72
|
+
state: {
|
|
73
|
+
pagination,
|
|
74
|
+
sorting,
|
|
75
|
+
columnFilters,
|
|
76
|
+
},
|
|
77
|
+
defaultColumn: {
|
|
78
|
+
size: 10, //starting column size
|
|
79
|
+
minSize: 10, //enforced during column resizing
|
|
80
|
+
maxSize: 10000, //enforced during column resizing
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
refreshData();
|
|
86
|
+
}, [pagination, sorting, columnFilters]);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<TableContext.Provider
|
|
90
|
+
value={{ table: { ...table }, refreshData: refreshData }}
|
|
91
|
+
>
|
|
92
|
+
{children}
|
|
93
|
+
</TableContext.Provider>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default DataTable;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Table } from "@tanstack/react-table";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
|
|
4
|
+
interface DataTableContext<T> {
|
|
5
|
+
// tableWidth: number;
|
|
6
|
+
// setTableWidth: (num: number) => void;
|
|
7
|
+
table: Table<T>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const TableContext = createContext<DataTableContext<any>>({
|
|
11
|
+
table: undefined,
|
|
12
|
+
refreshData: () => {},
|
|
13
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Flex,
|
|
3
|
+
IconButton,
|
|
4
|
+
Popover,
|
|
5
|
+
PopoverArrow,
|
|
6
|
+
PopoverBody,
|
|
7
|
+
PopoverContent,
|
|
8
|
+
PopoverTrigger,
|
|
9
|
+
Tooltip,
|
|
10
|
+
} from "@chakra-ui/react";
|
|
11
|
+
import { MdFilterAlt } from "react-icons/md";
|
|
12
|
+
import ResetFilteringButton from "./ResetFilteringButton";
|
|
13
|
+
import TableFilter from "./TableFilter";
|
|
14
|
+
|
|
15
|
+
const EditFilterButton = () => {
|
|
16
|
+
return (
|
|
17
|
+
<Popover placement="bottom-end">
|
|
18
|
+
<Tooltip label="Filter">
|
|
19
|
+
<PopoverTrigger>
|
|
20
|
+
<IconButton aria-label="filter" icon={<MdFilterAlt />} />
|
|
21
|
+
</PopoverTrigger>
|
|
22
|
+
</Tooltip>
|
|
23
|
+
|
|
24
|
+
<PopoverContent width={"auto"}>
|
|
25
|
+
<PopoverArrow />
|
|
26
|
+
<PopoverBody>
|
|
27
|
+
<Flex flexFlow={"column"} gap={"1rem"}>
|
|
28
|
+
<TableFilter />
|
|
29
|
+
<ResetFilteringButton />
|
|
30
|
+
</Flex>
|
|
31
|
+
</PopoverBody>
|
|
32
|
+
</PopoverContent>
|
|
33
|
+
</Popover>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default EditFilterButton;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Flex,
|
|
3
|
+
IconButton,
|
|
4
|
+
Popover,
|
|
5
|
+
PopoverArrow,
|
|
6
|
+
PopoverBody,
|
|
7
|
+
PopoverContent,
|
|
8
|
+
PopoverTrigger,
|
|
9
|
+
Tooltip,
|
|
10
|
+
} from "@chakra-ui/react";
|
|
11
|
+
import { MdOutlineSort } from "react-icons/md";
|
|
12
|
+
import ResetSortingButton from "./ResetSortingButton";
|
|
13
|
+
import TableSorter from "./TableSorter";
|
|
14
|
+
|
|
15
|
+
const EditSortingButton = () => {
|
|
16
|
+
return (
|
|
17
|
+
<Popover placement="bottom-end">
|
|
18
|
+
<Tooltip label="Filter">
|
|
19
|
+
<PopoverTrigger>
|
|
20
|
+
<IconButton aria-label="filter" icon={<MdOutlineSort />} />
|
|
21
|
+
</PopoverTrigger>
|
|
22
|
+
</Tooltip>
|
|
23
|
+
|
|
24
|
+
<PopoverContent width={"auto"}>
|
|
25
|
+
<PopoverArrow />
|
|
26
|
+
<PopoverBody>
|
|
27
|
+
<Flex flexFlow={"column"} gap={"0.25rem"}>
|
|
28
|
+
<TableSorter />
|
|
29
|
+
<ResetSortingButton />
|
|
30
|
+
</Flex>
|
|
31
|
+
</PopoverBody>
|
|
32
|
+
</PopoverContent>
|
|
33
|
+
</Popover>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default EditSortingButton;
|