PromucFlow_constructor/app/client/src/sagas/WidgetLoadingSaga.ts
Ankita Kinger c1e48f7486
feat: Refactor code for SAML integration (#12700)
* Implemented code splitting of some files for SAML integration

* Implemented code splitting of some more files for SAML integration

* updated redirect url component

* fixed an import statement

* fixed a unit test

* updated restart banner tooltip logic

* updated an import statement
2022-04-12 16:20:01 +05:30

80 lines
2.2 KiB
TypeScript

import { DependencyMap } from "utils/DynamicBindingUtils";
import { call, fork, put, select, take } from "redux-saga/effects";
import {
getEvaluationInverseDependencyMap,
getDataTree,
} from "selectors/dataTreeSelectors";
import { DataTree } from "entities/DataTree/dataTreeFactory";
import { getActions } from "selectors/entitiesSelector";
import {
ActionData,
ActionDataState,
} from "reducers/entityReducers/actionsReducer";
import {
ReduxActionErrorTypes,
ReduxActionTypes,
} from "@appsmith/constants/ReduxActionConstants";
import log from "loglevel";
import * as Sentry from "@sentry/react";
import { findLoadingEntities } from "utils/WidgetLoadingStateUtils";
const ACTION_EXECUTION_REDUX_ACTIONS = [
// Actions
ReduxActionTypes.RUN_ACTION_REQUEST,
ReduxActionTypes.RUN_ACTION_SUCCESS,
ReduxActionTypes.EXECUTE_PLUGIN_ACTION_REQUEST,
ReduxActionTypes.EXECUTE_PLUGIN_ACTION_SUCCESS,
ReduxActionErrorTypes.EXECUTE_PLUGIN_ACTION_ERROR,
// Widget evalution
ReduxActionTypes.SET_EVALUATED_TREE,
];
function* setWidgetsLoadingSaga() {
const actions: ActionDataState = yield select(getActions);
const isLoadingActions: string[] = actions
.filter((action: ActionData) => action.isLoading)
.map((action: ActionData) => action.config.name);
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);
const loadingEntities = findLoadingEntities(
isLoadingActions,
dataTree,
inverseMap,
);
yield put({
type: ReduxActionTypes.SET_LOADING_ENTITIES,
payload: loadingEntities,
});
}
}
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);
}
}
}