2022-04-07 16:18:49 +00:00
|
|
|
import { all, select, takeEvery } from "redux-saga/effects";
|
2022-04-12 10:50:01 +00:00
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2021-04-22 03:30:09 +00:00
|
|
|
import history from "utils/history";
|
2022-11-30 05:59:45 +00:00
|
|
|
import {
|
|
|
|
|
getGenerateCRUDEnabledPluginMap,
|
|
|
|
|
getPlugin,
|
|
|
|
|
} from "selectors/entitiesSelector";
|
2021-04-22 03:30:09 +00:00
|
|
|
import { Action, PluginType } from "entities/Action";
|
2022-11-30 05:59:45 +00:00
|
|
|
import { GenerateCRUDEnabledPluginMap, Plugin } from "api/PluginApi";
|
|
|
|
|
import {
|
|
|
|
|
generateTemplateFormURL,
|
|
|
|
|
saasEditorApiIdURL,
|
|
|
|
|
saasEditorDatasourceIdURL,
|
|
|
|
|
} from "RouteBuilder";
|
2022-07-11 04:06:29 +00:00
|
|
|
import { getCurrentPageId } from "selectors/editorSelectors";
|
2022-11-30 05:59:45 +00:00
|
|
|
import { CreateDatasourceSuccessAction } from "actions/datasourceActions";
|
|
|
|
|
import { getQueryParams } from "utils/URLUtils";
|
|
|
|
|
import { getIsGeneratePageInitiator } from "utils/GenerateCrudUtil";
|
2021-04-22 03:30:09 +00:00
|
|
|
|
2022-11-30 05:59:45 +00:00
|
|
|
function* handleDatasourceCreatedSaga(
|
|
|
|
|
actionPayload: CreateDatasourceSuccessAction,
|
|
|
|
|
) {
|
|
|
|
|
const { isDBCreated, payload } = actionPayload;
|
|
|
|
|
const plugin: Plugin | undefined = yield select(getPlugin, payload.pluginId);
|
2022-07-11 04:06:29 +00:00
|
|
|
const pageId: string = yield select(getCurrentPageId);
|
2021-04-22 03:30:09 +00:00
|
|
|
// Only look at SAAS plugins
|
2022-06-21 13:57:34 +00:00
|
|
|
if (!plugin) return;
|
2021-04-22 03:30:09 +00:00
|
|
|
if (plugin.type !== PluginType.SAAS) return;
|
|
|
|
|
|
2022-11-30 05:59:45 +00:00
|
|
|
const queryParams = getQueryParams();
|
|
|
|
|
const updatedDatasource = payload;
|
|
|
|
|
|
|
|
|
|
const isGeneratePageInitiator = getIsGeneratePageInitiator(
|
|
|
|
|
queryParams.isGeneratePageMode,
|
2021-04-22 03:30:09 +00:00
|
|
|
);
|
2022-11-30 05:59:45 +00:00
|
|
|
const generateCRUDSupportedPlugin: GenerateCRUDEnabledPluginMap = yield select(
|
|
|
|
|
getGenerateCRUDEnabledPluginMap,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// isGeneratePageInitiator ensures that datasource is being created from generate page with data
|
|
|
|
|
// then we check if the current plugin is supported for generate page with data functionality
|
|
|
|
|
// and finally isDBCreated ensures that datasource is not in temporary state and
|
|
|
|
|
// user has explicitly saved the datasource, before redirecting back to generate page
|
|
|
|
|
if (
|
|
|
|
|
isGeneratePageInitiator &&
|
|
|
|
|
updatedDatasource.pluginId &&
|
|
|
|
|
generateCRUDSupportedPlugin[updatedDatasource.pluginId] &&
|
|
|
|
|
isDBCreated
|
|
|
|
|
) {
|
|
|
|
|
history.push(
|
|
|
|
|
generateTemplateFormURL({
|
|
|
|
|
pageId,
|
|
|
|
|
params: {
|
|
|
|
|
datasourceId: updatedDatasource.id,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
history.push(
|
|
|
|
|
saasEditorDatasourceIdURL({
|
|
|
|
|
pageId,
|
|
|
|
|
pluginPackageName: plugin.packageName,
|
|
|
|
|
datasourceId: payload.id,
|
|
|
|
|
params: { from: "datasources", pluginId: plugin?.id },
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-04-22 03:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* handleActionCreatedSaga(actionPayload: ReduxAction<Action>) {
|
|
|
|
|
const { id, pluginId } = actionPayload.payload;
|
2022-06-21 13:57:34 +00:00
|
|
|
const plugin: Plugin | undefined = yield select(getPlugin, pluginId);
|
2022-07-11 04:06:29 +00:00
|
|
|
const pageId: string = yield select(getCurrentPageId);
|
2021-04-22 03:30:09 +00:00
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
if (!plugin) return;
|
2021-04-22 03:30:09 +00:00
|
|
|
if (plugin.type !== "SAAS") return;
|
|
|
|
|
history.push(
|
2022-03-25 10:43:26 +00:00
|
|
|
saasEditorApiIdURL({
|
2022-07-11 04:06:29 +00:00
|
|
|
pageId,
|
2022-03-25 10:43:26 +00:00
|
|
|
pluginPackageName: plugin.packageName,
|
|
|
|
|
apiId: id,
|
|
|
|
|
params: {
|
|
|
|
|
editName: "true",
|
|
|
|
|
from: "datasources",
|
|
|
|
|
},
|
2021-04-22 03:30:09 +00:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 16:18:49 +00:00
|
|
|
// since we are re-using the query editor form names for SAAS actions, all formValueChanges will be handled in the QuerypaneSagas.
|
2021-04-22 03:30:09 +00:00
|
|
|
|
|
|
|
|
export default function* root() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.CREATE_DATASOURCE_SUCCESS,
|
|
|
|
|
handleDatasourceCreatedSaga,
|
|
|
|
|
),
|
|
|
|
|
takeEvery(ReduxActionTypes.CREATE_ACTION_SUCCESS, handleActionCreatedSaga),
|
|
|
|
|
]);
|
|
|
|
|
}
|