Skip to content

Commit

Permalink
Merge branch 'next' into fork
Browse files Browse the repository at this point in the history
* next:
  Fix TabbedForm does not detect errors when source is a path Fixes marmelab#3695
  Update CoreAdminRouter.tsx
  Fix failing test in Node 12
  Add hooks to Reference list
  Add missing (double)quote in i18nProvider upgrade guide
  Add missing quote in i18nProvider upgrade guide
  Fix example for dispatch hook in upgrade guide
  useQuery/useQueryWithStore - fix loading state
  Welcome message should be visible on narrow screens
  • Loading branch information
heesienooi committed Oct 4, 2019
2 parents 681f53b + 5ef1a29 commit 33bff8e
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 24 deletions.
6 changes: 3 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ import {

-const ApproveButton = ({ dataProvider, dispatch, record }) => {
+const ApproveButton = ({ dataProvider, record }) => {
+ const dispatch = withDispatch();
+ const dispatch = useDispatch();
const handleClick = () => {
const updatedRecord = { ...record, is_approved: true };
dataProvider(UPDATE, 'comments', { id: record.id, data: updatedRecord })
Expand Down Expand Up @@ -1154,10 +1154,10 @@ const messages = {
en: englishMessages,
};
-const i18nProvider = locale => messages[locale];
+const i18nProvider = polyglotI18nProvider(locale => messages[locale], 'fr);
+const i18nProvider = polyglotI18nProvider(locale => messages[locale], 'fr');

const App = () => (
- <Admin locale="fr i18nProvider={i18nProvider}>
- <Admin locale="fr" i18nProvider={i18nProvider}>
+ <Admin i18nProvider={i18nProvider}>
...
</Admin>
Expand Down
2 changes: 2 additions & 0 deletions docs/Inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ import { FormDataConsumer } from 'react-admin';
**Tip**: When using a `FormDataConsumer` you can define `subscription` prop to pass to the `react-final-form`
{% raw %}
```jsx
import { FormDataConsumer } from 'react-admin';

Expand All @@ -1506,3 +1507,4 @@ import { FormDataConsumer } from 'react-admin';
</Edit>
);
```
{% endraw %}
63 changes: 62 additions & 1 deletion docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ title: "Reference"
* `<Actions>`
* [`<Admin>`](./Admin.md)
* `<AdminRoutes>`
* `<AppBar>`
* [`<AppBar>`](./Theming.md#customizing-the-appbar-content)
* [`<ArrayField>`](./Fields.md#arrayfield)
* [`<ArrayInput>`](./Inputs.md#arrayinput)
* [`<Authenticated>`](./Authentication.md#restricting-access-to-a-custom-page)
Expand All @@ -34,6 +34,7 @@ title: "Reference"
* [`<DateInput>`](./Inputs.md#dateinput)
* `<DeleteButton>`
* [`<Edit>`](./CreateEdit.md#the-create-and-edit-components)
* [`<EditGuesser>`](./CreateEdit.md#the-editguesser-component)
* `<EditActions>`
* `<EditButton>`
* [`<EmailField>`](./Fields.md#emailfield)
Expand All @@ -52,13 +53,16 @@ title: "Reference"
* [`<Layout>`](./Theming.md#using-a-custom-layout)
* [`<Loading>`](./Theming.md#Loading)
* [`<List>`](./List.md#the-list-component)
* [`<ListGuesser>`](./List.md#the-listguesser-component)
* `<ListButton>`
* [`<Menu>`](./Theming.md#using-a-custom-menu)
* [`<Mutation>`](./Actions.md#legacy-components-query-mutation-and-withdataprovider)
* `<Notification>`
* [`<NullableBooleanInput>`](./Inputs.md#booleaninput-and-nullablebooleaninput)
* [`<NumberField>`](./Fields.md#numberfield)
* [`<NumberInput>`](./Inputs.md#numberinput)
* [`<Pagination>`](./List.md#pagination)
* [`<Query>`](./Actions.md#legacy-components-query-mutation-and-withdataprovider)
* [`<RadioButtonGroupInput>`](./Inputs.md#radiobuttongroupinput)
* [`<ReferenceArrayField>`](./Fields.md#referencearrayfield)
* [`<ReferenceArrayInput>`](./Inputs.md#referencearrayinput)
Expand All @@ -73,6 +77,7 @@ title: "Reference"
* [`<SelectField>`](./Fields.md#selectfield)
* [`<SelectInput>`](./Inputs.md#selectinput)
* [`<Show>`](./Show.md#the-show-component)
* [`<ShowGuesser`](./Show.md#the-showguesser-component)
* `<ShowButton>`
* `<Sidebar>`
* `<SimpleList>`
Expand All @@ -84,11 +89,67 @@ title: "Reference"
* `<Tab>`
* [`<TabbedForm>`](./CreateEdit.md#the-tabbedform-component)
* [`<TabbedShowLayout>`](./Show.md#the-tabbedshowlayout-component)
* [`<TestContext>`](./UnitTesting.md#testing-custom-views)
* [`<TextField>`](./Fields.md#textfield)
* [`<TextInput>`](./Inputs.md#textinput)
* `<Title>`
* [`translate`](./Translation.md#withtranslate-hoc)
* `<Toolbar>`
* [`<UrlField>`](./Fields.md#urlfield)
* [`useAuthenticated`](./Authentication.md#useauth-hook)
* `useAuthProvider`
* [`useAuthState`](./Authentication.md#useauthstate-hook)
* `useCheckAuth`
* `useChoices`
* [`useCreate`](./Actions.md#specialized-hooks)
* `useCreateController`
* [`useDataProvider`](./Actions.md#usedataprovider-hook)
* [`useDelete`](./Actions.md#specialized-hooks)
* [`useDeleteMany`](./Actions.md#specialized-hooks)
* `useEditController`
* `useFilterState`
* [`useGetList`](./Actions.md#specialized-hooks)
* [`useGetMany`](./Actions.md#specialized-hooks)
* [`useGetManyReference`](./Actions.md#specialized-hooks)
* `useGetMatching`
* `useGetMatchingReferences`
* [`useGetOne`](./Actions.md#specialized-hooks)
* `useGetPermissions`
* `useInput`
* `useListController`
* `useListParams`
* `useLoading`
* [`useLocale`](./Translation.md#uselocale-getting-the-current-locale)
* [`useLogin`](./Authentication.md#customizing-the-login-and-logout-components)
* [`useLogout`]((./Authentication.md#customizing-the-login-and-logout-components))
* `useLogoutIfAccessDenied`
* [`useMediaQuery`](./Theming.md#usemediaquery-hook)
* [`useMutation`](./Actions.md#usemutation-hook)
* [`useNotify`](./Actions.md#handling-side-effects-in-usedataprovider)
* `usePaginationState`
* [`usePermissions`](./Authorization.mdusepermissions-hook)
* [`useQuery`](./Actions.md#usequery-hook)
* [`useQueryWithStore`](./Actions.md#usequerywithstore-hook)
* [`useRedirect`](./Actions.md#handling-side-effects-in-usedataprovider)
* `useReference`
* `useReferenceArrayFieldController`
* `useReferenceArrayInputController`
* `useReferenceInputController`
* `useReferenceManyFieldController`
* [`useRefresh`](./Actions.md#handling-side-effects-in-usedataprovider)
* [`useSetLocale`](./Translation.md#usesetlocale-changing-locale-at-runtime)
* `useShowController`
* `useSortState`
* [`useStyles`](./Theming.md#overriding-a-component-style)
* `useSuggestions`
* [`useTranslate`](./Translation.md#usetranslate-hook)
* [`useUpdate`](./Actions.md#specialized-hooks)
* `useUpdateLoading`
* [`useUpdateMany`](./Actions.md#specialized-hooks)
* [`useUnselectAll`](./Actions.md#handling-side-effects-in-usedataprovider)
* `useVersion`
* [`withDataProvider`](./Actions.md#legacy-components-query-mutation-and-withdataprovider)
* [`withTranslate`](./Translation.md#withtranslate-hoc)
* [`<WithPermissions>`](./Authorization.md#withpermissions)

</div>
17 changes: 3 additions & 14 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@
<a href="#useauth-hook"><code>useAuthenticated()</code> Hook</a>
</li>
<li class="chapter">
<a href="#useauth-hook"><code>&lt;Authenticated&gt;</code> Component</a>
<a href="#authenticated-component"><code>&lt;Authenticated&gt;</code> Component</a>
</li>
<li class="chapter">
<a href="#useauthstate-hook"><code>useAuthState()</code> Hook</a>
Expand Down Expand Up @@ -706,7 +706,7 @@
<a href="#using-a-custom-layout">Using a Custom Layout</a>
</li>
<li class="chapter">
<a href="#using-a-custom-appbar">Using a Custom AppBar</a>
<a href="#customizing-the-appbar-content">Using a Custom AppBar</a>
</li>
<li class="chapter">
<a href="#using-a-custom-menu">Using a Custom Menu</a>
Expand Down Expand Up @@ -736,7 +736,7 @@
<a href="#specialized-hooks">Specialized Hooks</a>
</li>
<li class="chapter">
<a href="#handling-side-effects-in-useDataProvider">Handling Side Effects</a>
<a href="#handling-side-effects-in-usedataprovider">Handling Side Effects</a>
</li>
<li class="chapter">
<a href="#optimistic-rendering-and-undo">Optimistic Rendering and Undo</a>
Expand Down Expand Up @@ -875,17 +875,6 @@
</div>
</div>
</div>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

ga('create', 'UA-46201426-1', 'auto');
ga('send', 'pageview');
</script>
<script src="js/prism.js"></script>
<script src="js/menu.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/CoreAdminRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {

const welcomeStyles: CSSProperties = {
width: '50%',
margin: '40vh',
margin: '40vh 25vw',
textAlign: 'center',
};

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/useListController.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('useListController', () => {
expect(updatedCrudGetListCalls[1][0].payload.filter).toEqual({
foo: 2,
});
expect(children).toBeCalledTimes(4);
expect(children).toBeCalledTimes(5);
// Check that the permanent filter is not included in the displayedFilters (passed to Filter form and button)
expect(children.mock.calls[3][0].displayedFilters).toEqual({});
// Check that the permanent filter is not included in the filterValues (passed to Filter form and button)
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/dataProvider/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const useMutation = (
callTimeOptions
);

setState({ loading: true });
setState(prevState => ({ ...prevState, loading: true }));

finalDataProvider[params.type](
params.resource,
Expand Down
2 changes: 2 additions & 0 deletions packages/ra-core/src/dataProvider/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const useQuery = (query: Query, options: QueryOptions = {}): UseQueryValue => {
? dataProviderWithDeclarativeSideEffects
: dataProvider;

setState(prevState => ({ ...prevState, loading: true }));

dataProviderWithSideEffects[type](resource, payload, rest)
.then(({ data, total }) => {
setState({
Expand Down
2 changes: 2 additions & 0 deletions packages/ra-core/src/dataProvider/useQueryWithStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ const useQueryWithStore = (
}
const dataProvider = useDataProvider();
useEffect(() => {
setState(prevState => ({ ...prevState, loading: true }));

dataProvider[type](resource, payload, options)
.then(() => {
// We don't care about the dataProvider response here, because
Expand Down
4 changes: 3 additions & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useInitializeFormWithRecord,
sanitizeEmptyValues,
} from 'ra-core';
import get from 'lodash/get';

import getFormInitialValues from './getFormInitialValues';
import Toolbar from './Toolbar';
Expand Down Expand Up @@ -287,7 +288,8 @@ export const findTabsWithErrors = (children, errors) => {

if (
inputs.some(
input => isValidElement(input) && errors[input.props.source]
input =>
isValidElement(input) && get(errors, input.props.source)
)
) {
return [...acc, child.props.label];
Expand Down
11 changes: 10 additions & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ describe('<TabbedForm />', () => {
const errors = {
field1: 'required',
field5: 'required',
field7: {
test: 'required',
},
};
const children = [
createElement(
Expand All @@ -76,10 +79,16 @@ describe('<TabbedForm />', () => {
createElement('input', { source: 'field5' }),
createElement('input', { source: 'field6' })
),
createElement(
FormTab,
{ label: 'tab4' },
createElement('input', { source: 'field7.test' }),
createElement('input', { source: 'field8' })
),
];

const tabs = findTabsWithErrors(children, errors);
expect(tabs).toEqual(['tab1', 'tab3']);
expect(tabs).toEqual(['tab1', 'tab3', 'tab4']);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ describe('<ReferenceArrayInput />', () => {
);

const myComponent = wrapper.find('MyComponent');
assert.notEqual(myComponent.prop('meta', undefined));
assert.notEqual(myComponent.prop('meta'), undefined);
});
});

0 comments on commit 33bff8e

Please sign in to comment.