PromucFlow_constructor/app/client/src/actions/evaluationActions.ts
Ayush Pahwa 2782994c7d
chore: add new condition for form conditionals (#38556)
## Description
Added an extra condition for form evaluation. This allows server to
render different components for application or any other editors.

Form configs can now use this as a conditional to show or hide
components `editorContextType === "PAGE"`. Valid values are `WORKFLOWS`,
`PAGE` or `MODULE`.

Fixes #37735 

## Automation

/ok-to-test tags="@tag.Sanity, @tag.IDE"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13294166183>
> Commit: 6ab73336517e1ad6491ae3e63a5387cd65112a7b
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13294166183&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity, @tag.IDE`
> Spec:
> <hr>Wed, 12 Feb 2025 21:15:04 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced context-aware evaluation actions to improve dynamic form
interactions.
  
- **Refactor**
- Streamlined the form evaluation workflow and standardized key
extraction for enhanced consistency and reliability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-02-14 15:32:30 +05:30

107 lines
2.9 KiB
TypeScript

import type { ReduxAction } from "./ReduxActionTypes";
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
import { intersection } from "lodash";
import type { DependencyMap } from "utils/DynamicBindingUtils";
import type { DiffWithNewTreeState } from "workers/Evaluation/helpers";
import {
EVALUATE_REDUX_ACTIONS,
EVAL_AND_LINT_REDUX_ACTIONS,
LINT_REDUX_ACTIONS,
LOG_REDUX_ACTIONS,
} from "ee/actions/evaluationActionsList";
import type {
ConditionalOutput,
DynamicValues,
} from "reducers/evaluationReducers/formEvaluationReducer";
export const shouldTriggerEvaluation = (action: ReduxAction<unknown>) => {
return (
shouldProcessAction(action) && EVALUATE_REDUX_ACTIONS.includes(action.type)
);
};
export const shouldTriggerLinting = (action: ReduxAction<unknown>) => {
return shouldProcessAction(action) && !!LINT_REDUX_ACTIONS[action.type];
};
export const getAllActionTypes = (action: ReduxAction<unknown>) => {
if (
action.type === ReduxActionTypes.BATCH_UPDATES_SUCCESS &&
Array.isArray(action.payload)
) {
const batchedActionTypes = action.payload.map(
(batchedAction) => batchedAction.type as string,
);
return batchedActionTypes;
}
return [action.type];
};
export const shouldProcessAction = (action: ReduxAction<unknown>) => {
const actionTypes = getAllActionTypes(action);
return intersection(EVAL_AND_LINT_REDUX_ACTIONS, actionTypes).length > 0;
};
export function shouldLog(action: ReduxAction<unknown>) {
if (
action.type === ReduxActionTypes.BATCH_UPDATES_SUCCESS &&
Array.isArray(action.payload)
) {
const batchedActionTypes = action.payload.map(
(batchedAction) => batchedAction.type,
);
return batchedActionTypes.some(
(actionType) => LOG_REDUX_ACTIONS[actionType],
);
}
return LOG_REDUX_ACTIONS[action.type];
}
export const setEvaluatedTree = (
updates: DiffWithNewTreeState[],
): ReduxAction<{ updates: DiffWithNewTreeState[] }> => {
return {
type: ReduxActionTypes.SET_EVALUATED_TREE,
payload: { updates },
};
};
export const setDependencyMap = (
inverseDependencyMap: DependencyMap,
): ReduxAction<{ inverseDependencyMap: DependencyMap }> => {
return {
type: ReduxActionTypes.SET_EVALUATION_INVERSE_DEPENDENCY_MAP,
payload: { inverseDependencyMap },
};
};
// These actions require the entire tree to be re-evaluated
const FORCE_EVAL_ACTIONS = {
[ReduxActionTypes.INSTALL_LIBRARY_SUCCESS]: true,
[ReduxActionTypes.UNINSTALL_LIBRARY_SUCCESS]: true,
};
export const shouldForceEval = (action: ReduxAction<unknown>) => {
return !!FORCE_EVAL_ACTIONS[action.type];
};
export const fetchFormDynamicValNextPage = (payload?: {
value: ConditionalOutput;
dynamicFetchedValues: DynamicValues;
actionId: string;
datasourceId: string;
pluginId: string;
identifier: string;
}) => {
if (payload) {
return {
type: ReduxActionTypes.FETCH_FORM_DYNAMIC_VAL_NEXT_PAGE_INIT,
payload,
};
}
};