Skip to content

Commit

Permalink
fix: [PROD-11540] stop pbi polling on workspace change
Browse files Browse the repository at this point in the history
  • Loading branch information
ardvi committed May 25, 2023
1 parent 9a3657d commit d291812
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/state/commons/PowerBIConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 4 additions & 0 deletions src/state/reducers/powerbi/PowerBIReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
9 changes: 6 additions & 3 deletions src/state/sagas/workspace/SelectWorkspace/SelectWorkspace.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// 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';
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;
Expand Down Expand Up @@ -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);
Expand All @@ -96,7 +99,7 @@ export function* selectWorkspace(action) {
)
);

yield fork(getPowerBIEmbedInfoSaga);
yield put(dispatchGetPowerBIEmbedInfo());

yield put({
type: APPLICATION_ACTIONS_KEY.SET_APPLICATION_STATUS,
Expand Down

0 comments on commit d291812

Please sign in to comment.