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

[Demo] Remove useless defaultProps usage #9586

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/Fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ And see [the Material UI system documentation](https://mui.com/system/the-sx-pro

This prop defines the text alignment of the field when rendered inside a `<Datagrid>` cell. By default, datagrid values are left-aligned ; for numeric values, it's often better to right-align them. Set `textAlign` to `right` for that.

[`<NumberField>`](./NumberField.md) already uses `textAlign="right"`. Set the default value for this prop if you create a custom numeric field.
[`<NumberField>`](./NumberField.md) already uses `textAlign="right"`. Set the default value for this prop if you create a custom numeric field.

```jsx
const BasketTotal = () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/crm/src/deals/DealList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DealList = () => {

const dealFilters = [
<SearchInput source="q" alwaysOn />,
<OnlyMineInput alwaysOn />,
<OnlyMineInput source="sales_id" alwaysOn />,
<SelectInput source="type" choices={typeChoices} />,
];

Expand Down
4 changes: 1 addition & 3 deletions examples/crm/src/deals/OnlyMineInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { useListFilterContext, useGetIdentity } from 'react-admin';
import { Box, Switch, FormControlLabel } from '@mui/material';

export const OnlyMineInput = (_: { alwaysOn: boolean }) => {
export const OnlyMineInput = (_: { alwaysOn: boolean; source: string }) => {
const {
filterValues,
displayedFilters,
Expand Down Expand Up @@ -35,5 +35,3 @@ export const OnlyMineInput = (_: { alwaysOn: boolean }) => {
</Box>
);
};

OnlyMineInput.defaultProps = { source: 'sales_id' };
1 change: 1 addition & 0 deletions examples/demo/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const customEnglishMessages: TranslationMessages = {
fields: {
commands: 'Orders',
first_seen: 'First seen',
full_name: 'Name',
groups: 'Segments',
last_seen: 'Last seen',
last_seen_gte: 'Visited Since',
Expand Down
1 change: 1 addition & 0 deletions examples/demo/src/i18n/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const customFrenchMessages: TranslationMessages = {
commands: 'Commandes',
first_name: 'Prénom',
first_seen: 'Première visite',
full_name: 'Nom',
groups: 'Segments',
has_newsletter: 'Abonné à la newsletter',
has_ordered: 'A commandé',
Expand Down
5 changes: 0 additions & 5 deletions examples/demo/src/orders/MobileGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,4 @@ const MobileGrid = () => {
);
};

MobileGrid.defaultProps = {
data: {},
ids: [],
};

export default MobileGrid;
13 changes: 4 additions & 9 deletions examples/demo/src/orders/NbItemsField.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as React from 'react';
import { FunctionField } from 'react-admin';
import { FunctionField, FieldProps } from 'react-admin';
import { Order } from '../types';

const render = (record: Order) => record.basket.length;

const NbItemsField = () => <FunctionField<Order> render={render} />;

NbItemsField.defaultProps = {
label: 'resources.commands.fields.nb_items',
textAlign: 'right',
};
const NbItemsField = (_: FieldProps) => (
<FunctionField<Order> render={record => record.basket.length} />
);

export default NbItemsField;
15 changes: 12 additions & 3 deletions examples/demo/src/orders/OrderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ const TabbedDatagrid = () => {
>
<AddressField />
</ReferenceField>
<NbItemsField />
<NbItemsField
label="resources.commands.fields.nb_items"
textAlign="right"
/>
<NumberField
source="total_ex_taxes"
options={{
Expand Down Expand Up @@ -190,7 +193,10 @@ const TabbedDatagrid = () => {
>
<AddressField />
</ReferenceField>
<NbItemsField />
<NbItemsField
label="resources.commands.fields.nb_items"
textAlign="right"
/>
<NumberField
source="total_ex_taxes"
options={{
Expand Down Expand Up @@ -242,7 +248,10 @@ const TabbedDatagrid = () => {
>
<AddressField />
</ReferenceField>
<NbItemsField />
<NbItemsField
label="resources.commands.fields.nb_items"
textAlign="right"
/>
<NumberField
source="total_ex_taxes"
options={{
Expand Down
7 changes: 1 addition & 6 deletions examples/demo/src/products/ProductRefField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link as MuiLink } from '@mui/material';
import { useRecordContext } from 'react-admin';
import { Product } from '../types';

const ProductRefField = () => {
const ProductRefField = (_: { source: string }) => {
const record = useRecordContext<Product>();
return record ? (
<MuiLink
Expand All @@ -17,9 +17,4 @@ const ProductRefField = () => {
) : null;
};

ProductRefField.defaultProps = {
source: 'id',
label: 'Reference',
};

export default ProductRefField;
4 changes: 0 additions & 4 deletions examples/demo/src/products/ProductReferenceField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ const ProductReferenceField = (
</ReferenceField>
);

ProductReferenceField.defaultProps = {
source: 'product_id',
};

export default ProductReferenceField;
2 changes: 1 addition & 1 deletion examples/demo/src/reviews/ReviewEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const ReviewEdit = ({ id, onCancel }: Props) => {
</Labeled>
</Grid>
<Grid item xs={6}>
<Labeled>
<Labeled label="resources.reviews.fields.product_id">
<ProductReferenceField />
</Labeled>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/reviews/ReviewListDesktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ReviewListDesktop = ({ selectedRow }: ReviewListDesktopProps) => (
>
<DateField source="date" />
<CustomerReferenceField link={false} />
<ProductReferenceField link={false} />
<ProductReferenceField source="product_id" link={false} />
<StarRatingField size="small" />
<TextField source="comment" />
<TextField source="status" />
Expand Down
14 changes: 0 additions & 14 deletions examples/demo/src/reviews/ReviewListMobile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { List } from '@mui/material';
import { RecordContextProvider, useListContext } from 'react-admin';

Expand All @@ -22,17 +21,4 @@ const ReviewListMobile = () => {
);
};

ReviewListMobile.propTypes = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Linter warning in this file.

data: PropTypes.any,
hasBulkActions: PropTypes.bool.isRequired,
ids: PropTypes.array,
onToggleItem: PropTypes.func,
selectedIds: PropTypes.arrayOf(PropTypes.any).isRequired,
};

ReviewListMobile.defaultProps = {
hasBulkActions: false,
selectedIds: [],
};

export default ReviewListMobile;
4 changes: 0 additions & 4 deletions examples/demo/src/visitors/CustomerLinkField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ const CustomerLinkField = (_: FieldProps<Customer>) => {
);
};

CustomerLinkField.defaultProps = {
source: 'customer_id',
};

export default CustomerLinkField;
5 changes: 4 additions & 1 deletion examples/demo/src/visitors/VisitorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const VisitorList = () => {
},
}}
>
<CustomerLinkField />
<CustomerLinkField
source="last_name"
label="resources.customers.fields.full_name"
/>
<DateField source="last_seen" />
<NumberField
source="nb_commands"
Expand Down
5 changes: 0 additions & 5 deletions examples/simple/src/comments/CommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ const CommentGrid = () => {
);
};

CommentGrid.defaultProps = {
data: {},
ids: [],
};

const CommentMobileList = () => (
<SimpleList
primaryText={record => record.author.name}
Expand Down
5 changes: 0 additions & 5 deletions packages/ra-ui-materialui/src/input/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ NumberInput.propTypes = {
step: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

NumberInput.defaultProps = {
step: 'any',
textAlign: 'right',
};

export interface NumberInputProps
extends CommonInputProps,
Omit<
Expand Down
Loading