Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig
export const THEME = EditorTheme.LIGHT;

export enum ActionRunBehaviour {
PAGE_LOAD = "PAGE_LOAD",
ON_PAGE_LOAD = "ON_PAGE_LOAD",
MANUAL = "MANUAL",
}

export const RUN_BEHAVIOR = {
PAGE_LOAD: {
ON_PAGE_LOAD: {
label: "On page load",
subText: "Query runs when the page loads or when manually triggered",
value: ActionRunBehaviour.PAGE_LOAD,
value: ActionRunBehaviour.ON_PAGE_LOAD,
},
MANUAL: {
label: "Manual",
Expand All @@ -21,3 +21,5 @@ export const RUN_BEHAVIOR = {
};

export const RUN_BEHAVIOR_VALUES = Object.values(RUN_BEHAVIOR);

export type ActionRunBehaviourType = `${ActionRunBehaviour}`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import {
MultiPartOptionTypes,
POST_BODY_FORMAT_OPTIONS,
} from "../constants/CommonApiConstants";
import { ActionRunBehaviour } from "PluginActionEditor/constants/PluginActionConstants";

// jest.mock("POST_");

const BASE_ACTION: ApiAction = {
dynamicBindingPathList: [],
cacheResponse: "",
executeOnLoad: false,
runBehavior: ActionRunBehaviour.MANUAL,
runBehavior: "MANUAL",
invalids: [],
isValid: false,
workspaceId: "",
Expand Down
13 changes: 7 additions & 6 deletions app/client/src/actions/pluginActionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { EventLocation } from "ee/utils/analyticsUtilTypes";
import type { GenerateDestinationIdInfoReturnType } from "ee/sagas/helpers";
import type { Span } from "instrumentation/types";
import type { EvaluationReduxAction } from "./EvaluationReduxActionTypes";
import type { ActionRunBehaviour } from "PluginActionEditor/constants/PluginActionConstants";

export const createActionRequest = (
payload: Partial<Action>,
Expand Down Expand Up @@ -351,29 +352,29 @@ export const executePageLoadActions = (
};
};

export const setActionsToExecuteOnPageLoad = (
export const setActionsRunBehavior = (
actions: Array<{
executeOnLoad: boolean;
runBehavior: ActionRunBehaviour;
id: string;
name: string;
}>,
) => {
return {
type: ReduxActionTypes.SET_ACTION_TO_EXECUTE_ON_PAGELOAD,
type: ReduxActionTypes.SET_ACTION_RUN_BEHAVIOR,
payload: actions,
};
};

export const setJSActionsToExecuteOnPageLoad = (
export const setJSActionsRunBehavior = (
actions: Array<{
executeOnLoad: boolean;
runBehavior: ActionRunBehaviour;
id: string;
name: string;
collectionId?: string;
}>,
) => {
return {
type: ReduxActionTypes.SET_JS_ACTION_TO_EXECUTE_ON_PAGELOAD,
type: ReduxActionTypes.SET_JS_ACTION_RUN_BEHAVIOR,
payload: actions,
};
};
Expand Down
9 changes: 5 additions & 4 deletions app/client/src/api/ActionAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { APIRequest } from "constants/AppsmithActionConstants/ActionConstan
import type { WidgetType } from "constants/WidgetConstants";
import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers";
import type { PostActionRunConfig } from "./types";
import type { ActionRunBehaviourType } from "PluginActionEditor/constants/PluginActionConstants";

export interface Property {
key: string;
Expand Down Expand Up @@ -301,12 +302,12 @@ class ActionAPI extends API {
});
}

static async toggleActionExecuteOnLoad(
static async updateActionRunBehavior(
actionId: string,
shouldExecute: boolean,
runBehavior: ActionRunBehaviourType,
) {
return API.put(ActionAPI.url + `/executeOnLoad/${actionId}`, undefined, {
flag: shouldExecute.toString(),
return API.put(ActionAPI.url + `/runBehavior/${actionId}`, undefined, {
behavior: runBehavior,
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/client/src/api/PageApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
import type { DSLWidget } from "WidgetProvider/constants";
import type { FetchApplicationResponse } from "ee/api/ApplicationApi";
import type { APP_MODE } from "entities/App";
import type { ActionRunBehaviour } from "PluginActionEditor/constants/PluginActionConstants";

export interface FetchPageRequest {
pageId: string;
Expand Down Expand Up @@ -69,7 +70,7 @@ export interface SavePageResponseData {
dsl: Partial<DSLWidget>;
messages: string[];
actionUpdates: Array<{
executeOnLoad: boolean;
runBehavior: ActionRunBehaviour;
id: string;
name: string;
collectionId?: string;
Expand Down
17 changes: 8 additions & 9 deletions app/client/src/ce/constants/ReduxActionConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ const JSEditorActionTypes = {
SET_FUNCTION_PROPERTY: "SET_FUNCTION_PROPERTY",
UPDATE_JS_FUNCTION_PROPERTY_INIT: "UPDATE_JS_FUNCTION_PROPERTY_INIT",
UPDATE_JS_FUNCTION_PROPERTY_SUCCESS: "UPDATE_JS_FUNCTION_PROPERTY_SUCCESS",
TOGGLE_FUNCTION_EXECUTE_ON_LOAD_INIT: "TOGGLE_FUNCTION_EXECUTE_ON_LOAD_INIT",
TOGGLE_FUNCTION_EXECUTE_ON_LOAD_SUCCESS:
"TOGGLE_FUNCTION_EXECUTE_ON_LOAD_SUCCESS",
SET_JS_ACTION_TO_EXECUTE_ON_PAGELOAD: "SET_JS_ACTION_TO_EXECUTE_ON_PAGELOAD",
SET_JS_ACTION_RUN_BEHAVIOR: "SET_JS_ACTION_RUN_BEHAVIOR",
SET_ACTIVE_JS_ACTION: "SET_ACTIVE_JS_ACTION",
UPDATE_FUNCTION_RUN_BEHAVIOR_INIT: "UPDATE_FUNCTION_RUN_BEHAVIOR_INIT",
UPDATE_FUNCTION_RUN_BEHAVIOR_SUCCESS: "UPDATE_FUNCTION_RUN_BEHAVIOR_SUCCESS",
};

const JSEditorActionErrorTypes = {
Expand All @@ -85,6 +84,7 @@ const JSEditorActionErrorTypes = {
REFACTOR_JS_ACTION_NAME_ERROR: "REFACTOR_JS_ACTION_NAME_ERROR",
UPDATE_JS_ACTION_BODY_ERROR: "UPDATE_JS_ACTION_BODY_ERROR",
UPDATE_JS_FUNCTION_PROPERTY_ERROR: "UPDATE_JS_FUNCTION_PROPERTY_ERROR",
UPDATE_FUNCTION_RUN_BEHAVIOR_ERROR: "UPDATE_FUNCTION_RUN_BEHAVIOR_ERROR",
};

const GitActionTypes = {
Expand Down Expand Up @@ -805,10 +805,9 @@ const ActionActionTypes = {
SET_ACTION_PROPERTY: "SET_ACTION_PROPERTY",
UPDATE_ACTION_PROPERTY: "UPDATE_ACTION_PROPERTY",
SWITCH_DATASOURCE: "SWITCH_DATASOURCE",
SET_ACTION_TO_EXECUTE_ON_PAGELOAD: "SET_ACTION_TO_EXECUTE_ON_PAGELOAD",
TOGGLE_ACTION_EXECUTE_ON_LOAD_SUCCESS:
"TOGGLE_ACTION_EXECUTE_ON_LOAD_SUCCESS",
TOGGLE_ACTION_EXECUTE_ON_LOAD_INIT: "TOGGLE_ACTION_EXECUTE_ON_LOAD_INIT",
SET_ACTION_RUN_BEHAVIOR: "SET_ACTION_RUN_BEHAVIOR",
UPDATE_ACTION_RUN_BEHAVIOR_INIT: "UPDATE_ACTION_RUN_BEHAVIOR_INIT",
UPDATE_ACTION_RUN_BEHAVIOR_SUCCESS: "UPDATE_ACTION_RUN_BEHAVIOR_SUCCESS",
};

const ActionActionErrorTypes = {
Expand All @@ -822,7 +821,7 @@ const ActionActionErrorTypes = {
FETCH_ACTIONS_FOR_PAGE_ERROR: "FETCH_ACTIONS_FOR_PAGE_ERROR",
SAVE_ACTION_NAME_ERROR: "SAVE_ACTION_NAME_ERROR",
SAVE_API_NAME_ERROR: "SAVE_API_NAME_ERROR",
TOGGLE_ACTION_EXECUTE_ON_LOAD_ERROR: "TOGGLE_ACTION_EXECUTE_ON_LOAD_ERROR",
UPDATE_ACTION_RUN_BEHAVIOR_ERROR: "UPDATE_ACTION_RUN_BEHAVIOR_ERROR",
};

const PropertyPanelActionTypes = {
Expand Down
8 changes: 4 additions & 4 deletions app/client/src/ce/entities/DataTree/dataTreeJSAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("generateDataTreeJSAction", () => {
body: "async () => {\n\t\t//use async-await or promises\n\t}",
jsArguments: [],
},
executeOnLoad: false,
runBehavior: "MANUAL",
dynamicBindingPathList: [
{
key: "body",
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("generateDataTreeJSAction", () => {
body: "() => {\n\t\t//write code here\n\t}",
jsArguments: [],
},
executeOnLoad: false,
runBehavior: "MANUAL",
clientSideExecution: true,
dynamicBindingPathList: [
{
Expand Down Expand Up @@ -239,7 +239,7 @@ describe("generateDataTreeJSAction", () => {
body: "async () => {\n\t\t//use async-await or promises\n\t}",
jsArguments: [],
},
executeOnLoad: false,
runBehavior: "MANUAL",
dynamicBindingPathList: [
{
key: "body",
Expand Down Expand Up @@ -286,7 +286,7 @@ describe("generateDataTreeJSAction", () => {
body: "() => {\n\t\t//write code here\n\t}",
jsArguments: [],
},
executeOnLoad: false,
runBehavior: "MANUAL",
clientSideExecution: true,
dynamicBindingPathList: [
{
Expand Down
9 changes: 5 additions & 4 deletions app/client/src/ce/reducers/entityReducers/actionsReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
UpdateActionPropertyActionPayload,
} from "actions/pluginActionActions";
import { klona } from "klona";
import type { ActionRunBehaviour } from "PluginActionEditor/constants/PluginActionConstants";

export interface ActionData {
isLoading: boolean;
Expand Down Expand Up @@ -310,11 +311,11 @@ export const handlers = {
},
]);
},
[ReduxActionTypes.SET_ACTION_TO_EXECUTE_ON_PAGELOAD]: (
[ReduxActionTypes.SET_ACTION_RUN_BEHAVIOR]: (
draftMetaState: ActionDataState,
action: ReduxAction<
Array<{
executeOnLoad: boolean;
runBehavior: ActionRunBehaviour;
id: string;
name: string;
}>
Expand All @@ -324,8 +325,8 @@ export const handlers = {

draftMetaState.forEach((action) => {
if (action.config.id in actionUpdateSearch) {
action.config.executeOnLoad =
actionUpdateSearch[action.config.id].executeOnLoad;
action.config.runBehavior =
actionUpdateSearch[action.config.id].runBehavior;
}
});
},
Expand Down
13 changes: 7 additions & 6 deletions app/client/src/ce/reducers/entityReducers/jsActionsReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { set, keyBy, findIndex, unset } from "lodash";
import { create } from "mutative";
import { klona } from "klona";
import type { ActionRunBehaviour } from "PluginActionEditor/constants/PluginActionConstants";

export const initialState: JSCollectionDataState = [];

Expand Down Expand Up @@ -360,19 +361,19 @@ export const handlers = {

return a;
}),
[ReduxActionTypes.TOGGLE_FUNCTION_EXECUTE_ON_LOAD_SUCCESS]: (
[ReduxActionTypes.UPDATE_FUNCTION_RUN_BEHAVIOR_SUCCESS]: (
state: JSCollectionDataState,
action: ReduxAction<{
actionId: string;
collectionId: string;
executeOnLoad: boolean;
runBehavior: ActionRunBehaviour;
}>,
): JSCollectionDataState =>
state.map((a) => {
if (a.config.id === action.payload.collectionId) {
const updatedActions = a.config.actions.map((jsAction) => {
if (jsAction.id === action.payload.actionId) {
set(jsAction, `executeOnLoad`, action.payload.executeOnLoad);
set(jsAction, `runBehavior`, action.payload.runBehavior);
}

return jsAction;
Expand All @@ -389,11 +390,11 @@ export const handlers = {

return a;
}),
[ReduxActionTypes.SET_JS_ACTION_TO_EXECUTE_ON_PAGELOAD]: (
[ReduxActionTypes.SET_JS_ACTION_RUN_BEHAVIOR]: (
state: JSCollectionDataState,
action: ReduxAction<
Array<{
executeOnLoad: boolean;
runBehavior: ActionRunBehaviour;
id: string;
name: string;
collectionId: string;
Expand All @@ -410,7 +411,7 @@ export const handlers = {

allActions.forEach((js) => {
if (js.id in actionUpdateSearch) {
js.executeOnLoad = actionUpdateSearch[js.id].executeOnLoad;
js.runBehavior = actionUpdateSearch[js.id].runBehavior;
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions app/client/src/ce/sagas/PageSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ import {
fetchActionsForPageError,
fetchActionsForPageSuccess,
fetchActionsForView,
setActionsToExecuteOnPageLoad,
setJSActionsToExecuteOnPageLoad,
setActionsRunBehavior,
setJSActionsRunBehavior,
} from "actions/pluginActionActions";
import type { UrlDataState } from "reducers/entityReducers/appReducer";
import { APP_MODE } from "entities/App";
Expand Down Expand Up @@ -536,15 +536,15 @@ export function* savePageSaga(action: ReduxAction<{ isRetry?: boolean }>) {
);

if (actions && actions.length) {
yield put(setActionsToExecuteOnPageLoad(actions));
yield put(setActionsRunBehavior(actions));
}

const jsActions = actionUpdates.filter((d) =>
d.hasOwnProperty("collectionId"),
);

if (jsActions && jsActions.length) {
yield put(setJSActionsToExecuteOnPageLoad(jsActions));
yield put(setJSActionsRunBehavior(jsActions));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const jsObject: JSCollectionData = {
jsArguments: [],
isAsync: false,
},
executeOnLoad: false,
runBehavior: "MANUAL",
clientSideExecution: true,
dynamicBindingPathList: [
{
Expand Down Expand Up @@ -86,7 +86,7 @@ const jsObject: JSCollectionData = {
jsArguments: [],
isAsync: true,
},
executeOnLoad: false,
runBehavior: "MANUAL",
clientSideExecution: true,
dynamicBindingPathList: [
{
Expand Down
Loading