2020-03-06 04:59:24 +00:00
|
|
|
import { all, put, takeLatest, take, select } from "redux-saga/effects";
|
2019-11-08 11:02:00 +00:00
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
ReduxActionTypes,
|
2019-11-22 14:02:55 +00:00
|
|
|
InitializeEditorPayload,
|
|
|
|
|
} from "constants/ReduxActionConstants";
|
|
|
|
|
|
2019-11-25 05:07:27 +00:00
|
|
|
import { fetchEditorConfigs } from "actions/configsActions";
|
2020-03-24 14:05:19 +00:00
|
|
|
import { fetchPage, fetchPageList } from "actions/pageActions";
|
2020-04-28 06:52:53 +00:00
|
|
|
import { fetchDatasources } from "actions/datasourceActions";
|
2019-11-29 05:22:49 +00:00
|
|
|
import { fetchPlugins } from "actions/pluginActions";
|
2020-01-24 09:54:40 +00:00
|
|
|
import { fetchActions } from "actions/actionActions";
|
2020-03-06 04:59:24 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2020-03-09 05:46:32 +00:00
|
|
|
import { getCurrentApplication } from "selectors/applicationSelectors";
|
2019-11-01 07:11:32 +00:00
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
function* initializeEditorSaga(
|
|
|
|
|
initializeEditorAction: ReduxAction<InitializeEditorPayload>,
|
|
|
|
|
) {
|
2020-03-24 14:05:19 +00:00
|
|
|
const { applicationId, pageId } = initializeEditorAction.payload;
|
2019-11-22 14:02:55 +00:00
|
|
|
// Step 1: Start getting all the data needed by the
|
2019-11-01 07:11:32 +00:00
|
|
|
yield all([
|
2019-11-29 05:22:49 +00:00
|
|
|
put(fetchPlugins()),
|
2019-11-22 14:02:55 +00:00
|
|
|
put(fetchPageList(applicationId)),
|
2019-11-22 12:15:33 +00:00
|
|
|
put(fetchEditorConfigs()),
|
2020-01-24 09:54:40 +00:00
|
|
|
put(fetchActions(applicationId)),
|
2019-11-07 09:32:38 +00:00
|
|
|
put(fetchDatasources()),
|
2020-03-24 14:05:19 +00:00
|
|
|
put(fetchPage(pageId)),
|
2019-11-01 07:11:32 +00:00
|
|
|
]);
|
|
|
|
|
// Step 2: Wait for all data to be in the state
|
|
|
|
|
yield all([
|
2019-11-29 05:22:49 +00:00
|
|
|
take(ReduxActionTypes.FETCH_PLUGINS_SUCCESS),
|
2019-11-01 07:11:32 +00:00
|
|
|
take(ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS),
|
2020-03-24 14:05:19 +00:00
|
|
|
take(ReduxActionTypes.FETCH_PAGE_SUCCESS),
|
|
|
|
|
take(ReduxActionTypes.UPDATE_CURRENT_PAGE),
|
2019-11-01 07:11:32 +00:00
|
|
|
take(ReduxActionTypes.FETCH_ACTIONS_SUCCESS),
|
2019-11-07 09:32:38 +00:00
|
|
|
take(ReduxActionTypes.FETCH_DATASOURCES_SUCCESS),
|
2019-11-01 07:11:32 +00:00
|
|
|
]);
|
2019-11-22 14:02:55 +00:00
|
|
|
|
2020-03-09 05:46:32 +00:00
|
|
|
const currentApplication = yield select(getCurrentApplication);
|
2020-03-06 04:59:24 +00:00
|
|
|
|
|
|
|
|
const appName = currentApplication ? currentApplication.name : "";
|
|
|
|
|
const appId = currentApplication ? currentApplication.id : "";
|
|
|
|
|
|
|
|
|
|
AnalyticsUtil.logEvent("EDITOR_OPEN", {
|
|
|
|
|
appId: appId,
|
|
|
|
|
appName: appName,
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
// Step 6: Notify UI that the editor is ready to go
|
2019-11-13 07:34:59 +00:00
|
|
|
yield put({
|
2019-11-14 11:17:36 +00:00
|
|
|
type: ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS,
|
2019-11-13 07:34:59 +00:00
|
|
|
});
|
2019-11-01 07:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-08 11:02:00 +00:00
|
|
|
export function* initializeAppViewerSaga(
|
2019-11-22 14:02:55 +00:00
|
|
|
action: ReduxAction<{ pageId: string; applicationId: string }>,
|
2019-11-08 11:02:00 +00:00
|
|
|
) {
|
2019-11-22 14:02:55 +00:00
|
|
|
const { applicationId } = action.payload;
|
2020-01-24 09:54:40 +00:00
|
|
|
yield all([
|
|
|
|
|
put(fetchActions(applicationId)),
|
|
|
|
|
put(fetchPageList(applicationId)),
|
|
|
|
|
]);
|
2019-11-22 14:02:55 +00:00
|
|
|
|
2019-11-08 11:02:00 +00:00
|
|
|
yield all([
|
|
|
|
|
take(ReduxActionTypes.FETCH_ACTIONS_SUCCESS),
|
2020-01-24 09:54:40 +00:00
|
|
|
take(ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS),
|
2019-11-08 11:02:00 +00:00
|
|
|
]);
|
2020-01-24 09:54:40 +00:00
|
|
|
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.INITIALIZE_PAGE_VIEWER_SUCCESS,
|
|
|
|
|
});
|
2019-11-08 11:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-01 07:11:32 +00:00
|
|
|
export default function* watchInitSagas() {
|
2019-11-08 11:02:00 +00:00
|
|
|
yield all([
|
2019-11-14 11:17:36 +00:00
|
|
|
takeLatest(ReduxActionTypes.INITIALIZE_EDITOR, initializeEditorSaga),
|
2019-11-08 11:02:00 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.INITIALIZE_PAGE_VIEWER,
|
|
|
|
|
initializeAppViewerSaga,
|
|
|
|
|
),
|
|
|
|
|
]);
|
2019-11-01 07:11:32 +00:00
|
|
|
}
|