PromucFlow_constructor/app/client/src/actions/evaluationActions.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

128 lines
4.2 KiB
TypeScript

import {
ReduxAction,
ReduxActionErrorTypes,
ReduxActionTypes,
} from "constants/ReduxActionConstants";
import _ from "lodash";
import { DataTree } from "entities/DataTree/dataTreeFactory";
import { DependencyMap } from "utils/DynamicBindingUtils";
import { Diff } from "deep-diff";
import { QueryActionConfig } from "../entities/Action";
export const FIRST_EVAL_REDUX_ACTIONS = [
// Pages
ReduxActionTypes.FETCH_PAGE_SUCCESS,
ReduxActionTypes.FETCH_PUBLISHED_PAGE_SUCCESS,
];
export const EVALUATE_REDUX_ACTIONS = [
...FIRST_EVAL_REDUX_ACTIONS,
// Actions
ReduxActionTypes.FETCH_PLUGIN_AND_JS_ACTIONS_SUCCESS,
ReduxActionTypes.FETCH_PLUGIN_FORM_CONFIGS_SUCCESS,
ReduxActionTypes.FETCH_ACTIONS_VIEW_MODE_SUCCESS,
ReduxActionErrorTypes.FETCH_ACTIONS_ERROR,
ReduxActionErrorTypes.FETCH_ACTIONS_VIEW_MODE_ERROR,
ReduxActionTypes.FETCH_ACTIONS_FOR_PAGE_SUCCESS,
ReduxActionTypes.SUBMIT_CURL_FORM_SUCCESS,
ReduxActionTypes.CREATE_ACTION_SUCCESS,
ReduxActionTypes.UPDATE_ACTION_PROPERTY,
ReduxActionTypes.DELETE_ACTION_SUCCESS,
ReduxActionTypes.COPY_ACTION_SUCCESS,
ReduxActionTypes.MOVE_ACTION_SUCCESS,
ReduxActionTypes.RUN_ACTION_SUCCESS,
ReduxActionErrorTypes.RUN_ACTION_ERROR,
ReduxActionTypes.EXECUTE_PLUGIN_ACTION_SUCCESS,
ReduxActionErrorTypes.EXECUTE_PLUGIN_ACTION_ERROR,
ReduxActionTypes.CLEAR_ACTION_RESPONSE,
// JS Actions
ReduxActionTypes.CREATE_JS_ACTION_SUCCESS,
ReduxActionErrorTypes.FETCH_JS_ACTIONS_ERROR,
ReduxActionTypes.DELETE_JS_ACTION_SUCCESS,
ReduxActionTypes.COPY_JS_ACTION_SUCCESS,
ReduxActionTypes.MOVE_JS_ACTION_SUCCESS,
ReduxActionErrorTypes.FETCH_JS_ACTIONS_ERROR,
ReduxActionTypes.FETCH_JS_ACTIONS_FOR_PAGE_SUCCESS,
ReduxActionTypes.FETCH_JS_ACTIONS_VIEW_MODE_SUCCESS,
ReduxActionErrorTypes.FETCH_JS_ACTIONS_VIEW_MODE_ERROR,
ReduxActionTypes.UPDATE_JS_ACTION_BODY_SUCCESS,
ReduxActionTypes.EXECUTE_JS_FUNCTION_SUCCESS,
// App Data
ReduxActionTypes.SET_APP_MODE,
ReduxActionTypes.FETCH_USER_DETAILS_SUCCESS,
ReduxActionTypes.UPDATE_APP_PERSISTENT_STORE,
ReduxActionTypes.UPDATE_APP_TRANSIENT_STORE,
ReduxActionTypes.SET_USER_CURRENT_GEO_LOCATION,
// Widgets
ReduxActionTypes.UPDATE_LAYOUT,
ReduxActionTypes.UPDATE_WIDGET_PROPERTY,
ReduxActionTypes.UPDATE_WIDGET_NAME_SUCCESS,
// Widget Meta
ReduxActionTypes.SET_META_PROP,
ReduxActionTypes.RESET_WIDGET_META,
// Batches
ReduxActionTypes.BATCH_UPDATES_SUCCESS,
];
// Topics used for datsource and query form evaluations
export const FORM_EVALUATION_REDUX_ACTIONS = [
ReduxActionTypes.INIT_FORM_EVALUATION,
ReduxActionTypes.RUN_FORM_EVALUATION,
];
export const shouldProcessBatchedAction = (action: ReduxAction<unknown>) => {
if (
action.type === ReduxActionTypes.BATCH_UPDATES_SUCCESS &&
Array.isArray(action.payload)
) {
const batchedActionTypes = action.payload.map(
(batchedAction) => batchedAction.type,
);
return (
_.intersection(EVALUATE_REDUX_ACTIONS, batchedActionTypes).length > 0
);
}
return true;
};
export const setEvaluatedTree = (
dataTree: DataTree,
updates: Diff<DataTree, DataTree>[],
): ReduxAction<{ dataTree: DataTree; updates: Diff<DataTree, DataTree>[] }> => {
return {
type: ReduxActionTypes.SET_EVALUATED_TREE,
payload: { dataTree, updates },
};
};
export const setDependencyMap = (
inverseDependencyMap: DependencyMap,
): ReduxAction<{ inverseDependencyMap: DependencyMap }> => {
return {
type: ReduxActionTypes.SET_EVALUATION_INVERSE_DEPENDENCY_MAP,
payload: { inverseDependencyMap },
};
};
// Called when a form is being setup, for setting up the base condition evaluations for the form
export const initFormEvaluations = (
editorConfig: any,
settingConfig: any,
formId: string,
) => {
return {
type: ReduxActionTypes.INIT_FORM_EVALUATION,
payload: { editorConfig, settingConfig, formId },
};
};
// Called when there is change in the data of the form, re evaluates the whole form
export const startFormEvaluations = (
formId: string,
formData: QueryActionConfig,
datasourceId: string,
pluginId: string,
) => {
return {
type: ReduxActionTypes.RUN_FORM_EVALUATION,
payload: { formId, actionConfiguration: formData, datasourceId, pluginId },
};
};