import { AnyAction } from 'redux' ; import { ThunkDispatch } from 'redux-thunk' ; import { connect } from 'react-redux' ; import { TOCEntry , OwnProps , ReduxDispatchProps , ReduxStateProps } from './toc_entry' ; import { MapStoreState } from '../../../../../reducers/store' ; import { FLYOUT_STATE } from '../../../../../reducers/ui' ; import { getMapZoom , hasDirtyState , getSelectedLayer , getEditState , } from '../../../../../selectors/map_selectors' ; import { getIsReadOnly , getOpenTOCDetails , getFlyoutDisplay , } from '../../../../../selectors/ui_selectors' ; import { fitToLayerExtent , setSelectedLayer , updateFlyout , hideTOCDetails , showTOCDetails , toggleLayerVisible , setDrawMode , updateDrawState , } from '../../../../../actions' ; import { DRAW_MODE } from '../../../../../../common/constants' ; function mapStateToProps ( state , ownProps ) { const flyoutDisplay = getFlyoutDisplay ( state ) ; return { isReadOnly : getIsReadOnly ( state ) , zoom : getMapZoom ( state ) , selectedLayer : getSelectedLayer ( state ) , hasDirtyStateSelector : hasDirtyState ( state ) , isLegendDetailsOpen : getOpenTOCDetails ( state ) . includes ( ownProps . layer . getId ( ) ) , isEditButtonDisabled : flyoutDisplay !== FLYOUT_STATE . NONE && flyoutDisplay !== FLYOUT_STATE . LAYER_PANEL , editModeActiveForLayer : getEditState ( state ) ?. layerId === ownProps . layer . getId ( ) , } ; } function mapDispatchToProps ( dispatch ) { return { fitToBounds : ( layerId ) => { dispatch ( fitToLayerExtent ( layerId ) ) ; } , openLayerPanel : async ( layerId ) => { await dispatch ( setSelectedLayer ( layerId ) ) ; dispatch ( updateFlyout ( FLYOUT_STATE . LAYER_PANEL ) ) ; } , hideTOCDetails : ( layerId ) => { dispatch ( hideTOCDetails ( layerId ) ) ; } , showTOCDetails : ( layerId ) => { dispatch ( showTOCDetails ( layerId ) ) ; } , toggleVisible : ( layerId ) => { dispatch ( toggleLayerVisible ( layerId ) ) ; } , cancelEditing : ( ) => { dispatch ( updateDrawState ( null ) ) ; dispatch ( setDrawMode ( DRAW_MODE . NONE ) ) ; } , } ; } const connected = connect < ReduxStateProps , ReduxDispatchProps , OwnProps , MapStoreState > ( mapStateToProps , mapDispatchToProps ) ( TOCEntry ) ; export { connected as TOCEntry } ;