Skip to content

Commit

Permalink
feat: [PROD-13567] allow disabling of dashboards display when dashboa…
Browse files Browse the repository at this point in the history
…rds config doesn't exist
  • Loading branch information
esasova committed Jul 17, 2024
1 parent 120ab7c commit 382fec5
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"unknownStatus": {
"label": "This scenario has an unknown state, if the problem persists, please, contact your administrator"
},
"resultsDisplayDisabled": "Scenario run was successful but the display of results is disabled",
"error": {
"unknown": {
"details": "Something went wrong when fetching PowerBI reports info",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"unknownStatus": {
"label": "Le scénario a un statut inconnu, si le problème persiste, merci de contacter votre administrateur"
},
"resultsDisplayDisabled": "La simulation s'est terminée avec succès mais l'affichage des résultats est désactivé",
"error": {
"unknown": {
"details": "Une erreur est survenue lors de la récupération des informations des rapports PowerBI",
Expand Down
4 changes: 3 additions & 1 deletion src/AppLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export const getTabsForCurrentWorkspace = (currentWorkspaceData) => {
export const filterTabsForCurrentWorkspace = (tabs, currentWorkspaceData) => {
const hideInstanceView = !ConfigUtils.isInstanceViewConfigValid(currentWorkspaceData?.webApp?.options?.instanceView);
const hideDatasetManager = !ConfigUtils.isDatasetManagerEnabledInWorkspace(currentWorkspaceData);
const hideDashboardsView = !ConfigUtils.isResultsDisplayEnabledInWorkspace(currentWorkspaceData);

return tabs.filter((tab) => {
if (
(hideInstanceView && tab.key === 'tabs.instance.key') ||
(hideDatasetManager && tab.key === 'tabs.datasetmanager.key')
(hideDatasetManager && tab.key === 'tabs.datasetmanager.key') ||
(hideDashboardsView && tab.key === 'tabs.dashboards.key')
)
return false;
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/components/CurrentScenarioPowerBIReport/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const getReportLabels = (t) => ({
'This scenario has an unknown state, if the problem persists, please, contact your administrator'
),
},
resultsDisplayDisabled: t(
'commoncomponents.iframe.scenario.resultsDisplayDisabled',
'Scenario run was successful but the display of results is disabled'
),
downloadButton: t('commoncomponents.iframe.scenario.results.button.downloadLogs', 'Download logs'),
refreshTooltip: t('commoncomponents.iframe.scenario.results.button.refresh', 'Refresh'),
errors: {
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/RouterHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ export const useRedirectFromDatasetManagerToScenarioView = () => {
}, [currentWorkspaceData?.webApp?.options?.datasetmanager, navigate]);
};

export const useRedirectFromDashboardsToScenarioView = () => {
const isUnmounted = useRef(false);
const currentWorkspaceData = useWorkspaceData();
const navigate = useNavigate();

useEffect(() => {
if (isUnmounted.current) {
return;
}
const isDatasetManagerViewEnabled = ConfigUtils.isResultsDisplayEnabledInWorkspace(currentWorkspaceData);
if (isDatasetManagerViewEnabled) return;
navigate('/workspaces');
return () => {
isUnmounted.current = true;
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentWorkspaceData?.webApp?.options?.charts, navigate]);
};

export const useRouterScenarioId = () => {
const routerParameters = useParams();
return routerParameters?.scenarioId;
Expand Down
6 changes: 5 additions & 1 deletion src/layouts/TabLayout/TabLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export const TabLayout = (props) => {
const shouldRedirectFromDatasetManager =
currentTabPathname.startsWith(`/${routerParameters.workspaceId}/datasetmanager`) &&
!ConfigUtils.isDatasetManagerEnabledInWorkspace(currentWorkspace?.data);
const shouldRedirect = shouldRedirectFromInstanceView || shouldRedirectFromDatasetManager;
const shouldRedirectFromDashboardsView =
currentTabPathname.startsWith(`/${routerParameters.workspaceId}/dashboards`) &&
!ConfigUtils.isResultsDisplayEnabledInWorkspace(currentWorkspace?.data);
const shouldRedirect =
shouldRedirectFromInstanceView || shouldRedirectFromDatasetManager || shouldRedirectFromDashboardsView;
const tabValue = shouldRedirect ? `/${routerParameters.workspaceId}/scenario` : currentTabPathname;

const viewTabs = (
Expand Down
1 change: 1 addition & 0 deletions src/state/commons/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const STATUSES = {
ERROR: 'ERROR',
SUCCESS: 'SUCCESS',
CREATED: 'CREATED',
DISABLED: 'DISABLED',
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { delay, put, select, takeLatest } from 'redux-saga/effects';
import { POWER_BI_INFO_POLLING_DELAY } from '../../../../services/config/FunctionalConstants';
import { PowerBIService } from '../../../../services/powerbi/PowerBIService';
import { forgePowerBIError } from '../../../../services/powerbi/errors';
import { PowerBIUtils } from '../../../../utils';
import { STATUSES } from '../../../commons/Constants';
import { POWER_BI_ACTIONS_KEY } from '../../../commons/PowerBIConstants';
Expand All @@ -27,16 +26,15 @@ export function* getPowerBIEmbedInfoSaga() {
const powerBIChartsConfig = yield select(getPowerBIChartsConfig);

if (powerBIChartsConfig == null) {
console.error(
'PowerBI charts configuration could not be found. Please configure the dashboards to be displayed in your ' +
'workspace, in [workspace].webApp.options.charts'
console.warn(
'PowerBI charts configuration could not be found and results display has been disabled. ' +
'If you want to activate it, please configure the dashboards to be displayed in your workspace, ' +
'in [workspace].webApp.options.charts'
);

yield put({
type: POWER_BI_ACTIONS_KEY.SET_EMBED_INFO,
data: noAccess,
error: forgePowerBIError('', 'Configuration error', 'Cannot find dashboards configuration in workspace data'),
status: STATUSES.ERROR,
status: STATUSES.DISABLED,
});
return;
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/ConfigUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ const isDatasetManagerEnabledInWorkspace = (workspace) => {
return true;
};

const isResultsDisplayEnabledInWorkspace = (workspace) => {
const reportsConfig = workspace?.webApp?.options?.charts;
return reportsConfig != null;
};

const checkUnknownKeysInConfig = (schema, data) => {
try {
schema.parse(data);
Expand Down Expand Up @@ -243,5 +248,6 @@ export const ConfigUtils = {
patchSolution,
isInstanceViewConfigValid,
isDatasetManagerEnabledInWorkspace,
isResultsDisplayEnabledInWorkspace,
checkUnknownKeysInConfig,
};
2 changes: 2 additions & 0 deletions src/views/Dashboards/Dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Card, CardContent, Grid, Tab, Tabs } from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import { useDashboardsViewReportsConfig } from '../../state/hooks/PowerBIHooks';
import { DashboardsPowerBiReport } from './components';
import {useRedirectFromDashboardsToScenarioView, useRedirectToWorkspaceView} from "../../hooks/RouterHooks";

const useStyles = makeStyles((theme) => ({
dashboardsRoot: {
Expand Down Expand Up @@ -70,6 +71,7 @@ const Dashboards = () => {
};

const dashboardsViewReportsConfig = useDashboardsViewReportsConfig();
useRedirectFromDashboardsToScenarioView();
const dashboardTitle = dashboardsViewReportsConfig?.[value]?.title?.[i18n.language] ?? DEFAULT_MISSING_TITLE;

return (
Expand Down

0 comments on commit 382fec5

Please sign in to comment.