2025-01-10 04:51:54 +00:00
|
|
|
import type { ReduxAction } from "./ReduxActionTypes";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
|
2023-11-10 08:04:09 +00:00
|
|
|
import { intersection } from "lodash";
|
|
|
|
|
import type { DependencyMap } from "utils/DynamicBindingUtils";
|
2024-03-27 09:07:46 +00:00
|
|
|
import type { DiffWithNewTreeState } from "workers/Evaluation/helpers";
|
2023-11-10 08:04:09 +00:00
|
|
|
import {
|
|
|
|
|
EVALUATE_REDUX_ACTIONS,
|
|
|
|
|
EVAL_AND_LINT_REDUX_ACTIONS,
|
|
|
|
|
LINT_REDUX_ACTIONS,
|
|
|
|
|
LOG_REDUX_ACTIONS,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/actions/evaluationActionsList";
|
2025-02-13 13:19:44 +00:00
|
|
|
import type {
|
|
|
|
|
ConditionalOutput,
|
|
|
|
|
DynamicValues,
|
|
|
|
|
} from "reducers/evaluationReducers/formEvaluationReducer";
|
2023-11-10 08:04:09 +00:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2023-11-10 08:04:09 +00:00
|
|
|
return batchedActionTypes;
|
|
|
|
|
}
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2023-11-10 08:04:09 +00:00
|
|
|
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,
|
|
|
|
|
);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2023-11-10 08:04:09 +00:00
|
|
|
return batchedActionTypes.some(
|
|
|
|
|
(actionType) => LOG_REDUX_ACTIONS[actionType],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return LOG_REDUX_ACTIONS[action.type];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setEvaluatedTree = (
|
2024-03-27 09:07:46 +00:00
|
|
|
updates: DiffWithNewTreeState[],
|
|
|
|
|
): ReduxAction<{ updates: DiffWithNewTreeState[] }> => {
|
2023-11-10 08:04:09 +00:00
|
|
|
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];
|
|
|
|
|
};
|
2025-02-13 13:19:44 +00:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|