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

convert ra-ui-materialui layout to typescript #4875

Closed
wants to merge 7 commits into from
Closed

convert ra-ui-materialui layout to typescript #4875

wants to merge 7 commits into from

Conversation

MohammedFaragallah
Copy link
Contributor

refs #4505

@MohammedFaragallah
Copy link
Contributor Author

MohammedFaragallah commented May 29, 2020

@fzaninotto some questions

  • I think we should create a separate ErrorBounday component and covert layout to a functional component
  • some component destructure classes property out I think we can remove this pattern and typescript will warn users if they pass a non-supported property

@fzaninotto
Copy link
Member

I think we should create a separate ErrorBounday component and convert Layout to a functional component

I agree, good idea!

some component destructure classes property out I think we can remove this pattern and typescript will warn users if they pass a non-supported property

Not sure I understand. Can you give me an example?

Copy link
Member

@fzaninotto fzaninotto left a 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: {
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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 {
Copy link
Member

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 />}
Copy link
Member

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;
Copy link
Member

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}>
Copy link
Member

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 {
Copy link
Member

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 });
Copy link
Member

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;
Copy link
Member

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

Copy link
Contributor Author

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;
Copy link
Member

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<
Copy link
Member

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;
Copy link
Member

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'];
Copy link
Member

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.

Copy link
Contributor Author

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'];
Copy link
Member

Choose a reason for hiding this comment

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

Optional I think

@fzaninotto fzaninotto closed this Jun 5, 2020
@MohammedFaragallah
Copy link
Contributor Author

@fzaninotto closed by milestone release?

@WiXSL
Copy link
Contributor

WiXSL commented Jul 15, 2020

Is this PR still valid?

@Luwangel
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants