diff --git a/app/client/src/workers/Evaluation/fns/actionFns.ts b/app/client/src/workers/Evaluation/fns/actionFns.ts index 16fdf12e27..e82de8ed88 100644 --- a/app/client/src/workers/Evaluation/fns/actionFns.ts +++ b/app/client/src/workers/Evaluation/fns/actionFns.ts @@ -1,8 +1,9 @@ import { isTrueObject } from "@appsmith/workers/Evaluation/evaluationUtils"; import { promisify } from "./utils/Promisify"; +import type { ActionEntity } from "entities/DataTree/types"; function runFnDescriptor( - this: any, + this: ActionEntity, onSuccessOrParams?: (data: any) => unknown | Record, onError?: (e: string) => unknown, params = {}, @@ -30,7 +31,7 @@ export type TRunDescription = ReturnType; export type TRunActionType = TRunDescription["type"]; export default async function run( - this: any, + this: ActionEntity, onSuccessOrParams?: (data: any) => unknown | Record, onError?: (e: string) => unknown, params = {}, @@ -38,6 +39,13 @@ export default async function run( const executor = promisify(runFnDescriptor.bind(this)); try { const response = await executor(onSuccessOrParams, onError, params); + + // @ts-expect-error: globalThis type is not defined + const action = globalThis[this.name]; + if (action) { + action.data = response[0]; + } + if (typeof onSuccessOrParams === "function") { onSuccessOrParams.apply(this, response); return; @@ -57,7 +65,7 @@ export default async function run( } } -function clearFnDescriptor(this: any) { +function clearFnDescriptor(this: ActionEntity) { return { type: "CLEAR_PLUGIN_ACTION" as const, payload: { @@ -70,6 +78,6 @@ export type TClearArgs = Parameters; export type TClearDescription = ReturnType; export type TClearActionType = TClearDescription["type"]; -export async function clear(this: any) { +export async function clear(this: ActionEntity) { return promisify(clearFnDescriptor.bind(this))(); } diff --git a/app/client/src/workers/Evaluation/fns/index.ts b/app/client/src/workers/Evaluation/fns/index.ts index 2d7adef1d9..39c6d27324 100644 --- a/app/client/src/workers/Evaluation/fns/index.ts +++ b/app/client/src/workers/Evaluation/fns/index.ts @@ -61,6 +61,7 @@ import { watchGeoLocation, } from "./geolocationFns"; import { getFnWithGuards, isAsyncGuard } from "./utils/fnGuard"; +import type { ActionEntity } from "entities/DataTree/types"; // cloudHosting -> to use in EE // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -119,16 +120,25 @@ export const entityFns = [ { name: "run", qualifier: (entity: DataTreeEntity) => isAction(entity), - fn: (entity: DataTreeEntity, entityName: string) => - getFnWithGuards(run.bind(entity), `${entityName}.run`, [isAsyncGuard]), + fn: (entity: DataTreeEntity, entityName: string) => { + // @ts-expect-error: name is not defined on ActionEntity + entity.name = entityName; + return getFnWithGuards( + run.bind(entity as ActionEntity), + `${entityName}.run`, + [isAsyncGuard], + ); + }, }, { name: "clear", qualifier: (entity: DataTreeEntity) => isAction(entity), fn: (entity: DataTreeEntity, entityName: string) => - getFnWithGuards(clear.bind(entity), `${entityName}.clear`, [ - isAsyncGuard, - ]), + getFnWithGuards( + clear.bind(entity as ActionEntity), + `${entityName}.clear`, + [isAsyncGuard], + ), }, { name: "getGeoLocation",