Skip to content

Commit

Permalink
Merge branch 'main' into fix-uncaught-in-promise-error
Browse files Browse the repository at this point in the history
  • Loading branch information
sBouzols authored Dec 19, 2024
2 parents 478b250 + 8e6701e commit f6327a9
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 558 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@gridsuite/commons-ui": "0.73.1",
"@gridsuite/commons-ui": "0.75.0",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
Expand Down
8 changes: 7 additions & 1 deletion src/components/app-wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
importParamsFr,
exportParamsEn,
exportParamsFr,
NotificationsProvider,
} from '@gridsuite/commons-ui';
import { IntlProvider } from 'react-intl';
import { BrowserRouter } from 'react-router-dom';
Expand Down Expand Up @@ -79,6 +80,7 @@ import {
MAP_BASEMAP_CARTO,
MAP_BASEMAP_CARTO_NOLABEL,
} from '../utils/config-params';
import useNotificationsUrlGenerator from 'hooks/use-notifications-url-generator';

let lightTheme = createTheme({
components: {
Expand Down Expand Up @@ -327,6 +329,8 @@ const AppWrapperWithRedux = () => {

const theme = useSelector((state) => state[PARAM_THEME]);

const urlMapper = useNotificationsUrlGenerator();

return (
<IntlProvider locale={computedLanguage} messages={messages[computedLanguage]}>
<BrowserRouter basename={basename}>
Expand All @@ -335,7 +339,9 @@ const AppWrapperWithRedux = () => {
<SnackbarProvider hideIconVariant={false}>
<CssBaseline />
<CardErrorBoundary>
<App />
<NotificationsProvider urls={urlMapper}>
<App />
</NotificationsProvider>
</CardErrorBoundary>
</SnackbarProvider>
</ThemeProvider>
Expand Down
113 changes: 34 additions & 79 deletions src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,18 @@ import {
getPreLoginPath,
initializeAuthenticationProd,
useSnackMessage,
useNotificationsListener,
} from '@gridsuite/commons-ui';
import PageNotFound from './page-not-found';
import { FormattedMessage } from 'react-intl';
import {
APP_NAME,
COMMON_APP_NAME,
PARAM_CENTER_LABEL,
PARAM_COMPONENT_LIBRARY,
PARAM_DEVELOPER_MODE,
PARAM_DIAGONAL_LABEL,
PARAM_FAVORITE_CONTINGENCY_LISTS,
PARAM_FLUX_CONVENTION,
PARAM_INIT_NAD_WITH_GEO_DATA,
PARAM_LANGUAGE,
PARAM_LIMIT_REDUCTION,
PARAM_LINE_FLOW_ALERT_THRESHOLD,
PARAM_LINE_FLOW_COLOR_MODE,
PARAM_LINE_FLOW_MODE,
PARAM_LINE_FULL_PATH,
PARAM_LINE_PARALLEL_PATH,
PARAM_MAP_BASEMAP,
PARAM_MAP_MANUAL_REFRESH,
PARAM_SUBSTATION_LAYOUT,
PARAM_THEME,
PARAM_USE_NAME,
} from '../utils/config-params';
Expand All @@ -55,7 +44,6 @@ import { getComputedLanguage } from '../utils/language';
import AppTopBar from './app-top-bar';
import { StudyContainer } from './study-container';
import { fetchValidateUser } from '../services/user-admin';
import { connectNotificationsWsUpdateConfig } from '../services/config-notification';
import { fetchConfigParameter, fetchConfigParameters } from '../services/config';
import { fetchDefaultParametersValues, fetchIdpSettings } from '../services/utils';
import { getOptionalServices } from '../services/study';
Expand All @@ -64,29 +52,20 @@ import {
changeLockedColumns,
changeReorderedColumns,
limitReductionModified,
selectCenterLabelState,
selectComponentLibrary,
selectComputedLanguage,
selectDiagonalLabelState,
selectEnableDeveloperMode,
selectFavoriteContingencyLists,
selectFluxConvention,
selectInitNadWithGeoData,
selectLanguage,
selectLimitReduction,
selectLineFlowAlertThreshold,
selectLineFlowColorMode,
selectLineFlowMode,
selectLineFullPathState,
selectLineParallelPathState,
selectMapBaseMap,
selectMapManualRefresh,
selectSubstationLayout,
selectTheme,
selectUseName,
setOptionalServices,
setParamsLoaded,
setUpdateNetworkVisualizationParameters,
} from '../redux/actions';
import { NOTIFICATIONS_URL_KEYS } from './utils/notificationsProvider-utils';
import { getNetworkVisualizationParameters } from '../services/study/study-config.ts';

const noUserManager = { instance: null, error: null };

Expand All @@ -96,6 +75,7 @@ const App = () => {
const { snackError } = useSnackMessage();

const user = useSelector((state) => state.user);
const studyUuid = useSelector((state) => state.studyUuid);
const tablesNamesIndexes = useSelector((state) => state.tables.namesIndexes);
const tablesDefinitionIndexes = useSelector((state) => state.tables.definitionIndexes);

Expand All @@ -113,6 +93,14 @@ const App = () => {

const [tabIndex, setTabIndex] = useState(0);

const updateNetworkVisualizationsParams = useCallback(
(params) => {
console.debug('received network visualizations parameters : ', params);
dispatch(setUpdateNetworkVisualizationParameters(params));
},
[dispatch]
);

const updateParams = useCallback(
(params) => {
console.debug('received UI parameters : ', params);
Expand All @@ -132,51 +120,15 @@ const App = () => {
dispatch(selectLanguage(param.value));
dispatch(selectComputedLanguage(getComputedLanguage(param.value)));
break;
case PARAM_CENTER_LABEL:
dispatch(selectCenterLabelState(param.value === 'true'));
break;
case PARAM_DIAGONAL_LABEL:
dispatch(selectDiagonalLabelState(param.value === 'true'));
break;
case PARAM_LIMIT_REDUCTION:
dispatch(selectLimitReduction(param.value));
break;
case PARAM_LINE_FLOW_ALERT_THRESHOLD:
dispatch(selectLineFlowAlertThreshold(param.value));
break;
case PARAM_LINE_FLOW_COLOR_MODE:
dispatch(selectLineFlowColorMode(param.value));
break;
case PARAM_LINE_FLOW_MODE:
dispatch(selectLineFlowMode(param.value));
break;
case PARAM_FLUX_CONVENTION:
dispatch(selectFluxConvention(param.value));
break;
case PARAM_DEVELOPER_MODE:
dispatch(selectEnableDeveloperMode(param.value === 'true'));
break;
case PARAM_INIT_NAD_WITH_GEO_DATA:
dispatch(selectInitNadWithGeoData(param.value === 'true'));
break;
case PARAM_LINE_FULL_PATH:
dispatch(selectLineFullPathState(param.value === 'true'));
break;
case PARAM_LINE_PARALLEL_PATH:
dispatch(selectLineParallelPathState(param.value === 'true'));
break;
case PARAM_SUBSTATION_LAYOUT:
dispatch(selectSubstationLayout(param.value));
break;
case PARAM_COMPONENT_LIBRARY:
dispatch(selectComponentLibrary(param.value));
break;
case PARAM_MAP_MANUAL_REFRESH:
dispatch(selectMapManualRefresh(param.value === 'true'));
break;
case PARAM_MAP_BASEMAP:
dispatch(selectMapBaseMap(param.value));
break;
case PARAM_USE_NAME:
dispatch(selectUseName(param.value === 'true'));
break;
Expand Down Expand Up @@ -270,10 +222,8 @@ const App = () => {
[dispatch, tablesNamesIndexes, tablesDefinitionIndexes]
);

const connectNotificationsUpdateConfig = useCallback(() => {
const ws = connectNotificationsWsUpdateConfig();

ws.onmessage = function (event) {
const updateConfig = useCallback(
(event) => {
let eventData = JSON.parse(event.data);
if (eventData.headers && eventData.headers['parameterName']) {
fetchConfigParameter(eventData.headers['parameterName'])
Expand All @@ -290,12 +240,13 @@ const App = () => {
})
);
}
};
ws.onerror = function (event) {
console.error('Unexpected Notification WebSocket error', event);
};
return ws;
}, [updateParams, snackError, dispatch]);
},
[dispatch, snackError, updateParams]
);

useNotificationsListener(NOTIFICATIONS_URL_KEYS.CONFIG, {
listenerCallbackMessage: updateConfig,
});

// Can't use lazy initializer because useRouteMatch is a hook
const [initialMatchSilentRenewCallbackUrl] = useState(
Expand Down Expand Up @@ -343,7 +294,11 @@ const App = () => {
}, [initialMatchSilentRenewCallbackUrl, dispatch, initialMatchSigninCallbackUrl]);

useEffect(() => {
if (user !== null) {
if (user !== null && studyUuid !== null) {
const fetchNetworkVisualizationParametersPromise = getNetworkVisualizationParameters(studyUuid).then(
(params) => updateNetworkVisualizationsParams(params)
);

const fetchCommonConfigPromise = fetchConfigParameters(COMMON_APP_NAME).then((params) =>
updateParams(params)
);
Expand Down Expand Up @@ -409,7 +364,12 @@ const App = () => {
// This might not be necessary but allows to gradually migrate parts
// of the code that don't subscribe to exactly the parameters they need.
// Code that depends on this could be rewritten to depend on what it acually needs.
Promise.all([fetchCommonConfigPromise, fetchAppConfigPromise, fetchOptionalServices])
Promise.all([
fetchNetworkVisualizationParametersPromise,
fetchCommonConfigPromise,
fetchAppConfigPromise,
fetchOptionalServices,
])
.then(() => {
dispatch(setParamsLoaded());
})
Expand All @@ -419,13 +379,8 @@ const App = () => {
headerId: 'paramsRetrievingError',
})
);

const ws = connectNotificationsUpdateConfig();
return function () {
ws.close();
};
}
}, [user, dispatch, updateParams, connectNotificationsUpdateConfig, snackError]);
}, [user, studyUuid, dispatch, updateParams, snackError, updateNetworkVisualizationsParams]);

const onChangeTab = useCallback((newTabIndex) => {
setTabIndex(newTabIndex);
Expand Down
61 changes: 36 additions & 25 deletions src/components/diagrams/diagram-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@

import { Fragment, useCallback, useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
PARAM_CENTER_LABEL,
PARAM_COMPONENT_LIBRARY,
PARAM_DIAGONAL_LABEL,
PARAM_INIT_NAD_WITH_GEO_DATA,
PARAM_LANGUAGE,
PARAM_SUBSTATION_LAYOUT,
PARAM_USE_NAME,
} from '../../utils/config-params';
import { PARAM_LANGUAGE, PARAM_USE_NAME } from '../../utils/config-params';
import { Box, Chip, Stack, Theme } from '@mui/material';
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
import TimelineIcon from '@mui/icons-material/Timeline';
Expand Down Expand Up @@ -60,11 +52,8 @@ const useDisplayView = (studyUuid: UUID, currentNode: CurrentTreeNode) => {
const { snackError } = useSnackMessage();
const paramUseName = useSelector((state: AppState) => state[PARAM_USE_NAME]);
const { getNameOrId } = useNameOrId();
const centerName = useSelector((state: AppState) => state[PARAM_CENTER_LABEL]);
const diagonalName = useSelector((state: AppState) => state[PARAM_DIAGONAL_LABEL]);
const substationLayout = useSelector((state: AppState) => state[PARAM_SUBSTATION_LAYOUT]);
const componentLibrary = useSelector((state: AppState) => state[PARAM_COMPONENT_LIBRARY]);
const language = useSelector((state: AppState) => state[PARAM_LANGUAGE]);
const networkVisuParams = useSelector((state: AppState) => state.networkVisualizationsParameters);

const checkAndGetVoltageLevelSingleLineDiagramUrl = useCallback(
(voltageLevelId: UUID) =>
Expand All @@ -74,14 +63,22 @@ const useDisplayView = (studyUuid: UUID, currentNode: CurrentTreeNode) => {
currentNode?.id,
voltageLevelId,
paramUseName,
centerName,
diagonalName,
componentLibrary,
networkVisuParams.singleLineDiagramParameters.centerLabel,
networkVisuParams.singleLineDiagramParameters.diagonalLabel,
networkVisuParams.singleLineDiagramParameters.componentLibrary,
SLD_DISPLAY_MODE.STATE_VARIABLE,
language
)
: null,
[currentNode, studyUuid, paramUseName, centerName, diagonalName, componentLibrary, language]
[
currentNode,
studyUuid,
paramUseName,
networkVisuParams.singleLineDiagramParameters.centerLabel,
networkVisuParams.singleLineDiagramParameters.diagonalLabel,
networkVisuParams.singleLineDiagramParameters.componentLibrary,
language,
]
);

const checkAndGetSubstationSingleLineDiagramUrl = useCallback(
Expand All @@ -92,22 +89,36 @@ const useDisplayView = (studyUuid: UUID, currentNode: CurrentTreeNode) => {
currentNode?.id,
voltageLevelId,
paramUseName,
centerName,
diagonalName,
substationLayout,
componentLibrary,
networkVisuParams.singleLineDiagramParameters.centerLabel,
networkVisuParams.singleLineDiagramParameters.diagonalLabel,
networkVisuParams.singleLineDiagramParameters.substationLayout,
networkVisuParams.singleLineDiagramParameters.componentLibrary,
language
)
: null,
[centerName, componentLibrary, diagonalName, studyUuid, substationLayout, paramUseName, currentNode, language]
[
networkVisuParams.singleLineDiagramParameters.centerLabel,
networkVisuParams.singleLineDiagramParameters.componentLibrary,
networkVisuParams.singleLineDiagramParameters.diagonalLabel,
studyUuid,
networkVisuParams.singleLineDiagramParameters.substationLayout,
paramUseName,
currentNode,
language,
]
);
const initNadWithGeoData = useSelector((state: AppState) => state[PARAM_INIT_NAD_WITH_GEO_DATA]);
const checkAndGetNetworkAreaDiagramUrl = useCallback(
(voltageLevelsIds: UUID[], depth: number) =>
isNodeBuilt(currentNode)
? getNetworkAreaDiagramUrl(studyUuid, currentNode?.id, voltageLevelsIds, depth, initNadWithGeoData)
? getNetworkAreaDiagramUrl(
studyUuid,
currentNode?.id,
voltageLevelsIds,
depth,
networkVisuParams.networkAreaDiagramParameters.initNadWithGeoData
)
: null,
[studyUuid, currentNode, initNadWithGeoData]
[studyUuid, currentNode, networkVisuParams.networkAreaDiagramParameters.initNadWithGeoData]
);

// this callback returns a promise
Expand Down
Loading

0 comments on commit f6327a9

Please sign in to comment.