Skip to content

Commit 0ff8382

Browse files
author
Hugo Marcellin
committed
Remove mutualized utils functions
1 parent 7b35954 commit 0ff8382

File tree

3 files changed

+6
-104
lines changed

3 files changed

+6
-104
lines changed

src/components/app-top-bar.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import {
1010
logout,
1111
TopBar,
1212
fetchAppsMetadata,
13+
fetchVersion,
1314
} from '@gridsuite/commons-ui';
1415
import ParametersDialog, {
1516
useParameterState,
1617
} from './dialogs/parameters-dialog';
1718
import { APP_NAME, PARAM_LANGUAGE, PARAM_THEME } from '../utils/config-params';
1819
import { useDispatch, useSelector } from 'react-redux';
19-
import { fetchVersion, getServersInfos } from '../utils/rest-api';
20+
import { getServersInfos } from '../utils/rest-api';
2021
import PropTypes from 'prop-types';
2122
import { useNavigate } from 'react-router-dom';
2223
import GridExploreLogoLight from '../images/GridExplore_logo_light.svg?react';

src/components/app.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import {
2828
CardErrorBoundary,
2929
getPreLoginPath,
3030
initializeAuthenticationProd,
31+
fetchAuthorizationCodeFlowFeatureFlag,
3132
} from '@gridsuite/commons-ui';
3233

3334
import { useMatch } from 'react-router-dom';
3435
import { FormattedMessage } from 'react-intl';
3536

3637
import {
3738
connectNotificationsWsUpdateConfig,
38-
fetchAuthorizationCodeFlowFeatureFlag,
3939
fetchConfigParameter,
4040
fetchConfigParameters,
4141
fetchValidateUser,
@@ -220,8 +220,8 @@ const App = () => {
220220
style={{
221221
flexGrow: 1,
222222
/* autosizer (used in virtual table) can return wrong size
223-
(off by 1) and it causes scrollbar to blink
224-
* */
223+
(off by 1) and it causes scrollbar to blink
224+
* */
225225
overflow: 'hidden',
226226
marginTop: '20px',
227227
}}

src/utils/rest-api.js

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { CONTINGENCY_ENDPOINTS } from './constants-endpoints';
1313
import {
1414
ElementType,
1515
getRequestParamFromList,
16-
fetchEnv,
1716
backendFetchJson,
1817
backendFetch,
18+
backendFetchText,
1919
} from '@gridsuite/commons-ui';
2020

2121
const PREFIX_USER_ADMIN_SERVER_QUERIES =
@@ -63,68 +63,6 @@ export function connectNotificationsWsUpdateConfig() {
6363
return reconnectingWebSocket;
6464
}
6565

66-
function parseError(text) {
67-
try {
68-
return JSON.parse(text);
69-
} catch (err) {
70-
return null;
71-
}
72-
}
73-
74-
function handleError(response) {
75-
return response.text().then((text) => {
76-
const errorName = 'HttpResponseError : ';
77-
let error;
78-
const errorJson = parseError(text);
79-
if (
80-
errorJson &&
81-
errorJson.status &&
82-
errorJson.error &&
83-
errorJson.message
84-
) {
85-
error = new Error(
86-
errorName +
87-
errorJson.status +
88-
' ' +
89-
errorJson.error +
90-
', message : ' +
91-
errorJson.message
92-
);
93-
error.status = errorJson.status;
94-
} else {
95-
error = new Error(
96-
errorName + response.status + ' ' + response.statusText
97-
);
98-
error.status = response.status;
99-
}
100-
throw error;
101-
});
102-
}
103-
104-
function prepareRequest(init, token) {
105-
if (!(typeof init == 'undefined' || typeof init == 'object')) {
106-
throw new TypeError(
107-
'Argument 2 of backendFetch is not an object' + typeof init
108-
);
109-
}
110-
const initCopy = Object.assign({}, init);
111-
initCopy.headers = new Headers(initCopy.headers || {});
112-
const tokenCopy = token ? token : getToken();
113-
initCopy.headers.append('Authorization', 'Bearer ' + tokenCopy);
114-
return initCopy;
115-
}
116-
117-
function safeFetch(url, initCopy) {
118-
return fetch(url, initCopy).then((response) =>
119-
response.ok ? response : handleError(response)
120-
);
121-
}
122-
123-
export function backendFetchText(url, init, token) {
124-
const initCopy = prepareRequest(init, token);
125-
return safeFetch(url, initCopy).then((safeResponse) => safeResponse.text());
126-
}
127-
12866
const getContingencyUriParamType = (contingencyListType) => {
12967
switch (contingencyListType) {
13068
case ContingencyListType.SCRIPT.id:
@@ -173,43 +111,6 @@ export function fetchValidateUser(user) {
173111
});
174112
}
175113

176-
export function fetchAuthorizationCodeFlowFeatureFlag() {
177-
console.info(`Fetching authorization code flow feature flag...`);
178-
return fetchEnv()
179-
.then((res) =>
180-
fetch(res.appsMetadataServerUrl + '/authentication.json')
181-
)
182-
.then((res) => res.json())
183-
.then((res) => {
184-
console.log(
185-
`Authorization code flow is ${
186-
res.authorizationCodeFlowFeatureFlag
187-
? 'enabled'
188-
: 'disabled'
189-
}`
190-
);
191-
return res.authorizationCodeFlowFeatureFlag;
192-
})
193-
.catch((error) => {
194-
console.error(error);
195-
console.warn(
196-
`Something wrong happened when retrieving authentication.json: authorization code flow will be disabled`
197-
);
198-
return false;
199-
});
200-
}
201-
202-
export function fetchVersion() {
203-
console.info(`Fetching global metadata...`);
204-
return fetchEnv()
205-
.then((env) => fetch(env.appsMetadataServerUrl + '/version.json'))
206-
.then((response) => response.json())
207-
.catch((reason) => {
208-
console.error('Error while fetching the version : ' + reason);
209-
return reason;
210-
});
211-
}
212-
213114
export function fetchConfigParameters(appName) {
214115
console.info('Fetching UI configuration params for app : ' + appName);
215116
const fetchParams =

0 commit comments

Comments
 (0)