import { getMapsCapabilities } from '../kibana_services' ; import { UPDATE_FLYOUT , SET_IS_LAYER_TOC_OPEN , SET_IS_TIME_SLIDER_OPEN , SET_FULL_SCREEN , SET_READ_ONLY , SET_OPEN_TOC_DETAILS , SHOW_TOC_DETAILS , HIDE_TOC_DETAILS , SET_DRAW_MODE , } from '../actions' ; import { DRAW_MODE } from '../../common/constants' ; export enum FLYOUT_STATE { NONE = 'NONE' , LAYER_PANEL = 'LAYER_PANEL' , ADD_LAYER_WIZARD = 'ADD_LAYER_WIZARD' , MAP_SETTINGS_PANEL = 'MAP_SETTINGS_PANEL' } export type MapUiState = { flyoutDisplay : FLYOUT_STATE ; drawMode : DRAW_MODE ; isFullScreen : boolean ; isReadOnly : boolean ; isLayerTOCOpen : boolean ; isTimesliderOpen : boolean ; openTOCDetails : string [ ] ; } ; export const DEFAULT_IS_LAYER_TOC_OPEN = true ; export const DEFAULT_MAP_UI_STATE = { flyoutDisplay : FLYOUT_STATE . NONE , drawMode : DRAW_MODE . NONE , isFullScreen : false , isReadOnly : ! getMapsCapabilities ( ) . save , isLayerTOCOpen : DEFAULT_IS_LAYER_TOC_OPEN , isTimesliderOpen : false , openTOCDetails : [ ] , } ; export function ui ( state = DEFAULT_MAP_UI_STATE , action ) { switch ( action . type ) { case UPDATE_FLYOUT : return { ... state , flyoutDisplay : action . display } ; case SET_DRAW_MODE : return { ... state , drawMode : action . drawMode } ; case SET_IS_LAYER_TOC_OPEN : return { ... state , isLayerTOCOpen : action . isLayerTOCOpen } ; case SET_IS_TIME_SLIDER_OPEN : return { ... state , isTimesliderOpen : action . isTimesliderOpen } ; case SET_FULL_SCREEN : return { ... state , isFullScreen : action . isFullScreen } ; case SET_READ_ONLY : return { ... state , isReadOnly : action . isReadOnly } ; case SET_OPEN_TOC_DETAILS : return { ... state , openTOCDetails : action . layerIds } ; case SHOW_TOC_DETAILS : return { ... state , openTOCDetails : [ ... state . openTOCDetails , action . layerId ] , } ; case HIDE_TOC_DETAILS : return { ... state , openTOCDetails : state . openTOCDetails . filter ( ( layerId ) => { return layerId !== action . layerId ; } ) , } ; default : return state ; } }