Skip to content

Commit d63deab

Browse files
migrate fetchers to new architecture
1 parent 2256495 commit d63deab

18 files changed

+221
-442
lines changed

src/components/App/app-top-bar.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
forwardRef,
1010
FunctionComponent,
1111
ReactElement,
12+
useCallback,
1213
useEffect,
1314
useMemo,
1415
useState,
@@ -25,7 +26,7 @@ import {
2526
import { NavLink, useMatches, useNavigate } from 'react-router-dom';
2627
import { useDispatch, useSelector } from 'react-redux';
2728
import { FormattedMessage } from 'react-intl';
28-
import { AppsMetadataSrv, StudySrv } from '../../services';
29+
import { appsMetadataSrv, studySrv } from '../../services';
2930
import GridAdminLogoLight from '../../images/GridAdmin_logo_light.svg?react';
3031
import GridAdminLogoDark from '../../images/GridAdmin_logo_dark.svg?react';
3132
import AppPackage from '../../../package.json';
@@ -90,11 +91,15 @@ const AppTopBar: FunctionComponent = () => {
9091
const [appsAndUrls, setAppsAndUrls] = useState<AppMetadataCommon[]>([]);
9192
useEffect(() => {
9293
if (user !== null) {
93-
AppsMetadataSrv.fetchAppsAndUrls().then((res) => {
94+
appsMetadataSrv.fetchAppsMetadata().then((res) => {
9495
setAppsAndUrls(res);
9596
});
9697
}
9798
}, [user]);
99+
const additionalModulesFetcher = useCallback(
100+
() => studySrv.getServersInfos(APP_NAME),
101+
[]
102+
);
98103

99104
return (
100105
<TopBar
@@ -114,11 +119,11 @@ const AppTopBar: FunctionComponent = () => {
114119
user={user ?? undefined}
115120
appsAndUrls={appsAndUrls}
116121
globalVersionPromise={() =>
117-
AppsMetadataSrv.fetchVersion().then(
118-
(res) => res?.deployVersion ?? 'unknown'
119-
)
122+
appsMetadataSrv
123+
.fetchVersion()
124+
.then((res) => res?.deployVersion ?? 'unknown')
120125
}
121-
additionalModulesPromise={StudySrv.getServersInfos}
126+
additionalModulesPromise={additionalModulesFetcher}
122127
onThemeClick={handleChangeTheme}
123128
theme={themeLocal}
124129
onLanguageClick={handleChangeLanguage}

src/components/App/app.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ import {
1313
} from 'react';
1414
import { useDispatch, useSelector } from 'react-redux';
1515
import { Grid } from '@mui/material';
16-
import { CardErrorBoundary, useSnackMessage } from '@gridsuite/commons-ui';
16+
import {
17+
CardErrorBoundary,
18+
ConfigParameters,
19+
useSnackMessage,
20+
} from '@gridsuite/commons-ui';
1721
import {
1822
selectComputedLanguage,
1923
selectLanguage,
2024
selectTheme,
2125
} from '../../redux/actions';
2226
import { AppState } from '../../redux/reducer';
23-
import { ConfigNotif, ConfigParameters, ConfigSrv } from '../../services';
27+
import { configSrv, configNotificationSrv } from '../../services';
2428
import {
2529
APP_NAME,
2630
COMMON_APP_NAME,
@@ -67,13 +71,15 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
6771

6872
const connectNotificationsUpdateConfig =
6973
useCallback((): ReconnectingWebSocket => {
70-
const ws = ConfigNotif.connectNotificationsWsUpdateConfig();
74+
const ws =
75+
configNotificationSrv.connectNotificationsWsUpdateConfig(
76+
APP_NAME
77+
);
7178
ws.onmessage = function (event) {
7279
let eventData = JSON.parse(event.data);
7380
if (eventData?.headers?.parameterName) {
74-
ConfigSrv.fetchConfigParameter(
75-
eventData.headers.parameterName
76-
)
81+
configSrv
82+
.fetchConfigParameter(eventData.headers.parameterName)
7783
.then((param) => updateParams([param]))
7884
.catch((error) =>
7985
snackError({
@@ -91,7 +97,8 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
9197

9298
useEffect(() => {
9399
if (user !== null) {
94-
ConfigSrv.fetchConfigParameters(COMMON_APP_NAME)
100+
configSrv
101+
.fetchConfigParameters(COMMON_APP_NAME)
95102
.then((params) => updateParams(params))
96103
.catch((error) =>
97104
snackError({
@@ -100,7 +107,8 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
100107
})
101108
);
102109

103-
ConfigSrv.fetchConfigParameters(APP_NAME)
110+
configSrv
111+
.fetchConfigParameters(APP_NAME)
104112
.then((params) => updateParams(params))
105113
.catch((error) =>
106114
snackError({

src/components/parameters.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { useCallback, useEffect, useState } from 'react';
99
import { useSelector } from 'react-redux';
10-
import { ConfigSrv } from '../services';
10+
import { configSrv } from '../services';
1111
import { useSnackMessage } from '@gridsuite/commons-ui';
1212
import { AppState, AppStateKey } from '../redux/reducer';
1313

@@ -25,7 +25,8 @@ export function useParameterState<K extends AppStateKey>(
2525
const handleChangeParamLocalState = useCallback(
2626
(value: AppState[K]) => {
2727
setParamLocalState(value);
28-
ConfigSrv.updateConfigParameter(paramName, value as string) //TODO how to check/cast?
28+
configSrv
29+
.updateConfigParameter(paramName, value as string) //TODO how to check/cast?
2930
.catch((error) => {
3031
setParamLocalState(paramGlobalState);
3132
snackError({

src/pages/profiles/add-profile-dialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import { FormattedMessage } from 'react-intl';
2020
import { Controller, useForm } from 'react-hook-form';
2121
import { ManageAccounts } from '@mui/icons-material';
22-
import { UserAdminSrv, UserProfile } from '../../services';
22+
import { userAdminSrv, UserProfile } from '../../services';
2323
import { useSnackMessage } from '@gridsuite/commons-ui';
2424
import { GridTableRef } from '../../components/Grid';
2525
import PaperForm from '../common/paper-form';
@@ -44,7 +44,8 @@ const AddProfileDialog: FunctionComponent<AddProfileDialogProps> = (props) => {
4444
const profileData: UserProfile = {
4545
name: name,
4646
};
47-
UserAdminSrv.addProfile(profileData)
47+
userAdminSrv
48+
.addProfile(profileData)
4849
.catch((error) =>
4950
snackError({
5051
messageTxt: error.message,

src/pages/profiles/modification/parameter-selection.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Grid, IconButton, Tooltip } from '@mui/material';
1212
import { useIntl } from 'react-intl';
1313
import { DirectoryItemSelector, ElementType } from '@gridsuite/commons-ui';
1414
import { useController, useWatch } from 'react-hook-form';
15-
import { DirectorySrv } from '../../../services';
15+
import { directorySrv } from '../../../services';
1616
import LinkedPathDisplay from './linked-path-display';
1717

1818
export interface ParameterSelectionProps {
@@ -45,7 +45,8 @@ const ParameterSelection: FunctionComponent<ParameterSelectionProps> = (
4545
setSelectedElementName(undefined);
4646
setParameterLinkValid(undefined);
4747
} else {
48-
DirectorySrv.fetchPath(watchParamId)
48+
directorySrv
49+
.fetchPath(watchParamId)
4950
.then((res: any) => {
5051
setParameterLinkValid(true);
5152
setSelectedElementName(

src/pages/profiles/modification/profile-modification-dialog.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
useState,
2323
} from 'react';
2424
import { CustomMuiDialog, useSnackMessage } from '@gridsuite/commons-ui';
25-
import { UserAdminSrv, UserProfile } from '../../../services';
25+
import { userAdminSrv, UserProfile } from '../../../services';
2626
import { UUID } from 'crypto';
2727

2828
// TODO remove FetchStatus when exported in commons-ui (available soon)
@@ -80,7 +80,8 @@ const ProfileModificationDialog: FunctionComponent<
8080
maxAllowedCases: profileFormData[USER_QUOTA_CASE_NB],
8181
maxAllowedBuilds: profileFormData[USER_QUOTA_BUILD_NB],
8282
};
83-
UserAdminSrv.modifyProfile(profileData)
83+
userAdminSrv
84+
.modifyProfile(profileData)
8485
.catch((error) => {
8586
snackError({
8687
messageTxt: error.message,
@@ -103,7 +104,8 @@ const ProfileModificationDialog: FunctionComponent<
103104
useEffect(() => {
104105
if (profileId && open) {
105106
setDataFetchStatus(FetchStatus.FETCHING);
106-
UserAdminSrv.getProfile(profileId)
107+
userAdminSrv
108+
.getProfile(profileId)
107109
.then((response) => {
108110
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
109111
reset({

src/pages/profiles/profiles-table.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
GridTable,
2626
GridTableRef,
2727
} from '../../components/Grid';
28-
import { UserAdminSrv, UserProfile } from '../../services';
28+
import { userAdminSrv, UserProfile } from '../../services';
2929
import {
3030
ColDef,
3131
GetRowIdParams,
@@ -74,7 +74,8 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
7474

7575
const deleteProfiles = useCallback(() => {
7676
let profileNames = rowsSelection.map((userProfile) => userProfile.name);
77-
return UserAdminSrv.deleteProfiles(profileNames)
77+
return userAdminSrv
78+
.deleteProfiles(profileNames)
7879
.catch((error) => {
7980
if (error.status === 422) {
8081
snackError({
@@ -149,7 +150,7 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
149150
return (
150151
<GridTable<UserProfile, {}>
151152
ref={props.gridRef}
152-
dataLoader={UserAdminSrv.fetchProfiles}
153+
dataLoader={userAdminSrv.fetchProfiles}
153154
columnDefs={columns}
154155
defaultColDef={defaultColDef}
155156
gridId="table-profiles"

src/pages/users/UsersPage.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
GridTable,
3333
GridTableRef,
3434
} from '../../components/Grid';
35-
import { UserAdminSrv, UserInfos, UserProfile } from '../../services';
35+
import { userAdminSrv, UserInfos, UserProfile } from '../../services';
3636
import { useSnackMessage } from '@gridsuite/commons-ui';
3737
import { Controller, SubmitHandler, useForm } from 'react-hook-form';
3838
import {
@@ -68,7 +68,8 @@ const UsersPage: FunctionComponent = () => {
6868
const [profileNameOptions, setprofileNameOptions] = useState<string[]>([]);
6969

7070
useEffect(() => {
71-
UserAdminSrv.fetchProfilesWithoutValidityCheck()
71+
userAdminSrv
72+
.fetchProfilesWithoutValidityCheck()
7273
.then((allProfiles: UserProfile[]) => {
7374
let profiles: string[] = [
7475
intl.formatMessage({ id: 'users.table.profile.none' }),
@@ -153,7 +154,8 @@ const UsersPage: FunctionComponent = () => {
153154
const [rowsSelection, setRowsSelection] = useState<UserInfos[]>([]);
154155
const deleteUsers = useCallback((): Promise<void> | undefined => {
155156
let subs = rowsSelection.map((user) => user.sub);
156-
return UserAdminSrv.deleteUsers(subs)
157+
return userAdminSrv
158+
.deleteUsers(subs)
157159
.catch((error) =>
158160
snackError({
159161
messageTxt: error.message,
@@ -169,7 +171,8 @@ const UsersPage: FunctionComponent = () => {
169171

170172
const addUser = useCallback(
171173
(id: string) => {
172-
UserAdminSrv.addUser(id)
174+
userAdminSrv
175+
.addUser(id)
173176
.catch((error) =>
174177
snackError({
175178
messageTxt: `Error while adding user "${id}"${
@@ -203,7 +206,8 @@ const UsersPage: FunctionComponent = () => {
203206
const handleCellEditingStopped = useCallback(
204207
(event: CellEditingStoppedEvent<UserInfos>) => {
205208
if (event.valueChanged && event.data) {
206-
UserAdminSrv.udpateUser(event.data)
209+
userAdminSrv
210+
.updateUser(event.data)
207211
.catch((error) =>
208212
snackError({
209213
messageTxt: error.message,
@@ -223,7 +227,7 @@ const UsersPage: FunctionComponent = () => {
223227
<Grid item container xs sx={{ width: 1 }}>
224228
<GridTable<UserInfos, {}>
225229
ref={gridRef}
226-
dataLoader={UserAdminSrv.fetchUsers}
230+
dataLoader={userAdminSrv.fetchUsers}
227231
columnDefs={columns}
228232
defaultColDef={defaultColDef}
229233
onCellEditingStopped={handleCellEditingStopped}

src/redux/store.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
import { legacy_createStore as createStore, Store } from 'redux';
99
import { Actions, AppState, reducer } from './reducer';
10-
import { initCommonServices } from '@gridsuite/commons-ui';
11-
import { APP_NAME } from '../utils/config-params';
1210

1311
export const store: Store<AppState, Actions> = createStore(reducer);
14-
initCommonServices(APP_NAME, () => store.getState().user);
1512
export type AppDispatch = typeof store.dispatch;
1613

1714
// to avoid to reset the state with HMR
1815
// https://redux.js.org/usage/configuring-your-store#hot-reloading
1916
if (import.meta.env.DEV && import.meta.hot) {
2017
import.meta.hot.accept('./reducer', () => store.replaceReducer(reducer));
2118
}
19+
20+
export function getUser() {
21+
return store.getState().user;
22+
}

src/routes/router.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from 'react-router-dom';
3131
import { useDispatch, useSelector } from 'react-redux';
3232
import { AppState } from '../redux/reducer';
33-
import { AppsMetadataSrv, UserAdminSrv } from '../services';
33+
import { appLocalSrv, userAdminSrv } from '../services';
3434
import { App } from '../components/App';
3535
import { Profiles, Users } from '../pages';
3636
import ErrorPage from './ErrorPage';
@@ -146,8 +146,8 @@ const AppAuthStateWithRouterLayer: FunctionComponent<
146146
(await initializeAuthenticationProd(
147147
dispatch,
148148
initialMatchSilentRenewCallbackUrl != null,
149-
AppsMetadataSrv.fetchIdpSettings,
150-
UserAdminSrv.fetchValidateUser,
149+
appLocalSrv.fetchIdpSettings,
150+
userAdminSrv.fetchValidateUser,
151151
initialMatchSignInCallbackUrl != null
152152
)) ?? null,
153153
null

0 commit comments

Comments
 (0)