PromucFlow_constructor/app/client/src/sagas/SaaSPaneSagas.ts
Ayush Pahwa 810f2baa1c
fix: fix redirect post datasource save (#23707)
## Description
PR fixes the issue of redirect once the datasource save is clicked.
Removed excess set view mode function calls.

#### PR fixes following issue(s)
Fixes #23706 

#### Media

https://theappsmith.slack.com/files/U025TQ6P4MA/F0579E38FBM/screen_recording_2023-05-11_at_4.39.56_pm.mov

#### Type of change
- Bug fix (non-breaking change which fixes an issue)

## Testing

#### How Has This Been Tested?
- [ ] Manual
- [ ] Jest
- [ ] Cypress

#### Issues raised during DP testing

## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-05-26 13:39:07 +07:00

106 lines
3.4 KiB
TypeScript

import { all, select, takeEvery } from "redux-saga/effects";
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
import history from "utils/history";
import {
getGenerateCRUDEnabledPluginMap,
getPlugin,
} from "selectors/entitiesSelector";
import type { Action } from "entities/Action";
import { PluginType } from "entities/Action";
import type { GenerateCRUDEnabledPluginMap, Plugin } from "api/PluginApi";
import {
generateTemplateFormURL,
saasEditorApiIdURL,
saasEditorDatasourceIdURL,
} from "RouteBuilder";
import { getCurrentPageId } from "selectors/editorSelectors";
import type { 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,
viewMode: "false",
},
}),
);
}
}
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),
]);
}