Skip to content
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

chore: add new condition for form conditionals #38556

Draft
wants to merge 3 commits into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions app/client/src/actions/evaluationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
LINT_REDUX_ACTIONS,
LOG_REDUX_ACTIONS,
} from "ee/actions/evaluationActionsList";
import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers";

export const shouldTriggerEvaluation = (action: ReduxAction<unknown>) => {
return (
Expand Down Expand Up @@ -99,6 +100,7 @@ export const startFormEvaluations = (
formData: QueryActionConfig,
datasourceId: string,
pluginId: string,
editorContextType: ActionParentEntityTypeInterface,
actionDiffPath?: string,
hasRouteChanged?: boolean,
datasourceConfiguration?: DatasourceConfiguration,
Expand All @@ -110,6 +112,7 @@ export const startFormEvaluations = (
actionConfiguration: formData,
datasourceId,
pluginId,
editorContextType,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
Expand Down
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 "api/PluginApi";
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
7 changes: 5 additions & 2 deletions app/client/src/sagas/QueryPaneSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import { TEMP_DATASOURCE_ID } from "constants/Datasource";
import { 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 @@ -184,6 +185,7 @@ function* changeQuerySaga(actionPayload: ReduxAction<ChangeQueryPayload>) {
//@ts-expect-error: id does not exists
action.datasource.id,
pluginId,
action.contextType,
),
);
}
Expand Down Expand Up @@ -272,7 +274,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 @@ -314,7 +316,7 @@ function* formValueChangeSaga(
"datasourceConfiguration",
)
) {
currentEnvironment = Object.keys(datasourceStorages)[0];
currentEnvironment = objectKeys(datasourceStorages)[0];
}

let dsConfig = {
Expand All @@ -335,6 +337,7 @@ function* formValueChangeSaga(
values.actionConfiguration,
values.datasource.id,
values.pluginId,
values.contextType,
field,
hasRouteChanged,
dsConfig,
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/sagas/ReplaySaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import { UIComponentTypes } from "api/PluginApi";
import { getCurrentEnvironmentId } from "ee/selectors/environmentSelectors";
import { updateAndSaveAnvilLayout } from "layoutSystems/anvil/utils/anvilChecksUtils";
import type { ReplayOperation } from "entities/Replay/ReplayEntity/ReplayOperations";
import { ActionParentEntityType } from "ee/entities/Engine/actionHelpers";

export interface UndoRedoPayload {
operation: ReplayOperation;
Expand Down Expand Up @@ -358,6 +359,7 @@ function* replayActionSaga(
replayEntity.actionConfiguration,
replayEntity.datasource.id || "",
replayEntity.pluginId,
replayEntity.contextType || ActionParentEntityType.PAGE,
u.modifiedProperty,
true,
datasource?.datasourceStorages[currentEnvironment]
Expand Down
20 changes: 16 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,8 @@ 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 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 +73,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 +308,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 +337,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 +437,7 @@ function evaluate(
currentEvalState[key]
.evaluateFormConfig as EvaluatedFormConfig
).evaluateFormConfigObject,
editorContextType,
datasourceConfiguration,
);
}
Expand All @@ -448,6 +455,7 @@ function getFormEvaluation(
formId: string,
actionConfiguration: ActionConfig,
currentEvalState: FormEvaluationState,
editorContextType: ActionParentEntityTypeInterface,
actionDiffPath?: string,
hasRouteChanged?: boolean,
datasourceConfiguration?: DatasourceConfiguration,
Expand Down Expand Up @@ -502,6 +510,7 @@ function getFormEvaluation(
conditionToBeEvaluated = evaluate(
actionConfiguration,
currentEvalState[formId],
editorContextType,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
Expand All @@ -514,6 +523,7 @@ function getFormEvaluation(
conditionToBeEvaluated = evaluate(
actionConfiguration,
conditionToBeEvaluated,
editorContextType,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
Expand Down Expand Up @@ -572,6 +582,7 @@ export function setFormEvaluationSaga(
actionConfiguration,
actionDiffPath,
datasourceConfiguration,
editorContextType,
formId,
hasRouteChanged,
} = payload;
Expand All @@ -584,6 +595,7 @@ export function setFormEvaluationSaga(
formId,
actionConfiguration,
currentEvalState,
editorContextType,
actionDiffPath,
hasRouteChanged,
datasourceConfiguration,
Expand Down
Loading