Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Table): Use latest react-table version 7.7.0. columnDefinition prop needs update. #172

Merged
merged 5 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"check:all": "yarn test:all && yarn build && yarn storybook:build && yarn styleguide:build",
"generate:attribution": "generate-attribution && mv oss-attribution/attribution.txt LICENSE-THIRD-PARTY",
"license:check": "license-checker --summary --production --onlyAllow 'MIT;Apache-2.0;Unlicense;BSD;BSD*;BSD-2-Clause;BSD-3-Clause;ISC;Zlib;WTFPL;Custom: https://github.com/tmcw/jsonlint;Custom: http://badges.github.io/stability-badges/dist/stable.svg;Custom: https://github.com/substack/node-browserify'",
"lint:fix": "eslint --fix --ext .ts --ext .tsx --ext .js --ext .jsx .",
"lint:fix": "eslint --fix --ext .ts --ext .tsx --ext .js --ext .jsx .",
"lint": "eslint --ext .ts --ext .tsx --ext .js --ext .jsx .",
"lint-staged": "lint-staged",
"prettier": "prettier --write {src,infra,styleguide}{/**/,/}**.{js,jsx,ts,tsx}",
Expand Down Expand Up @@ -123,14 +123,14 @@
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.45",
"@material-ui/pickers": "^3.2.10",
"@types/react-table": "7.0.10",
"@types/react-table": "7.7.0",
"@types/recharts": "^1.8.10",
"@types/uuid": "^7.0.0",
"clsx": "^1.1.1",
"date-fns": "^2.18.0",
"react-markdown": "^5.0.3",
"react-syntax-highlighter": "^15.4.3",
"react-table": "^7.6.3",
"react-table": "7.7.0",
"react-use-localstorage": "^3.4.1",
"recharts": "^1.8.5",
"remark-code-blocks": "^2.0.1",
Expand Down
10 changes: 5 additions & 5 deletions src/components/Table/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const columnDefinitions = [
id: 'accounts',
width: 200,
Header: '# Accounts',
accessor: 'accounts.length'
accessor: row => row.accounts ? row.accounts.length : 0
},
{
id: 'status',
Expand Down Expand Up @@ -149,7 +149,7 @@ const columnDefinitions = [
id: 'accounts',
width: 200,
Header: '# Accounts',
accessor: 'accounts.length'
accessor: row => row.accounts ? row.accounts.length : 0
}
];

Expand Down Expand Up @@ -189,7 +189,7 @@ const columnDefinitions = [
id: 'accounts',
width: 200,
Header: '# Accounts',
accessor: 'accounts.length'
accessor: row => row.accounts ? row.accounts.length : 0
},
{
id: 'status',
Expand Down Expand Up @@ -330,7 +330,7 @@ const columnDefinitions = [
id: 'accounts',
width: 200,
Header: '# Accounts',
accessor: 'accounts.length'
accessor: row => row.accounts ? row.accounts.length : 0
},
{
id: 'status',
Expand Down Expand Up @@ -537,7 +537,7 @@ const columnDefinitions = [
id: 'accounts',
width: 200,
Header: '# Accounts',
accessor: 'accounts.length'
accessor: row => row.accounts ? row.accounts.length : 0
}
];

Expand Down
9 changes: 7 additions & 2 deletions src/components/Table/data/columnDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
export default [
import { DataType } from './type';
import { Column } from '../';

const columnDefinition: Column<DataType>[] = [
{
id: 'id',
width: 200,
Expand All @@ -36,6 +39,8 @@ export default [
id: 'accounts',
width: 200,
Header: '# Accounts',
accessor: 'accounts.length',
accessor: (row) => row.accounts?.length,
},
];

export default columnDefinition;
21 changes: 21 additions & 0 deletions src/components/Table/data/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
export interface DataType {
id: string;
name: string;
createdDate?: string;
accounts?: string[];
}
15 changes: 10 additions & 5 deletions src/components/Table/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
******************************************************************************************************************** */
import React from 'react';
import { act, fireEvent, render } from '@testing-library/react';
import Table from '.';
import Table, { Column } from '.';

const data = [{ id: '123', name: 'Item one' }];
const data10 = [
interface DataType {
id: string;
name: string;
}

const data: DataType[] = [{ id: '123', name: 'Item one' }];
const data10: DataType[] = [
{ id: '0', name: 'Item0' },
{ id: '1', name: 'Item1' },
{ id: '2', name: 'Item2' },
Expand All @@ -30,7 +35,7 @@ const data10 = [
{ id: '8', name: 'Item8' },
{ id: '9', name: 'Item9' },
];
const dataGroup = [
const dataGroup: DataType[] = [
{ id: '0', name: 'Item0' },
{ id: '1', name: 'Item0' },
{ id: '2', name: 'Item1' },
Expand All @@ -43,7 +48,7 @@ const dataGroup = [
{ id: '9', name: 'Item4' },
]; // 5 groups by 'name'

const columnDefinitions = [
const columnDefinitions: Column<DataType>[] = [
{
id: 'id',
Header: 'Id',
Expand Down
3 changes: 3 additions & 0 deletions src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const useStyles = makeStyles((theme) => ({
zIndex: 1,
},
}));

export interface TableOptions<D extends object>
extends UseExpandedOptions<D>,
UseRowSelectOptions<D>,
Expand Down Expand Up @@ -574,3 +575,5 @@ export default function Table<D extends object>({
</Container>
);
}

export type { Column };
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3014,10 +3014,10 @@
dependencies:
"@types/react" "*"

"@types/react-table@7.0.10":
version "7.0.10"
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.0.10.tgz"
integrity sha512-kpUiIlGUpHn4D/0xcLqHEQ0M8Tbg6pbgZqXBDejfn1oBK2cjnOaZKLlqPrh5poIRp8JMJrOv2UWDCRiXARUGBA==
"@types/react-table@7.7.0":
version "7.7.0"
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.0.tgz#cb441a03af7303efd570b816b5ed0ea4d35ce705"
integrity sha512-xx2PJO9a0FEY7s96KWmadrhWNGxkNZgMnoKbXKPepqzz4FHKVds1tPDqWOU7NpP+dAsRli/wn0ysZ4MxWZI4Nw==
dependencies:
"@types/react" "*"

Expand Down Expand Up @@ -13771,10 +13771,10 @@ react-syntax-highlighter@^15.4.3:
prismjs "^1.22.0"
refractor "^3.2.0"

react-table@^7.6.3:
version "7.6.3"
resolved "https://registry.yarnpkg.com/react-table/-/react-table-7.6.3.tgz"
integrity sha512-hfPF13zDLxPMpLKzIKCE8RZud9T/XrRTsaCIf8zXpWZIZ2juCl7qrGpo3AQw9eAetXV5DP7s2GDm+hht7qq5Dw==
react-table@7.7.0:
version "7.7.0"
resolved "https://registry.yarnpkg.com/react-table/-/react-table-7.7.0.tgz#e2ce14d7fe3a559f7444e9ecfe8231ea8373f912"
integrity sha512-jBlj70iBwOTvvImsU9t01LjFjy4sXEtclBovl3mTiqjz23Reu0DKnRza4zlLtOPACx6j2/7MrQIthIK1Wi+LIA==

react-test-renderer@^17.0.1:
version "17.0.2"
Expand Down