`params.previousData` is undefined in `update` call with `hydraDataProvider`
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- react, typescript
調査の方向性
hydraDataProvider の update 呼び出しと、再現手順に示されているカスタム update オーバーライドから始め、save アクションが params.data と params.previousData をどのように渡しているかを追跡します。編集フローを再現し、previousData が存在しない理由を特定します。原因と期待される動作が明らかになり、回帰チェックまたはサポートされる update パラメーターの明確なドキュメントが用意されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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;
}
});
};
- 主要言語
- TypeScript
- スター
- 516
- フォーク
- 134
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/admin のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
api-platform/admin#616 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 64/100
api-platform/admin#660 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 50/100
api-platform/admin#659 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
api-platform/admin#631 · コメント 6 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/admin#626 · コメント 1 件 · リアクション 1 件 ·
api-platform/admin の issue をすべて見る
似ている issue
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
Mend: dependency security vulnerability untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100