diff --git a/app/client/src/actions/evaluationActions.ts b/app/client/src/actions/evaluationActions.ts index abc5a5a9a88f..2e4d6f825383 100644 --- a/app/client/src/actions/evaluationActions.ts +++ b/app/client/src/actions/evaluationActions.ts @@ -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, @@ -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, diff --git a/app/client/src/actions/formEvaluationActions.ts b/app/client/src/actions/formEvaluationActions.ts new file mode 100644 index 000000000000..25f95a375859 --- /dev/null +++ b/app/client/src/actions/formEvaluationActions.ts @@ -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, + }, + }; +}; diff --git a/app/client/src/sagas/FormEvaluationSaga.ts b/app/client/src/sagas/FormEvaluationSaga.ts index 4f5d126bc360..1385e727667d 100644 --- a/app/client/src/sagas/FormEvaluationSaga.ts +++ b/app/client/src/sagas/FormEvaluationSaga.ts @@ -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[]; @@ -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], diff --git a/app/client/src/sagas/QueryPaneSagas.ts b/app/client/src/sagas/QueryPaneSagas.ts index 8ba67fc1a101..4ae9940a6535 100644 --- a/app/client/src/sagas/QueryPaneSagas.ts +++ b/app/client/src/sagas/QueryPaneSagas.ts @@ -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"; @@ -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) { @@ -187,6 +191,7 @@ function* changeQuerySaga(actionPayload: ReduxAction) { //@ts-expect-error: id does not exists action.datasource.id, pluginId, + action.contextType, ), ); } @@ -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, }, }); @@ -317,7 +322,7 @@ function* formValueChangeSaga( "datasourceConfiguration", ) ) { - currentEnvironment = Object.keys(datasourceStorages)[0]; + currentEnvironment = objectKeys(datasourceStorages)[0]; } let dsConfig = { @@ -338,6 +343,7 @@ function* formValueChangeSaga( values.actionConfiguration, values.datasource.id, values.pluginId, + values.contextType || ActionParentEntityType.PAGE, field, hasRouteChanged, dsConfig, diff --git a/app/client/src/sagas/ReplaySaga.ts b/app/client/src/sagas/ReplaySaga.ts index ce2668705d5f..a1dc00a8b5bc 100644 --- a/app/client/src/sagas/ReplaySaga.ts +++ b/app/client/src/sagas/ReplaySaga.ts @@ -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; @@ -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; @@ -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]); @@ -357,6 +358,7 @@ function* replayActionSaga( replayEntity.actionConfiguration, replayEntity.datasource.id || "", replayEntity.pluginId, + replayEntity.contextType, u.modifiedProperty, true, datasource?.datasourceStorages[currentEnvironment] diff --git a/app/client/src/workers/Evaluation/formEval.ts b/app/client/src/workers/Evaluation/formEval.ts index 7439a85ebb64..3eddc56126d8 100644 --- a/app/client/src/workers/Evaluation/formEval.ts +++ b/app/client/src/workers/Evaluation/formEval.ts @@ -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 @@ -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) || @@ -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) => { @@ -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) { @@ -431,6 +440,7 @@ function evaluate( currentEvalState[key] .evaluateFormConfig as EvaluatedFormConfig ).evaluateFormConfigObject, + editorContextType, datasourceConfiguration, ); } @@ -448,6 +458,7 @@ function getFormEvaluation( formId: string, actionConfiguration: ActionConfig, currentEvalState: FormEvaluationState, + editorContextType: ActionParentEntityTypeInterface, actionDiffPath?: string, hasRouteChanged?: boolean, datasourceConfiguration?: DatasourceConfiguration, @@ -502,6 +513,7 @@ function getFormEvaluation( conditionToBeEvaluated = evaluate( actionConfiguration, currentEvalState[formId], + editorContextType, actionDiffPath, hasRouteChanged, datasourceConfiguration, @@ -514,6 +526,7 @@ function getFormEvaluation( conditionToBeEvaluated = evaluate( actionConfiguration, conditionToBeEvaluated, + editorContextType, actionDiffPath, hasRouteChanged, datasourceConfiguration, @@ -572,6 +585,7 @@ export function setFormEvaluationSaga( actionConfiguration, actionDiffPath, datasourceConfiguration, + editorContextType, formId, hasRouteChanged, } = payload; @@ -584,6 +598,7 @@ export function setFormEvaluationSaga( formId, actionConfiguration, currentEvalState, + editorContextType || ActionParentEntityType.PAGE, actionDiffPath, hasRouteChanged, datasourceConfiguration,