Skip to content

Commit 5cb8a0e

Browse files
Add comment explaining why init of prom client is needed
1 parent c9a6997 commit 5cb8a0e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ui/src/components/PlatformGlobalHealthBarFederated.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MetricsTimeSpanContext } from '@scality/core-ui/dist/components/charts/MetricsTimeSpanProvider';
22
import { useShellHooks } from '@scality/module-federation';
3-
import { useLayoutEffect, useMemo } from 'react';
3+
import { useEffect, useLayoutEffect, useMemo } from 'react';
44
import FederatedIntlProvider from '../containers/IntlProvider';
55
import StartTimeProvider from '../containers/StartTimeProvider';
66
import { initialize as initializePrometheus, setHeaders } from '../services/prometheus/api';
@@ -27,7 +27,13 @@ export default function PlatformGlobalHealthBarFederated({
2727
const { userData } = useAuth();
2828
const token = userData?.token;
2929

30-
useLayoutEffect(() => {
30+
31+
/**
32+
* Initialize the Prometheus client and set the authorization header if the token is available
33+
* The initialization of Prometheus client is neeeded here as it is shared with Module Federation to another ui
34+
* The prometheus client could not be initialized in the parent component rendering it.
35+
*/
36+
useEffect(() => {
3137
if (token) {
3238
initializePrometheus(prometheusUrl);
3339
setHeaders({ Authorization: `Bearer ${token}` });

0 commit comments

Comments
 (0)