Skip to content
Open
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
12 changes: 6 additions & 6 deletions src/components/app-top-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const styles = {
},
};

const AppTopBar = ({ user, userManager }) => {
const AppTopBar = ({ userProfile, userManager }) => {
const dispatch = useDispatch();
const theme = useSelector((state) => state[PARAM_THEME]);
const studyUuid = useSelector((state) => state.studyUuid);
Expand All @@ -66,20 +66,20 @@ const AppTopBar = ({ user, userManager }) => {
const [isDeveloperMode, handleChangeDeveloperMode] = useParameterState(PARAM_DEVELOPER_MODE);

useEffect(() => {
if (user !== null) {
if (userProfile !== null) {
fetchAppsMetadata().then((res) => {
setAppsAndUrls(res);
});
}
}, [user]);
}, [userProfile]);

return (
<TopBar
appName="Study"
appColor="#0CA789"
appLogo={theme === LIGHT_THEME ? <GridStudyLogoLight /> : <GridStudyLogoDark />}
onLogoutClick={() => logout(dispatch, userManager.instance)}
user={user}
userProfile={userProfile}
appsAndUrls={appsAndUrls}
onThemeClick={handleChangeTheme}
appVersion={AppPackage.version}
Expand All @@ -95,7 +95,7 @@ const AppTopBar = ({ user, userManager }) => {
language={languageLocal}
dense
>
{user && studyUuid && currentRootNetworkUuid && (
{userProfile && studyUuid && currentRootNetworkUuid && (
<Box sx={styles.boxContent}>
<Box sx={{ display: 'flex', alignItems: 'center', marginLeft: 1.5, marginRight: 'auto' }}>
<WorkspaceToolbar />
Expand All @@ -121,7 +121,7 @@ const AppTopBar = ({ user, userManager }) => {
};

AppTopBar.propTypes = {
user: PropTypes.object,
userProfile: PropTypes.object,
userManager: PropTypes.object.isRequired,
};

Expand Down
23 changes: 15 additions & 8 deletions src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { retrieveOptionalServices } from './utils/optional-services';
import { Navigate, Route, Routes, useLocation, useMatch, useNavigate } from 'react-router';
import {
Expand Down Expand Up @@ -89,7 +89,7 @@
.catch(() => cleanupStaleStudyData());
}, []);

const user = useSelector((state) => state.user);
const userProfile = useSelector((state) => state.user?.profile ?? null, shallowEqual);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai is shallowEqual the appropriate equal method here ?

const studyUuid = useSelector((state) => state.studyUuid);
const signInCallbackError = useSelector((state) => state.signInCallbackError);
const authenticationRouterError = useSelector((state) => state.authenticationRouterError);
Expand Down Expand Up @@ -343,7 +343,7 @@
}, [initialMatchSilentRenewCallbackUrl, dispatch, initialMatchSigninCallbackUrl]);

useEffect(() => {
if (user !== null && studyUuid !== null) {
if (userProfile !== null && studyUuid !== null) {
const fetchNetworkVisualizationParametersPromise = getNetworkVisualizationParameters(studyUuid).then(
(params) => updateNetworkVisualizationsParams(params)
);
Expand Down Expand Up @@ -386,8 +386,15 @@
})
.catch((error) => snackWithFallback(snackError, error, { headerId: 'paramsRetrievingError' }));
}
}, [user, studyUuid, dispatch, updateParams, snackError, updateNetworkVisualizationsParams, resetTableDefinitions]);

}, [
userProfile,
studyUuid,
dispatch,
updateParams,
snackError,
updateNetworkVisualizationsParams,
resetTableDefinitions,
]);
return (
<div
className="singlestretch-child"
Expand All @@ -396,8 +403,8 @@
flexDirection: 'column',
}}
>
<AppTopBar user={user} userManager={userManager} />
<AnnouncementNotification user={user} />
<AppTopBar userProfile={userProfile} userManager={userManager} />
<AnnouncementNotification userProfile={userProfile} />
<CardErrorBoundary>
<div
className="singlestretch-parent"
Expand All @@ -414,7 +421,7 @@
overflow: isStudyPane ? 'hidden' : 'auto',
}}
>
{user !== null ? (
{userProfile !== null ? (

Check warning on line 424 in src/components/app.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=gridsuite_gridstudy-app&issues=AZ3ZtZXOd-OP6O7Nap_u&open=AZ3ZtZXOd-OP6O7Nap_u&pullRequest=3898
<Routes>
<Route path="/studies/:studyUuid" element={<StudyContainer />} />
<Route
Expand Down
41 changes: 12 additions & 29 deletions src/hooks/use-notifications-url-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,31 @@ import {
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { type AppState } from 'redux/reducer.type';
import { getUrlWithToken, getWsBase } from 'services/utils';
import { getWsBase } from 'services/utils';
import { APP_NAME } from 'utils/config-params';

const useNotificationsUrlGenerator = (): Partial<Record<NotificationsUrlKeys, string | undefined>> => {
// The websocket API doesn't allow relative urls
const wsBase = getWsBase();
const tokenId = useSelector((state: AppState) => state.user?.id_token);
const studyUuid = useSelector((state: AppState) => state.studyUuid);

// return a mapColumns with NOTIFICATIONS_URL_KEYS and undefined value if URL is not yet buildable (tokenId)
// return a mapColumns with NOTIFICATIONS_URL_KEYS and undefined value if URL is not yet buildable (studyUuid)
// it will be used to register listeners as soon as possible.
return useMemo(
() => ({
[NotificationsUrlKeys.CONFIG]: tokenId
? getUrlWithToken(
`${wsBase}${PREFIX_CONFIG_NOTIFICATION_WS}/notify?${new URLSearchParams({
appName: APP_NAME,
})}`
)
[NotificationsUrlKeys.CONFIG]: `${wsBase}${PREFIX_CONFIG_NOTIFICATION_WS}/notify?${new URLSearchParams({ appName: APP_NAME })}`,
[NotificationsUrlKeys.GLOBAL_CONFIG]: `${wsBase}${PREFIX_CONFIG_NOTIFICATION_WS}/global`,
[NotificationsUrlKeys.STUDY]: studyUuid
? `${wsBase}${PREFIX_STUDY_NOTIFICATION_WS}/notify?studyUuid=${encodeURIComponent(studyUuid)}`
: undefined,
[NotificationsUrlKeys.GLOBAL_CONFIG]: tokenId
? getUrlWithToken(`${wsBase}${PREFIX_CONFIG_NOTIFICATION_WS}/global`)
: undefined,
[NotificationsUrlKeys.STUDY]:
tokenId && studyUuid
? getUrlWithToken(
`${wsBase}${PREFIX_STUDY_NOTIFICATION_WS}/notify?studyUuid=${encodeURIComponent(studyUuid)}`
)
: undefined,
[NotificationsUrlKeys.DIRECTORY_DELETE_STUDY]:
tokenId && studyUuid
? getUrlWithToken(
`${wsBase}${PREFIX_DIRECTORY_NOTIFICATION_WS}/notify?updateType=deleteElement&elementUuid=${encodeURIComponent(
studyUuid
)}`
)
: undefined,
[NotificationsUrlKeys.DIRECTORY]: tokenId
? getUrlWithToken(`${wsBase}${PREFIX_DIRECTORY_NOTIFICATION_WS}/notify?updateType=directories`)
[NotificationsUrlKeys.DIRECTORY_DELETE_STUDY]: studyUuid
? `${wsBase}${PREFIX_DIRECTORY_NOTIFICATION_WS}/notify?updateType=deleteElement&elementUuid=${encodeURIComponent(
studyUuid
)}`
: undefined,
[NotificationsUrlKeys.DIRECTORY]: `${wsBase}${PREFIX_DIRECTORY_NOTIFICATION_WS}/notify?updateType=directories`,
}),
[tokenId, wsBase, studyUuid]
[wsBase, studyUuid]
);
};

Expand Down
2 changes: 0 additions & 2 deletions src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { configureStore } from '@reduxjs/toolkit';
import { reducer } from './reducer';
import { setCommonStore } from '@gridsuite/commons-ui';
import { setUserStore } from './user-store';
import workspacesReducer from './slices/workspace-slice';
import { globalFiltersMiddleware } from './globalFiltersMiddleware';

Expand All @@ -35,7 +34,6 @@ export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

setCommonStore(store);
setUserStore(store);

// to avoid to reset the state with HMR
// https://redux.js.org/usage/configuring-your-store#hot-reloading
Expand Down
45 changes: 0 additions & 45 deletions src/redux/user-store.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { catchErrorHandler, fetchStudyMetadata, StudyMetadata } from '@gridsuite/commons-ui';
import { getUserToken } from '../redux/user-store';

export const FetchStatus = {
SUCCEED: 'SUCCEED',
FAILED: 'FAILED',
Expand Down Expand Up @@ -91,14 +89,6 @@ export const getQueryParamsList = (params: string[] | number[] | null | undefine
return '';
};

export function getUrlWithToken(baseUrl: string) {
if (baseUrl.includes('?')) {
return baseUrl + '&access_token=' + getUserToken();
} else {
return baseUrl + '?access_token=' + getUserToken();
}
}

export function fetchMapBoxToken() {
console.info(`Fetching MapBoxToken...`);
return fetchEnv().then((res) => res.mapBoxToken);
Expand Down
Loading