Repository navigation
refactor(list-view): eliminate any usage in ListView/utils.ts - #44186
Conversation
useTable()'s options/instance/state were all cast through `as any` because @types/react-table intentionally ships empty TableOptions/ TableInstance/TableState base interfaces, requiring consumers to merge in the plugin hooks they actually use via declaration merging. Superset never set this up, so every list-view hook consumer inherited `any`. Add src/types/react-table.d.ts augmenting TableOptions/TableInstance/ TableState with the five plugin hooks ListView uses (useFilters, useSortBy, usePagination, useRowState, useRowSelect), then genericize useListViewState<D> and its config, dropping every `as any` cast, the unused `count` spread, and the dead removeFromList/extractInputValue exports. CardCollection and TableCollection needed matching generic plumbing (and a memo-generics-preservation cast in TableCollection) to keep ListView.tsx compiling now that the hook's return values are properly typed instead of erased to `any`. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
Code Review Agent Run #b233bfActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #44186 +/- ##
===========================================
+ Coverage 66.18% 80.16% +13.98%
===========================================
Files 2925 2925
Lines 172563 172555 -8
Branches 40058 40056 -2
===========================================
+ Hits 114212 138337 +24125
+ Misses 55970 31621 -24349
- Partials 2381 2597 +216
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…lection Follow-up to apache#44186. ListView.tsx's own `columns`/bulkActions/inline row casts were still `any`, and making them properly typed exposed that TableCollection's `columns` prop was declared as `ColumnInstance<T>[]` (a react-table value that only exists post-useTable()) when what's actually passed everywhere is the raw column config array. Introduces `ListViewColumn<T>` (packages/superset-ui-core/src/components/TableCollection/utils.tsx) as a purpose-built type for that config shape: react-table's own `Column<D>` requires each column's `accessor` to be either a specific `keyof D` literal or an accessor function, but this codebase's ~20 list pages all write `accessor` as a plain (TypeScript-widened) string, so reusing `Column<D>` directly would need touching every one of those pages' column arrays — out of scope here. Also fixes a real gap uncovered along the way: `packages/superset-ui-core` and `superset-frontend`'s app code are separate TypeScript project references, so the react-table declaration-merging augmentation added in apache#44186 (app-level `src/types/react-table.d.ts`) isn't visible inside `superset-ui-core`'s own compilation. Adds a scoped copy at `packages/superset-ui-core/types/react-table.d.ts` for what that project actually uses (TableView's useTable() call, TableCollection reading isSorted/isSortedDesc off HeaderGroups). Deletes `packages/superset-ui-core/types/react-table-config.d.ts`, a pre-existing, never-effective "kitchen sink" version of the same idea: react-table's `Column` is a type alias, not an interface, so its `export interface Column<D> extends ... {}` augmentation could never actually merge. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
SUMMARY
First step in cleaning up the
anytypes that leak out ofsrc/components/ListView/utils.tsinto every consumer that callsuseListViewState(roughly 21 CRUD list pages across the app inherit it).@types/react-tabledeliberately shipsTableOptions/TableInstance/TableStateas near-empty base interfaces — the documented pattern is for each project to extend them via declaration merging with exactly the plugin hooks it uses (see the doc comment in@types/react-table's ownindex.d.ts, linking https://gist.github.com/ggascoigne/646e14c9d54258e40588a13aabf0102d). Superset never set this up, souseTable(...)inListView/utils.tswas fully cast throughas anyfor its options, initial state, and returned instance.This adds
src/types/react-table.d.ts, augmenting those three interfaces with the five plugin hooksListViewactually uses (useFilters,useSortBy,usePagination,useRowState,useRowSelect), then genericizesuseListViewState<D>and drops everyas anyin the file. Also removed two small pieces of dead code found along the way:removeFromListandextractInputValuewere both exported but had zero call sites anywhere in the codebase, and the...({ count } as any)spread intouseTable's options was a no-op (countisn't a recognized option on any react-table plugin, andpageCount— the thing actually derived from it — is already computed on the line above).CardCollectionandTableCollectionneeded matching generic plumbing to keepListView.tsxcompiling now that the hook's return values are properly typed instead of erased toanyend-to-end.TableCollectionalso needed a smallas typeof TableCollectioncast aftermemo(), sinceReact.memoerases a wrapped component's generic type parameter by default.ListView.tsxitself and its ~21 consumer pages still have plenty ofanyleft — this PR is scoped to the shared hook file only, as a first step.TESTING INSTRUCTIONS
npx tsc -b .— clean (the handful of remaining errors on a full--forcerebuild are pre-existing declaration-emit quirks in unrelated files:d3/echartstypes and a couple of.stories.tsxfiles, none of which this PR touches)npx jest src/components/ListView/ListView.test.tsx src/pages/DatasetList/DatasetList.listview.test.tsx src/pages/ChartList/ChartList.listview.test.tsx src/pages/DashboardList/DashboardList.listview.test.tsx packages/superset-ui-core/src/components/TableCollection/TableCollection.test.tsx— 5 suites, 116 tests, all passingpre-commit runon the changed files — cleanADDITIONAL INFORMATION