Skip to content

Commit 36df519

Browse files
authored
loading hidden variables (#37)
* loading hidden variables * suggested changes * type fix
1 parent 0998ba0 commit 36df519

File tree

8 files changed

+219
-344
lines changed

8 files changed

+219
-344
lines changed

public/app/core/reducers/fn-slice.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
22
import { WritableDraft } from 'immer/dist/internal';
33

44
import { GrafanaThemeType } from '@grafana/data';
5+
import { dispatch } from 'app/store/store';
56

67
import { AnyObject } from '../../fn-app/types';
78

@@ -16,6 +17,11 @@ export interface FnGlobalState {
1617
hiddenVariables: string[];
1718
}
1819

20+
export type UpdateFNGlobalStateAction = PayloadAction<{
21+
type: keyof FnGlobalState;
22+
payload: FnGlobalState[keyof FnGlobalState];
23+
}>;
24+
1925
const INITIAL_MODE = GrafanaThemeType.Light;
2026

2127
const initialState: FnGlobalState = {
@@ -33,14 +39,11 @@ const fnSlice = createSlice({
3339
name: 'fnGlobalState',
3440
initialState,
3541
reducers: {
36-
setInitialMountState: (state, action: PayloadAction<FnGlobalState>) => {
42+
setInitialMountState: (state, action: PayloadAction<Omit<FnGlobalState, 'hiddenVariables'>>) => {
3743
return { ...state, ...action.payload };
3844
},
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;
4447

4548
return {
4649
...state,
@@ -52,3 +55,15 @@ const fnSlice = createSlice({
5255

5356
export const { updateFnState, setInitialMountState } = fnSlice.actions;
5457
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

Comments
 (0)