Skip to content

chore(lint): convert class components to function components - #37902

Closed
rusackas wants to merge 0 commit into
masterfrom
chore/lint-cleanup-function-components
Closed

rusackas wants to merge 0 commit into
masterfrom
chore/lint-cleanup-function-components

Conversation

@rusackas

Copy link
Copy Markdown
Member

Summary

This PR converts all remaining React class components to function components using hooks to satisfy the react-prefer-function-component ESLint rule.

Key changes:

  • 76 files modified across dashboard, explore, SqlLab, Chart, and plugin areas
  • Converted class components using lifecycle methods to function components with hooks:
    • useState for state management
    • useCallback for memoized callbacks
    • useEffect for lifecycle methods (componentDidMount, componentDidUpdate, componentWillUnmount)
    • useRef for instance variables
    • useMemo for computed values
  • Updated associated test files with proper TypeScript typing
  • Fixed JSX.Element return types for components used as JSX
  • Added explicit ControlHeader props where needed
  • Fixed shouldFocus callback signature in WithPopoverMenu usage

Notable exceptions (not converted):

  • ErrorBoundary - Uses componentDidCatch which has no hook equivalent
  • DragDroppable - react-dnd's HOC system requires class instance properties

Test plan

  • Pre-commit prettier and eslint checks pass
  • CI tests pass (TypeScript errors in CI are pre-existing, not from this PR)
  • Manual testing of dashboard, explore, and SqlLab areas

Before/After

Before: Class components with lifecycle methods
After: Function components with hooks


🤖 Generated with Claude Code

@bito-code-review

bito-code-review Bot commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped - Large PR

Bito didn't auto-review this change because the pull request exceeded the line limit. No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.

@dosubot dosubot Bot added change:frontend Requires changing the frontend frontend:refactor Related to refactoring the frontend labels Feb 11, 2026
@rusackas

Copy link
Copy Markdown
Member Author

Addressed Review Comments

Thanks for the detailed review! I've addressed all 12 issues raised:

  1. ChartDataProvider.tsx:151 - ✅ Fixed: Removed handleFetchData from useEffect dependencies to prevent refetching when callbacks change
  2. reactify.tsx:101 - ✅ Fixed: Added .call({ container: containerRef.current }) to preserve legacy this context
  3. HorizonRow.tsx:73 - ✅ Fixed: Added rawData.length > 0 guard for empty array
  4. TTestTable.tsx:137-140 - ✅ Fixed: Added bounds checking with Math.min(control, data.length - 1)
  5. TableRenderers.tsx:712-717 - ✅ Fixed: Changed dependency array to use specific structural props instead of props object
  6. Chart.tsx:207 - ✅ Fixed: Initialized renderStartTimeRef with Logger.getTimestamp()
  7. DatasourceEditor.tsx:909-985 - ✅ Fixed: Pass validationErrors directly to callback instead of relying on async state
  8. Dashboard.tsx:101-103 - ✅ Fixed: Use event parameter instead of window.event
  9. SliceAdder.tsx:190-233 - ✅ Fixed: Added refs to track latest slices and selectedSliceIdsSet values
  10. Markdown.tsx:301-341 - ✅ Fixed: Added ErrorBoundary and handleRenderError callback that sets hasError to true
  11. SaveModal.tsx:760 - ✅ Fixed: Added isLoading to disabled condition for "Save & go to dashboard" button
  12. CollectionControl/index.tsx:86-206 - ✅ Fixed: Added rest spread ...headerProps to forward header props to ControlHeader

@rusackas
rusackas force-pushed the chore/lint-cleanup-function-components branch from 4c0a9e5 to 327c3c5 Compare February 12, 2026 01:07
@rusackas
rusackas requested a review from villebro as a code owner February 12, 2026 01:07
@rusackas
rusackas force-pushed the chore/lint-cleanup-function-components branch from 72ed19d to 95fbb22 Compare February 13, 2026 01:04
@rusackas
rusackas force-pushed the chore/lint-cleanup-function-components branch 2 times, most recently from 89cc44e to bd04c9f Compare February 24, 2026 03:00
@rusackas rusackas closed this Feb 25, 2026
@rusackas rusackas reopened this Feb 25, 2026
@rusackas
rusackas force-pushed the chore/lint-cleanup-function-components branch from 89951c3 to 9717d9b Compare February 26, 2026 02:05
@msyavuz

msyavuz commented Feb 27, 2026

Copy link
Copy Markdown
Member

I think this needs extensive testing on the migrated components. Not sure how we would proceed with confidence here

@rusackas
rusackas force-pushed the chore/lint-cleanup-function-components branch from df4a830 to bedf0a4 Compare February 27, 2026 23:41
@netlify

netlify Bot commented Feb 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 5106afb
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69e26d73a7b56b0008c0b7fe
😎 Deploy Preview https://deploy-preview-37902--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@rusackas

rusackas commented Mar 1, 2026

Copy link
Copy Markdown
Member Author

I think this needs extensive testing on the migrated components. Not sure how we would proceed with confidence here

Good point. I'll take a stab at adding more test coverage at least.

@rusackas
rusackas requested review from msyavuz and sadpandajoe March 2, 2026 20:17
@rusackas

rusackas commented Mar 2, 2026

Copy link
Copy Markdown
Member Author

@msyavuz I added a bunch of tests, and tried to update the DatasourceControl test here so that it doesn't crash as much (which I've been seeing on a lot of PRs). 🤞

@rusackas

rusackas commented Mar 2, 2026

Copy link
Copy Markdown
Member Author

Adding @sadpandajoe as a reviewer too... I know there's a lot of stuff going on here, curious if you have thoughts (beyond adding more AI tests) as to how to feel cozy with this long-standing tech debt cleanup :P

@geido geido added the 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR label Mar 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for db03fb1

• Environment: http://44.245.158.17:8080 (admin/admin)
• Lifetime: 48h auto-cleanup
• Updates: New commits create fresh environments automatically

import { logging } from '@apache-superset/core';
import { t } from '@apache-superset/core/ui';
import { t, SupersetTheme } from '@apache-superset/core/ui';
import { useTheme } from '@emotion/react';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you think it would make sense to import this from '@apache-superset/core/theme'?

Suggested change
import { useTheme } from '@emotion/react';
import { useTheme } from '@apache-superset/core/theme';

>
<Icons.PlusOutlined
iconSize="m"
data-test="crud-add-table-item"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be better to rely on the data-test attribute exposed by the Icon?

@rusackas

Copy link
Copy Markdown
Member Author

Thanks for the thorough testing @geido! A few notes on the findings:

  • Parallel Coordinates label color in dark mode — this file isn't touched by this PR, so that one's almost certainly pre-existing and unrelated.
  • % Rural JSON parse error and Country of Citizenship filter — these could be related since ChartRenderer.tsx and FilterScopeSelector.tsx are both converted here. Before I dig into the root cause, could you verify whether either of those reproduces on master? That'll help isolate whether they're regressions from this PR or pre-existing issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:frontend Requires changing the frontend frontend:refactor Related to refactoring the frontend packages plugins size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants