diff --git a/src/state/commons/PowerBIConstants.js b/src/state/commons/PowerBIConstants.js index dbc03d12d..621fac8b6 100644 --- a/src/state/commons/PowerBIConstants.js +++ b/src/state/commons/PowerBIConstants.js @@ -6,6 +6,7 @@ export const POWER_BI_ACTIONS_KEY = { SET_EMBED_INFO: 'SET_EMBED_INFO', SET_REPORTS_CONFIG: 'SET_REPORTS_CONFIG', GET_EMBED_INFO: 'GET_EMBED_INFO', + CLEAR_EMBED_INFO: 'CLEAR_EMBED_INFO', }; export const GET_EMBED_INFO_URL = '/api/get-embed-info'; diff --git a/src/state/reducers/powerbi/PowerBIReducer.js b/src/state/reducers/powerbi/PowerBIReducer.js index 5cf3e5ddd..bc88c4e64 100644 --- a/src/state/reducers/powerbi/PowerBIReducer.js +++ b/src/state/reducers/powerbi/PowerBIReducer.js @@ -26,5 +26,9 @@ export const powerBiReducer = createReducer(powerBiInitialState, (builder) => { }) .addCase(POWER_BI_ACTIONS_KEY.SET_REPORTS_CONFIG, (state, action) => { state.data.reportsConfig = action.reportsConfig; + }) + .addCase(POWER_BI_ACTIONS_KEY.CLEAR_EMBED_INFO, (state) => { + state.data = powerBiInitialState.data; + state.status = powerBiInitialState.status; }); }); diff --git a/src/state/sagas/powerbi/GetPowerBIEmbedInfo/GetPowerBIEmbedInfoData.js b/src/state/sagas/powerbi/GetPowerBIEmbedInfo/GetPowerBIEmbedInfoData.js index ad5bf72fd..768c7f610 100644 --- a/src/state/sagas/powerbi/GetPowerBIEmbedInfo/GetPowerBIEmbedInfoData.js +++ b/src/state/sagas/powerbi/GetPowerBIEmbedInfo/GetPowerBIEmbedInfoData.js @@ -1,7 +1,7 @@ // Copyright (c) Cosmo Tech. // Licensed under the MIT license. -import { delay, put, select, takeEvery } from 'redux-saga/effects'; +import { delay, put, select, takeLatest } from 'redux-saga/effects'; import { POWER_BI_ACTIONS_KEY } from '../../../commons/PowerBIConstants'; import { STATUSES } from '../../../commons/Constants'; import { POWER_BI_INFO_POLLING_DELAY } from '../../../../services/config/FunctionalConstants'; @@ -99,9 +99,8 @@ export function* getPowerBIEmbedInfoSaga() { } // generators function -// Here is a watcher that takes EVERY action dispatched named GET_EMBED_INFO and binds getPowerBIEmbedInfo saga to it +// Here is a watcher that takes the last action dispatched named GET_EMBED_INFO and binds getPowerBIEmbedInfo saga to it function* getPowerBIEmbedInfoData() { - yield takeEvery(POWER_BI_ACTIONS_KEY.GET_EMBED_INFO, getPowerBIEmbedInfoSaga); + yield takeLatest(POWER_BI_ACTIONS_KEY.GET_EMBED_INFO, getPowerBIEmbedInfoSaga); } - export default getPowerBIEmbedInfoData; diff --git a/src/state/sagas/workspace/SelectWorkspace/SelectWorkspace.js b/src/state/sagas/workspace/SelectWorkspace/SelectWorkspace.js index f02be6911..a580c9e74 100644 --- a/src/state/sagas/workspace/SelectWorkspace/SelectWorkspace.js +++ b/src/state/sagas/workspace/SelectWorkspace/SelectWorkspace.js @@ -1,7 +1,7 @@ // Copyright (c) Cosmo Tech. // Licensed under the MIT license. -import { all, call, fork, select, takeEvery, put } from 'redux-saga/effects'; +import { all, call, select, takeEvery, put } from 'redux-saga/effects'; import { STATUSES } from '../../../commons/Constants'; import { APPLICATION_ACTIONS_KEY } from '../../../commons/ApplicationConstants'; import { SCENARIO_ACTIONS_KEY } from '../../../commons/ScenarioConstants'; @@ -9,10 +9,11 @@ import { WORKSPACE_ACTIONS_KEY } from '../../../commons/WorkspaceConstants'; import { SCENARIO_RUN_STATE } from '../../../../services/config/ApiConstants'; import { getAllScenariosData } from '../../scenario/FindAllScenarios/FindAllScenariosData'; import { fetchSolutionByIdData } from '../../solution/FindSolutionById/FindSolutionByIdData'; -import { getPowerBIEmbedInfoSaga } from '../../powerbi/GetPowerBIEmbedInfo/GetPowerBIEmbedInfoData'; import { getFirstScenarioMaster } from '../../../../utils/SortScenarioListUtils'; import { dispatchSetApplicationErrorMessage } from '../../../dispatchers/app/ApplicationDispatcher'; import { t } from 'i18next'; +import { POWER_BI_ACTIONS_KEY } from '../../../commons/PowerBIConstants'; +import { dispatchGetPowerBIEmbedInfo } from '../../../dispatchers/powerbi/PowerBIDispatcher'; const getOrganizationId = (state) => state?.organization?.current?.data?.id; const selectSolutionIdFromCurrentWorkspace = (state) => state.workspace.current.data.solution.solutionId; @@ -70,6 +71,8 @@ export function* selectWorkspace(action) { type: SCENARIO_ACTIONS_KEY.STOP_ALL_SCENARIO_STATUS_POLLINGS, }); + yield put({ type: POWER_BI_ACTIONS_KEY.CLEAR_EMBED_INFO }); + yield call(getAllScenariosData, organizationId, selectedWorkspaceId); const solutionId = yield select(selectSolutionIdFromCurrentWorkspace); yield call(fetchSolutionByIdData, organizationId, selectedWorkspaceId, solutionId); @@ -96,7 +99,7 @@ export function* selectWorkspace(action) { ) ); - yield fork(getPowerBIEmbedInfoSaga); + yield put(dispatchGetPowerBIEmbedInfo()); yield put({ type: APPLICATION_ACTIONS_KEY.SET_APPLICATION_STATUS,