Skip to content

Commit eab8472

Browse files
author
React-Admin CI
committed
Merge branch 'master' into next
2 parents 2de6341 + 7b848c2 commit eab8472

41 files changed

Lines changed: 131 additions & 110 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/DateRangeInput.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const EventEdit = () => (
5656
| `sx` | - | `SxProps` | - | The style to apply to the component. |
5757
| `validate` | - | `function|Array` | - | Validation rules for the input. See the [Validation Documentation](./Validation.md#per-input-validation-built-in-field-validators) for details. |
5858

59-
`<DateRangeInput>` also accept the same props as [MUI X's `<DateRangePicker>`](https://mui.com/x/api/date-pickers/date-range-picker/), except for the `format` prop (renamed `mask`),
59+
`<DateRangeInput>` also accept the same props as [MUI X's `<DateRangePicker>`](https://mui.com/x/api/date-pickers/date-range-picker/), except for the `format` prop (renamed `mask`),
6060

6161
**Tip:** Since `<DateRangeInput>` stores its value as a date array, [react-admin's validators](./Validation.md#per-input-validation-built-in-field-validators) like `minValue` or `maxValue` won't work out of the box.
6262

@@ -142,6 +142,44 @@ const EventEdit = () => {
142142
};
143143
```
144144

145+
## Using `<DateRangeInput>` as a Filter
146+
147+
`<DateRangeInput>` can also be used to filter a `<List>`.
148+
149+
However, by default, `<DateRangeInput>` returns `Date` objects with their time set to 00:00:00, which makes the upper bound *exclusive*. Usually, users will expect the upper bound to be *inclusive*.
150+
151+
This can be achieved by providing a `parse` function that sets the time of the upper bound to 23:59:59.
152+
153+
Here is an example:
154+
155+
```tsx
156+
import { DateRangeInput } from '@react-admin/ra-form-layout/DateRangeInput';
157+
import { List, Datagrid, NumberField, TextField, DateField } from 'react-admin';
158+
import { endOfDay } from 'date-fns';
159+
160+
const dateRangeFilterParse = (dates: (Date | null)[]) => {
161+
return [dates[0], dates[1] ? endOfDay(dates[1]) : dates[1]];
162+
};
163+
164+
const eventsFilters = [
165+
<DateRangeInput
166+
source="date_between"
167+
key="date_filter"
168+
parse={dateRangeFilterParse}
169+
/>,
170+
];
171+
172+
export const EventsList = () => (
173+
<List filters={eventsFilters}>
174+
<Datagrid>
175+
<NumberField source="id" />
176+
<TextField source="name" />
177+
<DateField source="date" />
178+
</Datagrid>
179+
</List>
180+
);
181+
```
182+
145183
## Providing your own `LocalizationProvider`
146184

147185
MUI X Pickers need to be wrapped in a [LocalizationProvider](https://mui.com/components/pickers/#localization) to work properly. `<DateRangeInput>` already includes a default `<LocalizationProvider>` using the `date-fns` adapter and the `enUS` locale.
@@ -171,4 +209,4 @@ export const App = () => (
171209

172210
**Note:** React-admin only supports the `date-fns` adapter for now.
173211

174-
**Tip**: React-admin already depends on `date-fns` v3 but your package manager may require you to add it to your dependencies.
212+
**Tip**: React-admin already depends on `date-fns` v3 but your package manager may require you to add it to your dependencies.

examples/demo/src/products/ProductEdit.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import {
1313
TextInput,
1414
useRecordContext,
1515
} from 'react-admin';
16+
import PhotoCameraIcon from '@mui/icons-material/PhotoCamera';
17+
import AspectRatioIcon from '@mui/icons-material/AspectRatio';
18+
import EditNoteIcon from '@mui/icons-material/EditNote';
19+
import ReviewIcon from '@mui/icons-material/Comment';
1620

1721
import { ProductEditDetails } from './ProductEditDetails';
1822
import CustomerReferenceField from '../visitors/CustomerReferenceField';
@@ -37,7 +41,9 @@ const ProductEdit = () => (
3741
<TabbedForm>
3842
<TabbedForm.Tab
3943
label="resources.products.tabs.image"
40-
sx={{ maxWidth: '40em' }}
44+
sx={{ maxWidth: '40em', minHeight: 48 }}
45+
iconPosition="start"
46+
icon={<PhotoCameraIcon />}
4147
>
4248
<Poster />
4349
<TextInput source="image" validate={req} />
@@ -46,14 +52,18 @@ const ProductEdit = () => (
4652
<TabbedForm.Tab
4753
label="resources.products.tabs.details"
4854
path="details"
49-
sx={{ maxWidth: '40em' }}
55+
sx={{ maxWidth: '40em', minHeight: 48 }}
56+
iconPosition="start"
57+
icon={<AspectRatioIcon />}
5058
>
5159
<ProductEditDetails />
5260
</TabbedForm.Tab>
5361
<TabbedForm.Tab
5462
label="resources.products.tabs.description"
5563
path="description"
56-
sx={{ maxWidth: '40em' }}
64+
sx={{ maxWidth: '40em', minHeight: 48 }}
65+
iconPosition="start"
66+
icon={<EditNoteIcon />}
5767
>
5868
<RichTextInput source="description" label="" validate={req} />
5969
</TabbedForm.Tab>
@@ -67,6 +77,9 @@ const ProductEdit = () => (
6777
/>
6878
}
6979
path="reviews"
80+
sx={{ minHeight: 48 }}
81+
iconPosition="start"
82+
icon={<ReviewIcon />}
7083
>
7184
<ReferenceManyField
7285
reference="reviews"

examples/demo/src/visitors/FullNameField.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const FullNameField = (props: Props) => {
3030
mr: 1,
3131
mt: -0.5,
3232
mb: -0.5,
33+
textDecoration: 'underline',
34+
textDecorationColor: '#bdbdbd',
3335
}}
3436
/>
3537
{record.first_name} {record.last_name}

packages/ra-core/src/form/Form.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CoreAdminContext } from '../core';
1111
import { Form } from './Form';
1212
import { useNotificationContext } from '../notification';
1313
import { useInput } from './useInput';
14-
import { required } from './validate';
14+
import { required } from './validation/validate';
1515
import {
1616
FormLevelValidation,
1717
InputLevelValidation,

packages/ra-core/src/form/Form.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { Route, Routes, useNavigate, Link, HashRouter } from 'react-router-dom';
1313
import { CoreAdminContext } from '../core';
1414
import { Form } from './Form';
1515
import { useInput } from './useInput';
16-
import { required } from './validate';
17-
import ValidationError from './ValidationError';
16+
import { required, ValidationError } from './validation';
1817
import { mergeTranslations } from '../i18n';
1918
import { I18nProvider } from '../types';
2019
import { SaveContextProvider, useNotificationContext } from '..';

packages/ra-core/src/form/Form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
UNSAFE_DataRouterStateContext,
1212
} from 'react-router';
1313

14-
import { FormGroupsProvider } from './FormGroupsProvider';
14+
import { FormGroupsProvider } from './groups/FormGroupsProvider';
1515
import { RaRecord } from '../types';
1616
import {
1717
useRecordContext,
@@ -23,7 +23,7 @@ import {
2323
SourceContextValue,
2424
useResourceContext,
2525
} from '../core';
26-
import { ValidateForm } from './getSimpleValidationResolver';
26+
import { ValidateForm } from './validation/getSimpleValidationResolver';
2727
import { WarnWhenUnsavedChanges } from './WarnWhenUnsavedChanges';
2828
import { useAugmentedForm } from './useAugmentedForm';
2929

packages/ra-core/src/form/FormDataConsumer.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { render, waitFor, screen, fireEvent } from '@testing-library/react';
33

4-
import FormDataConsumer, { FormDataConsumerView } from './FormDataConsumer';
4+
import { FormDataConsumer, FormDataConsumerView } from './FormDataConsumer';
55
import { testDataProvider } from '../dataProvider';
66
import {
77
AdminContext,

packages/ra-core/src/form/FormDataConsumer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ import { useWrappedSource } from '../core';
4242
* </Edit>
4343
* );
4444
*/
45-
const FormDataConsumer = <TFieldValues extends FieldValues = FieldValues>(
45+
export const FormDataConsumer = <
46+
TFieldValues extends FieldValues = FieldValues,
47+
>(
4648
props: ConnectedProps<TFieldValues>
4749
) => {
4850
const form = useFormContext<TFieldValues>();
@@ -83,8 +85,6 @@ export const FormDataConsumerView = <
8385
return ret === undefined ? null : ret;
8486
};
8587

86-
export default FormDataConsumer;
87-
8888
const ArraySourceRegex = new RegExp(/.+\.\d+$/);
8989

9090
export interface FormDataConsumerRenderParams<
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './ChoicesContext';
22
export * from './ChoicesContextProvider';
33
export * from './useChoicesContext';
4+
export * from './useChoices';

packages/ra-core/src/form/useChoices.spec.tsx renamed to packages/ra-core/src/form/choices/useChoices.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import expect from 'expect';
33
import { render, screen } from '@testing-library/react';
44

55
import { useChoices } from './useChoices';
6-
import { TestTranslationProvider } from '../i18n';
7-
import { useRecordContext } from '../controller';
6+
import { TestTranslationProvider } from '../../i18n';
7+
import { useRecordContext } from '../../controller';
88

99
describe('useChoices hook', () => {
1010
const defaultProps = {

0 commit comments

Comments
 (0)