Skip to content

Commit f0b6ab6

Browse files
fix: use commons-ui config params api (app specific) (#3153)
* fix: use commons-ui config params api (app specific) Signed-off-by: Joris Mancini <[email protected]> * chore: update commons-ui version Signed-off-by: Joris Mancini <[email protected]> --------- Signed-off-by: Joris Mancini <[email protected]>
1 parent 69ef8b6 commit f0b6ab6

File tree

6 files changed

+23
-56
lines changed

6 files changed

+23
-56
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@emotion/react": "^11.14.0",
1313
"@emotion/styled": "^11.14.0",
14-
"@gridsuite/commons-ui": "0.119.2",
14+
"@gridsuite/commons-ui": "0.120.0",
1515
"@hello-pangea/dnd": "^18.0.1",
1616
"@hookform/resolvers": "^4.0.0",
1717
"@mui/icons-material": "^5.16.14",

src/components/app.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ import {
1717
AnnouncementNotification,
1818
AuthenticationRouter,
1919
CardErrorBoundary,
20+
COMMON_APP_NAME,
21+
fetchConfigParameter,
22+
fetchConfigParameters,
2023
getPreLoginPath,
2124
initializeAuthenticationProd,
25+
LAST_SELECTED_DIRECTORY,
2226
NotificationsUrlKeys,
2327
useNotificationsListener,
2428
useSnackMessage,
25-
LAST_SELECTED_DIRECTORY,
2629
} from '@gridsuite/commons-ui';
2730
import PageNotFound from './page-not-found';
2831
import { FormattedMessage } from 'react-intl';
2932
import {
3033
APP_NAME,
31-
COMMON_APP_NAME,
3234
PARAM_DEVELOPER_MODE,
3335
PARAM_FAVORITE_CONTINGENCY_LISTS,
3436
PARAM_LANGUAGE,
@@ -38,7 +40,6 @@ import {
3840
import { getComputedLanguage } from '../utils/language';
3941
import AppTopBar from './app-top-bar';
4042
import { StudyContainer } from './study-container';
41-
import { fetchConfigParameter, fetchConfigParameters } from '../services/config';
4243
import { fetchDefaultParametersValues, fetchIdpSettings } from '../services/utils';
4344
import { getOptionalServices } from '../services/study/index';
4445
import {
@@ -136,7 +137,7 @@ const App = () => {
136137
(event) => {
137138
let eventData = JSON.parse(event.data);
138139
if (eventData.headers && eventData.headers['parameterName']) {
139-
fetchConfigParameter(eventData.headers['parameterName'])
140+
fetchConfigParameter(APP_NAME, eventData.headers['parameterName'])
140141
.then((param) => {
141142
updateParams([param]);
142143
})

src/components/dialogs/parameters/use-parameters-state.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import { useCallback, useEffect, useState } from 'react';
99
import { useSelector } from 'react-redux';
1010

11-
import { useSnackMessage, updateConfigParameter } from '@gridsuite/commons-ui';
11+
import { updateConfigParameter, useSnackMessage } from '@gridsuite/commons-ui';
1212
import { AppConfigState } from 'redux/reducer';
1313

1414
import { simpleConverterToString } from '../../../utils/types-utils';
15+
import { APP_NAME } from '../../../utils/config-params';
1516

1617
// Overload for primitive types: paramValueUpdateConvertor is optional
1718
export function useParameterState<K extends keyof AppConfigState>(
@@ -44,15 +45,17 @@ export function useParameterState<K extends keyof AppConfigState>(
4445
const handleChangeParamLocalState = useCallback(
4546
(value: AppConfigState[K]) => {
4647
setParamLocalState(value);
47-
updateConfigParameter(paramName, (paramValueUpdateConvertor ?? simpleConverterToString)(value)).catch(
48-
(error) => {
49-
setParamLocalState(paramGlobalState);
50-
snackError({
51-
messageTxt: error.message,
52-
headerId: 'paramsChangingError',
53-
});
54-
}
55-
);
48+
updateConfigParameter(
49+
APP_NAME,
50+
paramName,
51+
(paramValueUpdateConvertor ?? simpleConverterToString)(value)
52+
).catch((error) => {
53+
setParamLocalState(paramGlobalState);
54+
snackError({
55+
messageTxt: error.message,
56+
headerId: 'paramsChangingError',
57+
});
58+
});
5659
},
5760
[paramName, snackError, paramGlobalState, paramValueUpdateConvertor]
5861
);

src/services/config.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/utils/config-params.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { LAST_SELECTED_DIRECTORY } from '@gridsuite/commons-ui';
9-
10-
export const COMMON_APP_NAME = 'common';
118
export const APP_NAME = 'study';
129

1310
// Commons config names
@@ -35,14 +32,3 @@ export const PARAM_PROVIDER_OPENLOADFLOW = 'OpenLoadFlow';
3532
export const PARAM_PROVIDER_DYNAFLOW = 'DynaFlow';
3633

3734
export const basemap_style_theme_key = (basemap: string) => basemap + 'Style';
38-
39-
const COMMON_CONFIG_PARAMS_NAMES = new Set([
40-
PARAM_THEME,
41-
PARAM_LANGUAGE,
42-
LAST_SELECTED_DIRECTORY,
43-
PARAM_DEVELOPER_MODE,
44-
]);
45-
46-
export function getAppName(paramName: string) {
47-
return COMMON_CONFIG_PARAMS_NAMES.has(paramName) ? COMMON_APP_NAME : APP_NAME;
48-
}

0 commit comments

Comments
 (0)