2022-07-11 04:06:29 +00:00
|
|
|
import {
|
|
|
|
|
fetchAppThemesAction,
|
|
|
|
|
fetchSelectedAppThemeAction,
|
|
|
|
|
} from "actions/appThemingActions";
|
|
|
|
|
import {
|
|
|
|
|
fetchDatasources,
|
|
|
|
|
fetchMockDatasources,
|
|
|
|
|
} from "actions/datasourceActions";
|
|
|
|
|
import {
|
|
|
|
|
fetchGitStatusInit,
|
|
|
|
|
remoteUrlInputValue,
|
|
|
|
|
resetPullMergeStatus,
|
|
|
|
|
} from "actions/gitSyncActions";
|
|
|
|
|
import { restoreRecentEntitiesRequest } from "actions/globalSearchActions";
|
|
|
|
|
import { resetEditorSuccess } from "actions/initActions";
|
|
|
|
|
import { fetchJSCollections } from "actions/jsActionActions";
|
2022-09-02 13:15:48 +00:00
|
|
|
import { loadGuidedTourInit } from "actions/onboardingActions";
|
2022-07-11 04:06:29 +00:00
|
|
|
import {
|
|
|
|
|
fetchAllPageEntityCompletion,
|
|
|
|
|
fetchPage,
|
|
|
|
|
fetchPageDSLs,
|
|
|
|
|
} from "actions/pageActions";
|
|
|
|
|
import {
|
|
|
|
|
executePageLoadActions,
|
|
|
|
|
fetchActions,
|
|
|
|
|
} from "actions/pluginActionActions";
|
|
|
|
|
import { fetchPluginFormConfigs, fetchPlugins } from "actions/pluginActions";
|
|
|
|
|
import {
|
|
|
|
|
ApplicationPayload,
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
2022-09-02 17:15:08 +00:00
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2022-07-11 04:06:29 +00:00
|
|
|
import { addBranchParam } from "constants/routes";
|
|
|
|
|
import { APP_MODE } from "entities/App";
|
2022-12-08 03:36:35 +00:00
|
|
|
import { call, put, select } from "redux-saga/effects";
|
2022-07-11 04:06:29 +00:00
|
|
|
import { failFastApiCalls } from "sagas/InitSagas";
|
|
|
|
|
import { getCurrentApplication } from "selectors/editorSelectors";
|
|
|
|
|
import { getCurrentGitBranch } from "selectors/gitSyncSelectors";
|
|
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
|
|
|
|
import history from "utils/history";
|
|
|
|
|
import PerformanceTracker, {
|
|
|
|
|
PerformanceTransactionName,
|
|
|
|
|
} from "utils/PerformanceTracker";
|
2022-07-27 10:55:41 +00:00
|
|
|
import AppEngine, {
|
|
|
|
|
ActionsNotFoundError,
|
|
|
|
|
AppEnginePayload,
|
|
|
|
|
PluginFormConfigsNotFoundError,
|
|
|
|
|
PluginsNotFoundError,
|
|
|
|
|
} from ".";
|
2022-12-21 17:14:47 +00:00
|
|
|
import { fetchJSLibraries } from "actions/JSLibraryActions";
|
|
|
|
|
import CodemirrorTernService from "utils/autocomplete/CodemirrorTernService";
|
2023-02-06 07:06:08 +00:00
|
|
|
import {
|
|
|
|
|
waitForSegmentInit,
|
|
|
|
|
waitForFetchUserSuccess,
|
|
|
|
|
} from "ce/sagas/userSagas";
|
2022-07-11 04:06:29 +00:00
|
|
|
|
|
|
|
|
export default class AppEditorEngine extends AppEngine {
|
|
|
|
|
constructor(mode: APP_MODE) {
|
|
|
|
|
super(mode);
|
|
|
|
|
this.setupEngine = this.setupEngine.bind(this);
|
|
|
|
|
this.loadAppData = this.loadAppData.bind(this);
|
|
|
|
|
this.loadAppURL = this.loadAppURL.bind(this);
|
|
|
|
|
this.loadAppEntities = this.loadAppEntities.bind(this);
|
|
|
|
|
this.loadGit = this.loadGit.bind(this);
|
|
|
|
|
this.completeChore = this.completeChore.bind(this);
|
|
|
|
|
this.loadPageThemesAndActions = this.loadPageThemesAndActions.bind(this);
|
|
|
|
|
this.loadPluginsAndDatasources = this.loadPluginsAndDatasources.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* this saga is called once then application is loaded.
|
|
|
|
|
* It will hold the editor in uninitialized till all the apis/actions are completed
|
|
|
|
|
*
|
|
|
|
|
* @param AppEnginePayload
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
public *setupEngine(payload: AppEnginePayload): any {
|
|
|
|
|
yield* super.setupEngine.call(this, payload);
|
|
|
|
|
yield put(resetEditorSuccess());
|
2022-12-21 17:14:47 +00:00
|
|
|
CodemirrorTernService.resetServer();
|
2022-07-11 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public startPerformanceTracking() {
|
|
|
|
|
PerformanceTracker.startAsyncTracking(
|
|
|
|
|
PerformanceTransactionName.INIT_EDIT_APP,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public stopPerformanceTracking() {
|
|
|
|
|
PerformanceTracker.stopAsyncTracking(
|
|
|
|
|
PerformanceTransactionName.INIT_EDIT_APP,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private *loadPageThemesAndActions(
|
|
|
|
|
toLoadPageId: string,
|
|
|
|
|
applicationId: string,
|
|
|
|
|
) {
|
|
|
|
|
const initActionsCalls = [
|
|
|
|
|
fetchPage(toLoadPageId, true),
|
|
|
|
|
fetchActions({ applicationId }, []),
|
|
|
|
|
fetchJSCollections({ applicationId }),
|
|
|
|
|
fetchSelectedAppThemeAction(applicationId),
|
|
|
|
|
fetchAppThemesAction(applicationId),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const successActionEffects = [
|
|
|
|
|
ReduxActionTypes.FETCH_JS_ACTIONS_SUCCESS,
|
|
|
|
|
ReduxActionTypes.FETCH_ACTIONS_SUCCESS,
|
|
|
|
|
ReduxActionTypes.FETCH_APP_THEMES_SUCCESS,
|
|
|
|
|
ReduxActionTypes.FETCH_SELECTED_APP_THEME_SUCCESS,
|
|
|
|
|
ReduxActionTypes.FETCH_PAGE_SUCCESS,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const failureActionEffects = [
|
|
|
|
|
ReduxActionErrorTypes.FETCH_JS_ACTIONS_ERROR,
|
|
|
|
|
ReduxActionErrorTypes.FETCH_ACTIONS_ERROR,
|
|
|
|
|
ReduxActionErrorTypes.FETCH_APP_THEMES_ERROR,
|
|
|
|
|
ReduxActionErrorTypes.FETCH_SELECTED_APP_THEME_ERROR,
|
|
|
|
|
ReduxActionErrorTypes.FETCH_PAGE_ERROR,
|
|
|
|
|
];
|
|
|
|
|
|
2023-02-01 05:07:39 +00:00
|
|
|
initActionsCalls.push(fetchJSLibraries(applicationId));
|
|
|
|
|
successActionEffects.push(ReduxActionTypes.FETCH_JS_LIBRARIES_SUCCESS);
|
2022-12-21 17:14:47 +00:00
|
|
|
|
2022-07-11 04:06:29 +00:00
|
|
|
const allActionCalls: boolean = yield call(
|
|
|
|
|
failFastApiCalls,
|
|
|
|
|
initActionsCalls,
|
|
|
|
|
successActionEffects,
|
|
|
|
|
failureActionEffects,
|
|
|
|
|
);
|
|
|
|
|
|
2022-07-27 10:55:41 +00:00
|
|
|
if (!allActionCalls)
|
|
|
|
|
throw new ActionsNotFoundError(
|
|
|
|
|
`Unable to fetch actions for the application: ${applicationId}`,
|
|
|
|
|
);
|
2023-01-06 14:09:38 +00:00
|
|
|
|
2023-02-06 07:06:08 +00:00
|
|
|
yield call(waitForFetchUserSuccess);
|
2023-01-06 14:09:38 +00:00
|
|
|
yield call(waitForSegmentInit, true);
|
2022-07-11 04:06:29 +00:00
|
|
|
yield put(fetchAllPageEntityCompletion([executePageLoadActions()]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private *loadPluginsAndDatasources() {
|
|
|
|
|
const initActions = [
|
|
|
|
|
fetchPlugins(),
|
|
|
|
|
fetchDatasources(),
|
|
|
|
|
fetchMockDatasources(),
|
|
|
|
|
fetchPageDSLs(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const successActions = [
|
|
|
|
|
ReduxActionTypes.FETCH_PLUGINS_SUCCESS,
|
|
|
|
|
ReduxActionTypes.FETCH_DATASOURCES_SUCCESS,
|
|
|
|
|
ReduxActionTypes.FETCH_MOCK_DATASOURCES_SUCCESS,
|
|
|
|
|
ReduxActionTypes.FETCH_PAGE_DSLS_SUCCESS,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const errorActions = [
|
|
|
|
|
ReduxActionErrorTypes.FETCH_PLUGINS_ERROR,
|
|
|
|
|
ReduxActionErrorTypes.FETCH_DATASOURCES_ERROR,
|
|
|
|
|
ReduxActionErrorTypes.FETCH_MOCK_DATASOURCES_ERROR,
|
|
|
|
|
ReduxActionErrorTypes.POPULATE_PAGEDSLS_ERROR,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const initActionCalls: boolean = yield call(
|
|
|
|
|
failFastApiCalls,
|
|
|
|
|
initActions,
|
|
|
|
|
successActions,
|
|
|
|
|
errorActions,
|
|
|
|
|
);
|
|
|
|
|
|
2022-07-27 10:55:41 +00:00
|
|
|
if (!initActionCalls)
|
|
|
|
|
throw new PluginsNotFoundError("Unable to fetch plugins");
|
2022-07-11 04:06:29 +00:00
|
|
|
|
|
|
|
|
const pluginFormCall: boolean = yield call(
|
|
|
|
|
failFastApiCalls,
|
|
|
|
|
[fetchPluginFormConfigs()],
|
|
|
|
|
[ReduxActionTypes.FETCH_PLUGIN_FORM_CONFIGS_SUCCESS],
|
|
|
|
|
[ReduxActionErrorTypes.FETCH_PLUGIN_FORM_CONFIGS_ERROR],
|
|
|
|
|
);
|
2022-07-27 10:55:41 +00:00
|
|
|
if (!pluginFormCall)
|
|
|
|
|
throw new PluginFormConfigsNotFoundError(
|
|
|
|
|
"Unable to fetch plugin form configs",
|
|
|
|
|
);
|
2022-07-11 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public *loadAppEntities(toLoadPageId: string, applicationId: string): any {
|
2022-12-08 03:36:35 +00:00
|
|
|
yield call(this.loadPageThemesAndActions, toLoadPageId, applicationId);
|
|
|
|
|
yield call(this.loadPluginsAndDatasources);
|
2022-07-11 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public *completeChore() {
|
|
|
|
|
const currentApplication: ApplicationPayload = yield select(
|
|
|
|
|
getCurrentApplication,
|
|
|
|
|
);
|
|
|
|
|
AnalyticsUtil.logEvent("EDITOR_OPEN", {
|
|
|
|
|
appId: currentApplication.id,
|
|
|
|
|
appName: currentApplication.name,
|
|
|
|
|
});
|
2022-09-02 13:15:48 +00:00
|
|
|
yield put(loadGuidedTourInit());
|
2022-07-11 04:06:29 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public *loadGit(applicationId: string) {
|
|
|
|
|
const branchInStore: string = yield select(getCurrentGitBranch);
|
|
|
|
|
yield put(
|
|
|
|
|
restoreRecentEntitiesRequest({
|
|
|
|
|
applicationId,
|
|
|
|
|
branch: branchInStore,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
// init of temporay remote url from old application
|
|
|
|
|
yield put(remoteUrlInputValue({ tempRemoteUrl: "" }));
|
|
|
|
|
// add branch query to path and fetch status
|
|
|
|
|
if (branchInStore) {
|
|
|
|
|
history.replace(addBranchParam(branchInStore));
|
|
|
|
|
yield put(fetchGitStatusInit());
|
|
|
|
|
}
|
|
|
|
|
yield put(resetPullMergeStatus());
|
|
|
|
|
}
|
|
|
|
|
}
|