Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for button components #4071

Merged
merged 5 commits into from
Nov 28, 2019
Merged

Add types for button components #4071

merged 5 commits into from
Nov 28, 2019

Conversation

fzaninotto
Copy link
Member

In the process of making the code more robust at compile time, I converted most Button components to TypeScript.

It took me no less than 6 hours. Let it be said that I don't like TypeScript.

@fzaninotto fzaninotto added the RFR Ready For Review label Nov 28, 2019
@fzaninotto fzaninotto added this to the 3.1.0 milestone Nov 28, 2019
return isSmall ? (
<Fab
component={Link}
color="primary"
className={classnames(classes.floating, className)}
to={`${basePath}/create`}
aria-label={label && translate(label)}
{...rest}
{...rest as any}
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to disable type checking here because of a material-ui bug: Button doesn't recognize the component prop :/

See mui/material-ui#15827

@fzaninotto
Copy link
Member Author

to improve readability for non-ts readers, I chose to move types to the end of each file. I did the same for secondary functions, so that a component file starts by the component definition.

...rest
}: any) => rest;

interface Props {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably extract the two first properties in a reusable interface for all our components

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the code is hard enough to read like that, I prefer a bit of duplication to a lot of indirection.

{ name: 'RaDeleteWithConfirmButton' }
);

interface Props {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lots of duplication with DeleteButton. Couldn't we improve that ?

Copy link
Member Author

Choose a reason for hiding this comment

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

That'd imply extracting the common part to another file (to avoid circular dependencies), and that would make all the Delete components harder to read... Again, I prefer some duplication for clarity.

{ name: 'RaDeleteWithUndoButton' }
);

interface Props {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

@djhi djhi merged commit 5edd79b into next Nov 28, 2019
@djhi djhi deleted the button-types branch November 28, 2019 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants