diff --git a/app/client/src/reducers/entityReducers/actionsReducer.tsx b/app/client/src/reducers/entityReducers/actionsReducer.tsx index 717b75c730..5c4b827640 100644 --- a/app/client/src/reducers/entityReducers/actionsReducer.tsx +++ b/app/client/src/reducers/entityReducers/actionsReducer.tsx @@ -10,6 +10,7 @@ import _ from "lodash"; import { RapidApiAction, RestAction } from "entities/Action"; import { UpdateActionPropertyActionPayload } from "actions/actionActions"; import produce from "immer"; +import { Datasource } from "api/DatasourcesApi"; export interface ActionData { isLoading: boolean; @@ -335,6 +336,52 @@ const actionsReducer = createReducer(initialState, { }); }); }, + [ReduxActionTypes.FETCH_DATASOURCES_SUCCESS]: ( + state: ActionDataState, + action: ReduxAction, + ) => { + const datasources = action.payload; + + return state.map(action => { + const datasourceId = action.config.datasource.id; + if (datasourceId) { + const datasource = datasources.find( + datasource => datasource.id === datasourceId, + ); + + return { + ...action, + config: { + ...action.config, + datasource: datasource, + }, + }; + } + + return action; + }); + }, + [ReduxActionTypes.UPDATE_DATASOURCE_SUCCESS]: ( + state: ActionDataState, + action: ReduxAction, + ) => { + const datasource = action.payload; + + return state.map(action => { + const datasourceId = action.config.datasource.id; + if (datasourceId && datasource.id === datasourceId) { + return { + ...action, + config: { + ...action.config, + datasource: datasource, + }, + }; + } + + return action; + }); + }, }); export default actionsReducer; diff --git a/app/client/src/sagas/ActionSagas.ts b/app/client/src/sagas/ActionSagas.ts index fb845d99db..6323d95002 100644 --- a/app/client/src/sagas/ActionSagas.ts +++ b/app/client/src/sagas/ActionSagas.ts @@ -50,6 +50,7 @@ import { ActionData } from "reducers/entityReducers/actionsReducer"; import { getAction, getCurrentPageNameByActionId, + getDatasource, getPageNameByPageId, } from "selectors/entitiesSelector"; import { PLUGIN_TYPE_API } from "constants/ApiEditorConstants"; @@ -87,7 +88,19 @@ export function* createActionSaga(actionPayload: ReduxAction) { pageName: pageName, ...actionPayload.payload.eventData, }); - yield put(createActionSuccess(response.data)); + + let newAction = response.data; + + if (newAction.datasource.id) { + const datasource = yield select(getDatasource, newAction.datasource.id); + + newAction = { + ...newAction, + datasource, + }; + } + + yield put(createActionSuccess(newAction)); } } catch (error) { yield put({ @@ -234,10 +247,26 @@ export function* updateActionSaga(actionPayload: ReduxAction<{ id: string }>) { pageName: pageName, }); } + + let updatedAction = response.data; + + if (updatedAction.datasource.id) { + const datasource = yield select( + getDatasource, + updatedAction.datasource.id, + ); + + updatedAction = { + ...updatedAction, + datasource, + }; + } + PerformanceTracker.stopAsyncTracking( PerformanceTransactionName.UPDATE_ACTION_API, ); - yield put(updateActionSuccess({ data: response.data })); + + yield put(updateActionSuccess({ data: updatedAction })); } } catch (error) { PerformanceTracker.stopAsyncTracking(