From 11a6536f50cb232e0fc0d2448593b99fbc58cbd7 Mon Sep 17 00:00:00 2001 From: Joris Mancini Date: Thu, 21 Aug 2025 16:32:57 +0200 Subject: [PATCH 1/2] fix: use commons-ui config params api (app specific) Signed-off-by: Joris Mancini --- src/components/App/app.tsx | 10 ++++++---- src/components/parameters.tsx | 6 +++--- src/services/config.ts | 29 +---------------------------- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/components/App/app.tsx b/src/components/App/app.tsx index 86746c1..3d3ae02 100644 --- a/src/components/App/app.tsx +++ b/src/components/App/app.tsx @@ -11,13 +11,15 @@ import { Grid } from '@mui/material'; import { AnnouncementNotification, CardErrorBoundary, + fetchConfigParameter, + fetchConfigParameters, NotificationsUrlKeys, useNotificationsListener, useSnackMessage, } from '@gridsuite/commons-ui'; import { selectComputedLanguage, selectLanguage, selectTheme } from '../../redux/actions'; import { AppState } from '../../redux/reducer'; -import { ConfigParameters, ConfigSrv } from '../../services'; +import { ConfigParameters } from '../../services'; import { APP_NAME, COMMON_APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../../utils/config-params'; import { getComputedLanguage } from '../../utils/language'; import AppTopBar from './app-top-bar'; @@ -56,7 +58,7 @@ export default function App({ children }: Readonly>) { (event: MessageEvent) => { const eventData = JSON.parse(event.data); if (eventData?.headers?.parameterName) { - ConfigSrv.fetchConfigParameter(eventData.headers.parameterName) + fetchConfigParameter(APP_NAME, eventData.headers.parameterName) .then((param) => updateParams([param])) .catch((error) => snackError({ messageTxt: error.message, headerId: 'paramsRetrievingError' })); } @@ -68,7 +70,7 @@ export default function App({ children }: Readonly>) { useEffect(() => { if (user !== null) { - ConfigSrv.fetchConfigParameters(COMMON_APP_NAME) + fetchConfigParameters(COMMON_APP_NAME) .then((params) => updateParams(params)) .catch((error) => snackError({ @@ -77,7 +79,7 @@ export default function App({ children }: Readonly>) { }) ); - ConfigSrv.fetchConfigParameters(APP_NAME) + fetchConfigParameters(APP_NAME) .then((params) => updateParams(params)) .catch((error) => snackError({ diff --git a/src/components/parameters.tsx b/src/components/parameters.tsx index 77a10c3..ab73c6b 100644 --- a/src/components/parameters.tsx +++ b/src/components/parameters.tsx @@ -7,9 +7,9 @@ import { useCallback, useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; -import { ConfigSrv } from '../services'; -import { useSnackMessage } from '@gridsuite/commons-ui'; +import { updateConfigParameter, useSnackMessage } from '@gridsuite/commons-ui'; import { AppState, AppStateKey } from '../redux/reducer'; +import { APP_NAME } from '../utils/config-params'; export function useParameterState(paramName: K): [AppState[K], (value: AppState[K]) => void] { const { snackError } = useSnackMessage(); @@ -23,7 +23,7 @@ export function useParameterState(paramName: K): [AppStat const handleChangeParamLocalState = useCallback( (value: AppState[K]) => { setParamLocalState(value); - ConfigSrv.updateConfigParameter(paramName, value as string) //TODO how to check/cast? + updateConfigParameter(APP_NAME, paramName, value as string) //TODO how to check/cast? .catch((error) => { setParamLocalState(paramGlobalState); snackError({ diff --git a/src/services/config.ts b/src/services/config.ts index e5e9ebf..9c7ec86 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -6,10 +6,7 @@ */ import { GsLang, GsTheme } from '@gridsuite/commons-ui'; -import { APP_NAME, getAppName, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params'; -import { backendFetch, backendFetchJson, getRestBase } from '../utils/api-rest'; - -const PREFIX_CONFIG_QUERIES = `${getRestBase()}/config`; +import { PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params'; // https://github.com/gridsuite/config-server/blob/main/src/main/java/org/gridsuite/config/server/dto/ParameterInfos.java export type ConfigParameter = @@ -22,27 +19,3 @@ export type ConfigParameter = value: GsTheme; }; export type ConfigParameters = ConfigParameter[]; - -export function fetchConfigParameters(appName: string = APP_NAME): Promise { - console.debug(`Fetching UI configuration params for app : ${appName}`); - const fetchParams = `${PREFIX_CONFIG_QUERIES}/v1/applications/${appName}/parameters`; - return backendFetchJson(fetchParams) as Promise; -} - -export function fetchConfigParameter(name: string): Promise { - const appName = getAppName(name); - console.debug(`Fetching UI config parameter '${name}' for app '${appName}'`); - const fetchParams = `${PREFIX_CONFIG_QUERIES}/v1/applications/${appName}/parameters/${name}`; - return backendFetchJson(fetchParams) as Promise; -} - -export function updateConfigParameter(name: string, value: Parameters[0]): Promise { - const appName = getAppName(name); - console.debug(`Updating config parameter '${name}=${value}' for app '${appName}'`); - const updateParams = `${PREFIX_CONFIG_QUERIES}/v1/applications/${appName}/parameters/${name}?value=${encodeURIComponent( - value - )}`; - return backendFetch(updateParams, { - method: 'put', - }) as Promise as Promise; -} From b6fc4104edf7902e4d2f4046f2513c8e4ad37ed1 Mon Sep 17 00:00:00 2001 From: Joris Mancini Date: Thu, 21 Aug 2025 17:42:27 +0200 Subject: [PATCH 2/2] chore: update commons-ui version Signed-off-by: Joris Mancini .com> Signed-off-by: Joris Mancini --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8e3b3d2..9ad27c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.0", - "@gridsuite/commons-ui": "0.112.0", + "@gridsuite/commons-ui": "0.120.0", "@hookform/resolvers": "^4.0.0", "@mui/icons-material": "^5.16.14", "@mui/lab": "5.0.0-alpha.175", @@ -3074,9 +3074,9 @@ } }, "node_modules/@gridsuite/commons-ui": { - "version": "0.112.0", - "resolved": "https://registry.npmjs.org/@gridsuite/commons-ui/-/commons-ui-0.112.0.tgz", - "integrity": "sha512-4xD4ZUCz8dJlogQJbRAmOXFPOBcWJ+mAQX0du2Mw6B9c1c/DBBd81OO/4lj2ccM3VoW4nJ8EtWQlgptnlTl83w==", + "version": "0.120.0", + "resolved": "https://registry.npmjs.org/@gridsuite/commons-ui/-/commons-ui-0.120.0.tgz", + "integrity": "sha512-OnzelE6c0rqDX81fjOExPp9lIvmKhC8UnuldLDf7PwOWWEY3ScLK0ofdrCwlX4XHvjhKuH47nh/2xJoj0YX1TQ==", "license": "MPL-2.0", "dependencies": { "@ag-grid-community/locale": "^33.1.0", diff --git a/package.json b/package.json index 9455b78..24443f5 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.0", - "@gridsuite/commons-ui": "0.112.0", + "@gridsuite/commons-ui": "0.120.0", "@hookform/resolvers": "^4.0.0", "@mui/icons-material": "^5.16.14", "@mui/lab": "5.0.0-alpha.175",