rusackas opened a new pull request, #40037:
URL: https://github.com/apache/superset/pull/40037
### SUMMARY
First feature-area migration of #39927 (react-redux v7 → v8 prep). Follows
the typed-hooks foundation laid in #40027.
Replaces \`useDispatch\` with the typed \`useAppDispatch\` in 18 SqlLab
files. Once every feature area has been migrated, the eventual v8 bump becomes
a one-line lockfile change.
### What's in scope
- \`useDispatch\` → \`useAppDispatch\` across all SqlLab files that consume
it (18 files).
- \`ExploreCtasResultsButton\`: drop the v7-era workaround
\`useDispatch<(dispatch: any) => Promise<JsonObject>>()\`. \`useAppDispatch\`
already returns the proper \`ThunkDispatch\` type.
- \`src/views/store.ts\`: fix \`AppDispatch\` to explicitly include
\`ThunkDispatch\` (see _Why store.ts changed_ below).
### What's deliberately NOT in scope
- **\`useSelector\` is left alone.** SqlLab uses
\`useSelector<SqlLabRootState, …>\` annotations to get tighter typing on the
\`sqlLab\` slice than the global \`RootState\` provides (the \`sqlLab\` reducer
isn't strictly typed; \`SqlLabRootState\` is a hand-rolled view of the store).
Swapping to \`useAppSelector\` would regress type quality for these callers.
Migrating \`useSelector\` is a separate concern that involves first tightening
the \`sqlLab\` reducer's types.
- **\`SaveDatasetModal/index.tsx\` is NOT migrated.** Its test uses
\`jest.spyOn(reactRedux, 'useDispatch')\`, which won't intercept calls routed
through \`useAppDispatch\` (the typed hook captures the function reference at
module evaluation time). Moving that file to the typed hook requires first
refactoring its test to use \`createWrapper\` + a mock store. Tracked for
follow-up.
- **No \`useStore\` / \`connect\` / \`shallowEqual\` migration.** These
react-redux exports remain imported from \`react-redux\` directly.
### Why store.ts changed
In a vanilla RTK setup, \`type AppDispatch = typeof store.dispatch\`
correctly includes \`ThunkDispatch\`. In Superset's setup, \`getMiddleware\` is
annotated as \`ConfigureStoreOptions['middleware']\` — a generic function type
that erases the middleware tuple. As a result, \`store.dispatch\` is inferred
as \`Dispatch<AnyAction>\`, and \`useAppDispatch()\` silently rejects thunks.
Three SqlLab files surfaced this on first try.
The minimal fix is to declare:
\`\`\`ts
export type AppDispatch = ThunkDispatch<RootState, undefined, AnyAction> &
typeof store.dispatch;
\`\`\`
A wider refactor of the middleware setup could restore inference and remove
this intersection. That's a separate cleanup.
### Why one bundled PR
All 18 swaps are the identical mechanical change (rename + import).
Splitting them into smaller PRs would multiply review noise without improving
safety, and keeping them together makes the pattern obvious for the next
feature area's migration (dashboard, explore, etc.).
### TESTING INSTRUCTIONS
1. \`pre-commit run --files\` on all 19 changed files passes cleanly
(verified locally).
2. \`npm test -- --testPathPatterns='SqlLab'\` — 408 / 411 pass on this
branch. The 3 failures are all in \`SaveDatasetModal.test.tsx\`, which is
**broken on master** (verified by stashing this PR's changes and re-running)
and not touched by this migration.
3. Open SQL Lab in dev, run queries, switch tabs, pin tables, preview
tables, save as dataset — all dispatch sites should behave identically.
### Follow-ups
- #39927 (parent): continue with dashboard, explore, components feature
areas.
- Tighten \`sqlLab\` reducer types so \`useAppSelector\` can replace
\`useSelector<SqlLabRootState, …>\`.
- Refactor \`SaveDatasetModal.test.tsx\` to use \`createWrapper\` + mock
store, then migrate \`SaveDatasetModal/index.tsx\`.
### ADDITIONAL INFORMATION
- [x] Has associated issue: #39927
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]