Skip to content

Commit

Permalink
avoid function getting overridden by the duplicate one
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhrathod01 committed Oct 21, 2024
1 parent d89f9d7 commit c8be91e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
3 changes: 0 additions & 3 deletions app/client/src/ce/entities/DataTree/dataTreeJSAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ export const generateDataTreeJSAction = (
for (let i = 0; i < actions.length; i++) {
const action = actions[i];

// If action already exists, skip adding it to the data tree
if (actionsData[action.name]) continue;

meta[action.name] = {
arguments: action.actionConfiguration?.jsArguments || [],
confirmBeforeExecute: !!action.confirmBeforeExecute,
Expand Down
26 changes: 14 additions & 12 deletions app/client/src/workers/Evaluation/JSObject/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import JSObjectCollection from "./Collection";
import ExecutionMetaData from "../fns/utils/ExecutionMetaData";
import { jsPropertiesState } from "./jsPropertiesState";
import { getFixedTimeDifference } from "workers/common/DataTreeEvaluator/utils";
interface ParseJSAction extends ParsedJSSubAction {
parsedFunction: unknown;
}

/**
* Here we update our unEvalTree according to the change in JSObject's body
Expand Down Expand Up @@ -114,18 +117,17 @@ export function saveResolvedFunctionsAndJSUpdates(
JSObjectName: entityName,
JSObjectASTParseTime,
});
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const actions: any = [];
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const variables: any = [];

const actionsMap: Record<string, ParseJSAction> = {};
const variablesMap: Record<string, { name: string; value: unknown }> = {};

if (success) {
if (!!parsedObject) {
jsPropertiesState.update(entityName, parsedObject);
parsedObject.forEach((parsedElement) => {
if (isJSFunctionProperty(parsedElement)) {
if (actionsMap[parsedElement.key]) return;

try {
ExecutionMetaData.setExecutionMetaData({
enableJSVarUpdateTracking: false,
Expand Down Expand Up @@ -164,12 +166,12 @@ export function saveResolvedFunctionsAndJSUpdates(
`${entityName}.${parsedElement.key}`,
functionString,
);
actions.push({
actionsMap[parsedElement.key] = {
name: parsedElement.key,
body: functionString,
arguments: params,
parsedFunction: result,
});
};
}
} catch {
// in case we need to handle error state
Expand All @@ -184,10 +186,10 @@ export function saveResolvedFunctionsAndJSUpdates(
? parsedElement.key.slice(1, -1)
: parsedElement.key;

variables.push({
variablesMap[parsedKey] = {
name: parsedKey,
value: parsedElement.value,
});
};
JSObjectCollection.updateUnEvalState(
`${entityName}.${parsedElement.key}`,
parsedElement.value,
Expand All @@ -196,8 +198,8 @@ export function saveResolvedFunctionsAndJSUpdates(
});
const parsedBody = {
body: entity.body,
actions: actions,
variables,
actions: Object.values(actionsMap),
variables: Object.values(variablesMap),
};

set(jsUpdates, `${entityName}`, {
Expand Down

0 comments on commit c8be91e

Please sign in to comment.