import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import { Filter , Query } from '../../services/data' ; import { ViewMode } from '../../services/embeddable' ; import type { DashboardControlGroupInput } from '../lib/dashboard_control_group' ; import { DashboardOptions , DashboardPanelMap , DashboardState } from '../../types' ; export const dashboardStateSlice = createSlice ( { name : 'dashboardState' , initialState : { } as DashboardState , reducers : { setDashboardState : ( state , action ) => { return action . payload ; } , updateState : ( state , action ) => { state = { ... state , ... action . payload } ; } , setDashboardOptions : ( state , action ) => { state . options = action . payload ; } , setStateFromSaveModal : ( state , action ) => { state . title = action . payload . title ; state . description = action . payload . description ; state . timeRestore = action . payload . timeRestore ; if ( action . payload . tags ) { state . tags = action . payload . tags ; } } , setControlGroupState : ( state , action ) => { state . controlGroupInput = action . payload ; } , setUseMargins : ( state , action ) => { state . options . useMargins = action . payload ; } , setSyncColors : ( state , action ) => { state . options . syncColors = action . payload ; } , setHidePanelTitles : ( state , action ) => { state . options . hidePanelTitles = action . payload ; } , setPanels : ( state , action ) => { state . panels = action . payload ; } , setExpandedPanelId : ( state , action ) => { state . expandedPanelId = action . payload ; } , setFullScreenMode : ( state , action ) => { state . fullScreenMode = action . payload ; } , setSavedQueryId : ( state , action ) => { state . savedQuery = action . payload ; } , setTimeRestore : ( state , action ) => { state . timeRestore = action . payload ; } , setDescription : ( state , action ) => { state . description = action . payload ; } , setViewMode : ( state , action ) => { state . viewMode = action . payload ; } , setFiltersAndQuery : ( state , action ) => { state . filters = action . payload . filters ; state . query = action . payload . query ; } , setFilters : ( state , action ) => { state . filters = action . payload ; } , setTags : ( state , action ) => { state . tags = action . payload ; } , setTitle : ( state , action ) => { state . description = action . payload ; } , setQuery : ( state , action ) => { state . query = action . payload ; } , } , } ) ; export const { setStateFromSaveModal , setControlGroupState , setDashboardOptions , setExpandedPanelId , setHidePanelTitles , setFiltersAndQuery , setDashboardState , setFullScreenMode , setSavedQueryId , setDescription , setTimeRestore , setSyncColors , setUseMargins , setViewMode , setFilters , setPanels , setTitle , setQuery , setTags , } = dashboardStateSlice . actions ;