Skip to content

Commit

Permalink
Merge branch 'release' into test/appimport
Browse files Browse the repository at this point in the history
  • Loading branch information
Aishwarya-U-R committed Sep 28, 2023
2 parents 3e8b6ea + d5ad29d commit c851cc6
Show file tree
Hide file tree
Showing 42 changed files with 1,158 additions and 299 deletions.
19 changes: 19 additions & 0 deletions app/client/src/actions/pluginActionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,25 @@ export const bindDataOnCanvas = (payload: {
};
};

export const updateActionData = ({
data,
dataPath,
entityName,
}: {
entityName: string;
dataPath: string;
data: unknown;
}) => {
return {
type: ReduxActionTypes.UPDATE_ACTION_DATA,
payload: {
entityName,
dataPath,
data,
},
};
};

export default {
createAction: createActionRequest,
fetchActions,
Expand Down
1 change: 0 additions & 1 deletion app/client/src/ce/actions/evaluationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const EVALUATE_REDUX_ACTIONS = [
ReduxActionTypes.FETCH_JS_ACTIONS_VIEW_MODE_SUCCESS,
ReduxActionErrorTypes.FETCH_JS_ACTIONS_VIEW_MODE_ERROR,
ReduxActionTypes.UPDATE_JS_ACTION_BODY_SUCCESS,
ReduxActionTypes.SET_JS_FUNCTION_EXECUTION_DATA,
// App Data
ReduxActionTypes.SET_APP_MODE,
ReduxActionTypes.FETCH_USER_DETAILS_SUCCESS,
Expand Down
1 change: 1 addition & 0 deletions app/client/src/ce/constants/ReduxActionConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ const ActionTypes = {
DELETE_MULTIPLE_APPLICATION_SUCCESS: "DELETE_MULTIPLE_APPLICATION_SUCCESS",
DELETE_MULTIPLE_APPLICATION_CANCEL: "DELETE_MULTIPLE_APPLICATION_CANCEL",
TRIGGER_EVAL: "TRIGGER_EVAL",
UPDATE_ACTION_DATA: "UPDATE_ACTION_DATA",
};

export const ReduxActionTypes = {
Expand Down
35 changes: 33 additions & 2 deletions app/client/src/ce/sagas/ActionExecution/ActionExecutionSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import type {
} from "constants/AppsmithActionConstants/ActionConstants";
import { TriggerKind } from "constants/AppsmithActionConstants/ActionConstants";
import * as log from "loglevel";
import { all, call, put, takeEvery, takeLatest } from "redux-saga/effects";
import {
all,
call,
put,
takeEvery,
takeLatest,
select,
} from "redux-saga/effects";
import {
evaluateActionSelectorFieldSaga,
evaluateAndExecuteDynamicTrigger,
Expand All @@ -19,7 +26,10 @@ import copySaga from "sagas/ActionExecution/CopyActionSaga";
import resetWidgetActionSaga from "sagas/ActionExecution/ResetWidgetActionSaga";
import showAlertSaga from "sagas/ActionExecution/ShowAlertActionSaga";
import executePluginActionTriggerSaga from "sagas/ActionExecution/PluginActionSaga";
import { clearActionResponse } from "actions/pluginActionActions";
import {
clearActionResponse,
updateActionData,
} from "actions/pluginActionActions";
import {
closeModalSaga,
openModalSaga,
Expand All @@ -32,6 +42,8 @@ import {
} from "sagas/ActionExecution/geolocationSaga";
import { postMessageSaga } from "sagas/ActionExecution/PostMessageSaga";
import type { ActionDescription } from "@appsmith/workers/Evaluation/fns";
import { getActionById } from "selectors/editorSelectors";
import type { AppState } from "@appsmith/reducers";

export type TriggerMeta = {
source?: TriggerSource;
Expand All @@ -58,6 +70,25 @@ export function* executeActionTriggers(
break;
case "CLEAR_PLUGIN_ACTION":
yield put(clearActionResponse(trigger.payload.actionId));
const action: ReturnType<typeof getActionById> = yield select(
(state: AppState) =>
getActionById(state, {
match: {
params: {
apiId: trigger.payload.actionId,
},
},
}),
);
if (action) {
yield put(
updateActionData({
entityName: action.name,
dataPath: "data",
data: undefined,
}),
);
}
break;
case "NAVIGATE_TO":
yield call(navigateActionSaga, trigger);
Expand Down
1 change: 1 addition & 0 deletions app/client/src/ce/workers/Evaluation/evalWorkerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum EVAL_WORKER_SYNC_ACTION {
INIT_FORM_EVAL = "INIT_FORM_EVAL",
UNINSTALL_LIBRARY = "UNINSTALL_LIBRARY",
LINT_TREE = "LINT_TREE",
UPDATE_ACTION_DATA = "UPDATE_ACTION_DATA",
}

export enum EVAL_WORKER_ASYNC_ACTION {
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/ce/workers/Evaluation/evaluationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ export function convertJSFunctionsToString(
for (const funcName in jsFunctions) {
if (jsCollection[funcName] instanceof String) {
if (has(jsCollection, [funcName, "data"])) {
set(jsCollection, [`${funcName}.data`], jsCollection[funcName].data);
set(jsCollection, [`${funcName}.data`], {});
}
set(jsCollection, funcName, jsCollection[funcName].toString());
}
Expand Down
4 changes: 3 additions & 1 deletion app/client/src/entities/DataTree/dataTreeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export const generateDataTreeAction = (
actionId: action.config.id,
run: {},
clear: {},
data: action.data ? action.data.body : undefined,
// Data is always set to undefined in the unevalTree
// Action data is updated directly to the dataTree (see updateActionData.ts)
data: undefined,
isLoading: action.isLoading,
responseMeta: {
statusCode: action.data?.statusCode,
Expand Down
14 changes: 3 additions & 11 deletions app/client/src/entities/DataTree/dataTreeJSAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ describe("generateDataTreeJSAction", () => {
},
],
},
data: {
abcd: {
users: [{ id: 1, name: "John" }],
},
},
data: {},
};
const expectedData = {
myVar1: [],
Expand All @@ -137,9 +133,7 @@ describe("generateDataTreeJSAction", () => {
body: "export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\tmyFun1: () => {\n\t\t//write code here\n\t},\n\tmyFun2: async () => {\n\t\t//use async-await or promises\n\t}\n}",

myFun2: {
data: {
users: [{ id: 1, name: "John" }],
},
data: {},
},
myFun1: {
data: {},
Expand Down Expand Up @@ -336,9 +330,7 @@ describe("generateDataTreeJSAction", () => {
body: "export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\tmyFun1: () => {\n\t\t//write code here\n\t return JSObject2.myFun2},\n\tmyFun2: async () => {\n\t\t//use async-await or promises\n\t}\n}",
ENTITY_TYPE: "JSACTION",
myFun2: {
data: {
users: [{ id: 1, name: "John" }],
},
data: {},
},
myFun1: {
data: {},
Expand Down
4 changes: 3 additions & 1 deletion app/client/src/entities/DataTree/dataTreeJSAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export const generateDataTreeJSAction = (js: JSCollectionData): any => {
dynamicBindingPathList.push({ key: action.name });
dependencyMap["body"].push(action.name);
actionsData[action.name] = {
data: (js.data && js.data[`${action.id}`]) || {},
// Data is always set to {} in the unevalTree
// Action data is updated directly to the dataTree (see updateActionData.ts)
data: {},
};
}
}
Expand Down
58 changes: 57 additions & 1 deletion app/client/src/sagas/ActionExecution/PluginActionSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
executePluginActionSuccess,
runAction,
updateAction,
updateActionData,
} from "actions/pluginActionActions";
import { makeUpdateJSCollection } from "sagas/JSPaneSagas";

Expand Down Expand Up @@ -101,7 +102,7 @@ import * as log from "loglevel";
import { EMPTY_RESPONSE } from "components/editorComponents/emptyResponse";
import type { AppState } from "@appsmith/reducers";
import { DEFAULT_EXECUTE_ACTION_TIMEOUT_MS } from "@appsmith/constants/ApiConstants";
import { evaluateActionBindings } from "sagas/EvaluationsSaga";
import { evalWorker, evaluateActionBindings } from "sagas/EvaluationsSaga";
import { isBlobUrl, parseBlobUrl } from "utils/AppsmithUtils";
import { getType, Types } from "utils/TypeHelpers";
import { matchPath } from "react-router";
Expand Down Expand Up @@ -158,6 +159,7 @@ import {
getCurrentEnvironmentDetails,
getCurrentEnvironmentName,
} from "@appsmith/selectors/environmentSelectors";
import { EVAL_WORKER_ACTIONS } from "@appsmith/workers/Evaluation/evalWorkerActions";

enum ActionResponseDataTypes {
BINARY = "BINARY",
Expand Down Expand Up @@ -1171,6 +1173,13 @@ function* executePageLoadAction(pageAction: PageAction) {
data: payload,
}),
);
yield put(
updateActionData({
entityName: action.name,
dataPath: "data",
data: payload.body,
}),
);
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.EXECUTE_ACTION,
{
Expand Down Expand Up @@ -1226,6 +1235,13 @@ function* executePageLoadAction(pageAction: PageAction) {
isPageLoad: true,
}),
);
yield put(
updateActionData({
entityName: action.name,
dataPath: "data",
data: payload.body,
}),
);
yield take(ReduxActionTypes.SET_EVALUATED_TREE);
}
}
Expand Down Expand Up @@ -1379,6 +1395,14 @@ function* executePluginActionSaga(
response: payload,
}),
);

yield put(
updateActionData({
entityName: pluginAction.name,
dataPath: "data",
data: payload.body,
}),
);
// TODO: Plugins are not always fetched before on page load actions are executed.
try {
let plugin: Plugin | undefined;
Expand Down Expand Up @@ -1432,6 +1456,13 @@ function* executePluginActionSaga(
response: EMPTY_RESPONSE,
}),
);
yield put(
updateActionData({
entityName: pluginAction.name,
dataPath: "data",
data: EMPTY_RESPONSE.body,
}),
);
if (e instanceof UserCancelledActionExecutionError) {
// Case: user cancelled the request of file upload
if (filePickerInstrumentation.numberOfFiles > 0) {
Expand Down Expand Up @@ -1500,6 +1531,13 @@ function* clearTriggerActionResponse() {
// Clear the action response if the action has data and is not executeOnLoad.
if (action.data && !action.config.executeOnLoad) {
yield put(clearActionResponse(action.config.id));
yield put(
updateActionData({
entityName: action.config.name,
dataPath: "data",
data: undefined,
}),
);
}
}
}
Expand Down Expand Up @@ -1542,6 +1580,23 @@ function* softRefreshActionsSaga() {
});
}

function* handleUpdateActionData(
action: ReduxAction<{
entityName: string;
dataPath: string;
data: unknown;
}>,
) {
const { data, dataPath, entityName } = action.payload;
yield call(evalWorker.request, EVAL_WORKER_ACTIONS.UPDATE_ACTION_DATA, [
{
entityName,
dataPath,
data,
},
]);
}

export function* watchPluginActionExecutionSagas() {
yield all([
takeLatest(ReduxActionTypes.RUN_ACTION_REQUEST, runActionSaga),
Expand All @@ -1555,5 +1610,6 @@ export function* watchPluginActionExecutionSagas() {
),
takeLatest(ReduxActionTypes.PLUGIN_SOFT_REFRESH, softRefreshActionsSaga),
takeEvery(ReduxActionTypes.EXECUTE_JS_UPDATES, makeUpdateJSCollection),
takeEvery(ReduxActionTypes.UPDATE_ACTION_DATA, handleUpdateActionData),
]);
}
12 changes: 11 additions & 1 deletion app/client/src/sagas/OnboardingSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ import { RenderModes } from "constants/WidgetConstants";
import log from "loglevel";
import { getDataTree } from "selectors/dataTreeSelectors";
import { getWidgets } from "./selectors";
import { clearActionResponse } from "actions/pluginActionActions";
import {
clearActionResponse,
updateActionData,
} from "actions/pluginActionActions";
import {
importApplication,
updateApplicationLayout,
Expand Down Expand Up @@ -216,6 +219,13 @@ function* setUpTourAppSaga() {
// Update getCustomers query body
const query: ActionData | undefined = yield select(getQueryAction);
yield put(clearActionResponse(query?.config.id ?? ""));
yield put(
updateActionData({
entityName: query?.config.name || "",
dataPath: "data",
data: undefined,
}),
);
const applicationId: string = yield select(getCurrentApplicationId);
yield put(
updateApplicationLayout(applicationId || "", {
Expand Down
34 changes: 34 additions & 0 deletions app/client/src/workers/Evaluation/dataStore/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { convertPathToString } from "@appsmith/workers/Evaluation/evaluationUtils";
import type { Diff } from "deep-diff";
import type { DataTree } from "entities/DataTree/dataTreeFactory";
import { get, set, unset } from "lodash";

export type TDataStore = Record<string, Record<string, unknown>>;
export default class DataStore {
private static store: TDataStore = {};

static setActionData(fullPath: string, value: unknown) {
set(this.store, fullPath, value);
}

static getActionData(fullPath: string): unknown | undefined {
return get(this.store, fullPath, undefined);
}
static getDataStore() {
return this.store;
}
static deleteActionData(fullPath: string) {
unset(this.store, fullPath);
}
static clear() {
this.store = {};
}
static update(dataTreeDiff: Diff<DataTree, DataTree>[]) {
const deleteDiffs = dataTreeDiff.filter((diff) => diff.kind === "D");
deleteDiffs.forEach((diff) => {
const deletedPath = diff.path || [];
const deletedPathString = convertPathToString(deletedPath);
this.deleteActionData(deletedPathString);
});
}
}
28 changes: 28 additions & 0 deletions app/client/src/workers/Evaluation/dataStore/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { DataTree } from "entities/DataTree/dataTreeFactory";
import type { TDataStore } from ".";
import {
isAction,
isJSAction,
} from "@appsmith/workers/Evaluation/evaluationUtils";
import { get, isEmpty, set } from "lodash";

export function updateTreeWithData(tree: DataTree, dataStore: TDataStore) {
if (isEmpty(dataStore)) return;
for (const entityName of Object.keys(tree)) {
const entity = tree[entityName];
if (!dataStore.hasOwnProperty(entityName)) continue;
if (isAction(entity)) {
set(entity, "data", get(dataStore, `${entityName}.data`));
}
if (isJSAction(entity)) {
const allFunctionsInStore = Object.keys(dataStore[entityName]);
allFunctionsInStore.forEach((functionName) => {
set(
entity[functionName],
`data`,
get(dataStore, `${entityName}.${functionName}.data`),
);
});
}
}
}
Loading

0 comments on commit c851cc6

Please sign in to comment.