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

Improve Table typing #1514

Merged
merged 217 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 211 commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
a1c1f80
Initial commit
xman343 Aug 14, 2023
f0a25cf
Merge branch 'dev' into xander-datepicker-a11y-fixes
xman343 Aug 14, 2023
a11c4b8
Merge branch 'dev' into xander-datepicker-a11y-fixes
xman343 Aug 14, 2023
23fc9bb
useId added to label date table by current month
xman343 Aug 14, 2023
d63332f
aria label added to DatePicker button in Menu ex
xman343 Aug 14, 2023
ee7425e
changeset
xman343 Aug 14, 2023
9c9f1d0
variable created for useId()
xman343 Aug 15, 2023
4a1712c
changeset update
xman343 Aug 15, 2023
4e60dd9
menu ex updated
xman343 Aug 15, 2023
4510505
menu ex label update
xman343 Aug 15, 2023
0fccd0e
Merge branch 'dev' into xander-datepicker-a11y-fixes
xman343 Aug 15, 2023
10be798
Merge branch 'dev' into xander-datepicker-a11y-fixes
xman343 Aug 15, 2023
7277515
Partially edited index.d.ts. Playground table from last week + remove…
r100-stack Aug 21, 2023
0db913c
Trying to add react-table package folder inside itwinui-react folder
r100-stack Aug 21, 2023
179330f
WIP
r100-stack Aug 21, 2023
482449b
WIP
r100-stack Aug 21, 2023
602e357
Temp allowing 1 warning in eslint
r100-stack Aug 21, 2023
26db866
Added react-table (backup) before removing the dep
r100-stack Aug 22, 2023
9932a6a
Fixed all errors (need to confirm if those changes are logically corr…
r100-stack Aug 22, 2023
b8c01a8
Change dep to local folder for `@types/react-table` and removed `colu…
r100-stack Aug 22, 2023
aa2bf77
Combined Cell from react-table-config with index.d.ts
r100-stack Aug 22, 2023
e3d6746
Combined everything from react-table-config with index.d.ts
r100-stack Aug 22, 2023
4ae39b5
WIP
r100-stack Aug 22, 2023
86b48f9
WIP
r100-stack Aug 23, 2023
2ff2b82
Working so far
r100-stack Aug 23, 2023
9b2a8f1
Not working after adding the definition for Renderer
r100-stack Aug 23, 2023
122c1f3
Working after removing other types
r100-stack Aug 23, 2023
5ba1ee7
Working after readding all definitions but removing unnecessary prope…
r100-stack Aug 23, 2023
e7adb00
WIP
r100-stack Aug 23, 2023
2f9235b
Stops working when both Filter and Cell are provided
r100-stack Aug 23, 2023
4ebff72
WIP
r100-stack Aug 23, 2023
22e1310
WIP
r100-stack Aug 23, 2023
47b3f34
WIP
r100-stack Aug 23, 2023
bfb60c5
Pasted newly merged index.d.ts from the playground
r100-stack Aug 23, 2023
538fd91
Wrapped index.d.ts code in declare module
r100-stack Aug 23, 2023
1089ecc
Deleted some comments and code from App.tsx
r100-stack Aug 23, 2023
fe5a45c
Commented out old-not-working-index.d.ts
r100-stack Aug 23, 2023
f250ba8
Removed dep on types/react-table
r100-stack Aug 23, 2023
83137c7
Fully commented out react-table-config.ts
r100-stack Aug 23, 2023
5fcc72c
Trying to import react-table types into Table.tsx
r100-stack Aug 23, 2023
df2fec3
WIP
r100-stack Aug 24, 2023
2cfc940
Updated the imports from react-table to the react-table-types.js file…
r100-stack Aug 27, 2023
eacefb4
Small trial and error changes
r100-stack Aug 28, 2023
a276dcd
Trying moving the types folder within code
r100-stack Aug 28, 2023
18d7aa5
Trying to move react-table-types.d.ts to src/core/Table/types
r100-stack Aug 28, 2023
02014c5
Add postBuildTypes.mjs to copy react-table-types.d.ts to the cjs/esm …
r100-stack Aug 28, 2023
acfb8fd
Working export of types (export type) instead of just values (export)
r100-stack Aug 28, 2023
d9914ba
Proper exports along the barrel files
r100-stack Aug 28, 2023
3eeb665
Changed some leftover imports from react-table to react-table-types.js
r100-stack Aug 28, 2023
9bfee47
Removed unnecessarily testing files
r100-stack Aug 28, 2023
e9da2e5
Modified a few files to start using TableTypes instead of directly fr…
r100-stack Aug 28, 2023
55b492c
Export TableProps
r100-stack Aug 28, 2023
6d58e8f
Fixed some type errors of missing ids in Table data's subRows
r100-stack Aug 28, 2023
ae34d45
Merge branch 'dev' into rohan/table-types
r100-stack Aug 28, 2023
6a58ad9
Added back all types on TableStoryDataType
r100-stack Aug 29, 2023
c2d1edf
Merge branch 'dev' into rohan/table-types
r100-stack Aug 29, 2023
a12ef70
Merge branch 'dev' into rohan/table-types
r100-stack Aug 29, 2023
b5ff12c
Changed all object to Record<string, unknown>
r100-stack Aug 29, 2023
4201b30
Undid some old trial and error type changes
r100-stack Aug 29, 2023
279f1be
Moved TableProps and TablePaginatorRendererProps from Table.tsx to re…
r100-stack Aug 30, 2023
0bd10bd
Moved back TableProps and TablePaginatorRendererProps from react-tabl…
r100-stack Aug 30, 2023
2557ea8
Fixed imports and undid unnecessary changes
r100-stack Aug 30, 2023
2e3424b
Undid previous trial and error change
r100-stack Aug 30, 2023
3600272
Changed flattenColumns to return columns itself since we don't suppor…
r100-stack Aug 30, 2023
76cccaa
Removed two unnecessary type assertions
r100-stack Aug 30, 2023
9749a71
Remove commented code
r100-stack Aug 30, 2023
31df020
Temporarily created react-table-objects.ts
r100-stack Aug 30, 2023
287551f
Deleted temp file react-table-objects
r100-stack Aug 30, 2023
61590ae
Corrected leftover paths
r100-stack Aug 30, 2023
034ef1d
Added paths to compilerOptions in tsconfig.json so that we can import…
r100-stack Aug 30, 2023
23c37e1
Added comment explanation
r100-stack Aug 30, 2023
3abee9f
Reformat file
r100-stack Aug 30, 2023
10e75f9
Changed all imports of the types file to now using react-table
r100-stack Aug 30, 2023
9521010
Removed the declare module wrapper to solve the "namespace does not e…
r100-stack Aug 30, 2023
30b882f
Reformat file
r100-stack Aug 30, 2023
a13ed81
Few parts of the written debug code
r100-stack Aug 30, 2023
e2df9fe
Some type error fixes
r100-stack Aug 31, 2023
26e9e4c
Some basic react table type tests
r100-stack Aug 31, 2023
4c9bd22
Added @ ts-expect-error for the existing unit test that is giving typ…
r100-stack Aug 31, 2023
afbfd2f
Added multiple @ts-ignore to stop tsc reporting the unused variable n…
r100-stack Aug 31, 2023
0e614aa
Added test:types to use tsconfig.test.json. Also edited the other pac…
r100-stack Aug 31, 2023
4e9bb57
Removed some unnecessary variable names that were unused. Thus, also …
r100-stack Aug 31, 2023
315a2d8
Fixed all type errors in Table.stories.tsx
r100-stack Aug 31, 2023
6cae5bd
Removed unnecessary satisfies
r100-stack Aug 31, 2023
00b6dc4
Exported DefaultCellProps and EditableCellProps
r100-stack Aug 31, 2023
9ab12fa
Removed code duplication
r100-stack Aug 31, 2023
c4ad330
Removed unnecessary comments
r100-stack Aug 31, 2023
45f54f7
Removed testing variables and unused imports
r100-stack Aug 31, 2023
d542969
Remove unnecessary comments
r100-stack Aug 31, 2023
6397770
Helpful explanation comments
r100-stack Aug 31, 2023
affa6e1
Tested that Column and TableTypes.Column are equivalent
r100-stack Aug 31, 2023
859d9e2
Removed unnecessary diff
r100-stack Aug 31, 2023
00396bc
Combined two similar type tests
r100-stack Aug 31, 2023
358f211
Removed unnecessary diffs
r100-stack Aug 31, 2023
c47954a
Delete old testing files
r100-stack Aug 31, 2023
eae6ee9
Removed unnecessary changes
r100-stack Aug 31, 2023
cc8ca64
Comment explanation
r100-stack Aug 31, 2023
f68aed0
Ignore react-table-types.test.tsx from jest since this file is only t…
r100-stack Aug 31, 2023
8ab6cff
Typo
r100-stack Aug 31, 2023
b8cb713
Fixed type errors in Table.stories.tsx
r100-stack Aug 31, 2023
12a99a0
Better structured code for test:types only for Table
r100-stack Aug 31, 2023
718e56f
Renamed postBuildTypes to postBuild_Types to not confuse it with scri…
r100-stack Aug 31, 2023
c5a3171
Removed unnecessary file from tsconfig.build.json
r100-stack Aug 31, 2023
732064b
Delete old testing files
r100-stack Aug 31, 2023
13e6747
Reverted playground
r100-stack Aug 31, 2023
24b09bb
Removed unnecessary `compilerOptions` from `tsconfig.json`
r100-stack Aug 31, 2023
3c1352d
Changeset
r100-stack Aug 31, 2023
e16a1c0
Merge branch 'dev' into rohan/table-types
r100-stack Aug 31, 2023
c9f583b
Revert eslint change
r100-stack Aug 31, 2023
fbbad82
Revert root level test:types to minimize file changes in PR
r100-stack Aug 31, 2023
174bf8e
Removed exporting of inner props
r100-stack Aug 31, 2023
5e94e8c
Fix a type error in Table stories
r100-stack Aug 31, 2023
67e8fcc
Reverted functionality change of the logic for flattenColumns. Added …
r100-stack Aug 31, 2023
7f9d5f4
Re-export TableProps
r100-stack Sep 1, 2023
8fa777d
Removed args
r100-stack Sep 1, 2023
6bd9547
Merge branch 'rohan/table-storybook-remove-args' into rohan/table-types
r100-stack Sep 1, 2023
45ca69b
Removed unnecessary type assertion
r100-stack Sep 1, 2023
a5bf4c7
Removed one more unnecessary type assertion
r100-stack Sep 1, 2023
4a30eeb
Merge branch 'dev' into rohan/table-storybook-remove-args
r100-stack Sep 1, 2023
ee701d4
Merge remote-tracking branch 'origin/rohan/table-storybook-remove-arg…
r100-stack Sep 1, 2023
9342581
Merge branch 'dev' into rohan/table-types
r100-stack Sep 1, 2023
08d5b6f
Added copyright header to react-table-types.tsx
r100-stack Sep 5, 2023
f7140d1
Trying to use .ts instead of .d.ts. Used declare and commented export…
r100-stack Sep 5, 2023
7bb6598
Testing change
r100-stack Sep 5, 2023
4194d20
Undid testing change
r100-stack Sep 5, 2023
fc3cfb5
Replaced default top of file comments with custom comments attributin…
r100-stack Sep 5, 2023
61137ea
Changed code divider comment's style
r100-stack Sep 5, 2023
0f47a7a
Added few reasons for hard fork of @ types/react-table
r100-stack Sep 5, 2023
fd13f3a
Change storybook types "test" to "build"
r100-stack Sep 5, 2023
8fe0b0f
Fixed type errors in Table.stories.tsx
r100-stack Sep 5, 2023
9863f51
Working exposing table entry point
r100-stack Sep 6, 2023
89bf4fe
Created a new endpoint called table
r100-stack Sep 6, 2023
2b7e175
Removed TableProps export
r100-stack Sep 6, 2023
2439952
Fixed Table storybook type errors
r100-stack Sep 6, 2023
2d0a0e5
Small Table story type improvements
r100-stack Sep 6, 2023
92c5474
Added a complex Table example
r100-stack Sep 6, 2023
28b107e
Corrected export path
r100-stack Sep 6, 2023
1980aed
Merge branch 'dev' into rohan/table-types
r100-stack Sep 6, 2023
facf20d
Removed incorrect export
r100-stack Sep 6, 2023
f262352
Removed unnecessary comment
r100-stack Sep 6, 2023
d2da820
Renamed /table entrypoint to /react-table
r100-stack Sep 6, 2023
0b9f523
Added test to confirm custom Filters don't give type errors
r100-stack Sep 6, 2023
2c31502
Revert playground
r100-stack Sep 6, 2023
de72f34
Leftover from rename /table to /react-table
r100-stack Sep 6, 2023
ddce4b5
Added the fallback react-table file
r100-stack Sep 6, 2023
2e5f0a1
Temp
r100-stack Sep 6, 2023
5d92efe
Deleted postBuild_types.mjs
r100-stack Sep 6, 2023
22df9d6
Reverted module and moduleResolution to Node16/NodeNext
r100-stack Sep 6, 2023
230b734
Revert excess change
r100-stack Sep 6, 2023
6ccf450
Merge branch 'dev' into rohan/table-types
r100-stack Sep 6, 2023
d854e1f
Removed copyfiles dep
r100-stack Sep 6, 2023
e9c27d7
Revert yarn.lock
r100-stack Sep 6, 2023
5a4fa69
Remove .stylelintrc.json leftover changes
r100-stack Sep 6, 2023
d3172f7
Remove .stylelintrc.json leftover changes
r100-stack Sep 6, 2023
30acb3b
WIP - still not working
r100-stack Sep 6, 2023
a1b9ebb
Undid .swcrc change
r100-stack Sep 6, 2023
54d0c48
Revert "WIP - still not working"
r100-stack Sep 6, 2023
a3edccd
Spacing for better text formatting
r100-stack Sep 6, 2023
40a6b72
Fixed use of incorrect endpoint
r100-stack Sep 6, 2023
809be55
Fixed reference to incorrect endpoint
r100-stack Sep 6, 2023
7a043ac
Added a small test to confirm types can be imported by file path or p…
r100-stack Sep 6, 2023
cab7f9c
Added ./react-table.d.ts to package.json -> files
r100-stack Sep 6, 2023
5bdfc9d
Mentioned "yarn test" to "yarn test:unit" in CONTRIBUTING.md
r100-stack Sep 6, 2023
174baa3
Added TODO
r100-stack Sep 6, 2023
60749e0
Build react-table types file in root folder using custom tsconfig. Re…
r100-stack Sep 6, 2023
a7f2c36
Removed unnecessary file
r100-stack Sep 6, 2023
d9830f5
Fixed few errors by fixing path
r100-stack Sep 6, 2023
5d2d043
Added emitDeclarationOnly
r100-stack Sep 7, 2023
523947f
Added react-table.d.ts to clean:build
r100-stack Sep 7, 2023
b33ef87
WIP testing
r100-stack Sep 7, 2023
e074fc5
Set module & moduleResolution to Node16 in tsconfigs. Added type: mod…
r100-stack Sep 7, 2023
6a4236c
Fixed an error of required extension for relative imports
r100-stack Sep 7, 2023
8bf2bbd
Workaround for emotion/styled not working in ESM
r100-stack Sep 7, 2023
07784ca
Fixed errors in next-playground
r100-stack Sep 7, 2023
2d95621
Merge branch 'rohan/playground-moduleResolution' into rohan/table-types
r100-stack Sep 7, 2023
5d4d1d3
Removed module/moduleResolution in astro playground
r100-stack Sep 7, 2023
06470ba
Reordering keys in package.json for clarity and uniformity
r100-stack Sep 7, 2023
efb929b
Changed moduleResolution from Node16 to Bundler
r100-stack Sep 7, 2023
a22d11c
Use moduleResolution=Node16 for next-playground since next may not su…
r100-stack Sep 7, 2023
0086c29
Merge branch 'rohan/playground-moduleResolution' into rohan/table-types
r100-stack Sep 7, 2023
eedcc83
Removed react-table.js from package.json
r100-stack Sep 7, 2023
7960276
Use file extensions when doing relative imports in the vite playground
r100-stack Sep 7, 2023
c380d88
Merge branch 'rohan/playground-moduleResolution' into rohan/table-types
r100-stack Sep 7, 2023
bc9f4c8
Updated changeset
r100-stack Sep 7, 2023
10d159e
Reverted few unnecessary changes
r100-stack Sep 7, 2023
d13ddb7
Renamed react-table-types.test.tsx to react-table.types-test.tsx to a…
r100-stack Sep 7, 2023
ab9223c
Removed unnecessary default
r100-stack Sep 7, 2023
3c953e9
Remove redundant --emitDeclarationsOnly
r100-stack Sep 7, 2023
ac68f3f
Move custom additions to the top
r100-stack Sep 7, 2023
7c1ca72
Corrected the path of tsconfig tests
r100-stack Sep 7, 2023
e19be97
Merge branch 'dev' into rohan/table-types
r100-stack Sep 7, 2023
25d7448
Merge branch 'rohan/table-types' of https://github.com/iTwin/iTwinUI …
r100-stack Sep 7, 2023
21d1c0f
Added generic to `<Table>`
r100-stack Sep 7, 2023
2f8cec6
Removed unnecessary type assertions
r100-stack Sep 7, 2023
cf815ff
Moved TableFilterProps to the custom additions section. Also moved al…
r100-stack Sep 8, 2023
2cd4729
Added clarifying comment
r100-stack Sep 8, 2023
d0c2a6a
Changed all subsets of TableRoeDataType to TableRowDataType
r100-stack Sep 8, 2023
fac1269
Fixed missing dep in dep array warning
r100-stack Sep 8, 2023
c4d7d59
Removed unnecessary test
r100-stack Sep 8, 2023
b71a06d
Revert "Removed unnecessary test"
r100-stack Sep 8, 2023
03243ad
Replaced all react-table types alias imports with individual imports …
r100-stack Sep 8, 2023
f7813ba
Leftover: Replaced all react-table types alias imports with individua…
r100-stack Sep 8, 2023
94c3e54
Removed unnecessary test
r100-stack Sep 8, 2023
280f183
Removed few unnecessary comments
r100-stack Sep 8, 2023
50ea7b9
Added react-table (remade).ts as a temp file to confirm if no types a…
r100-stack Sep 8, 2023
9655b76
Made a few changes to react-table.ts to be similar to react-table (re…
r100-stack Sep 8, 2023
f02bd8f
Deleted react-table (remade).ts
r100-stack Sep 8, 2023
2a1a04d
Reverted playground
r100-stack Sep 8, 2023
0007c27
Removed unnecessary generic type assignment
r100-stack Sep 8, 2023
6bd30f6
Make Column used in file
r100-stack Sep 8, 2023
33f9179
Reverse order of test:types and test:unit to pass --coverage in CI to…
r100-stack Sep 11, 2023
fdff0a9
Leftover changes of subset types to TableRowDataType
r100-stack Sep 11, 2023
234f4f8
Removed a few verbose types in favor of less strict types
r100-stack Sep 11, 2023
82881f6
Merge branch 'dev' into rohan/table-types
r100-stack Sep 11, 2023
7b4c2c8
Removed paths from tsconfig since they were hiding TS errors. In prog…
r100-stack Sep 12, 2023
6a76170
Revert "Removed paths from tsconfig since they were hiding TS errors.…
r100-stack Sep 12, 2023
177c226
Merge branch 'dev' into rohan/table-types
r100-stack Sep 12, 2023
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
5 changes: 5 additions & 0 deletions .changeset/fluffy-pianos-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': major
---

Table now has better type support. Users must now import types from `@itwin/itwinui-react/react-table` instead of from `@types/react-table`.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ More examples can be found in the [style guide](./STYLEGUIDE.md).

Each component has a corresponding jest test inside of its directory. Be sure to cover your added code with tests.

Use `yarn test` to run the tests. Add `--watch` flag if you want tests to rerun after changes.
Use `yarn test:unit` to run the unit tests. Run `yarn test:unit:watch` if you want unit tests to rerun after changes.

We usually do not use `describe` block and our test case should start with 'should'.

Expand Down
3 changes: 3 additions & 0 deletions apps/storybook/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ cypress-visual-screenshots/comparison
cypress-visual-screenshots/diff
cypress-visual-report
cypress/screenshots

# Compiled files
dist
2 changes: 1 addition & 1 deletion apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"vite": "^4.1.5"
},
"scripts": {
"build": "dotenv -v NODE_OPTIONS=\"--max-old-space-size=4096\" sb build",
"build": "tsc -p tsconfig.build.json && dotenv -v NODE_OPTIONS=\"--max-old-space-size=4096\" sb build",
"dev": "sb dev -p 6006 --no-open --quiet",
"lint": "eslint \"**/*.{ts,tsx}\" --max-warnings=0",
"test": "node scripts/run-tests.js",
Expand Down
2 changes: 1 addition & 1 deletion apps/storybook/src/InformationPanel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Story, Meta } from '@storybook/react';
import React from 'react';
import { CellProps } from 'react-table';
import { CellProps } from '@itwin/itwinui-react/react-table';
import { action } from '@storybook/addon-actions';
import { SvgEdit } from '@itwin/itwinui-icons-react';
import {
Expand Down
138 changes: 98 additions & 40 deletions apps/storybook/src/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type {
Row,
TableInstance,
TableState,
} from 'react-table';
TableOptions,
} from '@itwin/itwinui-react/react-table';
import {
Checkbox,
Code,
Expand All @@ -21,13 +22,10 @@ import {
Table,
Text,
tableFilters,
TableFilterValue,
TableProps,
Tooltip,
DefaultCell,
EditableCell,
TablePaginator,
TablePaginatorRendererProps,
ActionColumn,
Anchor,
SelectionColumn,
Expand All @@ -37,6 +35,10 @@ import {
ProgressRadial,
BaseFilter,
} from '@itwin/itwinui-react';
import type {
TableFilterValue,
TablePaginatorRendererProps,
} from '@itwin/itwinui-react';
import { useMemo, useState } from '@storybook/addons';
import { action } from '@storybook/addon-actions';
import {
Expand All @@ -47,6 +49,10 @@ import {
SvgStatusSuccess,
SvgStatusWarning,
} from '@itwin/itwinui-icons-react';
import { StoryFn } from '@storybook/react';

type TableProps<T extends Record<string, unknown> = Record<string, unknown>> =
React.ComponentProps<typeof Table<T>>;

export default {
title: 'Core/Table',
Expand Down Expand Up @@ -172,7 +178,9 @@ export const SelectableMulti = () => {
)}`,
)(),
[],
);
) satisfies NonNullable<
TableProps<{ name: string; description: string }>['onSelect']
>;

const onRowClick = useCallback(
(event: React.MouseEvent, row: Row) =>
Expand Down Expand Up @@ -245,7 +253,9 @@ export const Sortable = () => {
const onSort = useCallback(
(state) => action(`Sort changed. Table state: ${JSON.stringify(state)}`)(),
[],
);
) satisfies NonNullable<
TableProps<{ name: string; description: string }>['onSort']
>;

const columns = useMemo(
() => [
Expand Down Expand Up @@ -440,7 +450,7 @@ export const Filters = () => {
(
filters: TableFilterValue<TableStoryDataType>[],
state: TableState,
filteredData: Row<{ name: string; description: string }>[],
filteredData: Row<TableStoryDataType>[],
) => {
// rowInfo is used due to JSON errors when displaying row data
let rowInfo = '[';
Expand All @@ -456,7 +466,7 @@ export const Filters = () => {
)();
},
[],
);
) satisfies NonNullable<TableProps<TableStoryDataType>['onFilter']>;

return (
<Table
Expand Down Expand Up @@ -554,7 +564,12 @@ export const Expandable = () => {
)}`,
)(),
[],
);
) satisfies NonNullable<
TableProps<{
name: string;
description: string;
}>['onExpand']
>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make some of these less verbose by doing this?

Suggested change
) satisfies NonNullable<
TableProps<{
name: string;
description: string;
}>['onExpand']
>;
) satisfies NonNullable<TableProps['onExpand']>;

if the user needs additional type checking, they can add the extra data types, but shouldn't be required to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also noticed that state is any for some reason

Copy link
Member Author

@r100-stack r100-stack Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make some of these less verbose by doing this?

234f4f8: I removed all such satisfies NonNullable<...> that used { name: string; description; }. But I didn't remove the ones that already use TableStoryDataType or something similar because they were not too verbose. That way we can show some variations while still not being verbose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also noticed that state is any for some reason

Looks like this is happening when state is assigned a type from react-table-types.ts itself.

image

Because when I change it to some primitive type like string or number, the type of state is inferred correctly.

image

I haven't been able to find a fix so far, but just wanted to give a quick update while I am still searching for the fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that this was happening because in Table.tsx we were importing react-table, instead of importing by path.

E.g. in Table.d.ts generated by tsc using Table.tsx

- import type { CellProps, TableOptions, Row, TableState } from 'react-table';
+ import type { CellProps, TableOptions, Row, TableState } from../../react-table/react-table.js

Importing from react-table from this file imports from the real react-table package instead of from the path mentioned in paths of tsconfig.

I did this commit (7b4c2c8) to fix the above problem. I noticed quite a few type errors in Table.stories.tsx. To avoid convoluting this PR, I reverted that commit and will fix the above issue in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine by me


const columns = useMemo(
() => [
Expand Down Expand Up @@ -615,7 +630,12 @@ export const ExpandableSubrows = () => {
)}`,
)(),
[],
);
) satisfies NonNullable<
TableProps<{
name: string;
description: string;
}>['onExpand']
>;

const columns = useMemo(
() => [
Expand Down Expand Up @@ -826,7 +846,12 @@ export const RowInViewport = () => {

const onRowInViewport = useCallback((rowData) => {
action(`Row in view: ${JSON.stringify(rowData)}`)();
}, []);
}, []) satisfies NonNullable<
TableProps<{
name: string;
description: string;
}>['onRowInViewport']
>;

return (
<>
Expand Down Expand Up @@ -1052,7 +1077,7 @@ export const ControlledState = () => {
subRows: DemoData[];
};

const tableInstance = React.useRef<TableInstance>();
const tableInstance = React.useRef<TableInstance<DemoData>>();
const [selectedRows, setSelectedRows] = useState<DemoData[]>([]);
const [expandedRows, setExpandedRows] = useState<DemoData[]>([]);

Expand All @@ -1070,7 +1095,7 @@ export const ControlledState = () => {
},
],
[],
);
) satisfies Column<DemoData>[];

const data: DemoData[] = useMemo(
() => [
Expand Down Expand Up @@ -1135,9 +1160,24 @@ export const ControlledState = () => {
name: 'Row 2',
description: 'Description 2',
subRows: [
{ name: 'Row 2.1', description: 'Description 2.1', subRows: [] },
{ name: 'Row 2.2', description: 'Description 2.2', subRows: [] },
{ name: 'Row 2.3', description: 'Description 2.3', subRows: [] },
{
id: '2.1',
name: 'Row 2.1',
description: 'Description 2.1',
subRows: [],
},
{
id: '2.2',
name: 'Row 2.2',
description: 'Description 2.2',
subRows: [],
},
{
id: '2.3',
name: 'Row 2.3',
description: 'Description 2.3',
subRows: [],
},
],
},
{ id: '3', name: 'Row 3', description: 'Description 3', subRows: [] },
Expand Down Expand Up @@ -1180,18 +1220,28 @@ export const ControlledState = () => {
<Table
columns={columns}
emptyTableContent='No data.'
stateReducer={useCallback((newState, action, prevState, instance) => {
tableInstance.current = instance;
return newState;
}, [])}
stateReducer={
useCallback((newState, action, prevState, instance) => {
tableInstance.current = instance;
return newState;
}, []) satisfies NonNullable<TableOptions<DemoData>['stateReducer']>
}
isSelectable
onSelect={useCallback((selected) => {
setSelectedRows(selected ?? []);
}, [])}
onExpand={useCallback((expanded) => {
setExpandedRows(expanded);
}, [])}
getRowId={useCallback((rowData) => rowData.id, [])}
onSelect={
useCallback((selected) => {
setSelectedRows(selected ?? []);
}, []) satisfies NonNullable<TableProps<DemoData>['onSelect']>
}
onExpand={
useCallback((expanded) => {
setExpandedRows(expanded ?? []);
}, []) satisfies NonNullable<TableProps<DemoData>['onExpand']>
}
getRowId={
useCallback((rowData) => rowData.id, []) satisfies NonNullable<
TableOptions<DemoData>['getRowId']
>
}
data={data}
/>
</>
Expand Down Expand Up @@ -1462,9 +1512,9 @@ export const Full2 = () => {
[isRowDisabled, menuItems],
);

const rowProps = useCallback((row: Row<{ status: string | undefined }>) => {
const rowProps = useCallback((row: Row<TableStoryDataType>) => {
return {
status: row.original.status,
status: row.original.status satisfies TableStoryDataType['status'],
};
}, []);

Expand Down Expand Up @@ -1590,7 +1640,7 @@ export const Localized = () => {
};

Localized.decorators = [
(Story) => (
(Story: StoryFn) => (
<div style={{ height: '90vh' }}>
<Story />
</div>
Expand All @@ -1614,7 +1664,9 @@ export const Condensed = () => {
)}`,
)(),
[],
);
) satisfies NonNullable<
TableProps<{ name: string; description: string }>['onExpand']
>;

const columns = useMemo(
() => [
Expand Down Expand Up @@ -1864,7 +1916,7 @@ export const WithPaginator = () => {
};

WithPaginator.decorators = [
(Story) => (
(Story: StoryFn) => (
<div style={{ height: '90vh' }}>
<Story />
</div>
Expand Down Expand Up @@ -2073,7 +2125,7 @@ export const WithManualPaginatorAndFilter = () => {
};

WithManualPaginatorAndFilter.decorators = [
(Story) => (
(Story: StoryFn) => (
<div style={{ height: '90vh' }}>
<Story />
</div>
Expand Down Expand Up @@ -2231,7 +2283,7 @@ export const CustomFilter = () => {
};

CustomFilter.decorators = [
(Story) => (
(Story: StoryFn) => (
<div style={{ height: '90vh' }}>
<Story />
</div>
Expand Down Expand Up @@ -2335,7 +2387,7 @@ export const ResizableColumns = () => {
);

const [columnResizeMode, setColumnResizeMode] =
React.useState<TableProps['columnResizeMode']>('fit');
React.useState<TableProps<TableStoryDataType>['columnResizeMode']>('fit');

return (
<>
Expand Down Expand Up @@ -2563,7 +2615,7 @@ export const HorizontalScroll = () => {
};

HorizontalScroll.decorators = [
(Story) => (
(Story: StoryFn) => (
<div
style={{
height: '375px',
Expand Down Expand Up @@ -2904,7 +2956,7 @@ export const CustomizedColumns = () => {
)}`,
)(),
[],
);
) satisfies NonNullable<TableProps<(typeof data)[number]>['onExpand']>;

const data = useMemo(
() => [
Expand Down Expand Up @@ -2952,9 +3004,9 @@ export const CustomizedColumns = () => {
Header: 'Name',
accessor: 'name',
cellRenderer: (props) => (
<DefaultCell
<DefaultCell<(typeof data)[number]>
{...props}
isDisabled={(rowData) =>
isDisabled={(rowData: (typeof data)[number]) =>
isCellDisabled(rowData) || isRowDisabled(rowData)
}
/>
Expand Down Expand Up @@ -3000,6 +3052,11 @@ export const ColumnManager = () => {
id: string;
startDate: Date;
endDate: Date;
price: string;
color: string;
stock: number;
rating: string;
location: string;
};

const columns = useMemo(
Expand Down Expand Up @@ -3314,7 +3371,7 @@ export const StickyColumns = () => {
};

StickyColumns.decorators = [
(Story) => (
(Story: StoryFn) => (
<div
style={{
height: '375px',
Expand All @@ -3338,6 +3395,7 @@ export const StatusAndCellIcons = () => {
props: CellRendererProps<{
startIcon: JSX.Element;
endIcon: JSX.Element;
isLoading?: boolean;
}>,
) => (
<DefaultCell
Expand Down
13 changes: 13 additions & 0 deletions apps/storybook/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.json",

// Temporarily testing only Table.stories.tsx.
// TODO: Fix all tsc errors in all stories and then include all stories.
"include": [],
"files": ["src/Table.stories.tsx"],

"compilerOptions": {
"outDir": "dist"
}
}
Loading