Skip to content

db-console: convert email subscription and input components to functional components#164287

Merged
trunk-io[bot] merged 2 commits intocockroachdb:masterfrom
jasonlmfong:jf/console-login-func
Feb 27, 2026
Merged

db-console: convert email subscription and input components to functional components#164287
trunk-io[bot] merged 2 commits intocockroachdb:masterfrom
jasonlmfong:jf/console-login-func

Conversation

@jasonlmfong
Copy link
Member

@jasonlmfong jasonlmfong commented Feb 24, 2026

Convert the following class components to functional style:

  • EmailSubscription:
    1. connect → useSelector + useDispatch
    2. componentDidMount/componentWillUnmount → useEffect with cleanup return
  • PasswordInput (components/input/passwordInput.tsx):
    1. Replace showPassword class state with useState
    2. Inline renderPasswordIcon helper into JSX
    3. Convert handleOnTextChange and togglePassword to local functions
  • TextInput (components/input/textInput.tsx):
    1. Replace 5 class state vars with individual useState hooks
    2. Replace static defaultProps with default parameter values
    3. Convert validateInput, handleOnTextChange, handleOnBlur to local functions

Epic: CRDB-58145
Release note: None

@trunk-io
Copy link
Contributor

trunk-io bot commented Feb 24, 2026

😎 Merged successfully - details.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jasonlmfong jasonlmfong force-pushed the jf/console-login-func branch 2 times, most recently from a4f0c95 to b751154 Compare February 25, 2026 19:17
Copy link
Member Author

@jasonlmfong jasonlmfong Feb 25, 2026

Choose a reason for hiding this comment

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

this one looks like a lot less but it's actually faithful

@jasonlmfong jasonlmfong marked this pull request as ready for review February 25, 2026 19:23
@jasonlmfong jasonlmfong requested a review from a team as a code owner February 25, 2026 19:23
import "./emailSubscription.scss";

type EmailSubscriptionProps = MapDispatchToProps & MapStateToProps;
const EmailSubscription: React.FC = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: how come some components are typed with React.FC (like this one) and others arent (like the TextInput Above)

Copy link
Member Author

Choose a reason for hiding this comment

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

no particular reason, i can make them unified

loginState,
handleLogin,
}) => {
// TODO(vilterp): focus username field on mount
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove this TODO

export class TextInput extends React.Component<TextInputProps, TextInputState> {
static defaultProps = {
initialValue: "",
validate: () => false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get why TS doesn't have an issue with this since it clearly doesn't match the type of the validate filed in TextInputProps.

Copy link
Member Author

Choose a reason for hiding this comment

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

static defaultProps wasn't typechecked unfortunately

);
};

const LoginPageConnected: React.FC<RouteComponentProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this wrapper component actually needed? Can we just pass the LoginPage component to the router directly? Also there is a location prop on the RouteComponentProps` object, so I would think that you could use that instead of the location object stored in the router reducer. Do you know if there is a reason for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

state.router.location is from redux so i imagine that was a convenience thing, i will use the location in the new version

as for removing the wrapper i left it alone because i just wanted to do the functional change

Convert the following class components to functional style:
- PasswordInput (components/input/passwordInput.tsx):
    1. Replace `showPassword` class state with `useState`
    2. Inline `renderPasswordIcon` helper into JSX
    3. Convert `handleOnTextChange` and `togglePassword` to local functions
- TextInput (components/input/textInput.tsx):
    1. Replace 5 class state vars with individual `useState` hooks
    2. Replace `static defaultProps` with default parameter values
    3. Convert `validateInput`, `handleOnTextChange`, `handleOnBlur` to local functions

Epic: CRDB-58145
Release note: None
Convert the following class components to functional style:
- EmailSubscription:
    1. connect → useSelector + useDispatch
    2. componentDidMount/componentWillUnmount → useEffect with cleanup return

Epic: CRDB-58145
Release note: None
@jasonlmfong jasonlmfong force-pushed the jf/console-login-func branch from b751154 to 2204662 Compare February 27, 2026 19:10
@jasonlmfong
Copy link
Member Author

split out the actual login changes to #164534
making it more rollback friendly

@jasonlmfong jasonlmfong changed the title db-console: convert email subscription and login components to functional components db-console: convert email subscription and input components to functional components Feb 27, 2026
@jasonlmfong
Copy link
Member Author

/trunk merge

TFTR!

@trunk-io trunk-io bot merged commit 0542ffe into cockroachdb:master Feb 27, 2026
26 checks passed
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.

3 participants