Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Announcements #398

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
CardErrorBoundary,
getPreLoginPath,
initializeAuthenticationProd,
useAnnouncementsSubscriber,
} from '@gridsuite/commons-ui';

import { useMatch } from 'react-router-dom';
Expand All @@ -39,6 +40,8 @@ import {
fetchConfigParameter,
fetchConfigParameters,
fetchValidateUser,
getAnnouncementsWsUrl,
getToken,
} from '../utils/rest-api';
import {
APP_NAME,
Expand Down Expand Up @@ -79,6 +82,8 @@ const App = () => {

const location = useLocation();

useAnnouncementsSubscriber(getAnnouncementsWsUrl(), getToken());

const updateParams = useCallback(
(params) => {
console.debug('received UI parameters : ', params);
Expand Down
22 changes: 14 additions & 8 deletions src/utils/rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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';
Comment on lines +50 to +51
Copy link
Contributor

Choose a reason for hiding this comment

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

could be inlined

}

export function connectNotificationsWsUpdateConfig() {
const webSocketBaseUrl = document.baseURI
.replace(/^http:\/\//, 'ws://')
.replace(/^https:\/\//, 'wss://');
const webSocketBaseUrl = getWsBase()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

const webSocketUrl =
webSocketBaseUrl +
PREFIX_CONFIG_NOTIFICATION_WS +
Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

const webSocketUrl =
webSocketBaseUrl +
PREFIX_NOTIFICATION_WS +
Expand Down
Loading