Skip to content

chore: flexible return for test payload extraction func #38443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 2, 2025
Merged
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
20 changes: 14 additions & 6 deletions app/client/src/ce/utils/actionExecutionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getCurrentEnvironmentDetails } from "ee/selectors/environmentSelectors"
import type { Plugin } from "api/PluginApi";
import { get, isNil } from "lodash";
import type { JSCollectionData } from "ee/reducers/entityReducers/jsActionsReducer";
import { objectKeys } from "@appsmith/utils";

export function getPluginActionNameToDisplay(action: Action) {
return action.name;
Expand All @@ -20,7 +21,7 @@ export const getActionProperties = (
) => {
const actionProperties: Record<string, unknown> = {};

Object.keys(keyConfig).forEach((key) => {
objectKeys(keyConfig).forEach((key) => {
const value = get(action, key);

if (!isNil(value)) {
Expand Down Expand Up @@ -69,7 +70,7 @@ export function getActionExecutionAnalytics(
datasourceId: datasourceId,
isMock: !!datasource?.isMock,
actionId: action?.id,
inputParams: Object.keys(params).length,
inputParams: objectKeys(params).length,
source: ActionExecutionContext.EVALUATION_ACTION_TRIGGER, // Used in analytic events to understand who triggered action execution
};

Expand Down Expand Up @@ -98,17 +99,24 @@ export function isBrowserExecutionAllowed(..._args: any[]) {
return true;
}

// Function to extract the test payload from the collection data
/**
* Function to extract the test payload from the collection data
* @param [collectionData] from the js Object
* @param [defaultValue=""] to be returned if no information is found,
* returns an empty string by default
* @returns stored value from the collectionData
* */
export const getTestPayloadFromCollectionData = (
collectionData: JSCollectionData | undefined,
defaultValue = "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite understand the reasoning behind adding this. Basically we are passing a default value to a function which it will return when the collectionData is not there or something else is missing. Can't this function return null and the caller of this function can just do getTestPayloadFromCollectionData() || defaultValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main use is in the EE side of this change. Empty string is treated as a falsy value and for my use case I want the default value to be used only if the item is undefined. While I could do that check during consumption of this functions, but since the check is already happening here I preferred to update the function definition.

): string => {
if (!collectionData) return "";
if (!collectionData) return defaultValue;

const activeJSActionId = collectionData?.activeJSActionId;
const testPayload: Record<string, unknown> | undefined = collectionData?.data
?.testPayload as Record<string, unknown>;

if (!activeJSActionId || !testPayload) return "";
if (!activeJSActionId || !testPayload) return defaultValue;

return (testPayload[activeJSActionId] as string) || "";
return testPayload[activeJSActionId] as string;
};
Loading