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.1",
"@gridsuite/commons-ui": "0.211.0",
"@gridsuite/commons-ui": "0.214.0",
"@hookform/resolvers": "^4.1.3",
"@mui/icons-material": "^6.5.0",
"@mui/lab": "6.0.1-beta.36",
Expand Down
12 changes: 6 additions & 6 deletions src/components/App/App.tsx
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 { Grid } from '@mui/material';
import {
AnnouncementNotification,
Expand Down Expand Up @@ -43,7 +43,7 @@ export default function App() {
useDebugRender('app');
const { snackError } = useSnackMessage();
const dispatch = useDispatch<AppDispatch>();
const user = useSelector((state: AppState) => state.user);
const userProfile = useSelector((state: AppState) => state.user?.profile ?? null, shallowEqual);

const updateParams = useCallback(
(params: ConfigParameters) => {
Expand Down Expand Up @@ -82,7 +82,7 @@ export default function App() {
useNotificationsListener(NotificationsUrlKeys.CONFIG, { listenerCallbackMessage: updateConfig });

useEffect(() => {
if (user !== null) {
if (userProfile !== null) {
fetchConfigParameters(COMMON_APP_NAME)
.then((params) => updateParams(params))
.catch((error) => snackWithFallback(snackError, error, { headerId: 'paramsRetrievingError' }));
Expand All @@ -91,7 +91,7 @@ export default function App() {
.then((params) => updateParams(params))
.catch((error) => snackWithFallback(snackError, error, { headerId: 'paramsRetrievingError' }));
}
}, [user, dispatch, updateParams, snackError]);
}, [userProfile, dispatch, updateParams, snackError]);

const signInCallbackError = useSelector((state: AppState) => state.signInCallbackError);
const authenticationRouterError = useSelector((state: AppState) => state.authenticationRouterError);
Expand Down Expand Up @@ -149,7 +149,7 @@ export default function App() {
<AppTopBar userManagerInstance={userManager.instance} />
</Grid>
<Grid item xs="auto">
<AnnouncementNotification user={user} />
<AnnouncementNotification userProfile={userProfile} />
</Grid>
<Grid item container xs component="main" height={'100%'}>
<CardErrorBoundary>
Expand All @@ -159,7 +159,7 @@ export default function App() {
flexGrow: 1,
}}
>
{user !== null ? (
{userProfile !== null ? (
<Routes>
<Route path={'/'} element={<HomePage />} />
<Route path={`/${MainPaths.users}`} element={<Users />} />
Expand Down
12 changes: 6 additions & 6 deletions src/components/App/AppTopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { useParameterState } from '../parameters';
import { APP_NAME } from '../../utils/config-params';
import { NavLink, type To, useNavigate } from 'react-router';
import { useDispatch, useSelector } from 'react-redux';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { FormattedMessage } from 'react-intl';
import { AppsMetadataSrv, StudySrv } from '../../services';
import GridAdminLogoLight from '../../images/GridAdmin_logo_light.svg?react';
Expand Down Expand Up @@ -96,7 +96,7 @@ type AppTopBarProps = {
export default function AppTopBar({ userManagerInstance }: Readonly<AppTopBarProps>) {
const theme = useTheme();
const dispatch = useDispatch<AppDispatch>();
const user = useSelector((state: AppState) => state.user);
const userProfile = useSelector((state: AppState) => state.user?.profile ?? null, shallowEqual);

const navigate = useNavigate();

Expand All @@ -107,12 +107,12 @@ export default function AppTopBar({ userManagerInstance }: Readonly<AppTopBarPro
const [tabValue, setTabValue] = useState<TabsProps['value']>(false);

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

const handleChange = (_: SyntheticEvent, newValue: number) => {
setTabValue(newValue);
Expand All @@ -127,7 +127,7 @@ export default function AppTopBar({ userManagerInstance }: Readonly<AppTopBarPro
appLicense={AppPackage.license}
onLogoutClick={() => logout(dispatch, userManagerInstance)}
onLogoClick={() => navigate('/', { replace: true })}
user={user ?? undefined}
userProfile={userProfile ?? undefined}
appsAndUrls={appsAndUrls}
globalVersionPromise={() => AppsMetadataSrv.fetchVersion().then((res) => res?.deployVersion ?? 'unknown')}
additionalModulesPromise={StudySrv.getServersInfos}
Expand All @@ -143,7 +143,7 @@ export default function AppTopBar({ userManagerInstance }: Readonly<AppTopBarPro
scrollButtons="auto"
aria-label="Main navigation menu"
sx={{
visibility: !user ? 'hidden' : undefined,
visibility: !userProfile ? 'hidden' : undefined,
flexGrow: 1,
}}
value={tabValue}
Expand Down
7 changes: 0 additions & 7 deletions src/utils/api-ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { getToken } from './api';

export type * from './api';

export const getWsBase = () => document.baseURI.replace(/^http:\/\//, 'ws://').replace(/^https:\/\//, 'wss://');

export function getUrlWithToken(baseUrl: string): string {
const querySymbol = baseUrl.includes('?') ? '&' : '?';
return `${baseUrl}${querySymbol}access_token=${getToken()}`;
}
21 changes: 6 additions & 15 deletions src/utils/notifications-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,22 @@
*/

import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import type { AppState } from '../redux/reducer';
import { getUrlWithToken, getWsBase } from './api-ws';
import { getWsBase } from './api-ws';
import { APP_NAME } from './config-params';
import { NotificationsUrlKeys, PREFIX_CONFIG_NOTIFICATION_WS } from '@gridsuite/commons-ui';

export function useNotificationsUrlGenerator() {
// The websocket API doesn't allow relative urls
const wsBase = getWsBase();
const tokenId = useSelector((state: AppState) => state.user?.id_token);

// return a mapper with NOTIFICATIONS_URL_KEYS and undefined value if URL is not yet buildable (tokenId)
// return a mapper with NOTIFICATIONS_URL_KEYS value
// 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 })}`
)
: undefined,
[NotificationsUrlKeys.GLOBAL_CONFIG]: tokenId
? getUrlWithToken(`${wsBase}${PREFIX_CONFIG_NOTIFICATION_WS}/global`)
: undefined,
}) satisfies Partial<Record<NotificationsUrlKeys, string | undefined>>,
[wsBase, tokenId]
[NotificationsUrlKeys.CONFIG]: `${wsBase}${PREFIX_CONFIG_NOTIFICATION_WS}/notify?${new URLSearchParams({ appName: APP_NAME })}`,
[NotificationsUrlKeys.GLOBAL_CONFIG]: `${wsBase}${PREFIX_CONFIG_NOTIFICATION_WS}/global`,
}) satisfies Partial<Record<NotificationsUrlKeys, string>>,
[wsBase]
);
}
Loading