React Admin 的 useUpdateMany 钩子空放

React Admin's useUpdateMany hook making empty put

我在使用 useUpdateMany 的 React Admin 挂钩时遇到问题。

如果我尝试使用 useUpdate 它可以工作,但对于很多人来说,它会发送一个空信息,这里有一些代码:

const BulkActions = props => {

    const refresh = useRefresh();
    const notify = useNotify();

    const unselectAll = useUnselectAll();
    const [updateMany, { loading, error }] = useUpdateMany(
        props.resource,
        props.selectedIds,
        { totalCommission: '100' },
        {
            onSuccess: () => {
                refresh();
                notify('Information updated', 'info', {}, true);
                unselectAll(props.resource);
            },
            onFailure: error => notify('Error: posts not updated', 'warning'),
            undoable: true
        }
    );


    return (
        <Fragment>
            <Button label="Confirm" variant="contained" onClick={ updateMany } disabled={loading} />
        </Fragment>
    );
};

我还可以看到提取正在触发信息

{
  type: 'CUSTOM_FETCH_OPTIMISTIC',
  payload: {
    ids: [
      '/api/purchases/22'
    ],
    data: {
      totalCommission: '100'
    }
  },
  meta: {
    resource: 'purchases',
    fetch: 'UPDATE_MANY',
    optimistic: true
  }
}

编辑

这是数据提供者

import React from "react";
import { Redirect, Route } from "react-router-dom";
import {API_BASE_URL} from '../constants/constants'
import { hydraDataProvider as baseHydraDataProvider, fetchHydra as baseFetchHydra } from "@api-platform/admin";
import { parseHydraDocumentation } from "@api-platform/api-doc-parser";

const entrypoint = API_BASE_URL;

const fetchHeaders = { Authorization: `Bearer ${localStorage.getItem("token")}` };
const fetchHydra = (url, options = {}) => baseFetchHydra(url, {
    ...options,
    headers: new Headers(fetchHeaders),
});

const apiDocumentationParser = entrypoint => parseHydraDocumentation(entrypoint, { headers: new Headers(fetchHeaders) })
    .then(
        ({ api }) => ({ api }),
        (result) => {
            const {api, status} = result;
            if (result.status === 401) {
                return Promise.resolve({
                    api,
                    status,
                    customRoutes: [
                        <Route path="/" render={() => <Redirect to="/login" />} />,
                    ],
                });
            }

            return Promise.reject(result);
        },
    );
let dataProvider = baseHydraDataProvider(entrypoint, fetchHydra, apiDocumentationParser, true);

export default dataProvider;

有什么想法吗?

我找到了解决方案,如您所见 here,发送空对象的 api-platform/admin 包出现错误。 解决方案来自版本 2.4.4