Skip to content

refactor(list-view): eliminate any usage in ListView/utils.ts - #44186

Merged
rusackas merged 1 commit into
apache:masterfrom
rusackas:refactor/listview-utils-typing
Sep 14, 2026
Merged

rusackas merged 1 commit into
apache:masterfrom
rusackas:refactor/listview-utils-typing

Conversation

@rusackas

Copy link
Copy Markdown
Member

SUMMARY

First step in cleaning up the any types that leak out of src/components/ListView/utils.ts into every consumer that calls useListViewState (roughly 21 CRUD list pages across the app inherit it).

@types/react-table deliberately ships TableOptions/TableInstance/TableState as 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 own index.d.ts, linking https://gist.github.com/ggascoigne/646e14c9d54258e40588a13aabf0102d). Superset never set this up, so useTable(...) in ListView/utils.ts was fully cast through as any for its options, initial state, and returned instance.

This adds src/types/react-table.d.ts, augmenting those three interfaces with the five plugin hooks ListView actually uses (useFilters, useSortBy, usePagination, useRowState, useRowSelect), then genericizes useListViewState<D> and drops every as any in the file. Also removed two small pieces of dead code found along the way: removeFromList and extractInputValue were both exported but had zero call sites anywhere in the codebase, and the ...({ count } as any) spread into useTable's options was a no-op (count isn't a recognized option on any react-table plugin, and pageCount — the thing actually derived from it — is already computed on the line above).

CardCollection and TableCollection needed matching generic plumbing to keep ListView.tsx compiling now that the hook's return values are properly typed instead of erased to any end-to-end. TableCollection also needed a small as typeof TableCollection cast after memo(), since React.memo erases a wrapped component's generic type parameter by default.

ListView.tsx itself and its ~21 consumer pages still have plenty of any left — 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 --force rebuild are pre-existing declaration-emit quirks in unrelated files: d3/echarts types and a couple of .stories.tsx files, 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 passing
  • pre-commit run on the changed files — clean

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

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]>
@bito-code-review

bito-code-review Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b233bf

Actionable Suggestions - 0
Review Details
  • Files reviewed - 5 · Commit Range: 87b8fd7..87b8fd7
    • superset-frontend/packages/superset-ui-core/src/components/TableCollection/index.tsx
    • superset-frontend/src/components/ListView/CardCollection.tsx
    • superset-frontend/src/components/ListView/ListView.tsx
    • superset-frontend/src/components/ListView/utils.ts
    • superset-frontend/src/types/react-table.d.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.16%. Comparing base (36361d9) to head (87b8fd7).
⚠️ Report is 4 commits behind head on master.

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     
Flag Coverage Δ
javascript 75.67% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas
rusackas merged commit 23bd14e into apache:master Sep 14, 2026
87 checks passed
rusackas added a commit to rusackas/superset that referenced this pull request Sep 14, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants