-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Conversation
There was a problem hiding this 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! 💯
export type ShowButtonProps = Props & ButtonProps; | ||
export type ShowButtonProps<RecordType extends RaRecord = any> = Props< | ||
RecordType | ||
> & | ||
ButtonProps; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ButtonProps already extends MuiButtonProps
@@ -61,12 +56,12 @@ const sanitizeRestProps = ({ | |||
}: Omit<CloneButtonProps, 'label' | 'scrollToTop' | 'icon'>) => rest; | |||
|
|||
interface Props { | |||
record?: Partial<RaRecord>; | |||
record?: any; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Problem
The
<Button>
component accepts arecord
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.