## Description UnEvalTree, dataTree and configTree's entities needs to be extended on EE to accommodate module inputs and different types of modules hence the separation. I have added few more sanity checks in the existing code which were throwing errors/warning on EE. #### PR fixes following issue(s) Fixes # (issue number) #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change - Chore (housekeeping or task changes that don't impact user perception) > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
170 lines
5.0 KiB
TypeScript
170 lines
5.0 KiB
TypeScript
import { all, call, put, spawn, take } from "redux-saga/effects";
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
|
import { MAIN_THREAD_ACTION } from "@appsmith/workers/Evaluation/evalWorkerActions";
|
|
import log from "loglevel";
|
|
import {
|
|
evalErrorHandler,
|
|
logJSVarMutationEvent,
|
|
} from "../sagas/PostEvaluationSagas";
|
|
import type { Channel } from "redux-saga";
|
|
import { storeLogs } from "../sagas/DebuggerSagas";
|
|
import type {
|
|
BatchedJSExecutionData,
|
|
BatchedJSExecutionErrors,
|
|
} from "reducers/entityReducers/jsActionsReducer";
|
|
import type { TMessage } from "utils/MessageUtil";
|
|
import { MessageType } from "utils/MessageUtil";
|
|
import type { ResponsePayload } from "../sagas/EvaluationsSaga";
|
|
import {
|
|
evalWorker,
|
|
executeTriggerRequestSaga,
|
|
updateDataTreeHandler,
|
|
} from "../sagas/EvaluationsSaga";
|
|
import { logJSFunctionExecution } from "@appsmith/sagas/JSFunctionExecutionSaga";
|
|
import { handleStoreOperations } from "./ActionExecution/StoreActionSaga";
|
|
import type {
|
|
EvalTreeResponseData,
|
|
JSVarMutatedEvents,
|
|
} from "workers/Evaluation/types";
|
|
import isEmpty from "lodash/isEmpty";
|
|
import type { UnEvalTree } from "entities/DataTree/dataTreeTypes";
|
|
import { sortJSExecutionDataByCollectionId } from "workers/Evaluation/JSObject/utils";
|
|
import type { LintTreeSagaRequestData } from "plugins/Linting/types";
|
|
export type UpdateDataTreeMessageData = {
|
|
workerResponse: EvalTreeResponseData;
|
|
unevalTree: UnEvalTree;
|
|
};
|
|
|
|
export function* handleEvalWorkerRequestSaga(listenerChannel: Channel<any>) {
|
|
while (true) {
|
|
const request: TMessage<any> = yield take(listenerChannel);
|
|
yield spawn(handleEvalWorkerMessage, request);
|
|
}
|
|
}
|
|
|
|
export function* lintTreeActionHandler(message: any) {
|
|
const { body } = message;
|
|
const { data } = body;
|
|
const { configTree, unevalTree } = data as LintTreeSagaRequestData;
|
|
yield put({
|
|
type: ReduxActionTypes.LINT_TREE,
|
|
payload: {
|
|
unevalTree,
|
|
configTree,
|
|
},
|
|
});
|
|
}
|
|
|
|
export function* processLogsHandler(message: any) {
|
|
const { body } = message;
|
|
const { data } = body;
|
|
yield call(storeLogs, data);
|
|
}
|
|
|
|
export function* processJSFunctionExecution(message: any) {
|
|
const { body } = message;
|
|
const {
|
|
data: { JSExecutionData, JSExecutionErrors },
|
|
} = body;
|
|
const {
|
|
sortedData,
|
|
sortedErrors,
|
|
}: {
|
|
sortedData: BatchedJSExecutionData;
|
|
sortedErrors: BatchedJSExecutionErrors;
|
|
} = yield* sortJSExecutionDataByCollectionId(
|
|
JSExecutionData,
|
|
JSExecutionErrors,
|
|
);
|
|
if (!isEmpty(sortedData)) {
|
|
yield put({
|
|
type: ReduxActionTypes.SET_JS_FUNCTION_EXECUTION_DATA,
|
|
payload: sortedData,
|
|
});
|
|
}
|
|
if (!isEmpty(sortedErrors)) {
|
|
yield put({
|
|
type: ReduxActionTypes.SET_JS_FUNCTION_EXECUTION_ERRORS,
|
|
payload: sortedErrors,
|
|
});
|
|
}
|
|
}
|
|
|
|
export function* processTriggerHandler(message: any) {
|
|
const { body } = message;
|
|
const { data } = body;
|
|
const { eventType, trigger, triggerMeta } = data;
|
|
const { messageType } = message;
|
|
log.debug({ trigger: data.trigger });
|
|
const result: ResponsePayload = yield call(
|
|
executeTriggerRequestSaga,
|
|
trigger,
|
|
eventType,
|
|
triggerMeta,
|
|
);
|
|
if (messageType === MessageType.REQUEST)
|
|
yield call(evalWorker.respond, message.messageId, result);
|
|
}
|
|
|
|
export function* handleEvalWorkerMessage(message: TMessage<any>) {
|
|
const { body } = message;
|
|
const { data, method } = body;
|
|
switch (method) {
|
|
case MAIN_THREAD_ACTION.LINT_TREE: {
|
|
yield call(lintTreeActionHandler, message);
|
|
break;
|
|
}
|
|
case MAIN_THREAD_ACTION.PROCESS_LOGS: {
|
|
yield call(processLogsHandler, message);
|
|
break;
|
|
}
|
|
case MAIN_THREAD_ACTION.PROCESS_JS_FUNCTION_EXECUTION: {
|
|
yield call(processJSFunctionExecution, message);
|
|
break;
|
|
}
|
|
case MAIN_THREAD_ACTION.PROCESS_TRIGGER: {
|
|
yield call(processTriggerHandler, message);
|
|
break;
|
|
}
|
|
case MAIN_THREAD_ACTION.PROCESS_STORE_UPDATES: {
|
|
yield call(handleStoreOperations, data);
|
|
break;
|
|
}
|
|
case MAIN_THREAD_ACTION.LOG_JS_FUNCTION_EXECUTION: {
|
|
yield call(logJSFunctionExecution, message);
|
|
break;
|
|
}
|
|
case MAIN_THREAD_ACTION.PROCESS_BATCHED_TRIGGERS: {
|
|
const batchedTriggers = data;
|
|
yield all(
|
|
batchedTriggers.map((data: any) => {
|
|
const { eventType, trigger, triggerMeta } = data;
|
|
return call(
|
|
executeTriggerRequestSaga,
|
|
trigger,
|
|
eventType,
|
|
triggerMeta,
|
|
);
|
|
}),
|
|
);
|
|
break;
|
|
}
|
|
case MAIN_THREAD_ACTION.UPDATE_DATATREE: {
|
|
const { unevalTree, workerResponse } = data as UpdateDataTreeMessageData;
|
|
yield call(updateDataTreeHandler, {
|
|
evalTreeResponse: workerResponse as EvalTreeResponseData,
|
|
unevalTree,
|
|
requiresLogging: false,
|
|
});
|
|
break;
|
|
}
|
|
|
|
case MAIN_THREAD_ACTION.PROCESS_JS_VAR_MUTATION_EVENTS: {
|
|
const jsVarMutatedEvents: JSVarMutatedEvents = data;
|
|
yield call(logJSVarMutationEvent, jsVarMutatedEvents);
|
|
}
|
|
}
|
|
|
|
yield call(evalErrorHandler, data?.errors || []);
|
|
}
|