@@ -2,6 +2,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2
2
import { WritableDraft } from 'immer/dist/internal' ;
3
3
4
4
import { GrafanaThemeType } from '@grafana/data' ;
5
+ import { dispatch } from 'app/store/store' ;
5
6
6
7
import { AnyObject } from '../../fn-app/types' ;
7
8
@@ -16,6 +17,11 @@ export interface FnGlobalState {
16
17
hiddenVariables : string [ ] ;
17
18
}
18
19
20
+ export type UpdateFNGlobalStateAction = PayloadAction < {
21
+ type : keyof FnGlobalState ;
22
+ payload : FnGlobalState [ keyof FnGlobalState ] ;
23
+ } > ;
24
+
19
25
const INITIAL_MODE = GrafanaThemeType . Light ;
20
26
21
27
const initialState : FnGlobalState = {
@@ -33,14 +39,11 @@ const fnSlice = createSlice({
33
39
name : 'fnGlobalState' ,
34
40
initialState,
35
41
reducers : {
36
- setInitialMountState : ( state , action : PayloadAction < FnGlobalState > ) => {
42
+ setInitialMountState : ( state , action : PayloadAction < Omit < FnGlobalState , 'hiddenVariables' > > ) => {
37
43
return { ...state , ...action . payload } ;
38
44
} ,
39
- updateFnState : (
40
- state : WritableDraft < FnGlobalState > ,
41
- action : PayloadAction < { type : keyof FnGlobalState ; payload : FnGlobalState [ keyof FnGlobalState ] } >
42
- ) => {
43
- const { type, payload } = action ;
45
+ updateFnState : ( state : WritableDraft < FnGlobalState > , action : UpdateFNGlobalStateAction ) => {
46
+ const { type, payload } = action . payload ;
44
47
45
48
return {
46
49
...state ,
@@ -52,3 +55,15 @@ const fnSlice = createSlice({
52
55
53
56
export const { updateFnState, setInitialMountState } = fnSlice . actions ;
54
57
export const fnSliceReducer = fnSlice . reducer ;
58
+
59
+ export const updateFNGlobalState = (
60
+ type : keyof FnGlobalState ,
61
+ payload : UpdateFNGlobalStateAction [ 'payload' ] [ 'payload' ]
62
+ ) : void => {
63
+ dispatch (
64
+ updateFnState ( {
65
+ type,
66
+ payload,
67
+ } )
68
+ ) ;
69
+ } ;
0 commit comments