-
-
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
convert ra-ui-materialui layout to typescript #4875
Conversation
@fzaninotto some questions
|
I agree, good idea!
Not sure I understand. Can you give me an example? |
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.
Great work!
One general note: I tend to put the type definition after the component definition, to let JS-only developers read the code without being bothered by types first.
@@ -7,11 +27,6 @@ export default { | |||
contrastText: '#fff', | |||
}, | |||
}, | |||
typography: { |
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.
Why did you remove this one?
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.
I didn't mean to push that with this PR but I checked everywhere there is no use for variant title
const CardContentInner = props => { | ||
const { className, children } = props; | ||
const CardContentInner: FC<CardContentProps> = props => { | ||
const { className, children, ...rest } = props; |
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.
Not necessary for now, may have side effects... Please revert this change.
@@ -52,7 +52,15 @@ function goBack() { | |||
window.history.go(-1); | |||
} | |||
|
|||
const Error = props => { | |||
export interface ErrorComponentProps { |
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.
ErrocComponentProps => ErrorProps (we never include the name "component" in other interface names)
@@ -86,12 +94,8 @@ const Error = props => { | |||
</ExpansionPanel> | |||
)} | |||
<div className={classes.toolbar}> | |||
<Button | |||
variant="contained" | |||
icon={<History />} |
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.
I think startIcon
is the right prop to get the alignment icon/text
notification?: ComponentType<NotificationProps>; | ||
open?: boolean; | ||
sidebar?: ComponentType<DrawerProps>; | ||
title: TitleComponent; |
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.
It's optional at build time (but required at runtime).
@@ -62,8 +69,8 @@ const NotFound = props => { | |||
<div>{translate('ra.message.not_found')}.</div> | |||
</div> | |||
<div className={classes.toolbar}> | |||
<Button variant="contained" icon={<History />} onClick={goBack}> |
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.
use startIcon
classes: classesOverride, | ||
...rest | ||
} = props; | ||
interface Props extends DrawerProps { |
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.
let's call it SidebarProps
and export it.
const handleClose = () => dispatch(setSidebarVisibility(false)); | ||
const toggleSidebar = () => dispatch(setSidebarVisibility(!open)); | ||
const classes = useStyles({ ...props, open }); | ||
const classes = useStyles({ open }); |
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.
not good, we must pass the complete props
object or this will cause rerenderings
...rest | ||
} = props; | ||
interface Props extends DrawerProps { | ||
children: ReactElement; |
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.
I think it should be React.ReactNode
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.
ReactNode gives an error
Type 'string' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.
} | ||
|
||
const TitleForRecord: FC<Props> = props => | ||
props.record ? <Title {...props} /> : null; |
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.
the previous version white listed the props it passed to the <Title>
component. Please keep that behavior.
|
||
import { ErrorProps } from './Error'; | ||
|
||
class _ErrorBoundary extends Component< |
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 don't use the _
prefix for private classes in react-admin. I'd call the two components ErrorBoundary
and ErrorBoundaryWithRoute
.
@@ -26,6 +32,13 @@ const Title = ({ className, defaultTitle, locale, record, title, ...rest }) => { | |||
return createPortal(titleElement, container); | |||
}; | |||
|
|||
export interface TitleProps { | |||
defaultTitle: TitleComponent; |
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.
it's optional. Either one of title
or defaultTitle
should be defined.
) : null; | ||
|
||
interface Props extends TitleProps { | ||
record: TitleProps['record']; |
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.
I don't understand this type. It specializes nothing.
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.
to make record
required, but to make things more clear I can add a helper type?
export type SomeRequired<T, U extends keyof T> = Omit<T, U> &
Required<Pick<T, U>>;
+ interface Props extends <TitleProps,'record'> {
- interface Props extends TitleProps {
- record: TitleProps['record'];
|
||
export interface NotFoundProps extends RouteComponentProps { | ||
className: string; | ||
title: TitleProps['defaultTitle']; |
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.
Optional I think
@fzaninotto closed by milestone release? |
Is this PR still valid? |
@WiXSL I don't know. Let's ask François, he'll be back soon 😉 @fzaninotto I'm not sure I understand why you closed that PR. |
refs #4505