2023-12-06 19:18:52 +00:00
|
|
|
import type { Action } from "entities/Action";
|
2024-03-12 10:06:33 +00:00
|
|
|
import { ActionExecutionContext } from "entities/Action";
|
2023-12-06 19:18:52 +00:00
|
|
|
import type { JSAction, JSCollection } from "entities/JSCollection";
|
2023-12-19 10:58:02 +00:00
|
|
|
import type { ApplicationPayload } from "@appsmith/constants/ReduxActionConstants";
|
|
|
|
|
import store from "store";
|
|
|
|
|
import { getAppMode } from "@appsmith/selectors/applicationSelectors";
|
|
|
|
|
import { getDatasource } from "@appsmith/selectors/entitiesSelector";
|
|
|
|
|
import { getCurrentEnvironmentDetails } from "@appsmith/selectors/environmentSelectors";
|
|
|
|
|
import type { Plugin } from "api/PluginApi";
|
2024-01-24 16:49:55 +00:00
|
|
|
import { get, isNil } from "lodash";
|
2024-05-04 00:16:37 +00:00
|
|
|
import type { JSCollectionData } from "@appsmith/reducers/entityReducers/jsActionsReducer";
|
2023-12-06 19:18:52 +00:00
|
|
|
|
|
|
|
|
export function getPluginActionNameToDisplay(action: Action) {
|
|
|
|
|
return action.name;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 16:49:55 +00:00
|
|
|
export const getActionProperties = (
|
|
|
|
|
action: Action,
|
|
|
|
|
keyConfig: Record<string, string>,
|
|
|
|
|
) => {
|
|
|
|
|
const actionProperties: Record<string, unknown> = {};
|
|
|
|
|
Object.keys(keyConfig).forEach((key) => {
|
|
|
|
|
const value = get(action, key);
|
|
|
|
|
if (!isNil(value)) {
|
|
|
|
|
actionProperties[keyConfig[key]] = get(action, key);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return actionProperties;
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-06 19:18:52 +00:00
|
|
|
export function getJSActionPathNameToDisplay(
|
|
|
|
|
action: JSAction,
|
|
|
|
|
collection: JSCollection,
|
|
|
|
|
) {
|
|
|
|
|
return collection.name + "." + action.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getJSActionNameToDisplay(action: JSAction) {
|
|
|
|
|
return action.name;
|
|
|
|
|
}
|
2023-12-19 10:58:02 +00:00
|
|
|
|
2024-02-07 11:06:01 +00:00
|
|
|
export function getCollectionNameToDisplay(
|
|
|
|
|
_: JSAction,
|
|
|
|
|
collectionName: string,
|
|
|
|
|
) {
|
|
|
|
|
return collectionName;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-19 10:58:02 +00:00
|
|
|
export function getActionExecutionAnalytics(
|
|
|
|
|
action: Action,
|
|
|
|
|
plugin: Plugin,
|
|
|
|
|
params: Record<string, unknown>,
|
|
|
|
|
currentApp: ApplicationPayload,
|
|
|
|
|
datasourceId: string,
|
|
|
|
|
) {
|
|
|
|
|
let appMode;
|
|
|
|
|
const state = store.getState();
|
|
|
|
|
const datasource = getDatasource(state, datasourceId);
|
|
|
|
|
const currentEnvDetails = getCurrentEnvironmentDetails(state);
|
|
|
|
|
const resultObj = {
|
|
|
|
|
type: action?.pluginType,
|
|
|
|
|
name: action?.name,
|
|
|
|
|
environmentId: currentEnvDetails.id,
|
|
|
|
|
environmentName: currentEnvDetails.name,
|
|
|
|
|
pluginName: plugin?.name,
|
|
|
|
|
datasourceId: datasourceId,
|
|
|
|
|
isMock: !!datasource?.isMock,
|
|
|
|
|
actionId: action?.id,
|
|
|
|
|
inputParams: Object.keys(params).length,
|
2024-03-12 10:06:33 +00:00
|
|
|
source: ActionExecutionContext.EVALUATION_ACTION_TRIGGER, // Used in analytic events to understand who triggered action execution
|
2023-12-19 10:58:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!!currentApp) {
|
|
|
|
|
appMode = getAppMode(state);
|
|
|
|
|
return {
|
|
|
|
|
...resultObj,
|
|
|
|
|
isExampleApp: currentApp.appIsExample,
|
|
|
|
|
pageId: action?.pageId,
|
|
|
|
|
appId: currentApp.id,
|
|
|
|
|
appMode: appMode,
|
|
|
|
|
appName: currentApp.name,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultObj;
|
|
|
|
|
}
|
2024-05-04 00:16:37 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function to check if the browser execution is allowed for the action
|
|
|
|
|
* This is just for code splitting, main feature is in EE
|
|
|
|
|
* */
|
2024-07-31 15:41:28 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
2024-05-04 00:16:37 +00:00
|
|
|
export function isBrowserExecutionAllowed(..._args: any[]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Function to extract the test payload from the collection data
|
|
|
|
|
export const getTestPayloadFromCollectionData = (
|
|
|
|
|
collectionData: JSCollectionData | undefined,
|
|
|
|
|
): string => {
|
|
|
|
|
if (!collectionData) return "";
|
|
|
|
|
const activeJSActionId = collectionData?.activeJSActionId;
|
|
|
|
|
const testPayload: Record<string, unknown> | undefined = collectionData?.data
|
|
|
|
|
?.testPayload as Record<string, unknown>;
|
|
|
|
|
if (!activeJSActionId || !testPayload) return "";
|
|
|
|
|
return (testPayload[activeJSActionId] as string) || "";
|
|
|
|
|
};
|