Skip to content

Commit 133f0eb

Browse files
added fix for theme mode update
1 parent b1d871b commit 133f0eb

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

public/app/fn-app/create-mfe.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
mfeDispatch,
2525
updateRenderingDashboardUID,
2626
updatePartialMfeStates,
27+
mfeGetStoreState,
28+
updateMfeMode,
2729
} from 'app/store/configureMfeStore';
2830

2931
import { FNDashboardProps, FailedToMountGrafanaErrorName } from './types';
@@ -205,6 +207,9 @@ class createMfe {
205207
};
206208

207209
createMfe.logger.info('[FN Grafana] Dispatching initial state.', { initialState });
210+
if (props.mode && mfeGetStoreState().fnGlobalReducer.mode !== props.mode) {
211+
mfeDispatch(updateMfeMode(props.mode));
212+
}
208213
mfeDispatch(updatePartialMfeStates(initialState));
209214

210215
createMfe.renderMfeComponent(props, () => {
@@ -259,12 +264,8 @@ class createMfe {
259264
}: FNDashboardProps & {
260265
readonly renderingDashboardUid?: string;
261266
}) => {
262-
if (mode) {
263-
mfeDispatch(
264-
updatePartialMfeStates({
265-
mode,
266-
})
267-
);
267+
if (mode && mfeGetStoreState().fnGlobalReducer.mode !== mode) {
268+
mfeDispatch(updateMfeMode(mode));
268269

269270
createMfe.loadFnTheme(mode);
270271
}

public/app/store/configureMfeStore.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ const reducers: SliceCaseReducers<MfeGlobalState> = {
7878

7979
state.renderingDashboardUID = action.payload;
8080
},
81+
82+
updateMfeMode: (state, action: PayloadAction<GrafanaThemeType.Light | GrafanaThemeType.Dark>) => {
83+
FnLoggerService.info('Updating MFE mode', {
84+
state,
85+
mode: action.payload,
86+
});
87+
88+
state.mode = action.payload;
89+
},
8190
};
8291

8392
export interface MfeGlobalState extends MfeState {
@@ -97,7 +106,8 @@ const fnSlice = createSlice<MfeGlobalState, SliceCaseReducers<MfeGlobalState>, s
97106
reducers,
98107
});
99108

100-
export const { updatePartialMfeStates, removeGrafanaStoreAndDashboard, updateRenderingDashboardUID } = fnSlice.actions;
109+
export const { updatePartialMfeStates, updateMfeMode, removeGrafanaStoreAndDashboard, updateRenderingDashboardUID } =
110+
fnSlice.actions;
101111
export const fnSliceReducer = fnSlice.reducer;
102112

103113
export type MfeStore = {

public/microfrontends/fn_dashboard/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<script nonce="" src="../../../public/build/runtime~fn_dashboard.551314fa089c5f51c211.js" type="text/javascript"></script>
2121

22-
<script nonce="" src="../../../public/build/fn_dashboard.95f3d679653900a42786.js" type="text/javascript"></script>
22+
<script nonce="" src="../../../public/build/fn_dashboard.770e4e6d381c2fe6a321.js" type="text/javascript"></script>
2323

2424
</body>
2525
</html>

0 commit comments

Comments
 (0)