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

Remove deprecated defaultProps in jsx components #9124

Merged
merged 53 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
bca8db1
remove defaultProps in ReferenceField and une destructuring instead
adguernier Jul 24, 2023
08bdb97
remove defaultProps in Login and use destructuring instead
adguernier Jul 24, 2023
c756a46
remove defaultProps in BulkUpdateButton and use destructuring instead
adguernier Jul 24, 2023
08b649e
remove defaultProps in NumberField and use destructuring instead
adguernier Jul 24, 2023
fabe44a
remove defaultProps in ReferenceManyInput and use destructuring instead
adguernier Jul 24, 2023
670dc2f
remove defaultProps in ReferenceOneField and use destructuring instead
adguernier Jul 24, 2023
6d21201
remove defaultProps in SelectField ans use destructuring instead
adguernier Jul 24, 2023
eaa1fad
remove defaultProps in BooleanInput and use destructuring instead
adguernier Jul 24, 2023
117f957
remove defaultProps in FileInputPreview and use destructuring instead
adguernier Jul 24, 2023
7412886
remove defaultProps and useless props in NumberInput and use destruct…
adguernier Jul 24, 2023
cfe504b
remove defaultProps in RadioButtonGroupInput and use destructuring in…
adguernier Jul 24, 2023
a93a266
prevent multiple <DefaultLoginForm/> instanciation
adguernier Jul 25, 2023
d9c77c3
Revert "remove defaultProps in NumberField and use destructuring inst…
adguernier Jul 25, 2023
5c4eecc
re-define sortable in defaultProps in ReferenceOneField
adguernier Jul 25, 2023
bfee258
remove default props in ReferenceArrayInput and use destucturing instead
adguernier Jul 25, 2023
826ce94
remove defaultProps in ReferenceInput and use destructuring instead
adguernier Jul 25, 2023
149559b
add default sort and filter to ReferenceArrayInput
adguernier Jul 25, 2023
a4269f2
remove defaultProps in SelectInput and use destructuring instead
adguernier Jul 25, 2023
5006f08
remove defaultProps option in ArrayInput
adguernier Jul 25, 2023
73d913f
remove defaultProps in SelectArrayInput and use destucturing instead
adguernier Jul 25, 2023
b83f8b8
remove useless defaultProps in TextInput
adguernier Jul 25, 2023
8d81e38
remove defaultProps in SimpleFormIterator and use destructuring instead
adguernier Jul 25, 2023
f81e5a3
remove useless defaultProps in Loading
adguernier Jul 25, 2023
ff3e14a
remove defaultProps in InfiniteList
adguernier Jul 25, 2023
b2498da
remove defaultProps in List
adguernier Jul 25, 2023
6915841
remove defaultProps in DatagridBody
adguernier Jul 25, 2023
c421b7c
remove defaultProps in DatagridRow
adguernier Jul 25, 2023
d8910d4
remove defaultProps in LIstAction
adguernier Jul 25, 2023
b3f48a9
remove defaultProps for PureDatagridBody
adguernier Jul 25, 2023
9126559
extract data param to defaultData const to avoid a new instance of an…
adguernier Jul 28, 2023
969c0af
extract filter and sort param in const to avoid a new instance of a n…
adguernier Jul 28, 2023
51f74be
extract options param to avoid new instance of an object at each render
adguernier Jul 28, 2023
ad0b4af
remoce useless default param
adguernier Jul 28, 2023
cda1eeb
extract options params to avoid a new instance of an object at each r…
adguernier Jul 28, 2023
8f6a113
remove useless default value
adguernier Jul 28, 2023
5ecc5a7
extract default filter param
adguernier Jul 28, 2023
5a1ee3d
extract default options param
adguernier Jul 28, 2023
26de41c
extract default filter param
adguernier Jul 28, 2023
28f31d8
extract default filter param
adguernier Jul 28, 2023
6b988d9
extract default selectIds and onUnselectItems param
adguernier Jul 28, 2023
e2da27c
extract default data param
adguernier Jul 28, 2023
cec5eb3
step and textAlign defaultProps in NumberInput as before
adguernier Jul 28, 2023
2531c51
removed options in TextInput propTypes as they are not used
adguernier Jul 28, 2023
17c51aa
removed options in SelectInput propTypes as they are not used
adguernier Jul 28, 2023
6ae0220
removed options in NumberInput propTypes as they are not used
adguernier Jul 28, 2023
baa1f4c
removed required from hasBulkActions in propTypes as is not required …
adguernier Jul 28, 2023
27f69ec
make options prop optional in BooleanInput
adguernier Jul 31, 2023
65a69e1
Merge remote-tracking branch 'origin/master' into 9112-destructuring-…
adguernier Jul 31, 2023
78fc5d6
Fix tests
fzaninotto Jul 31, 2023
df75c63
Merge branch '9112-destructuring-defaultprops' of github.com:marmelab…
adguernier Jul 31, 2023
a9ff078
update source propTypes to optional, because it's optional in interface
adguernier Jul 31, 2023
93c6cec
make optionText and optionValue propTypes optional, because it's opti…
adguernier Jul 31, 2023
63eb7ca
make perPage propTypes optional, because it's optional in interfaces
adguernier Jul 31, 2023
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
8 changes: 3 additions & 5 deletions packages/ra-ui-materialui/src/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { LoginForm as DefaultLoginForm } from './LoginForm';
* );
*/
export const Login = (props: LoginProps) => {
const { children, backgroundImage, ...rest } = props;
const { children = defaultLoginForm, backgroundImage, ...rest } = props;
const containerRef = useRef<HTMLDivElement>();
let backgroundImageLoaded = false;
const checkAuth = useCheckAuth();
Expand Down Expand Up @@ -79,6 +79,8 @@ export const Login = (props: LoginProps) => {
);
};

const defaultLoginForm = <DefaultLoginForm />;

export interface LoginProps extends HtmlHTMLAttributes<HTMLDivElement> {
backgroundImage?: string;
children?: ReactNode;
Expand Down Expand Up @@ -127,7 +129,3 @@ Login.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
};

Login.defaultProps = {
children: <DefaultLoginForm />,
};
15 changes: 8 additions & 7 deletions packages/ra-ui-materialui/src/button/BulkUpdateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ import { MutationMode } from 'ra-core';
* );
*/
export const BulkUpdateButton = (props: BulkUpdateButtonProps) => {
const { mutationMode, ...rest } = props;
const { mutationMode = 'undoable', data = defaultData, ...rest } = props;

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

Expand All @@ -58,7 +62,4 @@ BulkUpdateButton.propTypes = {
icon: PropTypes.element,
};

BulkUpdateButton.defaultProps = {
mutationMode: 'undoable',
data: [],
};
const defaultData = [];
9 changes: 3 additions & 6 deletions packages/ra-ui-materialui/src/field/ReferenceField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const ReferenceField = <
>(
props: ReferenceFieldProps<RecordType, ReferenceRecordType>
) => {
const { source, emptyText, ...rest } = props;
const { source, emptyText, link = 'edit', ...rest } = props;
const record = useRecordContext<RecordType>(props);
const id = get(record, source);
const translate = useTranslate();
Expand All @@ -77,6 +77,7 @@ export const ReferenceField = <
) : (
<NonEmptyReferenceField<RecordType, ReferenceRecordType>
{...rest}
link={link}
emptyText={emptyText}
record={record}
id={id as Identifier}
Expand All @@ -102,11 +103,7 @@ ReferenceField.propTypes = {
PropTypes.string,
PropTypes.bool,
PropTypes.func,
]).isRequired,
};

ReferenceField.defaultProps = {
link: 'edit',
]),
};

export interface ReferenceFieldProps<
Expand Down
20 changes: 8 additions & 12 deletions packages/ra-ui-materialui/src/field/ReferenceManyField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export const ReferenceManyField = <
) => {
const {
children,
filter,
filter = defaultFilter,
page = 1,
pagination = null,
perPage,
perPage = 25,
reference,
resource,
sort,
source,
sort = defaultSort,
source = 'id',
target,
} = props;
const record = useRecordContext(props);
Expand Down Expand Up @@ -128,21 +128,14 @@ ReferenceManyField.propTypes = {
resource: PropTypes.string,
sortBy: PropTypes.string,
sortByOrder: fieldPropTypes.sortByOrder,
source: PropTypes.string.isRequired,
source: PropTypes.string,
sort: PropTypes.exact({
field: PropTypes.string,
order: PropTypes.string,
}),
target: PropTypes.string.isRequired,
};

ReferenceManyField.defaultProps = {
filter: {},
perPage: 25,
sort: { field: 'id', order: 'DESC' },
source: 'id',
};

// FIXME kept for backwards compatibility, unused, to be removed in v5
export const ReferenceManyFieldView: FC<ReferenceManyFieldViewProps> = props => {
const { children, pagination } = props;
Expand Down Expand Up @@ -181,3 +174,6 @@ ReferenceManyFieldView.propTypes = {
reference: PropTypes.string,
setSort: PropTypes.func,
};

const defaultFilter = {};
const defaultSort = { field: 'id', order: 'DESC' };
5 changes: 2 additions & 3 deletions packages/ra-ui-materialui/src/field/ReferenceOneField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ReferenceOneField = <
const {
children,
reference,
source,
source = 'id',
target,
emptyText,
sort,
Expand Down Expand Up @@ -120,13 +120,12 @@ ReferenceOneField.propTypes = {
label: fieldPropTypes.label,
record: PropTypes.any,
reference: PropTypes.string.isRequired,
source: PropTypes.string.isRequired,
source: PropTypes.string,
target: PropTypes.string.isRequired,
queryOptions: PropTypes.any,
};

ReferenceOneField.defaultProps = {
source: 'id',
// disable sorting on this field by default as its default source prop ('id')
// will match the default sort ({ field: 'id', order: 'DESC'})
// leading to an incorrect sort indicator in a datagrid header
Expand Down
11 changes: 3 additions & 8 deletions packages/ra-ui-materialui/src/field/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ const SelectFieldImpl = <
emptyText,
source,
choices,
optionValue,
optionText,
translateChoice,
optionValue = 'id',
optionText = 'name',
translateChoice = true,
...rest
} = props;
const record = useRecordContext(props);
Expand Down Expand Up @@ -142,11 +142,6 @@ SelectFieldImpl.propTypes = {
translateChoice: PropTypes.bool,
};

SelectFieldImpl.defaultProps = {
optionText: 'name',
optionValue: 'id',
translateChoice: true,
};
SelectFieldImpl.displayName = 'SelectFieldImpl';

export const SelectField = genericMemo(SelectFieldImpl);
Expand Down
4 changes: 0 additions & 4 deletions packages/ra-ui-materialui/src/input/ArrayInput/ArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ export const ArrayInput = (props: ArrayInputProps) => {
);
};

ArrayInput.defaultProps = {
options: {},
};

export const getArrayInputError = error => {
if (Array.isArray(error)) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export const SimpleFormIterator = (props: SimpleFormIteratorProps) => {
resource,
source,
disabled,
disableAdd,
disableAdd = false,
disableClear,
disableRemove,
disableRemove = false,
disableReordering,
inline,
getItemLabel = false,
Expand Down Expand Up @@ -229,11 +229,6 @@ export const SimpleFormIterator = (props: SimpleFormIteratorProps) => {
) : null;
};

SimpleFormIterator.defaultProps = {
disableAdd: false,
disableRemove: false,
};

SimpleFormIterator.propTypes = {
addButton: PropTypes.element,
removeButton: PropTypes.element,
Expand Down
10 changes: 4 additions & 6 deletions packages/ra-ui-materialui/src/input/BooleanInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const BooleanInput = (props: BooleanInputProps) => {
resource,
source,
validate,
options,
options = defaultOptions,
sx,
...rest
} = props;
Expand Down Expand Up @@ -114,12 +114,10 @@ BooleanInput.propTypes = {
disabled: PropTypes.bool,
};

BooleanInput.defaultProps = {
options: {},
};

export type BooleanInputProps = CommonInputProps &
SwitchProps &
Omit<FormGroupProps, 'defaultValue' | 'onChange' | 'onBlur' | 'onFocus'> & {
options: SwitchProps;
options?: SwitchProps;
};

const defaultOptions = {};
4 changes: 0 additions & 4 deletions packages/ra-ui-materialui/src/input/FileInputPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ FileInputPreview.propTypes = {
removeIcon: PropTypes.element,
};

FileInputPreview.defaultProps = {
file: undefined,
};

const PREFIX = 'RaFileInputPreview';

const FileInputPreviewClasses = {
Expand Down
4 changes: 1 addition & 3 deletions packages/ra-ui-materialui/src/input/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const NumberInput = ({
parse,
resource,
source,
step,
step = 'any',
min,
max,
validate,
Expand Down Expand Up @@ -165,14 +165,12 @@ NumberInput.propTypes = {
PropTypes.bool,
PropTypes.element,
]),
options: PropTypes.object,
resource: PropTypes.string,
source: PropTypes.string,
step: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

NumberInput.defaultProps = {
options: {},
step: 'any',
textAlign: 'right',
};
Expand Down
20 changes: 7 additions & 13 deletions packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export const RadioButtonGroupInput = (props: RadioButtonGroupInputProps) => {
margin = 'dense',
onBlur,
onChange,
options,
optionText,
optionValue,
options = defaultOptions,
optionText = 'name',
optionValue = 'id',
parse,
resource: resourceProp,
row,
row = true,
source: sourceProp,
translateChoice,
translateChoice = true,
validate,
...rest
} = props;
Expand Down Expand Up @@ -234,14 +234,6 @@ RadioButtonGroupInput.propTypes = {
translateChoice: PropTypes.bool,
};

RadioButtonGroupInput.defaultProps = {
options: {},
optionText: 'name',
optionValue: 'id',
row: true,
translateChoice: true,
};

const sanitizeRestProps = ({
afterSubmit,
allowNull,
Expand Down Expand Up @@ -299,3 +291,5 @@ const StyledFormControl = styled(FormControl, {
transformOrigin: `top ${theme.direction === 'ltr' ? 'left' : 'right'}`,
},
}));

const defaultOptions = {};
22 changes: 13 additions & 9 deletions packages/ra-ui-materialui/src/input/ReferenceArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,23 @@ import { AutocompleteArrayInput } from './AutocompleteArrayInput';
* a `setFilters` function. You can call this function to filter the results.
*/
export const ReferenceArrayInput = (props: ReferenceArrayInputProps) => {
const { children, reference } = props;
const {
children = defaultChildren,
reference,
sort,
filter = defaultFilter,
} = props;
if (React.Children.count(children) !== 1) {
throw new Error(
'<ReferenceArrayInput> only accepts a single child (like <Datagrid>)'
);
}

const controllerProps = useReferenceArrayInputController(props);
const controllerProps = useReferenceArrayInputController({
...props,
sort,
filter,
});

return (
<ResourceContextProvider value={reference}>
Expand All @@ -111,13 +120,8 @@ ReferenceArrayInput.propTypes = {
source: PropTypes.string,
};

ReferenceArrayInput.defaultProps = {
filter: {},
page: 1,
perPage: 25,
sort: { field: 'id', order: 'DESC' },
children: <AutocompleteArrayInput />,
};
const defaultChildren = <AutocompleteArrayInput />;
const defaultFilter = {};

export interface ReferenceArrayInputProps
extends InputProps,
Expand Down
21 changes: 12 additions & 9 deletions packages/ra-ui-materialui/src/input/ReferenceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,18 @@ import { AutocompleteInput } from './AutocompleteInput';
* a `setFilters` function. You can call this function to filter the results.
*/
export const ReferenceInput = (props: ReferenceInputProps) => {
const { children, reference } = props;
const {
children = defaultChildren,
reference,
sort = { field: 'id', order: 'DESC' },
filter = {},
} = props;

const controllerProps = useReferenceInputController(props);
const controllerProps = useReferenceInputController({
...props,
sort,
filter,
});

if (Children.count(children) !== 1) {
throw new Error('<ReferenceInput> only accepts a single child');
Expand Down Expand Up @@ -104,13 +113,7 @@ ReferenceInput.propTypes = {
source: PropTypes.string,
};

ReferenceInput.defaultProps = {
filter: {},
page: 1,
perPage: 25,
sort: { field: 'id', order: 'DESC' },
children: <AutocompleteInput />,
};
const defaultChildren = <AutocompleteInput />;

export interface ReferenceInputProps
extends InputProps,
Expand Down
Loading