fix: datagrid typescript declarations #6122
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refs #5257, #6115.
This fixes some (but not all) of the Typescript issues with Datagrid.
Specifically:
Export DataGridState type. Maybe other types should be exported too. Note that in other places the G is not capitalized, but it is for the type.
onAllRowSelect() is (and should be) optional.
Presumably you aren't required to have a button on your empty state screens, so "emptyStateAction" should be optional.
"allRowsLabel" should be optional because you only need it if your table has a "Select all" checkbox. And also because it's optional in PropTypes.
Properties like "page" are only necessary if your table has pagination, so make UsePaginationInstanceProps props optional.
UseFiltersInstanceProps defines a bunch of weird and required properties like "preFilteredRows", "preFilteredFlatRows", "preFilteredRowsById". AFAICT none of those are valid for DataGridState except for setFilter() and setAllFilters(), and even those should be optional.
The original DataGridState class extended both UseRowSelectInstanceProps and Pick<UseRowSelectInstanceProps, 'toggleAllRowsSelected'>. Obviously that doesn't make sense because of the redundancy. But I'm not sure what does make sense. AFAIK users don't directly defined functions like toggleRowSelected() or toggleAllRowsSelected()... but there is code that calls them.
This PR doesn't address the main issues with the types, where useDatagrid() returns a TableInstance but Datagrid.datagridState is a DataGridState.
Further, I think maybe DataGridState needs to be split into two types. Consider that:
What did you change?
Typescript declarations for Datagrid.
How did you test and verify your work?
Tested locally with my own app.