(Component) =>
- connect<{}, DispatchProps, T>(
- null,
- mapDispatchToProps
- )(Component as any);
+const withDataProvider = (
+ Component: React.ComponentType
+): React.SFC
=> (props: P) => (
+
+);
export default withDataProvider;
diff --git a/packages/ra-core/src/index.ts b/packages/ra-core/src/index.ts
index 0422262ee4e..60a57683f06 100644
--- a/packages/ra-core/src/index.ts
+++ b/packages/ra-core/src/index.ts
@@ -22,6 +22,7 @@ export {
export * from './dataFetchActions';
export * from './actions';
export * from './auth';
+export * from './fetch';
export * from './i18n';
export * from './inference';
export * from './util';
diff --git a/packages/ra-core/src/util/Mutation.tsx b/packages/ra-core/src/util/Mutation.tsx
deleted file mode 100644
index 6613dfb22a8..00000000000
--- a/packages/ra-core/src/util/Mutation.tsx
+++ /dev/null
@@ -1,83 +0,0 @@
-import { Component, ReactNode } from 'react';
-import withDataProvider from './withDataProvider';
-
-type DataProviderCallback = (
- type: string,
- resource: string,
- payload?: any,
- options?: any
-) => Promise;
-
-interface ChildrenFuncParams {
- data?: any;
- loading: boolean;
- error?: any;
-}
-
-interface RawProps {
- children: (mutate: () => void, params: ChildrenFuncParams) => ReactNode;
- type: string;
- resource: string;
- payload?: any;
- options?: any;
-}
-
-interface Props extends RawProps {
- dataProvider: DataProviderCallback;
-}
-
-interface State {
- data?: any;
- loading: boolean;
- error?: any;
-}
-
-/**
- * Craft a callback to fetch the data provider and pass it to a child function
- *
- * @example
- *
- * const ApproveButton = ({ record }) => (
- *
- * {(approve) => (
- *
- * )}
- *
- * );
- */
-class Mutation extends Component {
- state = {
- data: null,
- loading: false,
- error: null,
- };
-
- mutate = () => {
- this.setState({ loading: true });
- const { dataProvider, type, resource, payload, options } = this.props;
- dataProvider(type, resource, payload, options)
- .then(({ data }) => {
- this.setState({
- data,
- loading: false,
- });
- })
- .catch(error => {
- this.setState({
- error,
- loading: false,
- });
- });
- };
-
- render() {
- const { children } = this.props;
- return children(this.mutate, this.state);
- }
-}
-
-export default withDataProvider(Mutation);
diff --git a/packages/ra-core/src/util/Query.tsx b/packages/ra-core/src/util/Query.tsx
deleted file mode 100644
index a565961534c..00000000000
--- a/packages/ra-core/src/util/Query.tsx
+++ /dev/null
@@ -1,123 +0,0 @@
-import { Component, ReactNode } from 'react';
-import { shallowEqual } from 'recompose';
-import withDataProvider from './withDataProvider';
-
-type DataProviderCallback = (
- type: string,
- resource: string,
- payload?: any,
- options?: any
-) => Promise;
-
-interface ChildrenFuncParams {
- data?: any;
- total?: number;
- loading: boolean;
- error?: any;
-}
-
-interface RawProps {
- children: (params: ChildrenFuncParams) => ReactNode;
- type: string;
- resource: string;
- payload?: any;
- options?: any;
-}
-
-interface Props extends RawProps {
- dataProvider: DataProviderCallback;
-}
-
-interface State {
- data?: any;
- total?: number;
- loading: boolean;
- error?: any;
-}
-
-/**
- * Fetch the data provider and pass the result to a child function
- *
- * @example
- *
- * const UserProfile = ({ record }) => (
- *
- * {({ data, loading, error }) => {
- * if (loading) { return ; }
- * if (error) { return ERROR
; }
- * return User {data.username}
;
- * }}
- *
- * );
- *
- * @example
- *
- * const payload = {
- * pagination: { page: 1, perPage: 10 },
- * sort: { field: 'username', order: 'ASC' },
- * };
- * const UserList = () => (
- *
- * {({ data, total, loading, error }) => {
- * if (loading) { return ; }
- * if (error) { return ERROR
; }
- * return (
- *
- *
Total users: {total}
- *
- * {data.map(user => - {user.username}
)}
- *
- *
- * );
- * }}
- *
- * );
- */
-class Query extends Component {
- state = {
- data: null,
- total: null,
- loading: true,
- error: null,
- };
-
- callDataProvider = () => {
- const { dataProvider, type, resource, payload, options } = this.props;
- dataProvider(type, resource, payload, options)
- .then(({ data, total }) => {
- this.setState({
- data,
- total,
- loading: false,
- });
- })
- .catch(error => {
- this.setState({
- error,
- loading: false,
- });
- });
- };
-
- componentDidMount = () => {
- this.callDataProvider();
- };
-
- componentDidUpdate = prevProps => {
- if (
- prevProps.type !== this.props.type ||
- prevProps.resource !== this.props.resource ||
- !shallowEqual(prevProps.payload, this.props.payload) ||
- !shallowEqual(prevProps.options, this.props.options)
- ) {
- this.callDataProvider();
- }
- };
-
- render() {
- const { children } = this.props;
- return children(this.state);
- }
-}
-
-export default withDataProvider(Query);
diff --git a/packages/ra-core/src/util/index.ts b/packages/ra-core/src/util/index.ts
index 52f502471f7..03bc482572f 100644
--- a/packages/ra-core/src/util/index.ts
+++ b/packages/ra-core/src/util/index.ts
@@ -3,33 +3,23 @@ import FieldTitle from './FieldTitle';
import getFetchedAt from './getFetchedAt';
import getFieldLabelTranslationArgs from './getFieldLabelTranslationArgs';
import ComponentPropType from './ComponentPropType';
-import HttpError from './HttpError';
import linkToRecord from './linkToRecord';
-import Mutation from './Mutation';
-import Query from './Query';
import removeEmpty from './removeEmpty';
import removeKey from './removeKey';
import resolveRedirectTo from './resolveRedirectTo';
import TestContext from './TestContext';
import warning from './warning';
-import withDataProvider from './withDataProvider';
-import * as fetchUtils from './fetch';
export {
- fetchUtils,
downloadCSV,
FieldTitle,
getFetchedAt,
getFieldLabelTranslationArgs,
ComponentPropType,
- HttpError,
linkToRecord,
- Mutation,
- Query,
removeEmpty,
removeKey,
resolveRedirectTo,
TestContext,
warning,
- withDataProvider,
};
diff --git a/yarn.lock b/yarn.lock
index 1888ad18cd5..37bc6b5bb27 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6375,14 +6375,15 @@ dom-serializer@0, dom-serializer@~0.1.0:
domelementtype "~1.1.1"
entities "~1.1.1"
-dom-testing-library@^3.12.0:
- version "3.12.2"
- resolved "https://registry.yarnpkg.com/dom-testing-library/-/dom-testing-library-3.12.2.tgz#9828a94f6c505780bb1e1e9e29afd319594e01a4"
- integrity sha512-kMj5UFm5lSxnMDtD6XWkJuzK0CX+XdMd5NSnvtpneeYQFORTF5Q5C6mdweH6hhwFcKYzAsHCfnvldg9c8HuFOA==
+dom-testing-library@^4.0.0:
+ version "4.0.1"
+ resolved "https://registry.yarnpkg.com/dom-testing-library/-/dom-testing-library-4.0.1.tgz#f21ef42aea0bd635969b4227a487e4704dbea735"
+ integrity sha512-Yr0yWlpI2QdTDEgPEk0TEekwP4VyZlJpl9E7nKP2FCKni44cb1jzjsy9KX6hBDsNA7EVlPpq9DHzO2eoEaqDZg==
dependencies:
+ "@babel/runtime" "^7.4.3"
"@sheerun/mutationobserver-shim" "^0.3.2"
- pretty-format "^23.6.0"
- wait-for-expect "^1.0.0"
+ pretty-format "^24.7.0"
+ wait-for-expect "^1.1.1"
dom-walk@^0.1.0:
version "0.1.1"
@@ -13352,14 +13353,6 @@ pretty-error@^2.0.2, pretty-error@^2.1.1:
renderkid "^2.0.1"
utila "~0.4"
-pretty-format@^23.6.0:
- version "23.6.0"
- resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.6.0.tgz#5eaac8eeb6b33b987b7fe6097ea6a8a146ab5760"
- integrity sha512-zf9NV1NSlDLDjycnwm6hpFATCGl/K1lt0R/GdkAK2O5LN/rwJoB+Mh93gGJjut4YbmecbfgLWVGSTCr0Ewvvbw==
- dependencies:
- ansi-regex "^3.0.0"
- ansi-styles "^3.2.0"
-
pretty-format@^24.7.0:
version "24.7.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.7.0.tgz#d23106bc2edcd776079c2daa5da02bcb12ed0c10"
@@ -13972,12 +13965,13 @@ react-test-renderer@~16.8.6:
react-is "^16.8.6"
scheduler "^0.13.6"
-react-testing-library@^5.2.3:
- version "5.2.3"
- resolved "https://registry.yarnpkg.com/react-testing-library/-/react-testing-library-5.2.3.tgz#c3be44bfa5eb1ba2acc1fb218785c40ebbdfe8ed"
- integrity sha512-Bw52++7uORuIQnL55lK/WQfppqAc9+8yFG4lWUp/kmSOvYDnt8J9oI5fNCfAGSQi9iIhAv9aNsI2G5rtid0nrA==
+react-testing-library@^7.0.0:
+ version "7.0.0"
+ resolved "https://registry.yarnpkg.com/react-testing-library/-/react-testing-library-7.0.0.tgz#d3b535e44de94d7b0a83c56cd2e3cfed752dcec1"
+ integrity sha512-8SHqwG+uhN9VhAgNVkVa3f7VjTw/L5CIaoAxKmy+EZuDQ6O+VsfcpRAyUw3MDL1h8S/gGrEiazmHBVL/uXsftA==
dependencies:
- dom-testing-library "^3.12.0"
+ "@babel/runtime" "^7.4.3"
+ dom-testing-library "^4.0.0"
react-themeable@^1.1.0:
version "1.1.0"
@@ -16705,10 +16699,10 @@ w3c-xmlserializer@^1.1.2:
webidl-conversions "^4.0.2"
xml-name-validator "^3.0.0"
-wait-for-expect@^1.0.0:
- version "1.0.1"
- resolved "https://registry.yarnpkg.com/wait-for-expect/-/wait-for-expect-1.0.1.tgz#73ab346ed56ed2ef66c380a59fd623755ceac0ce"
- integrity sha512-TPZMSxGWUl2DWmqdspLDEy97/S1Mqq0pzbh2A7jTq0WbJurUb5GKli+bai6ayeYdeWTF0rQNWZmUvCVZ9gkrfA==
+wait-for-expect@^1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/wait-for-expect/-/wait-for-expect-1.1.1.tgz#9cd10e07d52810af9e0aaf509872e38f3c3d81ae"
+ integrity sha512-vd9JOqqEcBbCDhARWhW85ecjaEcfBLuXgVBqatfS3iw6oU4kzAcs+sCNjF+TC9YHPImCW7ypsuQc+htscIAQCw==
wait-on@^3.2.0:
version "3.2.0"