From 8ae9c12844fd5bf04f933dbf57da8fe1da34b427 Mon Sep 17 00:00:00 2001 From: Florent MILLOT Date: Thu, 28 Mar 2024 15:14:07 +0100 Subject: [PATCH 1/6] Add a missing any Signed-off-by: Florent MILLOT --- package.json | 2 +- public/idpSettings.json | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 5cd0bf862..4a3d0cef5 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "yup": "^1.0.0" }, "scripts": { - "start": "react-scripts start", + "start": "PORT=3001 react-scripts start", "build": "react-scripts build", "test": "react-scripts test --watchAll=false --transformIgnorePatterns \"node_modules/(?!@gridsuite/commons-ui)/\"", "eject": "react-scripts eject" diff --git a/public/idpSettings.json b/public/idpSettings.json index 80a89b227..7fe9713c3 100644 --- a/public/idpSettings.json +++ b/public/idpSettings.json @@ -1,8 +1,8 @@ { "authority": "http://172.17.0.1:9090/", - "client_id": "my-client-2", - "redirect_uri": "http://localhost:3000/sign-in-callback", - "post_logout_redirect_uri": "http://localhost:3000/logout-callback", - "silent_redirect_uri": "http://localhost:3000/silent-renew-callback", + "client_id": "gridexplore-local", + "redirect_uri": "http://localhost:3001/sign-in-callback", + "post_logout_redirect_uri": "http://localhost:3001/logout-callback", + "silent_redirect_uri": "http://localhost:3001/silent-renew-callback", "scope": "openid" -} +} \ No newline at end of file From 5263d9c769a07ba059a3c1c0bac4f81062f78a8e Mon Sep 17 00:00:00 2001 From: Florent MILLOT Date: Thu, 28 Mar 2024 15:29:02 +0100 Subject: [PATCH 2/6] Update charset to UTF-8 in idpSettings.json. Signed-off-by: Florent MILLOT --- public/idpSettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/idpSettings.json b/public/idpSettings.json index 7fe9713c3..ecc40fd4e 100644 --- a/public/idpSettings.json +++ b/public/idpSettings.json @@ -5,4 +5,4 @@ "post_logout_redirect_uri": "http://localhost:3001/logout-callback", "silent_redirect_uri": "http://localhost:3001/silent-renew-callback", "scope": "openid" -} \ No newline at end of file +} From 880a21bf994f1763acb0d9cf252ea985b9e82aac Mon Sep 17 00:00:00 2001 From: Florent MILLOT Date: Thu, 28 Mar 2024 17:39:00 +0100 Subject: [PATCH 3/6] Update redirect URIs to use port 3000 instead of 3001. Signed-off-by: Florent MILLOT --- public/idpSettings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/idpSettings.json b/public/idpSettings.json index ecc40fd4e..e4ec87735 100644 --- a/public/idpSettings.json +++ b/public/idpSettings.json @@ -1,8 +1,8 @@ { "authority": "http://172.17.0.1:9090/", "client_id": "gridexplore-local", - "redirect_uri": "http://localhost:3001/sign-in-callback", - "post_logout_redirect_uri": "http://localhost:3001/logout-callback", - "silent_redirect_uri": "http://localhost:3001/silent-renew-callback", + "redirect_uri": "http://localhost:3000/sign-in-callback", + "post_logout_redirect_uri": "http://localhost:3000/logout-callback", + "silent_redirect_uri": "http://localhost:3000/silent-renew-callback", "scope": "openid" } From d912a97ebb3ccaae462f7b87bc3a22393fe1c4d6 Mon Sep 17 00:00:00 2001 From: Florent MILLOT Date: Thu, 28 Mar 2024 17:44:55 +0100 Subject: [PATCH 4/6] Change start script port from 3001 to 3000 in package.json. Signed-off-by: Florent MILLOT --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a3d0cef5..0d7a8ac8f 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "yup": "^1.0.0" }, "scripts": { - "start": "PORT=3001 react-scripts start", + "start": "PORT=3000 react-scripts start", "build": "react-scripts build", "test": "react-scripts test --watchAll=false --transformIgnorePatterns \"node_modules/(?!@gridsuite/commons-ui)/\"", "eject": "react-scripts eject" From ec6b23f4ac4a6adc85e7417265b77e09dc997db0 Mon Sep 17 00:00:00 2001 From: Florent MILLOT Date: Thu, 28 Mar 2024 17:47:38 +0100 Subject: [PATCH 5/6] remove ueless code Signed-off-by: Florent MILLOT --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d7a8ac8f..5cd0bf862 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "yup": "^1.0.0" }, "scripts": { - "start": "PORT=3000 react-scripts start", + "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --watchAll=false --transformIgnorePatterns \"node_modules/(?!@gridsuite/commons-ui)/\"", "eject": "react-scripts eject" From 6e2d3db6b6ae61df5fadd916b70f1652861c5a01 Mon Sep 17 00:00:00 2001 From: Florent MILLOT Date: Thu, 28 Mar 2024 17:56:11 +0100 Subject: [PATCH 6/6] Add getToken function to retrieve user's id token and useAnnouncementsSubscriber to subscribe to announcements updates. Signed-off-by: Florent MILLOT --- src/components/app.js | 5 +++++ src/utils/rest-api.js | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/components/app.js b/src/components/app.js index 6bd138546..c15d90d29 100644 --- a/src/components/app.js +++ b/src/components/app.js @@ -28,6 +28,7 @@ import { CardErrorBoundary, getPreLoginPath, initializeAuthenticationProd, + useAnnouncementsSubscriber, } from '@gridsuite/commons-ui'; import { useMatch } from 'react-router-dom'; @@ -39,6 +40,8 @@ import { fetchConfigParameter, fetchConfigParameters, fetchValidateUser, + getAnnouncementsWsUrl, + getToken, } from '../utils/rest-api'; import { APP_NAME, @@ -79,6 +82,8 @@ const App = () => { const location = useLocation(); + useAnnouncementsSubscriber(getAnnouncementsWsUrl(), getToken()); + const updateParams = useCallback( (params) => { console.debug('received UI parameters : ', params); diff --git a/src/utils/rest-api.js b/src/utils/rest-api.js index 8a864e351..39a9cffbc 100644 --- a/src/utils/rest-api.js +++ b/src/utils/rest-api.js @@ -30,9 +30,9 @@ const PREFIX_FILTERS_QUERIES = process.env.REACT_APP_API_GATEWAY + '/filter/v1/filters'; const PREFIX_STUDY_QUERIES = process.env.REACT_APP_API_GATEWAY + '/study'; -function getToken() { +export function getToken() { const state = store.getState(); - return state.user.id_token; + return state.user?.id_token; } export const getRequestParamFromList = (params, paramName) => { @@ -41,10 +41,18 @@ export const getRequestParamFromList = (params, paramName) => { ); }; +export const getWsBase = () => + document.baseURI + .replace(/^http:\/\//, 'ws://') + .replace(/^https:\/\//, 'wss://'); + +export function getAnnouncementsWsUrl() { + const webSocketBaseUrl = getWsBase(); + return webSocketBaseUrl + PREFIX_CONFIG_NOTIFICATION_WS + '/global'; +} + export function connectNotificationsWsUpdateConfig() { - const webSocketBaseUrl = document.baseURI - .replace(/^http:\/\//, 'ws://') - .replace(/^https:\/\//, 'wss://'); + const webSocketBaseUrl = getWsBase() const webSocketUrl = webSocketBaseUrl + PREFIX_CONFIG_NOTIFICATION_WS + @@ -798,9 +806,7 @@ export function newScriptFromFiltersContingencyList( * @returns {ReconnectingWebSocket} */ export function connectNotificationsWsUpdateDirectories() { - const webSocketBaseUrl = document.baseURI - .replace(/^http:\/\//, 'ws://') - .replace(/^https:\/\//, 'wss://'); + const webSocketBaseUrl = getWsBase() const webSocketUrl = webSocketBaseUrl + PREFIX_NOTIFICATION_WS +