PromucFlow_constructor/app/client/src/ce/actions/evaluationActions.ts
Favour Ohanekwu 23ba0921c7
feat: Update isLoading peoperty of widgets after API/Query execution (#27406)
## Description
In this PR, we ensure that after API execution, data is available in the
dataTree before setting widget isLoading to false.

#### PR fixes following issue(s)
Fixes #26935 

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-18 19:45:44 +01:00

240 lines
7.9 KiB
TypeScript

import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import {
ReduxActionErrorTypes,
ReduxActionTypes,
} from "@appsmith/constants/ReduxActionConstants";
import { intersection, union } from "lodash";
import type { DependencyMap } from "utils/DynamicBindingUtils";
import type { QueryActionConfig } from "entities/Action";
import type { DatasourceConfiguration } from "entities/Datasource";
import type { DiffWithReferenceState } from "workers/Evaluation/helpers";
import store from "store";
import { getAppMode } from "@appsmith/selectors/applicationSelectors";
import { APP_MODE } from "entities/App";
export const FIRST_EVAL_REDUX_ACTIONS = [
// Pages
ReduxActionTypes.FETCH_ALL_PAGE_ENTITY_COMPLETION,
];
export const LINT_REDUX_ACTIONS = {
[ReduxActionTypes.FETCH_ALL_PAGE_ENTITY_COMPLETION]: true,
[ReduxActionTypes.CREATE_ACTION_SUCCESS]: true,
[ReduxActionTypes.UPDATE_ACTION_PROPERTY]: true,
[ReduxActionTypes.DELETE_ACTION_SUCCESS]: true,
[ReduxActionTypes.COPY_ACTION_SUCCESS]: true,
[ReduxActionTypes.MOVE_ACTION_SUCCESS]: true,
[ReduxActionTypes.CREATE_JS_ACTION_SUCCESS]: true,
[ReduxActionTypes.DELETE_JS_ACTION_SUCCESS]: true,
[ReduxActionTypes.COPY_JS_ACTION_SUCCESS]: true,
[ReduxActionTypes.MOVE_JS_ACTION_SUCCESS]: true,
[ReduxActionTypes.SET_USER_CURRENT_GEO_LOCATION]: true,
[ReduxActionTypes.UPDATE_LAYOUT]: true,
[ReduxActionTypes.UPDATE_WIDGET_PROPERTY]: true,
[ReduxActionTypes.UPDATE_WIDGET_NAME_SUCCESS]: true,
[ReduxActionTypes.UPDATE_JS_ACTION_BODY_INIT]: true, // "lint only" action
[ReduxActionTypes.META_UPDATE_DEBOUNCED_EVAL]: true,
[ReduxActionTypes.FETCH_JS_ACTIONS_FOR_PAGE_SUCCESS]: true,
[ReduxActionTypes.FETCH_ACTIONS_FOR_PAGE_SUCCESS]: true,
[ReduxActionTypes.INSTALL_LIBRARY_SUCCESS]: true,
[ReduxActionTypes.UNINSTALL_LIBRARY_SUCCESS]: true,
[ReduxActionTypes.BUFFERED_ACTION]: true,
[ReduxActionTypes.BATCH_UPDATES_SUCCESS]: true,
};
export const LOG_REDUX_ACTIONS = {
[ReduxActionTypes.UPDATE_LAYOUT]: true,
[ReduxActionTypes.UPDATE_WIDGET_PROPERTY]: true,
[ReduxActionTypes.UPDATE_WIDGET_NAME_SUCCESS]: true,
[ReduxActionTypes.CREATE_ACTION_SUCCESS]: true,
[ReduxActionTypes.UPDATE_ACTION_PROPERTY]: true,
};
export const EVALUATE_REDUX_ACTIONS = [
...FIRST_EVAL_REDUX_ACTIONS,
// Actions
ReduxActionTypes.FETCH_PLUGIN_FORM_CONFIGS_SUCCESS,
ReduxActionTypes.FETCH_ACTIONS_VIEW_MODE_SUCCESS,
ReduxActionErrorTypes.FETCH_ACTIONS_ERROR,
ReduxActionErrorTypes.FETCH_ACTIONS_VIEW_MODE_ERROR,
ReduxActionTypes.FETCH_ACTIONS_FOR_PAGE_SUCCESS,
ReduxActionTypes.SUBMIT_CURL_FORM_SUCCESS,
ReduxActionTypes.CREATE_ACTION_SUCCESS,
ReduxActionTypes.UPDATE_ACTION_PROPERTY,
ReduxActionTypes.DELETE_ACTION_SUCCESS,
ReduxActionTypes.COPY_ACTION_SUCCESS,
ReduxActionTypes.MOVE_ACTION_SUCCESS,
ReduxActionTypes.RUN_ACTION_SUCCESS,
ReduxActionErrorTypes.RUN_ACTION_ERROR,
ReduxActionTypes.EXECUTE_PLUGIN_ACTION_SUCCESS,
ReduxActionErrorTypes.EXECUTE_PLUGIN_ACTION_ERROR,
ReduxActionTypes.CLEAR_ACTION_RESPONSE,
// JS Actions
ReduxActionTypes.CREATE_JS_ACTION_SUCCESS,
ReduxActionTypes.DELETE_JS_ACTION_SUCCESS,
ReduxActionTypes.COPY_JS_ACTION_SUCCESS,
ReduxActionTypes.MOVE_JS_ACTION_SUCCESS,
ReduxActionErrorTypes.FETCH_JS_ACTIONS_ERROR,
ReduxActionTypes.FETCH_JS_ACTIONS_FOR_PAGE_SUCCESS,
ReduxActionTypes.FETCH_JS_ACTIONS_VIEW_MODE_SUCCESS,
ReduxActionErrorTypes.FETCH_JS_ACTIONS_VIEW_MODE_ERROR,
ReduxActionTypes.UPDATE_JS_ACTION_BODY_SUCCESS,
ReduxActionTypes.SET_JS_FUNCTION_EXECUTION_DATA,
// App Data
ReduxActionTypes.SET_APP_MODE,
ReduxActionTypes.FETCH_USER_DETAILS_SUCCESS,
ReduxActionTypes.UPDATE_APP_STORE,
ReduxActionTypes.SET_USER_CURRENT_GEO_LOCATION,
// Widgets
ReduxActionTypes.UPDATE_LAYOUT,
ReduxActionTypes.UPDATE_WIDGET_PROPERTY,
ReduxActionTypes.UPDATE_WIDGET_NAME_SUCCESS,
// Meta Widgets
ReduxActionTypes.MODIFY_META_WIDGETS,
ReduxActionTypes.DELETE_META_WIDGETS,
// Widget Meta
ReduxActionTypes.SET_META_PROP_AND_EVAL,
ReduxActionTypes.META_UPDATE_DEBOUNCED_EVAL,
ReduxActionTypes.RESET_WIDGET_META,
// Batches
ReduxActionTypes.BATCH_UPDATES_SUCCESS,
// App Theme
ReduxActionTypes.UPDATE_SELECTED_APP_THEME_SUCCESS,
ReduxActionTypes.CHANGE_SELECTED_APP_THEME_SUCCESS,
ReduxActionTypes.SET_PREVIEW_APP_THEME,
// Custom Library
ReduxActionTypes.INSTALL_LIBRARY_SUCCESS,
ReduxActionTypes.UNINSTALL_LIBRARY_SUCCESS,
// Buffer
ReduxActionTypes.BUFFERED_ACTION,
// Generic
ReduxActionTypes.TRIGGER_EVAL,
];
// Topics used for datasource and query form evaluations
export const FORM_EVALUATION_REDUX_ACTIONS = [
ReduxActionTypes.INIT_FORM_EVALUATION,
ReduxActionTypes.RUN_FORM_EVALUATION,
];
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: DiffWithReferenceState[],
): ReduxAction<{ updates: DiffWithReferenceState[] }> => {
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 },
};
};
// Called when a form is being setup, for setting up the base condition evaluations for the form
export const initFormEvaluations = (
editorConfig: 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,
[ReduxActionTypes.UNINSTALL_LIBRARY_SUCCESS]: true,
};
export const shouldForceEval = (action: ReduxAction<unknown>) => {
return !!FORCE_EVAL_ACTIONS[action.type];
};
export const EVAL_AND_LINT_REDUX_ACTIONS = union(
EVALUATE_REDUX_ACTIONS,
Object.keys(LINT_REDUX_ACTIONS),
);
export function getRequiresLinting(action: ReduxAction<unknown>) {
const appMode: ReturnType<typeof getAppMode> = getAppMode(store.getState());
const requiresLinting =
appMode === APP_MODE.EDIT && shouldTriggerLinting(action);
return requiresLinting;
}