Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 {
AnnouncementNotification,
CardErrorBoundary,
fetchConfigParameter,

Check failure on line 14 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Module '"@gridsuite/commons-ui"' has no exported member 'fetchConfigParameter'.
fetchConfigParameters,

Check failure on line 15 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Module '"@gridsuite/commons-ui"' has no exported member '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,9 +58,9 @@
(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]))

Check failure on line 62 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'param' implicitly has an 'any' type.
.catch((error) => snackError({ messageTxt: error.message, headerId: 'paramsRetrievingError' }));

Check failure on line 63 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'error' implicitly has an 'any' type.
}
},
[updateParams, snackError]
Expand All @@ -68,18 +70,18 @@

useEffect(() => {
if (user !== null) {
ConfigSrv.fetchConfigParameters(COMMON_APP_NAME)
fetchConfigParameters(COMMON_APP_NAME)
.then((params) => updateParams(params))

Check failure on line 74 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'params' implicitly has an 'any' type.
.catch((error) =>

Check failure on line 75 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'error' implicitly has an 'any' type.
snackError({
messageTxt: error.message,
headerId: 'paramsRetrievingError',
})
);

ConfigSrv.fetchConfigParameters(APP_NAME)
fetchConfigParameters(APP_NAME)
.then((params) => updateParams(params))

Check failure on line 83 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'params' implicitly has an 'any' type.
.catch((error) =>

Check failure on line 84 in src/components/App/app.tsx

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'error' implicitly has an 'any' type.
snackError({
messageTxt: error.message,
headerId: 'paramsRetrievingError',
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';

Check failure on line 10 in src/components/parameters.tsx

View workflow job for this annotation

GitHub Actions / build / build

'"@gridsuite/commons-ui"' has no exported member named 'updateConfigParameter'. Did you mean 'updateParameter'?
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,8 +23,8 @@
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) => {

Check failure on line 27 in src/components/parameters.tsx

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'error' implicitly has an 'any' type.
setParamLocalState(paramGlobalState);
snackError({
messageTxt: error.message,
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