Skip to content
New issue

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

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

Already on GitHub? # to your account

[RFR] Remove FC usage from ra-ui-materialui components #6514

Merged
merged 27 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5875e28
Remove FC usage from Link component
Aug 18, 2021
b981ac2
Remove FC usage from FilterList and FilterLiveSearch component
Aug 18, 2021
9fa718a
Remove FC usage from Pagination component
Aug 18, 2021
d3154dc
Remove FC usage from List related components
Aug 18, 2021
4020d19
Remove FC usage from Button components
Aug 18, 2021
0252515
Remove FC usage from DeleteButton and LoginForm components
Aug 18, 2021
4a645f6
Remove FC usage from BulkExportButton component
Aug 18, 2021
5ba6a57
Remove FC usage from Form related components
Aug 18, 2021
235e500
prettier on DeleteButton component
Aug 18, 2021
d427144
prettier on TabbedFormTabs
Aug 18, 2021
f656321
Remove FC usage from Layout related components
Aug 18, 2021
b79787a
Remove FC usage from BooleanField component
Aug 18, 2021
35651f0
prettier on BooleanField component
Aug 18, 2021
603caea
Remove FC usage from Fields components
Aug 18, 2021
ef0f0bf
Revert "Remove FC usage from Fields components"
Aug 18, 2021
6bb1f5b
Remove FC usage from Input components
Aug 18, 2021
ee58e62
prettier on ReferenceInput
Aug 18, 2021
45a719c
Remove FC usage from FileInput component
Aug 18, 2021
f257440
Fix BulkDeleteButton props
Aug 19, 2021
0902946
Fix passed missing `undoable` prop to DeleteWithConfirmButton
Aug 19, 2021
9eb2996
Added children prop to FileInputProps
Aug 26, 2021
76bbcc0
Added placeholder prop to FileInputProps
Aug 26, 2021
9f24cc6
Chnage children and placeholder props from ReactElement to ReactNode
Aug 26, 2021
85cb03c
Fix tests
Aug 26, 2021
4e66473
Fix lint error
Aug 26, 2021
b6a83a9
Fix FileInputProps.placeholder type
Aug 26, 2021
6291a93
Change `string | ReactNode` for `ReactNode` in the docs
Aug 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/ra-ui-materialui/src/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { FC } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Link as RRLink, LinkProps as RRLinkProps } from 'react-router-dom';
Expand All @@ -23,7 +22,7 @@ export interface LinkProps extends RRLinkProps {
className?: string;
}

const Link: FC<LinkProps> = props => {
const Link = (props: LinkProps) => {
const {
to,
children,
Expand Down
3 changes: 1 addition & 2 deletions packages/ra-ui-materialui/src/auth/#Form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { FunctionComponent } from 'react';
import PropTypes from 'prop-types';
import { Field, Form } from 'react-final-form';
import {
Expand Down Expand Up @@ -52,7 +51,7 @@ const Input = ({
/>
);

const LoginForm: FunctionComponent<Props> = props => {
const LoginForm = (props: Props) => {
const { redirectTo } = props;
const [loading, setLoading] = useSafeSetState(false);
const login = useLogin();
Expand Down
5 changes: 2 additions & 3 deletions packages/ra-ui-materialui/src/button/BulkDeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { FC } from 'react';
import PropTypes from 'prop-types';
import BulkDeleteWithConfirmButton, {
BulkDeleteWithConfirmButtonProps,
Expand Down Expand Up @@ -31,8 +30,8 @@ import BulkDeleteWithUndoButton, {
* </List>
* );
*/
const BulkDeleteButton: FC<BulkDeleteButtonProps> = ({ undoable, ...props }) =>
undoable ? (
const BulkDeleteButton = (props: BulkDeleteButtonProps) =>
props.undoable ? (
<BulkDeleteWithUndoButton {...props} />
) : (
<BulkDeleteWithConfirmButton {...props} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, Fragment, useState, ReactElement } from 'react';
import { Fragment, useState, ReactElement } from 'react';
import PropTypes from 'prop-types';
import ActionDelete from '@material-ui/icons/Delete';
import { fade } from '@material-ui/core/styles/colorManipulator';
Expand Down Expand Up @@ -37,7 +37,9 @@ const useStyles = makeStyles(

const defaultIcon = <ActionDelete />;

const BulkDeleteWithConfirmButton: FC<BulkDeleteWithConfirmButtonProps> = props => {
const BulkDeleteWithConfirmButton = (
props: BulkDeleteWithConfirmButtonProps
) => {
const {
basePath,
classes: classesOverride,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, ReactElement } from 'react';
import { ReactElement } from 'react';
import PropTypes from 'prop-types';
import ActionDelete from '@material-ui/icons/Delete';
import { fade } from '@material-ui/core/styles/colorManipulator';
Expand Down Expand Up @@ -33,7 +33,7 @@ const useStyles = makeStyles(
{ name: 'RaBulkDeleteWithUndoButton' }
);

const BulkDeleteWithUndoButton: FC<BulkDeleteWithUndoButtonProps> = props => {
const BulkDeleteWithUndoButton = (props: BulkDeleteWithUndoButtonProps) => {
const {
basePath,
classes: classesOverride,
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/BulkExportButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useCallback, FunctionComponent } from 'react';
import { useCallback } from 'react';
import PropTypes from 'prop-types';
import DownloadIcon from '@material-ui/icons/GetApp';
import {
Expand Down Expand Up @@ -36,7 +36,7 @@ import Button, { ButtonProps } from './Button';
* </List>
* );
*/
const BulkExportButton: FunctionComponent<BulkExportButtonProps> = props => {
const BulkExportButton = (props: BulkExportButtonProps) => {
const {
onClick,
label = 'ra.action.export',
Expand Down
15 changes: 7 additions & 8 deletions packages/ra-ui-materialui/src/button/BulkUpdateButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { FC } from 'react';
import PropTypes from 'prop-types';
import BulkUpdateWithConfirmButton, {
BulkUpdateWithConfirmButtonProps,
Expand Down Expand Up @@ -32,15 +31,15 @@ import { MutationMode } from 'ra-core';
* </List>
* );
*/
const BulkUpdateButton: FC<BulkUpdateButtonProps> = ({
mutationMode,
...props
}) =>
mutationMode === 'undoable' ? (
<BulkUpdateWithUndoButton {...props} />
const BulkUpdateButton = (props: BulkUpdateButtonProps) => {
const { mutationMode, ...rest } = props;

return mutationMode === 'undoable' ? (
<BulkUpdateWithUndoButton {...rest} />
) : (
<BulkUpdateWithConfirmButton mutationMode={mutationMode} {...props} />
<BulkUpdateWithConfirmButton mutationMode={mutationMode} {...rest} />
);
};

interface Props {
mutationMode?: MutationMode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, Fragment, useState, ReactElement } from 'react';
import { Fragment, useState, ReactElement } from 'react';
import PropTypes from 'prop-types';
import ActionUpdate from '@material-ui/icons/Update';
import { fade } from '@material-ui/core/styles/colorManipulator';
Expand Down Expand Up @@ -38,7 +38,9 @@ const useStyles = makeStyles(

const defaultIcon = <ActionUpdate />;

const BulkUpdateWithConfirmButton: FC<BulkUpdateWithConfirmButtonProps> = props => {
const BulkUpdateWithConfirmButton = (
props: BulkUpdateWithConfirmButtonProps
) => {
const notify = useNotify();
const refresh = useRefresh();
const translate = useTranslate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, ReactElement } from 'react';
import { ReactElement } from 'react';
import PropTypes from 'prop-types';
import ActionUpdate from '@material-ui/icons/Update';
import { fade } from '@material-ui/core/styles/colorManipulator';
Expand Down Expand Up @@ -33,7 +33,7 @@ const useStyles = makeStyles(
{ name: 'RaBulkUpdateWithUndoButton' }
);

const BulkUpdateWithUndoButton: FC<BulkUpdateWithUndoButtonProps> = props => {
const BulkUpdateWithUndoButton = (props: BulkUpdateWithUndoButtonProps) => {
const { selectedIds } = useListContext(props);
const classes = useStyles(props);
const notify = useNotify();
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, ReactElement, SyntheticEvent, ReactNode } from 'react';
import { ReactElement, SyntheticEvent, ReactNode } from 'react';
import PropTypes from 'prop-types';
import {
Button as MuiButton,
Expand Down Expand Up @@ -28,7 +28,7 @@ import { LocationDescriptor } from 'history';
* </Button>
*
*/
const Button: FC<ButtonProps> = props => {
const Button = (props: ButtonProps) => {
const {
alignIcon = 'left',
children,
Expand Down
20 changes: 11 additions & 9 deletions packages/ra-ui-materialui/src/button/CloneButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, memo, ReactElement } from 'react';
import { memo, ReactElement } from 'react';
import PropTypes from 'prop-types';
import Queue from '@material-ui/icons/Queue';
import { Link } from 'react-router-dom';
Expand All @@ -8,14 +8,16 @@ import { Record, useResourceContext } from 'ra-core';

import Button, { ButtonProps } from './Button';

export const CloneButton: FC<CloneButtonProps> = ({
basePath = '',
label = 'ra.action.clone',
scrollToTop = true,
record,
icon = defaultIcon,
...rest
}) => {
export const CloneButton = (props: CloneButtonProps) => {
const {
basePath = '',
label = 'ra.action.clone',
scrollToTop = true,
record,
icon = defaultIcon,
...rest
} = props;

const resource = useResourceContext();
const pathname = basePath ? `${basePath}/create` : `/${resource}/create`;
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/CreateButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, ReactElement, memo, useMemo } from 'react';
import { ReactElement, memo, useMemo } from 'react';
import PropTypes from 'prop-types';
import { Fab, useMediaQuery, Theme } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
Expand All @@ -23,7 +23,7 @@ import Button, { ButtonProps, sanitizeButtonRestProps } from './Button';
* <CreateButton basePath="/comments" label="Create comment" />
* );
*/
const CreateButton: FC<CreateButtonProps> = props => {
const CreateButton = (props: CreateButtonProps) => {
const {
basePath = '',
className,
Expand Down
13 changes: 5 additions & 8 deletions packages/ra-ui-materialui/src/button/DeleteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,21 @@ import { DeleteWithConfirmButton } from './DeleteWithConfirmButton';
* return <Edit actions={<EditActions />} {...props} />;
* };
*/
export const DeleteButton = ({
undoable,
mutationMode,
record,
...props
}: DeleteButtonProps) => {
export const DeleteButton = (props: DeleteButtonProps) => {
const { undoable, mutationMode, record, ...rest } = props;
const mode = getMutationMode(mutationMode, undoable);
if (!record || record.id == null) {
return null;
}

return mode === 'undoable' ? (
<DeleteWithUndoButton record={record} {...props} />
<DeleteWithUndoButton record={record} {...rest} />
) : (
<DeleteWithConfirmButton
mutationMode={mode}
record={record}
{...props}
undoable={undoable}
{...rest}
/>
);
};
Expand Down
19 changes: 10 additions & 9 deletions packages/ra-ui-materialui/src/button/EditButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, ReactElement, useMemo } from 'react';
import { ReactElement, useMemo } from 'react';
import PropTypes from 'prop-types';
import ContentCreate from '@material-ui/icons/Create';
import { ButtonProps as MuiButtonProps } from '@material-ui/core/Button';
Expand All @@ -18,14 +18,15 @@ import Button, { ButtonProps } from './Button';
* <EditButton basePath="/comments" label="Edit comment" record={record} />
* );
*/
const EditButton: FC<EditButtonProps> = ({
basePath = '',
icon = defaultIcon,
label = 'ra.action.edit',
record,
scrollToTop = true,
...rest
}) => {
const EditButton = (props: EditButtonProps) => {
const {
basePath = '',
icon = defaultIcon,
label = 'ra.action.edit',
record,
scrollToTop = true,
...rest
} = props;
const resource = useResourceContext();
return (
<Button
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/ExportButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useCallback, FunctionComponent } from 'react';
import { useCallback } from 'react';
import PropTypes from 'prop-types';
import DownloadIcon from '@material-ui/icons/GetApp';
import {
Expand All @@ -14,7 +14,7 @@ import {
} from 'ra-core';
import Button, { ButtonProps } from './Button';

const ExportButton: FunctionComponent<ExportButtonProps> = props => {
const ExportButton = (props: ExportButtonProps) => {
const {
maxResults = 1000,
onClick,
Expand Down
15 changes: 8 additions & 7 deletions packages/ra-ui-materialui/src/button/ListButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { FC, ReactElement } from 'react';
import { ReactElement } from 'react';
import PropTypes from 'prop-types';
import ActionList from '@material-ui/icons/List';
import { Link } from 'react-router-dom';
Expand Down Expand Up @@ -33,12 +33,13 @@ import Button, { ButtonProps } from './Button';
* </Edit>
* );
*/
const ListButton: FC<ListButtonProps> = ({
basePath = '',
icon = defaultIcon,
label = 'ra.action.list',
...rest
}) => {
const ListButton = (props: ListButtonProps) => {
const {
basePath = '',
icon = defaultIcon,
label = 'ra.action.list',
...rest
} = props;
const resource = useResourceContext();
return (
<Button
Expand Down
15 changes: 8 additions & 7 deletions packages/ra-ui-materialui/src/button/RefreshButton.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import * as React from 'react';
import { FC, ReactElement, MouseEvent, useCallback } from 'react';
import { ReactElement, MouseEvent, useCallback } from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import NavigationRefresh from '@material-ui/icons/Refresh';
import { refreshView } from 'ra-core';

import Button, { ButtonProps } from './Button';

const RefreshButton: FC<RefreshButtonProps> = ({
label = 'ra.action.refresh',
icon = defaultIcon,
onClick,
...rest
}) => {
const RefreshButton = (props: RefreshButtonProps) => {
const {
label = 'ra.action.refresh',
icon = defaultIcon,
onClick,
...rest
} = props;
const dispatch = useDispatch();
const handleClick = useCallback(
event => {
Expand Down
17 changes: 9 additions & 8 deletions packages/ra-ui-materialui/src/button/RefreshIconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import * as React from 'react';
import { useCallback, FC, ReactElement } from 'react';
import { useCallback, ReactElement } from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import Tooltip from '@material-ui/core/Tooltip';
import IconButton, { IconButtonProps } from '@material-ui/core/IconButton';
import NavigationRefresh from '@material-ui/icons/Refresh';
import { refreshView, useTranslate } from 'ra-core';

const RefreshIconButton: FC<RefreshIconButtonProps> = ({
label = 'ra.action.refresh',
icon = defaultIcon,
onClick,
className,
...rest
}) => {
const RefreshIconButton = (props: RefreshIconButtonProps) => {
const {
label = 'ra.action.refresh',
icon = defaultIcon,
onClick,
className,
...rest
} = props;
const dispatch = useDispatch();
const translate = useTranslate();
const handleClick = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/button/SaveButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { cloneElement, FC, ReactElement, SyntheticEvent } from 'react';
import React, { cloneElement, ReactElement, SyntheticEvent } from 'react';
import PropTypes from 'prop-types';
import Button, { ButtonProps } from '@material-ui/core/Button';
import CircularProgress from '@material-ui/core/CircularProgress';
Expand Down Expand Up @@ -58,7 +58,7 @@ import { FormRenderProps } from 'react-final-form';
* return <SaveButton {...props} onSuccess={onSuccess} />;
* }
*/
const SaveButton: FC<SaveButtonProps> = props => {
const SaveButton = (props: SaveButtonProps) => {
const {
className,
classes: classesOverride,
Expand Down
Loading