PromucFlow_constructor/app/client/src/sagas/SaaSPaneSagas.ts
sneha122 b5902bf035
feat: Datasource autosave improvements (#17649)
* Datasource autosave improvements WIP

* authenticated API and ds name updates

* popup updates, api to datasource updates

* issue fixes for new ds in new workspace

* formatter issue fixed

* console warning issue fixed

* refresh edge case handled for temp ds

* DS creation cypress update

* datasource improvements issue fixes

* CreateDS flow change cypress update

* reconnect issue fixed

* added space

* Create Ds related script updates

* SaveDs changes updated

* DatasourceForm_spec.js fix

* GoogleSheetsQuery_spec.js - still spec will fail

* GoogleSheetsStub_spec.ts fix

* MongoDatasource_spec.js fix

* ElasticSearchDatasource_spec.js fix

* AuthenticatedApiDatasource_spec.js

* RestApiDatasource_spec.js - will stil fail

* RedshiftDataSourceStub_spec.js fix

* issue fixes for datasource autosave

* save as datasource issue fixed

* SKipped - Bug 18035

* MySQL spec fix

* PostgresDatasource_spec.js fix

* MySQLDataSourceStub_spec.js fix

* MsSQLDataSourceStub_spec.js fix

* Bug16702_Spec.ts fix

* SwitchDatasource_spec.js fix

* ArangoDataSourceStub_spec.js fix

* code review changes, save and authorise issue fixed

* cypress test issue and cypress tests fixed

* client build failure issue fixed

* test failure fixes

* ReconnectDatasource_spec.js fix

* Entity_Explorer_CopyQuery_RenameDatasource_spec.js fix

* GitImport_spec.js fix

* Index add

* undo redo test issue fixed

* fixed cypress tests of rest api ds

* globalsearch_spec.js fixed

* code review changes

* code review comments addressed

* ds schema cypress issue fixed

* cypress test updates

* fix updateDatasource path

* rest api cypress test fixed

* cypress code review changes

* Removing few random .only's

* replay editor fix

* indexed

* adding .skip

Co-authored-by: “sneha122” <“sneha@appsmith.com”>
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2022-11-30 11:29:45 +05:30

104 lines
3.2 KiB
TypeScript

import { all, select, takeEvery } from "redux-saga/effects";
import {
ReduxAction,
ReduxActionTypes,
} from "@appsmith/constants/ReduxActionConstants";
import history from "utils/history";
import {
getGenerateCRUDEnabledPluginMap,
getPlugin,
} from "selectors/entitiesSelector";
import { Action, PluginType } from "entities/Action";
import { GenerateCRUDEnabledPluginMap, Plugin } from "api/PluginApi";
import {
generateTemplateFormURL,
saasEditorApiIdURL,
saasEditorDatasourceIdURL,
} from "RouteBuilder";
import { getCurrentPageId } from "selectors/editorSelectors";
import { CreateDatasourceSuccessAction } from "actions/datasourceActions";
import { getQueryParams } from "utils/URLUtils";
import { getIsGeneratePageInitiator } from "utils/GenerateCrudUtil";
function* handleDatasourceCreatedSaga(
actionPayload: CreateDatasourceSuccessAction,
) {
const { isDBCreated, payload } = actionPayload;
const plugin: Plugin | undefined = yield select(getPlugin, payload.pluginId);
const pageId: string = yield select(getCurrentPageId);
// Only look at SAAS plugins
if (!plugin) return;
if (plugin.type !== PluginType.SAAS) return;
const queryParams = getQueryParams();
const updatedDatasource = payload;
const isGeneratePageInitiator = getIsGeneratePageInitiator(
queryParams.isGeneratePageMode,
);
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 },
}),
);
}
}
function* handleActionCreatedSaga(actionPayload: ReduxAction<Action>) {
const { id, pluginId } = actionPayload.payload;
const plugin: Plugin | undefined = yield select(getPlugin, pluginId);
const pageId: string = yield select(getCurrentPageId);
if (!plugin) return;
if (plugin.type !== "SAAS") return;
history.push(
saasEditorApiIdURL({
pageId,
pluginPackageName: plugin.packageName,
apiId: id,
params: {
editName: "true",
from: "datasources",
},
}),
);
}
// since we are re-using the query editor form names for SAAS actions, all formValueChanges will be handled in the QuerypaneSagas.
export default function* root() {
yield all([
takeEvery(
ReduxActionTypes.CREATE_DATASOURCE_SUCCESS,
handleDatasourceCreatedSaga,
),
takeEvery(ReduxActionTypes.CREATE_ACTION_SUCCESS, handleActionCreatedSaga),
]);
}