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

[TypeScript] Fix Button component props accepts a record #7764

Merged
merged 9 commits into from
May 30, 2022

Conversation

fzaninotto
Copy link
Member

Problem

The <Button> component accepts a record prop for historical reasons (it used to be injected by the Toolbar), but it doesn't make sense since it is purely a presentational component and it can be used outside of a Record context (e.g. for list view buttons)

Solution

Remove the record prop from the <Button> component, and re-add it to the descendants of <Button> that require it.

Copy link
Contributor

@slax57 slax57 left a comment

Choose a reason for hiding this comment

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

Otherwise, that's good for me! 💯

Comment on lines -68 to +74
export type ShowButtonProps = Props & ButtonProps;
export type ShowButtonProps<RecordType extends RaRecord = any> = Props<
RecordType
> &
ButtonProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

EditButton also has MuiButtonProps allowed. Should we add them here as well? (although I agree this is beyond the scope of the problem solved by this PR)

Copy link
Member Author

Choose a reason for hiding this comment

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

ButtonProps already extends MuiButtonProps

packages/ra-ui-materialui/src/button/Button.tsx Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/button/Button.tsx Outdated Show resolved Hide resolved
@fzaninotto fzaninotto changed the title Fix Button component accepts a record prop [TypeScript] Fix Button component props accepts a record May 30, 2022
packages/ra-ui-materialui/src/button/Button.spec.tsx Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/button/Button.spec.tsx Outdated Show resolved Hide resolved
@@ -61,12 +56,12 @@ const sanitizeRestProps = ({
}: Omit<CloneButtonProps, 'label' | 'scrollToTop' | 'icon'>) => rest;

interface Props {
record?: Partial<RaRecord>;
record?: any;
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 prefer Record<string, unknown> instead of any. Same everywhere we accept a RecordType

Copy link
Member Author

Choose a reason for hiding this comment

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

here, we used to accept a Partial<RaRecord>, which is indeed any

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 fix that everywhere in a dedicated PR. Passing a number as record does not make sense for instance

@djhi djhi merged commit 0ead475 into master May 30, 2022
@djhi djhi deleted the button-without-record branch May 30, 2022 12:01
@fzaninotto fzaninotto added this to the 4.1.1 milestone May 30, 2022
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

3 participants