PromucFlow_constructor/app/client/src/entities/DataTree/dataTreeJSAction.ts
Apeksha Bhosale 79e165af96
feat: Settings js editor (#9984)
* POC

* Closing channels

* WIP

* v1

* get working with JS editor

* autocomplete

* added comments

* try removing an import

* different way of import

* dependency map added to body

* triggers can be part of js editor functions hence

* removed unwanted lines

* new flow chnages

* Resolve conflicts

* small css changes for empty state

* Fix prettier

* Fixes

* flow changes part 2

* Mock web worker for testing

* Throw errors during evaluation

* Action execution should be non blocking on the main thread to evaluation of further actions

* WIP

* Fix build issue

* Fix warnings

* Rename

* Refactor and add tests for worker util

* Fix response flow post refactor

* added settings icon for js editor

* WIP

* WIP

* WIP

* Tests for promises

* settings for each function of js object added

* Error handling

* Error handing action validation

* Update test

* Passing callback data in the eval trigger flow

* log triggers to be executed

* WIP

* confirm before execution

* Remove debugging

* Fix backwards compatibility

* Avoid passing trigger meta around

* fix button loading

* handle error callbacks

* fix tests

* tests

* fix console error when checking for async

* Fix async function check

* Fix async function check again

* fix bad commit

* Add some comments

* added clientSideExecution flag for js functions

* css changes for settings icon

* unsued code removed

* on page load PART 1

* onPageLoad rest iof changes

* corrected async badge

* removed duplicate test cases

* added confirm modal for js functions

* removed unused code

* small chnage

* dependency was not getting created

* Fix confirmation modal

* unused code removed

* replaced new confirmsaga

* confirmaton box changes

* Fixing JSEditor Run butn locator

* corrected property

* dependency map was failing

* changed key for confirmation box

Co-authored-by: hetunandu <hetu@appsmith.com>
Co-authored-by: Hetu Nandu <hetunandu@gmail.com>
Co-authored-by: Arpit Mohan <arpit@appsmith.com>
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2022-03-17 17:35:17 +05:30

66 lines
2.2 KiB
TypeScript

import {
DataTreeJSAction,
ENTITY_TYPE,
MetaArgs,
} from "entities/DataTree/dataTreeFactory";
import { JSCollectionData } from "reducers/entityReducers/jsActionsReducer";
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
import { DependencyMap } from "utils/DynamicBindingUtils";
export const generateDataTreeJSAction = (
js: JSCollectionData,
): DataTreeJSAction => {
const meta: Record<string, MetaArgs> = {};
const dynamicBindingPathList = [];
const bindingPaths: Record<string, EvaluationSubstitutionType> = {};
const variableList: Record<string, any> = {};
const variables = js.config.variables;
const listVariables: Array<string> = [];
dynamicBindingPathList.push({ key: "body" });
const reg = /this\./g;
const removeThisReference = js.config.body.replace(reg, `${js.config.name}.`);
bindingPaths["body"] = EvaluationSubstitutionType.SMART_SUBSTITUTE;
if (variables) {
for (let i = 0; i < variables.length; i++) {
const variable = variables[i];
variableList[variable.name] = variable.value;
listVariables.push(variable.name);
}
}
const dependencyMap: DependencyMap = {};
dependencyMap["body"] = [];
const actions = js.config.actions;
const actionsData: Record<string, any> = {};
if (actions) {
for (let i = 0; i < actions.length; i++) {
const action = actions[i];
meta[action.name] = {
arguments: action.actionConfiguration.jsArguments,
isAsync: action.actionConfiguration.isAsync,
confirmBeforeExecute: !!action.confirmBeforeExecute,
};
bindingPaths[action.name] = EvaluationSubstitutionType.SMART_SUBSTITUTE;
dynamicBindingPathList.push({ key: action.name });
dependencyMap["body"].push(action.name);
actionsData[action.name] = {
data: (js.data && js.data[`${action.id}`]) || {},
};
}
}
return {
...variableList,
name: js.config.name,
actionId: js.config.id,
pluginType: js.config.pluginType,
ENTITY_TYPE: ENTITY_TYPE.JSACTION,
body: removeThisReference,
meta: meta,
bindingPaths: bindingPaths,
dynamicBindingPathList: dynamicBindingPathList,
variables: listVariables,
dependencyMap: dependencyMap,
...actionsData,
};
};