Skip to content
Merged
42 changes: 0 additions & 42 deletions app/client/src/actions/evaluationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { ReduxAction } from "./ReduxActionTypes";
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
import { intersection } from "lodash";
import type { DependencyMap } from "utils/DynamicBindingUtils";
import type { QueryActionConfig } from "entities/Action";
import type { DatasourceConfiguration } from "entities/Datasource";
import type { DiffWithNewTreeState } from "workers/Evaluation/helpers";
import {
EVALUATE_REDUX_ACTIONS,
Expand Down Expand Up @@ -77,46 +75,6 @@ export const setDependencyMap = (
};
};

// Called when a form is being setup, for setting up the base condition evaluations for the form
export const initFormEvaluations = (
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
editorConfig: any,
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
settingConfig: any,
formId: string,
) => {
return {
type: ReduxActionTypes.INIT_FORM_EVALUATION,
payload: { editorConfig, settingConfig, formId },
};
};

// Called when there is change in the data of the form, re evaluates the whole form
export const startFormEvaluations = (
formId: string,
formData: QueryActionConfig,
datasourceId: string,
pluginId: string,
actionDiffPath?: string,
hasRouteChanged?: boolean,
datasourceConfiguration?: DatasourceConfiguration,
) => {
return {
type: ReduxActionTypes.RUN_FORM_EVALUATION,
payload: {
formId,
actionConfiguration: formData,
datasourceId,
pluginId,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
},
};
};

// These actions require the entire tree to be re-evaluated
const FORCE_EVAL_ACTIONS = {
[ReduxActionTypes.INSTALL_LIBRARY_SUCCESS]: true,
Expand Down
46 changes: 46 additions & 0 deletions app/client/src/actions/formEvaluationActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
import type { QueryActionConfig } from "entities/Action";
import type { DatasourceConfiguration } from "entities/Datasource";
import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers";

// Called when a form is being setup, for setting up the base condition evaluations for the form
export const initFormEvaluations = (
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
editorConfig: any,
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
settingConfig: any,
formId: string,
) => {
return {
type: ReduxActionTypes.INIT_FORM_EVALUATION,
payload: { editorConfig, settingConfig, formId },
};
};

// Called when there is change in the data of the form, re evaluates the whole form
export const startFormEvaluations = (
formId: string,
formData: QueryActionConfig,
datasourceId: string,
pluginId: string,
editorContextType?: ActionParentEntityTypeInterface,
actionDiffPath?: string,
hasRouteChanged?: boolean,
datasourceConfiguration?: DatasourceConfiguration,
) => {
return {
type: ReduxActionTypes.RUN_FORM_EVALUATION,
payload: {
formId,
actionConfiguration: formData,
datasourceId,
pluginId,
editorContextType,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
},
};
};
9 changes: 7 additions & 2 deletions app/client/src/sagas/FormEvaluationSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ import {
import type { DatasourceConfiguration } from "entities/Datasource";
import { buffers } from "redux-saga";
import type { Plugin } from "entities/Plugin";
import { doesPluginRequireDatasource } from "ee/entities/Engine/actionHelpers";
import {
doesPluginRequireDatasource,
type ActionParentEntityTypeInterface,
} from "ee/entities/Engine/actionHelpers";
import { klonaLiteWithTelemetry } from "utils/helpers";
import { objectKeys } from "@appsmith/utils";

export interface FormEvalActionPayload {
formId: string;
datasourceId?: string;
pluginId?: string;
editorContextType: ActionParentEntityTypeInterface;
actionConfiguration?: ActionConfig;
editorConfig?: FormConfigType[];
settingConfig?: FormConfigType[];
Expand Down Expand Up @@ -138,7 +143,7 @@ export function* fetchDynamicValuesSaga(
datasourceId: string,
pluginId: string,
) {
for (const key of Object.keys(queueOfValuesToBeFetched)) {
for (const key of objectKeys(queueOfValuesToBeFetched)) {
queueOfValuesToBeFetched[key].fetchDynamicValues = yield call(
fetchDynamicValueSaga,
queueOfValuesToBeFetched[key],
Expand Down
14 changes: 10 additions & 4 deletions app/client/src/sagas/QueryPaneSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import get from "lodash/get";
import {
initFormEvaluations,
startFormEvaluations,
} from "actions/evaluationActions";
} from "actions/formEvaluationActions";
import { updateReplayEntity } from "actions/pageActions";
import { ENTITY_TYPE } from "ee/entities/AppsmithConsole/utils";
import type { EventLocation } from "ee/utils/analyticsUtilTypes";
Expand Down Expand Up @@ -85,9 +85,13 @@ import {
getCurrentApplicationIdForCreateNewApp,
} from "ee/selectors/applicationSelectors";
import { TEMP_DATASOURCE_ID } from "constants/Datasource";
import { doesPluginRequireDatasource } from "ee/entities/Engine/actionHelpers";
import {
ActionParentEntityType,
doesPluginRequireDatasource,
} from "ee/entities/Engine/actionHelpers";
import { convertToBasePageIdSelector } from "selectors/pageListSelectors";
import { openGeneratePageModalWithSelectedDS } from "../utils/GeneratePageUtils";
import { objectKeys } from "@appsmith/utils";

// Called whenever the query being edited is changed via the URL or query pane
function* changeQuerySaga(actionPayload: ReduxAction<ChangeQueryPayload>) {
Expand Down Expand Up @@ -187,6 +191,7 @@ function* changeQuerySaga(actionPayload: ReduxAction<ChangeQueryPayload>) {
//@ts-expect-error: id does not exists
action.datasource.id,
pluginId,
action.contextType,
),
);
}
Expand Down Expand Up @@ -275,7 +280,7 @@ function* formValueChangeSaga(
type: ReduxActionTypes.SET_TRIGGER_VALUES_LOADING,
payload: {
formId: values.id,
keys: Object.keys(allTriggers),
keys: objectKeys(allTriggers),
value: true,
},
});
Expand Down Expand Up @@ -317,7 +322,7 @@ function* formValueChangeSaga(
"datasourceConfiguration",
)
) {
currentEnvironment = Object.keys(datasourceStorages)[0];
currentEnvironment = objectKeys(datasourceStorages)[0];
}

let dsConfig = {
Expand All @@ -338,6 +343,7 @@ function* formValueChangeSaga(
values.actionConfiguration,
values.datasource.id,
values.pluginId,
values.contextType || ActionParentEntityType.PAGE,
field,
hasRouteChanged,
dsConfig,
Expand Down
10 changes: 6 additions & 4 deletions app/client/src/sagas/ReplaySaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ import {
import { AppThemingMode } from "selectors/appThemingSelectors";
import { generateAutoHeightLayoutTreeAction } from "actions/autoHeightActions";
import { SelectionRequestType } from "sagas/WidgetSelectUtils";
import { startFormEvaluations } from "actions/evaluationActions";
import { startFormEvaluations } from "actions/formEvaluationActions";
import { getUIComponent } from "pages/Editor/QueryEditor/helpers";
import { type Plugin, UIComponentTypes } from "entities/Plugin";
import { getCurrentEnvironmentId } from "ee/selectors/environmentSelectors";
import { updateAndSaveAnvilLayout } from "layoutSystems/anvil/utils/anvilChecksUtils";
import type { ReplayOperation } from "entities/Replay/ReplayEntity/ReplayOperations";
import { objectKeys } from "@appsmith/utils";

export interface UndoRedoPayload {
operation: ReplayOperation;
Expand All @@ -103,7 +104,7 @@ export default function* undoRedoListenerSaga() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function* openPropertyPaneSaga(replay: any) {
try {
const replayWidgetId = Object.keys(replay.widgets)[0];
const replayWidgetId = objectKeys(replay.widgets)[0] as string;

if (!replayWidgetId || !replay.widgets[replayWidgetId].propertyUpdates)
return;
Expand Down Expand Up @@ -155,9 +156,9 @@ export function* postUndoRedoSaga(replay: any) {
processUndoRedoToasts(replay.toasts);
}

if (!replay.widgets || Object.keys(replay.widgets).length <= 0) return;
if (!replay.widgets || objectKeys(replay.widgets).length <= 0) return;

const widgetIds = Object.keys(replay.widgets);
const widgetIds = objectKeys(replay.widgets) as string[];

yield put(selectWidgetInitAction(SelectionRequestType.Multiple, widgetIds));
scrollWidgetIntoView(widgetIds[0]);
Expand Down Expand Up @@ -357,6 +358,7 @@ function* replayActionSaga(
replayEntity.actionConfiguration,
replayEntity.datasource.id || "",
replayEntity.pluginId,
replayEntity.contextType,
u.modifiedProperty,
true,
datasource?.datasourceStorages[currentEnvironment]
Expand Down
23 changes: 19 additions & 4 deletions app/client/src/workers/Evaluation/formEval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { extractEvalConfigFromFormConfig } from "components/formControls/utils";
import { isDynamicValue } from "utils/DynamicBindingUtils";
import { isTrueObject } from "ee/workers/Evaluation/evaluationUtils";
import type { DatasourceConfiguration } from "entities/Datasource";
import { objectKeys } from "@appsmith/utils";
import {
ActionParentEntityType,
type ActionParentEntityTypeInterface,
} from "ee/entities/Engine/actionHelpers";

export enum ConditionType {
HIDE = "hide", // When set, the component will be shown until condition is true
Expand Down Expand Up @@ -71,7 +76,7 @@ const generateInitialEvalState = (formConfig: FormConfigType) => {

// Any element is only added to the eval state if they have a conditional statement present, if not they are allowed to be rendered
if ("conditionals" in formConfig && !!formConfig.conditionals) {
const allConditionTypes = Object.keys(formConfig.conditionals);
const allConditionTypes = objectKeys(formConfig.conditionals);

if (
allConditionTypes.includes(ConditionType.HIDE) ||
Expand Down Expand Up @@ -306,12 +311,15 @@ function evaluateDynamicValuesConfig(
}

function evaluateFormConfigElements(
/* eslint-disable @typescript-eslint/no-unused-vars */
actionConfiguration: ActionConfig,
config: FormConfigEvalObject,
/* eslint-disable @typescript-eslint/no-unused-vars */
editorContextType: ActionParentEntityTypeInterface,
/* eslint-disable @typescript-eslint/no-unused-vars */
datasourceConfiguration?: DatasourceConfiguration,
) {
const paths = Object.keys(config);
const paths = objectKeys(config);

if (paths.length > 0) {
paths.forEach((path) => {
Expand All @@ -332,17 +340,18 @@ function evaluateFormConfigElements(
function evaluate(
actionConfiguration: ActionConfig,
currentEvalState: FormEvalOutput,
editorContextType: ActionParentEntityTypeInterface,
actionDiffPath?: string,
hasRouteChanged?: boolean,
datasourceConfiguration?: DatasourceConfiguration,
) {
Object.keys(currentEvalState).forEach((key: string) => {
objectKeys(currentEvalState).forEach((key: string) => {
try {
if (currentEvalState[key].hasOwnProperty("conditionals")) {
const conditionBlock = currentEvalState[key].conditionals;

if (!!conditionBlock) {
Object.keys(conditionBlock).forEach((conditionType: string) => {
objectKeys(conditionBlock).forEach((conditionType: string) => {
const output = eval(conditionBlock[conditionType]);

if (conditionType === ConditionType.HIDE) {
Expand Down Expand Up @@ -431,6 +440,7 @@ function evaluate(
currentEvalState[key]
.evaluateFormConfig as EvaluatedFormConfig
).evaluateFormConfigObject,
editorContextType,
datasourceConfiguration,
);
}
Expand All @@ -448,6 +458,7 @@ function getFormEvaluation(
formId: string,
actionConfiguration: ActionConfig,
currentEvalState: FormEvaluationState,
editorContextType: ActionParentEntityTypeInterface,
actionDiffPath?: string,
hasRouteChanged?: boolean,
datasourceConfiguration?: DatasourceConfiguration,
Expand Down Expand Up @@ -502,6 +513,7 @@ function getFormEvaluation(
conditionToBeEvaluated = evaluate(
actionConfiguration,
currentEvalState[formId],
editorContextType,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
Expand All @@ -514,6 +526,7 @@ function getFormEvaluation(
conditionToBeEvaluated = evaluate(
actionConfiguration,
conditionToBeEvaluated,
editorContextType,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
Expand Down Expand Up @@ -572,6 +585,7 @@ export function setFormEvaluationSaga(
actionConfiguration,
actionDiffPath,
datasourceConfiguration,
editorContextType,
formId,
hasRouteChanged,
} = payload;
Expand All @@ -584,6 +598,7 @@ export function setFormEvaluationSaga(
formId,
actionConfiguration,
currentEvalState,
editorContextType || ActionParentEntityType.PAGE,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
Expand Down
Loading