PromucFlow_constructor/app/client/src/sagas/EvaluationsSaga.ts

613 lines
16 KiB
TypeScript
Raw Normal View History

import {
actionChannel,
all,
call,
fork,
put,
select,
spawn,
take,
2021-12-07 09:45:18 +00:00
delay,
} from "redux-saga/effects";
import {
EvaluationReduxAction,
ReduxAction,
ReduxActionType,
ReduxActionTypes,
ReduxActionWithoutPayload,
} from "constants/ReduxActionConstants";
import {
getDataTree,
getUnevaluatedDataTree,
} from "selectors/dataTreeSelectors";
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
import { getWidgets } from "sagas/selectors";
import WidgetFactory, { WidgetTypeConfigMap } from "../utils/WidgetFactory";
2021-02-22 05:00:16 +00:00
import { GracefulWorkerService } from "utils/WorkerUtil";
import Worker from "worker-loader!../workers/evaluation.worker";
import {
EVAL_WORKER_ACTIONS,
PropertyEvaluationErrorType,
} from "utils/DynamicBindingUtils";
import log from "loglevel";
2021-02-22 05:00:16 +00:00
import { WidgetProps } from "widgets/BaseWidget";
import PerformanceTracker, {
PerformanceTransactionName,
} from "../utils/PerformanceTracker";
import * as Sentry from "@sentry/react";
2020-12-30 13:26:44 +00:00
import { Action } from "redux";
import {
2021-07-20 10:02:56 +00:00
EVALUATE_REDUX_ACTIONS,
FIRST_EVAL_REDUX_ACTIONS,
setDependencyMap,
setEvaluatedTree,
shouldProcessBatchedAction,
} from "actions/evaluationActions";
import {
2021-07-20 10:02:56 +00:00
evalErrorHandler,
logSuccessfulBindings,
postEvalActionDispatcher,
updateTernDefinitions,
} from "./PostEvaluationSagas";
import { JSAction } from "entities/JSCollection";
2021-07-30 10:24:22 +00:00
import { getAppMode } from "selectors/applicationSelectors";
import { APP_MODE } from "entities/App";
import { get, isUndefined } from "lodash";
import {
setEvaluatedArgument,
setEvaluatedSnippet,
setGlobalSearchFilterContext,
} from "actions/globalSearchActions";
import {
executeActionTriggers,
TriggerMeta,
} from "./ActionExecution/ActionExecutionSagas";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
import { Toaster } from "components/ads/Toast";
import { Variant } from "components/ads/common";
import {
createMessage,
SNIPPET_EXECUTION_FAILED,
SNIPPET_EXECUTION_SUCCESS,
} from "constants/messages";
import { validate } from "workers/validations";
import { diff } from "deep-diff";
2021-12-07 09:45:18 +00:00
import { REPLAY_DELAY } from "entities/Replay/replayUtils";
import { EvaluationVersion } from "api/ApplicationApi";
import { makeUpdateJSCollection } from "sagas/JSPaneSagas";
2021-12-07 09:45:18 +00:00
import { ENTITY_TYPE } from "entities/AppsmithConsole";
import { Replayable } from "entities/Replay/ReplayEntity/ReplayEditor";
import {
logActionExecutionError,
UncaughtPromiseError,
} from "sagas/ActionExecution/errorUtils";
import { Channel } from "redux-saga";
import { ActionDescription } from "entities/DataTree/actionTriggers";
import { FormEvaluationState } from "reducers/evaluationReducers/formEvaluationReducer";
import { FormEvalActionPayload } from "./FormEvaluationSaga";
let widgetTypeConfigMap: WidgetTypeConfigMap;
const worker = new GracefulWorkerService(Worker);
function* evaluateTreeSaga(
postEvalActions?: Array<ReduxAction<unknown> | ReduxActionWithoutPayload>,
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
shouldReplay?: boolean,
) {
2021-03-31 07:40:59 +00:00
const unevalTree = yield select(getUnevaluatedDataTree);
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
const widgets = yield select(getWidgets);
2021-03-31 07:40:59 +00:00
log.debug({ unevalTree });
PerformanceTracker.startAsyncTracking(
PerformanceTransactionName.DATA_TREE_EVALUATION,
);
const workerResponse = yield call(
worker.request,
EVAL_WORKER_ACTIONS.EVAL_TREE,
{
unevalTree,
widgetTypeConfigMap,
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
widgets,
shouldReplay,
},
);
const {
dataTree,
dependencies,
errors,
evaluationOrder,
jsUpdates,
logs,
unEvalUpdates,
} = workerResponse;
2021-03-31 07:40:59 +00:00
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.DATA_TREE_EVALUATION,
);
PerformanceTracker.startAsyncTracking(
PerformanceTransactionName.SET_EVALUATED_TREE,
);
const oldDataTree = yield select(getDataTree);
const updates = diff(oldDataTree, dataTree) || [];
2021-07-20 10:02:56 +00:00
yield put(setEvaluatedTree(dataTree, updates));
PerformanceTracker.stopAsyncTracking(
2021-03-31 07:40:59 +00:00
PerformanceTransactionName.SET_EVALUATED_TREE,
);
const updatedDataTree = yield select(getDataTree);
log.debug({ jsUpdates: jsUpdates });
log.debug({ dataTree: updatedDataTree });
logs?.forEach((evalLog: any) => log.debug(evalLog));
yield call(evalErrorHandler, errors, updatedDataTree, evaluationOrder);
2021-07-30 10:24:22 +00:00
const appMode = yield select(getAppMode);
if (appMode !== APP_MODE.PUBLISHED) {
yield call(makeUpdateJSCollection, jsUpdates);
2021-07-30 10:24:22 +00:00
yield fork(
logSuccessfulBindings,
unevalTree,
updatedDataTree,
evaluationOrder,
);
yield fork(updateTernDefinitions, updatedDataTree, unEvalUpdates);
2021-07-30 10:24:22 +00:00
}
2021-07-20 10:02:56 +00:00
yield put(setDependencyMap(dependencies));
if (postEvalActions && postEvalActions.length) {
yield call(postEvalActionDispatcher, postEvalActions);
}
}
2021-01-14 14:37:21 +00:00
export function* evaluateActionBindings(
bindings: string[],
executionParams: Record<string, any> | string = {},
2020-12-14 18:48:13 +00:00
) {
const workerResponse = yield call(
worker.request,
2021-01-14 14:37:21 +00:00
EVAL_WORKER_ACTIONS.EVAL_ACTION_BINDINGS,
{
2021-01-14 14:37:21 +00:00
bindings,
executionParams,
},
);
2021-01-14 14:37:21 +00:00
const { errors, values } = workerResponse;
yield call(evalErrorHandler, errors);
2021-01-14 14:37:21 +00:00
return values;
}
/*
* Used to evaluate and execute dynamic trigger end to end
* Widget action fields and JS Object run triggers this flow
*
* We start a duplex request with the worker and wait till the time we get a 'finished' event from the
* worker. Worker will evaluate a block of code and ask the main thread to execute it. The result of this
* execution is returned to the worker where it can resolve/reject the current promise.
*/
export function* evaluateAndExecuteDynamicTrigger(
dynamicTrigger: string,
eventType: EventType,
triggerMeta: TriggerMeta,
2020-11-20 09:30:50 +00:00
callbackData?: Array<any>,
) {
const unEvalTree = yield select(getUnevaluatedDataTree);
log.debug({ execute: dynamicTrigger });
const { requestChannel, responseChannel } = yield call(
worker.duplexRequest,
EVAL_WORKER_ACTIONS.EVAL_TRIGGER,
{ dataTree: unEvalTree, dynamicTrigger, callbackData },
);
let keepAlive = true;
while (keepAlive) {
const { requestData } = yield take(requestChannel);
log.debug({ requestData });
if (requestData.finished) {
keepAlive = false;
/* Handle errors during evaluation
* A finish event with errors means that the error was not caught by the user code.
* We raise an error telling the user that an uncaught error has occured
* */
if (requestData.result.errors.length) {
throw new UncaughtPromiseError(
requestData.result.errors[0].errorMessage,
);
}
// It is possible to get a few triggers here if the user
// still uses the old way of action runs and not promises. For that we
// need to manually execute these triggers outside the promise flow
const { triggers } = requestData.result;
if (triggers && triggers.length) {
log.debug({ triggers });
yield all(
triggers.map((trigger: ActionDescription) =>
call(executeActionTriggers, trigger, eventType, triggerMeta),
),
);
}
// Return value of a promise is returned
return requestData.result;
}
yield call(evalErrorHandler, requestData.errors);
if (requestData.trigger) {
// if we have found a trigger, we need to execute it and respond back
log.debug({ trigger: requestData.trigger });
yield spawn(
executeTriggerRequestSaga,
requestData,
eventType,
responseChannel,
triggerMeta,
);
}
}
}
interface ResponsePayload {
data: {
subRequestId: string;
reason?: string;
resolve?: unknown;
};
success: boolean;
}
/*
* It is necessary to respond back as the worker is waiting with a pending promise and wanting to know if it should
* resolve or reject it with the data the execution has provided
*/
function* executeTriggerRequestSaga(
requestData: { trigger: ActionDescription; subRequestId: string },
eventType: EventType,
responseChannel: Channel<unknown>,
triggerMeta: TriggerMeta,
) {
const responsePayload: ResponsePayload = {
data: {
resolve: undefined,
reason: undefined,
subRequestId: requestData.subRequestId,
},
success: false,
};
try {
responsePayload.data.resolve = yield call(
executeActionTriggers,
requestData.trigger,
eventType,
triggerMeta,
);
responsePayload.success = true;
} catch (e) {
// When error occurs in execution of triggers,
// a success: false is sent to reject the promise
responsePayload.data.reason = e;
responsePayload.success = false;
}
responseChannel.put({
method: EVAL_WORKER_ACTIONS.PROCESS_TRIGGER,
...responsePayload,
});
}
export function* clearEvalCache() {
yield call(worker.request, EVAL_WORKER_ACTIONS.CLEAR_CACHE);
return true;
}
export function* clearEvalPropertyCache(propertyPath: string) {
yield call(worker.request, EVAL_WORKER_ACTIONS.CLEAR_PROPERTY_CACHE, {
propertyPath,
});
}
feat: JS Editor (#6003) * Changes to add js plugin * routes+reducer+create template * added debugger to js editor page * entity explorer changes * create js function * added copy, move and delete action * added js plugin * added existing js functions to data tree * removed actionconfig for js collection * new js function added to data tree and entity as well * parsing flow added * changes to data tree * parse and update js functions * small changes for def creator for js action * create delete modified * small changes for update * update flow change * entity properties added * removed linting errors * small changes in entity explorer * changes for update * move, copy implementation * conflict resolved * changes for dependecy map creation * Only make the variables the binding paths * Basic eval sync working * Minor fixes * removed unwanted code * entity props and autocomplete * saving in progress show * redirection fix after delete js action * removed unnecessary line * Fixing merge conflict * added sample body * removed dummy data and added plugin Type * few PR comments fixed * automplete fix * few more PR comments fix * PR commnets fix * move and copy api change * js colleciton name refactor & 'move to page' changes & search * view changes * autocomplete added for js collections * removing till async is implemented * small changes * separate js pane response view * Executing functions * js collection to js objects * entity explorer issue and resolve action on page switch * removed unused line * small color fix * js file icon added * added js action to property pane * Property pane changes for actions * property pane changes for js functions * showing syntax error for now * actions sorted in response tab * added js objects to slash and recent entitties * enabling this to be used inside of function * eval fix * feature flag changes for entity explorer and property pane * debugger changes * copy bug fix * small changes for eval * debugger bug fix * chnaged any to specific types * error in console fix * icons update * fixed test case * test case fix * non empty check for functions * evaluate test case fix * added new icons * text change * updated time for debounce for trial * after release mereg * changed icon * after merge * PR comments simple * fixed PR comments - redux form, settings remove * js object interface changes * name refactor * export default change * delete resolve actions chnage * after merge * adding execute fn as 3rd option and removed create new js function * issue 7054 fixed - app crash * execute function on response tab changes * refactor function name part 1 * refactor of js function name * try catch added refactor * test fix * not used line removed * test cases locator fixed Co-authored-by: Nidhi <nidhi.nair93@gmail.com> Co-authored-by: hetunandu <hetu@appsmith.com>
2021-09-08 17:32:22 +00:00
export function* executeFunction(collectionName: string, action: JSAction) {
const functionCall = `${collectionName}.${action.name}()`;
const { isAsync } = action.actionConfiguration;
let response;
if (isAsync) {
try {
response = yield call(
evaluateAndExecuteDynamicTrigger,
functionCall,
EventType.ON_JS_FUNCTION_EXECUTE,
{},
);
} catch (e) {
if (e instanceof UncaughtPromiseError) {
logActionExecutionError(e.message);
}
response = { errors: [e], result: undefined };
}
} else {
response = yield call(worker.request, EVAL_WORKER_ACTIONS.EXECUTE_SYNC_JS, {
functionCall,
});
}
feat: JS Editor (#6003) * Changes to add js plugin * routes+reducer+create template * added debugger to js editor page * entity explorer changes * create js function * added copy, move and delete action * added js plugin * added existing js functions to data tree * removed actionconfig for js collection * new js function added to data tree and entity as well * parsing flow added * changes to data tree * parse and update js functions * small changes for def creator for js action * create delete modified * small changes for update * update flow change * entity properties added * removed linting errors * small changes in entity explorer * changes for update * move, copy implementation * conflict resolved * changes for dependecy map creation * Only make the variables the binding paths * Basic eval sync working * Minor fixes * removed unwanted code * entity props and autocomplete * saving in progress show * redirection fix after delete js action * removed unnecessary line * Fixing merge conflict * added sample body * removed dummy data and added plugin Type * few PR comments fixed * automplete fix * few more PR comments fix * PR commnets fix * move and copy api change * js colleciton name refactor & 'move to page' changes & search * view changes * autocomplete added for js collections * removing till async is implemented * small changes * separate js pane response view * Executing functions * js collection to js objects * entity explorer issue and resolve action on page switch * removed unused line * small color fix * js file icon added * added js action to property pane * Property pane changes for actions * property pane changes for js functions * showing syntax error for now * actions sorted in response tab * added js objects to slash and recent entitties * enabling this to be used inside of function * eval fix * feature flag changes for entity explorer and property pane * debugger changes * copy bug fix * small changes for eval * debugger bug fix * chnaged any to specific types * error in console fix * icons update * fixed test case * test case fix * non empty check for functions * evaluate test case fix * added new icons * text change * updated time for debounce for trial * after release mereg * changed icon * after merge * PR comments simple * fixed PR comments - redux form, settings remove * js object interface changes * name refactor * export default change * delete resolve actions chnage * after merge * adding execute fn as 3rd option and removed create new js function * issue 7054 fixed - app crash * execute function on response tab changes * refactor function name part 1 * refactor of js function name * try catch added refactor * test fix * not used line removed * test cases locator fixed Co-authored-by: Nidhi <nidhi.nair93@gmail.com> Co-authored-by: hetunandu <hetu@appsmith.com>
2021-09-08 17:32:22 +00:00
const { errors, result } = response;
feat: JS Editor (#6003) * Changes to add js plugin * routes+reducer+create template * added debugger to js editor page * entity explorer changes * create js function * added copy, move and delete action * added js plugin * added existing js functions to data tree * removed actionconfig for js collection * new js function added to data tree and entity as well * parsing flow added * changes to data tree * parse and update js functions * small changes for def creator for js action * create delete modified * small changes for update * update flow change * entity properties added * removed linting errors * small changes in entity explorer * changes for update * move, copy implementation * conflict resolved * changes for dependecy map creation * Only make the variables the binding paths * Basic eval sync working * Minor fixes * removed unwanted code * entity props and autocomplete * saving in progress show * redirection fix after delete js action * removed unnecessary line * Fixing merge conflict * added sample body * removed dummy data and added plugin Type * few PR comments fixed * automplete fix * few more PR comments fix * PR commnets fix * move and copy api change * js colleciton name refactor & 'move to page' changes & search * view changes * autocomplete added for js collections * removing till async is implemented * small changes * separate js pane response view * Executing functions * js collection to js objects * entity explorer issue and resolve action on page switch * removed unused line * small color fix * js file icon added * added js action to property pane * Property pane changes for actions * property pane changes for js functions * showing syntax error for now * actions sorted in response tab * added js objects to slash and recent entitties * enabling this to be used inside of function * eval fix * feature flag changes for entity explorer and property pane * debugger changes * copy bug fix * small changes for eval * debugger bug fix * chnaged any to specific types * error in console fix * icons update * fixed test case * test case fix * non empty check for functions * evaluate test case fix * added new icons * text change * updated time for debounce for trial * after release mereg * changed icon * after merge * PR comments simple * fixed PR comments - redux form, settings remove * js object interface changes * name refactor * export default change * delete resolve actions chnage * after merge * adding execute fn as 3rd option and removed create new js function * issue 7054 fixed - app crash * execute function on response tab changes * refactor function name part 1 * refactor of js function name * try catch added refactor * test fix * not used line removed * test cases locator fixed Co-authored-by: Nidhi <nidhi.nair93@gmail.com> Co-authored-by: hetunandu <hetu@appsmith.com>
2021-09-08 17:32:22 +00:00
yield call(evalErrorHandler, errors);
return result;
feat: JS Editor (#6003) * Changes to add js plugin * routes+reducer+create template * added debugger to js editor page * entity explorer changes * create js function * added copy, move and delete action * added js plugin * added existing js functions to data tree * removed actionconfig for js collection * new js function added to data tree and entity as well * parsing flow added * changes to data tree * parse and update js functions * small changes for def creator for js action * create delete modified * small changes for update * update flow change * entity properties added * removed linting errors * small changes in entity explorer * changes for update * move, copy implementation * conflict resolved * changes for dependecy map creation * Only make the variables the binding paths * Basic eval sync working * Minor fixes * removed unwanted code * entity props and autocomplete * saving in progress show * redirection fix after delete js action * removed unnecessary line * Fixing merge conflict * added sample body * removed dummy data and added plugin Type * few PR comments fixed * automplete fix * few more PR comments fix * PR commnets fix * move and copy api change * js colleciton name refactor & 'move to page' changes & search * view changes * autocomplete added for js collections * removing till async is implemented * small changes * separate js pane response view * Executing functions * js collection to js objects * entity explorer issue and resolve action on page switch * removed unused line * small color fix * js file icon added * added js action to property pane * Property pane changes for actions * property pane changes for js functions * showing syntax error for now * actions sorted in response tab * added js objects to slash and recent entitties * enabling this to be used inside of function * eval fix * feature flag changes for entity explorer and property pane * debugger changes * copy bug fix * small changes for eval * debugger bug fix * chnaged any to specific types * error in console fix * icons update * fixed test case * test case fix * non empty check for functions * evaluate test case fix * added new icons * text change * updated time for debounce for trial * after release mereg * changed icon * after merge * PR comments simple * fixed PR comments - redux form, settings remove * js object interface changes * name refactor * export default change * delete resolve actions chnage * after merge * adding execute fn as 3rd option and removed create new js function * issue 7054 fixed - app crash * execute function on response tab changes * refactor function name part 1 * refactor of js function name * try catch added refactor * test fix * not used line removed * test cases locator fixed Co-authored-by: Nidhi <nidhi.nair93@gmail.com> Co-authored-by: hetunandu <hetu@appsmith.com>
2021-09-08 17:32:22 +00:00
}
/**
* clears all cache keys of a widget
*
* @param widgetName
*/
export function* clearEvalPropertyCacheOfWidget(widgetName: string) {
yield call(
worker.request,
EVAL_WORKER_ACTIONS.CLEAR_PROPERTY_CACHE_OF_WIDGET,
{
widgetName,
},
);
}
export function* validateProperty(
property: string,
value: any,
props: WidgetProps,
) {
const unevalTree = yield select(getUnevaluatedDataTree);
const validation = unevalTree[props.widgetName].validationPaths[property];
return yield call(worker.request, EVAL_WORKER_ACTIONS.VALIDATE_PROPERTY, {
property,
value,
props,
validation,
});
}
2020-12-30 13:26:44 +00:00
function evalQueueBuffer() {
let canTake = false;
2020-12-30 13:26:44 +00:00
let postEvalActions: any = [];
const take = () => {
if (canTake) {
2020-12-30 13:26:44 +00:00
const resp = postEvalActions;
postEvalActions = [];
canTake = false;
return { postEvalActions: resp, type: "BUFFERED_ACTION" };
2020-12-30 13:26:44 +00:00
}
};
const flush = () => {
if (canTake) {
2020-12-30 13:26:44 +00:00
return [take() as Action];
}
return [];
};
const put = (action: EvaluationReduxAction<unknown | unknown[]>) => {
2021-07-20 10:02:56 +00:00
if (!shouldProcessBatchedAction(action)) {
return;
}
canTake = true;
2020-12-30 13:26:44 +00:00
// TODO: If the action is the same as before, we can send only one and ignore duplicates.
if (action.postEvalActions) {
postEvalActions.push(...action.postEvalActions);
}
};
return {
take,
put,
isEmpty: () => {
return !canTake;
2020-12-30 13:26:44 +00:00
},
flush,
};
}
function* evaluationChangeListenerSaga() {
// Explicitly shutdown old worker if present
yield call(worker.shutdown);
yield call(worker.start);
yield call(worker.request, EVAL_WORKER_ACTIONS.SETUP);
2020-12-30 13:26:44 +00:00
widgetTypeConfigMap = WidgetFactory.getWidgetTypeConfigMap();
const initAction = yield take(FIRST_EVAL_REDUX_ACTIONS);
yield fork(evaluateTreeSaga, initAction.postEvalActions);
2020-12-30 13:26:44 +00:00
const evtActionChannel = yield actionChannel(
EVALUATE_REDUX_ACTIONS,
evalQueueBuffer(),
);
while (true) {
const action: EvaluationReduxAction<unknown | unknown[]> = yield take(
evtActionChannel,
);
if (shouldProcessBatchedAction(action)) {
feat: Undo/Redo (#6654) * Scaffolding for undo-redo * undo redo working Poc commit * memory performance improvements by diffing * dont run update on undo/redo" * merging widget postion update and canvas bottom row update into one dsl update. * fix tabs widget * Visible updates per undo redo action (#6838) Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> * resize atomic operation * fix switch control state issue * disallow undo/redo for snipping and comment mode * disallow undo/redo for snipping and comment mode * fix color picker issue in undo/redo * add test for replayDSL * option control fix, adding logs * minor position change undo redo updates * add test cases for replayHelpers * property Upade visual change * remove unused code * global hot key jest test for undo redo * Fixing batch updates on property change.. * add tests for toggle control in property pane * unwanted utils. * add tests for text control * add tests for deletion * add tests for dropping a new widget * adding jest test for replayUtils * add move widget tests * add tests for color picker control * add analytics for undo/redo * add analytics for undo/redo * tab addition atomic * cypress tests for propertyPane, toasts and radiowidget optionControl * replayDSL end of redo stack fix * property update changes * menu option control debounce input * color picker empty undo fix * fix cypress tests * widget add/remove atomic * revert alternative approach to handle atomic operations * update replayDSL test * add some comments * addressing review comments * flash color for property pane controls * Fixing adding of tabs widget as well. * code review comments. * merging widget postion update and canvas bottom row update into one dsl update. * fix ordering of tabs property control * meta property update canvas min height. * fixing failed specs. * Fixing entity explorer update on deleting tab from entity explorer. * address review comments and minor property update changes * fixing failing tests * merge conflicts * changes to cater widget api. * fix suggested widget table issue * draggable list for undo redo * fix widget name focus * excluding canvas updates. * fixing codeEditor update on propertySection collapse * fixed failing test case Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: Rahul R <rahulramesha@Rahuls-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-09-21 07:55:56 +00:00
yield call(
evaluateTreeSaga,
action.postEvalActions,
get(action, "payload.shouldReplay"),
);
}
}
}
export function* evaluateSnippetSaga(action: any) {
try {
let { expression } = action.payload;
const { dataType, isTrigger } = action.payload;
if (isTrigger) {
expression = `function() { ${expression} }`;
}
const workerResponse: {
errors: any;
result: any;
triggers: any;
} = yield call(worker.request, EVAL_WORKER_ACTIONS.EVAL_EXPRESSION, {
expression,
dataType,
isTrigger,
});
const { errors, result, triggers } = workerResponse;
if (triggers && triggers.length > 0) {
yield all(
triggers.map((trigger: any) =>
call(
executeActionTriggers,
trigger,
EventType.ON_SNIPPET_EXECUTE,
{},
),
),
);
//Result is when trigger is present. Following code will hide the evaluated snippet section
yield put(setEvaluatedSnippet(result));
} else {
/*
JSON.stringify(undefined) is undefined.
We need to set it manually to "undefined" for codeEditor to display it.
*/
yield put(
setEvaluatedSnippet(
errors?.length
? JSON.stringify(errors, null, 2)
: isUndefined(result)
? "undefined"
: JSON.stringify(result),
),
);
}
Toaster.show({
text: createMessage(
errors?.length ? SNIPPET_EXECUTION_FAILED : SNIPPET_EXECUTION_SUCCESS,
),
variant: errors?.length ? Variant.danger : Variant.success,
});
yield put(
setGlobalSearchFilterContext({
executionInProgress: false,
}),
);
} catch (e) {
yield put(
setGlobalSearchFilterContext({
executionInProgress: false,
}),
);
Toaster.show({
text: createMessage(SNIPPET_EXECUTION_FAILED),
variant: Variant.danger,
});
log.error(e);
Sentry.captureException(e);
}
}
export function* evaluateArgumentSaga(action: any) {
const { name, type, value } = action.payload;
try {
const workerResponse = yield call(
worker.request,
EVAL_WORKER_ACTIONS.EVAL_EXPRESSION,
{
expression: value,
},
);
const lintErrors = (workerResponse.errors || []).filter(
(error: any) => error.errorType !== PropertyEvaluationErrorType.LINT,
);
if (workerResponse.result) {
const validation = validate({ type }, workerResponse.result, {});
if (!validation.isValid)
validation.messages?.map((message) => {
lintErrors.unshift({
...validation,
...{
errorType: PropertyEvaluationErrorType.VALIDATION,
errorMessage: message,
},
});
});
}
yield put(
setEvaluatedArgument({
[name]: {
type,
value: workerResponse.result,
name,
errors: lintErrors,
isInvalid: lintErrors.length > 0,
},
}),
);
} catch (e) {
log.error(e);
Sentry.captureException(e);
}
}
2021-12-07 09:45:18 +00:00
export function* updateReplayEntitySaga(
actionPayload: ReduxAction<{
entityId: string;
entity: Replayable;
entityType: ENTITY_TYPE;
}>,
) {
//Delay updates to replay object to not persist every keystroke
yield delay(REPLAY_DELAY);
const { entity, entityId, entityType } = actionPayload.payload;
const workerResponse = yield call(
worker.request,
EVAL_WORKER_ACTIONS.UPDATE_REPLAY_OBJECT,
{
entityId,
entity,
entityType,
},
);
return workerResponse;
}
export function* workerComputeUndoRedo(operation: string, entityId: string) {
const workerResponse: any = yield call(worker.request, operation, {
entityId,
});
return workerResponse;
}
// Type to represent the state of the evaluation reducer
export interface FormEvaluationConfig
extends ReduxAction<FormEvalActionPayload> {
currentEvalState: FormEvaluationState;
}
// Function to trigger the form eval job in the worker
export function* evalFormConfig(formEvaluationConfigObj: FormEvaluationConfig) {
const workerResponse: any = yield call(
worker.request,
EVAL_WORKER_ACTIONS.INIT_FORM_EVAL,
formEvaluationConfigObj,
);
return workerResponse;
}
export function* setAppVersionOnWorkerSaga(action: {
type: ReduxActionType;
payload: EvaluationVersion;
}) {
const version: EvaluationVersion = action.payload;
yield call(worker.request, EVAL_WORKER_ACTIONS.SET_EVALUATION_VERSION, {
version,
});
}
export default function* evaluationSagaListeners() {
2020-12-30 13:26:44 +00:00
yield take(ReduxActionTypes.START_EVALUATION);
while (true) {
try {
yield call(evaluationChangeListenerSaga);
} catch (e) {
log.error(e);
Sentry.captureException(e);
}
}
}