Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 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 @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions src/components/App/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -56,7 +58,7 @@ export default function App({ children }: Readonly<PropsWithChildren<{}>>) {
(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' }));
}
Expand All @@ -68,7 +70,7 @@ export default function App({ children }: Readonly<PropsWithChildren<{}>>) {

useEffect(() => {
if (user !== null) {
ConfigSrv.fetchConfigParameters(COMMON_APP_NAME)
fetchConfigParameters(COMMON_APP_NAME)
.then((params) => updateParams(params))
.catch((error) =>
snackError({
Expand All @@ -77,7 +79,7 @@ export default function App({ children }: Readonly<PropsWithChildren<{}>>) {
})
);

ConfigSrv.fetchConfigParameters(APP_NAME)
fetchConfigParameters(APP_NAME)
.then((params) => updateParams(params))
.catch((error) =>
snackError({
Expand Down
6 changes: 3 additions & 3 deletions src/components/parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<K extends AppStateKey>(paramName: K): [AppState[K], (value: AppState[K]) => void] {
const { snackError } = useSnackMessage();
Expand All @@ -23,7 +23,7 @@ export function useParameterState<K extends AppStateKey>(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({
Expand Down
29 changes: 1 addition & 28 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -22,27 +19,3 @@ export type ConfigParameter =
value: GsTheme;
};
export type ConfigParameters = ConfigParameter[];

export function fetchConfigParameters(appName: string = APP_NAME): Promise<ConfigParameters> {
console.debug(`Fetching UI configuration params for app : ${appName}`);
const fetchParams = `${PREFIX_CONFIG_QUERIES}/v1/applications/${appName}/parameters`;
return backendFetchJson(fetchParams) as Promise<ConfigParameters>;
}

export function fetchConfigParameter(name: string): Promise<ConfigParameter> {
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<ConfigParameter>;
}

export function updateConfigParameter(name: string, value: Parameters<typeof encodeURIComponent>[0]): Promise<void> {
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<unknown> as Promise<void>;
}
Loading