Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`params.previousData` is undefined in `update` call with `hydraDataProvider`

Đang mở
#520 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
react, typescript
Lĩnh vực
api, frontend

Hướng nghiên cứu

Bắt đầu từ lời gọi cập nhật hydraDataProvider và phần ghi đè update tùy chỉnh được hiển thị trong bản tái hiện, sau đó theo dõi cách thao tác lưu cung cấp params.data và params.previousData. Tái hiện quy trình chỉnh sửa và xác định lý do previousData không tồn tại; công việc được xem là hoàn tất khi nguyên nhân và hành vi dự kiến đã được xác lập, kèm theo kiểm tra hồi quy hoặc tài liệu rõ ràng về các tham số update được hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

API Platform version(s) affected: 3.4.4

Description
We need to use PATCH instead of PUT to update existing resources, so I drew inspiration from this comment https://github.com/api-platform/admin/issues/370#issuecomment-831749350 and overwrote the update method of our data provider, which is an instance of hydraDataProvider.

The new update method should create a diff between the current resource data (given in params.data) and the previous data (given in params.previousData) and then execute a PATCH request.

However, params.previousData is undefined when a user edits a resource and clicks the save button.

I figured it may be caused by some previous error on the page where this behavior occurs, but there are no errors in the JavaScript console on that page. The first error that occurs is that params.previousData is undefined when our diff function is called.

We haven't added much custom logic to our admin implementation, most things are done by the default implementations and automations of API Platform Admin.

What could cause this issue? Is params.previousData supposed to be empty?

How to reproduce

// We use the built-in fetchHydra() and parseHydraDocumentation() functions, 
// but wrapped them to handle authorization as shown in the API Platform Admin docs and examples
const baseDataProvider = hydraDataProvider({
    entrypoint: ENTRYPOINT,
    httpClient: fetchHydraWithAuthentication, 
    apiDocumentationParser: apiDocumentationParser
});

baseDataProvider.update = function(resource, params) {
    return this.httpClient(`${this.entrypoint}/${resource}/${params.id}`, {
        method: 'PATCH',
        body: JSON.stringify(diff(params.data, params.previousData)), 
    }).then(({json}) => ({data: json}));
};

// We use lodash helpers to implement this diff function
const diff = (object, base) => {
    return transform(object, (result, value, key) => {
        if (!isEqual(value, base[key])) {
            result[key] = isObject(value) && isObject(base[key]) ? diff(value, base[key]) : value;
        }
    });
};
Ngôn ngữ chính
TypeScript
Star
516
Fork
134
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của api-platform/admin

Tất cả issue của api-platform/admin

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.