2022-03-08 13:56:03 +00:00
|
|
|
import { DependencyMap } from "utils/DynamicBindingUtils";
|
2021-01-14 14:37:21 +00:00
|
|
|
import { call, fork, put, select, take } from "redux-saga/effects";
|
2021-12-14 07:55:58 +00:00
|
|
|
import {
|
|
|
|
|
getEvaluationInverseDependencyMap,
|
|
|
|
|
getDataTree,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "selectors/dataTreeSelectors";
|
2022-03-08 13:56:03 +00:00
|
|
|
import { DataTree } from "entities/DataTree/dataTreeFactory";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { getActions } from "selectors/entitiesSelector";
|
2022-03-08 13:56:03 +00:00
|
|
|
import {
|
|
|
|
|
ActionData,
|
|
|
|
|
ActionDataState,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "reducers/entityReducers/actionsReducer";
|
2021-01-14 14:37:21 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2021-01-14 14:37:21 +00:00
|
|
|
import log from "loglevel";
|
|
|
|
|
import * as Sentry from "@sentry/react";
|
2022-03-08 13:56:03 +00:00
|
|
|
import { findLoadingEntities } from "utils/WidgetLoadingStateUtils";
|
2021-01-14 14:37:21 +00:00
|
|
|
|
|
|
|
|
const ACTION_EXECUTION_REDUX_ACTIONS = [
|
2021-12-14 07:55:58 +00:00
|
|
|
// Actions
|
2021-01-14 14:37:21 +00:00
|
|
|
ReduxActionTypes.RUN_ACTION_REQUEST,
|
|
|
|
|
ReduxActionTypes.RUN_ACTION_SUCCESS,
|
2021-08-27 09:25:28 +00:00
|
|
|
ReduxActionTypes.EXECUTE_PLUGIN_ACTION_REQUEST,
|
|
|
|
|
ReduxActionTypes.EXECUTE_PLUGIN_ACTION_SUCCESS,
|
|
|
|
|
ReduxActionErrorTypes.EXECUTE_PLUGIN_ACTION_ERROR,
|
2021-12-14 07:55:58 +00:00
|
|
|
// Widget evalution
|
|
|
|
|
ReduxActionTypes.SET_EVALUATED_TREE,
|
2021-01-14 14:37:21 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function* setWidgetsLoadingSaga() {
|
2022-03-08 13:56:03 +00:00
|
|
|
const actions: ActionDataState = yield select(getActions);
|
2021-01-14 14:37:21 +00:00
|
|
|
const isLoadingActions: string[] = actions
|
|
|
|
|
.filter((action: ActionData) => action.isLoading)
|
|
|
|
|
.map((action: ActionData) => action.config.name);
|
|
|
|
|
|
2022-03-08 13:56:03 +00:00
|
|
|
if (isLoadingActions.length === 0) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SET_LOADING_ENTITIES,
|
|
|
|
|
payload: new Set<string>(),
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const inverseMap: DependencyMap = yield select(
|
|
|
|
|
getEvaluationInverseDependencyMap,
|
|
|
|
|
);
|
|
|
|
|
const dataTree: DataTree = yield select(getDataTree);
|
2021-01-14 14:37:21 +00:00
|
|
|
|
2022-03-08 13:56:03 +00:00
|
|
|
const loadingEntities = findLoadingEntities(
|
|
|
|
|
isLoadingActions,
|
|
|
|
|
dataTree,
|
|
|
|
|
inverseMap,
|
|
|
|
|
);
|
2021-12-14 07:55:58 +00:00
|
|
|
|
2022-03-08 13:56:03 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SET_LOADING_ENTITIES,
|
|
|
|
|
payload: loadingEntities,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-01-14 14:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* actionExecutionChangeListenerSaga() {
|
|
|
|
|
while (true) {
|
|
|
|
|
yield take(ACTION_EXECUTION_REDUX_ACTIONS);
|
|
|
|
|
yield fork(setWidgetsLoadingSaga);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function* actionExecutionChangeListeners() {
|
|
|
|
|
yield take(ReduxActionTypes.START_EVALUATION);
|
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
|
|
|
|
yield call(actionExecutionChangeListenerSaga);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.error(e);
|
|
|
|
|
Sentry.captureException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|