From f8f5ebbbef8fd0eb336bb33cf41cefe062d6b2a5 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Wed, 26 Jun 2024 15:12:56 +0530 Subject: [PATCH] chore: Strict API payloads for JSObjects and more (#34471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of #33724. Fixes for JSObject API calls and `EvaluatedValuePopUp_spec` test. **/test sanity binding** > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: d48cd19bfc2165bd06d605608ee632faa042a820 > Cypress dashboard. > Tags: `@tag.Sanity, @tag.Binding` ## Summary by CodeRabbit - **Refactor** - Improved the structure of API request payloads for JS collections, ensuring more efficient data handling. - **Bug Fixes** - Removed unnecessary parameters from dynamic value fetching functions, streamlining the process and reducing potential errors. --- app/client/src/ce/api/JSActionAPI.tsx | 39 ++++++++++++++++++---- app/client/src/sagas/FormEvaluationSaga.ts | 4 --- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/client/src/ce/api/JSActionAPI.tsx b/app/client/src/ce/api/JSActionAPI.tsx index c53450b8c8..578476836b 100644 --- a/app/client/src/ce/api/JSActionAPI.tsx +++ b/app/client/src/ce/api/JSActionAPI.tsx @@ -95,8 +95,20 @@ class JSActionAPI extends API { static async updateJSCollection( jsConfig: JSCollection, ): Promise> { - const jsAction = Object.assign({}, jsConfig); - return API.put(`${JSActionAPI.url}/${jsAction.id}`, jsAction); + const payload = { + ...jsConfig, + actions: + jsConfig.actions?.map((action) => ({ + ...action, + entityReferenceType: undefined, + datasource: (action as any).datasource && { + ...(action as any).datasource, + isValid: undefined, + new: undefined, + }, + })) ?? undefined, + }; + return API.put(`${JSActionAPI.url}/${jsConfig.id}`, payload); } static async deleteJSCollection(id: string) { @@ -128,10 +140,25 @@ class JSActionAPI extends API { static async updateJSCollectionActionRefactor( updateJSCollectionActionName: UpdateCollectionActionNameRequest, ) { - return API.put( - JSActionAPI.url + "/refactorAction", - updateJSCollectionActionName, - ); + const payload = { + ...updateJSCollectionActionName, + actionCollection: updateJSCollectionActionName.actionCollection && { + ...updateJSCollectionActionName.actionCollection, + actions: + updateJSCollectionActionName.actionCollection.actions?.map( + (action) => ({ + ...action, + entityReferenceType: undefined, + datasource: (action as any).datasource && { + ...(action as any).datasource, + isValid: undefined, + new: undefined, + }, + }), + ) ?? undefined, + }, + }; + return API.put(JSActionAPI.url + "/refactorAction", payload); } } diff --git a/app/client/src/sagas/FormEvaluationSaga.ts b/app/client/src/sagas/FormEvaluationSaga.ts index e1e0d55110..632a660b60 100644 --- a/app/client/src/sagas/FormEvaluationSaga.ts +++ b/app/client/src/sagas/FormEvaluationSaga.ts @@ -139,7 +139,6 @@ export function* fetchDynamicValuesSaga( formId, datasourceId, pluginId, - key, ); } @@ -159,7 +158,6 @@ function* fetchDynamicValueSaga( actionId: string, datasourceId: string, pluginId: string, - configProperty: string, ) { try { const { config, evaluatedConfig } = @@ -247,9 +245,7 @@ function* fetchDynamicValueSaga( url, { actionId, - configProperty, datasourceId, - pluginId, ...evaluatedParams, }, );