`params.previousData` is undefined in `update` call with `hydraDataProvider`
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
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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của api-platform/admin
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
api-platform/admin#616 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 64/100
api-platform/admin#660 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 50/100
api-platform/admin#659 · 1 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
api-platform/admin#631 · 6 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
api-platform/admin#626 · 1 bình luận · 1 reaction ·
Tất cả issue của api-platform/admin
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
vercel-labs/just-bash#464 ·
-
looksLikeSlug() is ASCII-only, so non-Latin entity slugs (e.g. Korean) skip exact match and collapse Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
TanStack/tanstack.com#1293 ·